From 6971e9216f02cbb7fa161bc5e8f9c8f31c087a2d Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 15 Apr 2020 14:52:59 +0200 Subject: [PATCH] Added central error strings. --- apps/date65.c | 18 +------ apps/hfs65.c | 15 +----- apps/tweet65.c | 21 +------- apps/wget65.c | 21 +------- inc/error.inc | 2 +- inc/ip65.h | 47 ++++++++++------- ip65/Makefile | 1 + ip65/dns.s | 4 +- ip65/error.s | 139 +++++++++++++++++++++++++++++++++++++++++++++++++ ip65/ip65_c.s | 4 ++ 10 files changed, 179 insertions(+), 93 deletions(-) create mode 100644 ip65/error.s diff --git a/apps/date65.c b/apps/date65.c index d99433e..5216516 100644 --- a/apps/date65.c +++ b/apps/date65.c @@ -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); } diff --git a/apps/hfs65.c b/apps/hfs65.c index 3c6571d..264a4fb 100644 --- a/apps/hfs65.c +++ b/apps/hfs65.c @@ -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()) { diff --git a/apps/tweet65.c b/apps/tweet65.c index 40d55d3..0b13b8c 100644 --- a/apps/tweet65.c +++ b/apps/tweet65.c @@ -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); } diff --git a/apps/wget65.c b/apps/wget65.c index 7dd1f75..b75e5c2 100644 --- a/apps/wget65.c +++ b/apps/wget65.c @@ -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); diff --git a/inc/error.inc b/inc/error.inc index 1ce2436..206a50c 100644 --- a/inc/error.inc +++ b/inc/error.inc @@ -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 diff --git a/inc/ip65.h b/inc/ip65.h index 5b9b414..5fb7731 100644 --- a/inc/ip65.h +++ b/inc/ip65.h @@ -4,25 +4,6 @@ #include #include -// 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 diff --git a/ip65/Makefile b/ip65/Makefile index 9de3e58..2a98f45 100644 --- a/ip65/Makefile +++ b/ip65/Makefile @@ -23,6 +23,7 @@ IP65OBJS=\ dottedquad_c.o \ download.o \ download_c.o \ + error.o \ eth.o \ eth_c.o \ http.o \ diff --git a/ip65/dns.s b/ip65/dns.s index edafaae..aea9ca0 100644 --- a/ip65/dns.s +++ b/ip65/dns.s @@ -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: diff --git a/ip65/error.s b/ip65/error.s new file mode 100644 index 0000000..faa19e3 --- /dev/null +++ b/ip65/error.s @@ -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 -- diff --git a/ip65/ip65_c.s b/ip65/ip65_c.s index 2ca754f..abc406f 100644 --- a/ip65/ip65_c.s +++ b/ip65/ip65_c.s @@ -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