Added central error strings.

This commit is contained in:
Oliver Schmidt 2020-04-15 14:52:59 +02:00
parent 773de74bc4
commit 6971e9216f
10 changed files with 179 additions and 93 deletions

View File

@ -22,23 +22,7 @@
void error_exit(void)
{
switch (ip65_error)
{
case IP65_ERROR_DEVICE_FAILURE:
printf("- No device found\n");
break;
case IP65_ERROR_ABORTED_BY_USER:
printf("- User abort\n");
break;
case IP65_ERROR_TIMEOUT_ON_RECEIVE:
printf("- Timeout\n");
break;
case IP65_ERROR_DNS_LOOKUP_FAILED:
printf("- Lookup failed\n");
break;
default:
printf("- Error $%X\n", ip65_error);
}
printf("- %s\n", ip65_strerror(ip65_error));
exit(EXIT_FAILURE);
}

View File

@ -274,20 +274,7 @@ void http_server(uint32_t client, const char* method, const char* path)
void error_exit(void)
{
switch (ip65_error)
{
case IP65_ERROR_DEVICE_FAILURE:
printf("- No device found\n");
break;
case IP65_ERROR_ABORTED_BY_USER:
printf("- User abort\n");
break;
case IP65_ERROR_TIMEOUT_ON_RECEIVE:
printf("- Timeout\n");
break;
default:
printf("- Error $%X\n", ip65_error);
}
printf("- %s\n", ip65_strerror(ip65_error));
if (doesclrscrafterexit())
{

View File

@ -17,26 +17,7 @@ char text[280 + 1];
void error_exit(void)
{
switch (ip65_error)
{
case IP65_ERROR_DEVICE_FAILURE:
printf("- No device found\n");
break;
case IP65_ERROR_ABORTED_BY_USER:
printf("- User abort\n");
break;
case IP65_ERROR_TIMEOUT_ON_RECEIVE:
printf("- Timeout\n");
break;
case IP65_ERROR_MALFORMED_URL:
printf("- Malformed URL\n");
break;
case IP65_ERROR_DNS_LOOKUP_FAILED:
printf("- Lookup failed\n");
break;
default:
printf("- Error $%X\n", ip65_error);
}
printf("- %s\n", ip65_strerror(ip65_error));
exit(EXIT_FAILURE);
}

View File

@ -26,26 +26,7 @@ char name[16];
void ip65_error_exit(bool quit)
{
switch (ip65_error)
{
case IP65_ERROR_DEVICE_FAILURE:
printf("- No Uthernet II found\n");
break;
case IP65_ERROR_ABORTED_BY_USER:
printf("- User abort\n");
break;
case IP65_ERROR_TIMEOUT_ON_RECEIVE:
printf("- Timeout\n");
break;
case IP65_ERROR_MALFORMED_URL:
printf("- Malformed URL\n");
break;
case IP65_ERROR_DNS_LOOKUP_FAILED:
printf("- Lookup failed\n");
break;
default:
printf("- Error $%X\n", ip65_error);
}
printf("- %s\n", ip65_strerror(ip65_error));
if (quit)
{
exit(EXIT_FAILURE);

View File

@ -2,7 +2,7 @@ IP65_ERROR_PORT_IN_USE = $80
IP65_ERROR_TIMEOUT_ON_RECEIVE = $81
IP65_ERROR_TRANSMIT_FAILED = $82
IP65_ERROR_TRANSMISSION_REJECTED_BY_PEER = $83
IP65_ERROR_INPUT_TOO_LARGE = $84
IP65_ERROR_NAME_TOO_LONG = $84
IP65_ERROR_DEVICE_FAILURE = $85
IP65_ERROR_ABORTED_BY_USER = $86
IP65_ERROR_LISTENER_NOT_AVAILABLE = $87

View File

@ -4,25 +4,6 @@
#include <stdint.h>
#include <stdbool.h>
// Error codes
//
#define IP65_ERROR_PORT_IN_USE 0x80
#define IP65_ERROR_TIMEOUT_ON_RECEIVE 0x81
#define IP65_ERROR_TRANSMIT_FAILED 0x82
#define IP65_ERROR_TRANSMISSION_REJECTED_BY_PEER 0x83
#define IP65_ERROR_INPUT_TOO_LARGE 0x84
#define IP65_ERROR_DEVICE_FAILURE 0x85
#define IP65_ERROR_ABORTED_BY_USER 0x86
#define IP65_ERROR_LISTENER_NOT_AVAILABLE 0x87
#define IP65_ERROR_CONNECTION_RESET_BY_PEER 0x89
#define IP65_ERROR_CONNECTION_CLOSED 0x8A
#define IP65_ERROR_MALFORMED_URL 0xA0
#define IP65_ERROR_DNS_LOOKUP_FAILED 0xA1
// Last error code
//
extern uint8_t ip65_error;
// Ethernet driver initialization parameter values
//
#if defined(__APPLE2__)
@ -52,6 +33,34 @@ bool __fastcall__ ip65_init(uint8_t eth_init);
extern uint8_t cfg_mac[6]; // MAC address of local machine
extern char eth_name[]; // Zero terminated string containing Ethernet driver name
// Error codes
//
#define IP65_ERROR_PORT_IN_USE 0x80
#define IP65_ERROR_TIMEOUT_ON_RECEIVE 0x81
#define IP65_ERROR_TRANSMIT_FAILED 0x82
#define IP65_ERROR_TRANSMISSION_REJECTED_BY_PEER 0x83
#define IP65_ERROR_NAME_TOO_LONG 0x84
#define IP65_ERROR_DEVICE_FAILURE 0x85
#define IP65_ERROR_ABORTED_BY_USER 0x86
#define IP65_ERROR_LISTENER_NOT_AVAILABLE 0x87
#define IP65_ERROR_CONNECTION_RESET_BY_PEER 0x89
#define IP65_ERROR_CONNECTION_CLOSED 0x8A
#define IP65_ERROR_MALFORMED_URL 0xA0
#define IP65_ERROR_DNS_LOOKUP_FAILED 0xA1
// Last error code
//
extern uint8_t ip65_error;
// Convert error code into a string describing the error
//
// The pointer returned is a static string, which mustn't be modified.
//
// Inputs: err_code: Error code
// Output: Zero terminated string describing the error
//
char* __fastcall__ ip65_strerror(uint8_t err_code);
// Main IP polling loop
//
// This routine should be periodically called by an application at any time

View File

@ -23,6 +23,7 @@ IP65OBJS=\
dottedquad_c.o \
download.o \
download_c.o \
error.o \
eth.o \
eth_c.o \
http.o \

View File

@ -164,7 +164,7 @@ dns_set_hostname:
rts
@hostname_too_long:
lda #IP65_ERROR_INPUT_TOO_LARGE
lda #IP65_ERROR_NAME_TOO_LONG
sta ip65_error
sec
rts
@ -282,7 +282,7 @@ send_dns_query:
sta output_buffer+dns_qname,x
inx
bpl @hostname_still_ok
lda #IP65_ERROR_INPUT_TOO_LARGE
lda #IP65_ERROR_NAME_TOO_LONG
sta ip65_error
jmp @error_on_send ; if we got past 128 bytes, there's a problem
@hostname_still_ok:

139
ip65/error.s Normal file
View File

@ -0,0 +1,139 @@
.include "../inc/common.inc"
.include "../inc/error.inc"
.export ip65_strerror
.code
;convert error code into a string describing the error
;inputs:
; A = error code
;outputs:
; AX = pointer to zero terminated string describing the error
ip65_strerror:
cmp #IP65_ERROR_PORT_IN_USE
bne :+
ldax #str_port_in_use
rts
: cmp #IP65_ERROR_TIMEOUT_ON_RECEIVE
bne :+
ldax #str_timeout_on_receive
rts
: cmp #IP65_ERROR_TRANSMIT_FAILED
bne :+
ldax #str_transmit_failed
rts
: cmp #IP65_ERROR_TRANSMISSION_REJECTED_BY_PEER
bne :+
ldax #str_transmission_rejected_by_peer
rts
: cmp #IP65_ERROR_NAME_TOO_LONG
bne :+
ldax #str_name_too_long
rts
: cmp #IP65_ERROR_DEVICE_FAILURE
bne :+
ldax #str_device_failure
rts
: cmp #IP65_ERROR_ABORTED_BY_USER
bne :+
ldax #str_aborted_by_user
rts
: cmp #IP65_ERROR_LISTENER_NOT_AVAILABLE
bne :+
ldax #str_listener_not_available
rts
: cmp #IP65_ERROR_CONNECTION_RESET_BY_PEER
bne :+
ldax #str_connection_reset_by_peer
rts
: cmp #IP65_ERROR_CONNECTION_CLOSED
bne :+
ldax #str_connection_closed
rts
: cmp #IP65_ERROR_MALFORMED_URL
bne :+
ldax #str_malformed_url
rts
: cmp #IP65_ERROR_DNS_LOOKUP_FAILED
bne :+
ldax #str_dns_lookup_failed
rts
: ldax #str_unknown
rts
.rodata
str_port_in_use:
.byte "Port in use",0
str_timeout_on_receive:
.byte "Timeout",0
str_transmit_failed:
.byte "Send failed",0
str_transmission_rejected_by_peer:
.byte "Data rejected",0
str_name_too_long:
.byte "Name too long",0
str_device_failure:
.byte "No device found",0
str_aborted_by_user:
.byte "User abort",0
str_listener_not_available:
.byte "No more listener",0
str_connection_reset_by_peer:
.byte "Connection reset by peer",0
str_connection_closed:
.byte "Connection closed",0
str_malformed_url:
.byte "Malformed URL",0
str_dns_lookup_failed:
.byte "Lookup failed",0
str_unknown:
.byte "Unknown error",0
; -- LICENSE FOR error.s --
; The contents of this file are subject to the Mozilla Public License
; Version 1.1 (the "License"); you may not use this file except in
; compliance with the License. You may obtain a copy of the License at
; http://www.mozilla.org/MPL/
;
; Software distributed under the License is distributed on an "AS IS"
; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
; License for the specific language governing rights and limitations
; under the License.
;
; The Original Code is ip65.
;
; The Initial Developer of the Original Code is Per Olofsson,
; MagerValp@gmail.com.
; Portions created by the Initial Developer are Copyright (C) 2009
; Per Olofsson. All Rights Reserved.
; -- LICENSE END --

View File

@ -4,11 +4,13 @@
.export _ip65_process
.export _ip65_random_word
.export _ip65_error
.export _ip65_strerror
.import ip65_init
.import ip65_process
.import ip65_random_word
.import ip65_error
.import ip65_strerror
_ip65_init:
jsr ip65_init
@ -27,3 +29,5 @@ _ip65_process:
_ip65_random_word := ip65_random_word
_ip65_error := ip65_error
_ip65_strerror := ip65_strerror