From: Bernard Blackham Date: Mon, 21 Jun 2004 17:59:59 +0000 (+0000) Subject: Accept both CR and LF to denote newline. X-Git-Tag: ROMW~28 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=8209e6e9a79982684e617d386505952a338b15f2;p=uccvend-snackrom.git Accept both CR and LF to denote newline. Ignore empty packets. Use my_strncpy for cleanliness. --- diff --git a/ROM2/main_basic.c b/ROM2/main_basic.c index 3e88648..888932e 100644 --- a/ROM2/main_basic.c +++ b/ROM2/main_basic.c @@ -123,18 +123,14 @@ void ping_pong() { /* make sure it's really a ping */ if (sci_rx_buf[1] != 'I' || sci_rx_buf[2] != 'N' || - sci_rx_buf[3] != 'G') { + sci_rx_buf[3] != 'G' || + sci_rx_buf[4] != '\0') { send_nack(); return; } /* respond with ack & pong */ wait_for_tx_free(); - sci_tx_buf[0] = 'P'; - sci_tx_buf[1] = 'O'; - sci_tx_buf[2] = 'N'; - sci_tx_buf[3] = 'G'; - sci_tx_buf[4] = '\n'; - sci_tx_buf[5] = 0; + my_strncpy(sci_tx_buf, "PONG\n", BUFFER_LEN); send_packet(); } diff --git a/ROM2/sci.c b/ROM2/sci.c index 2346b28..739d706 100644 --- a/ROM2/sci.c +++ b/ROM2/sci.c @@ -40,7 +40,9 @@ void sci_rx_int() { return; } sci_rx_buf[sci_rx_buf_ptr] = _io_ports[M6811_SCDR]; - if (sci_rx_buf[sci_rx_buf_ptr] == '\n') { + if (sci_rx_buf[sci_rx_buf_ptr] == '\n' || + sci_rx_buf[sci_rx_buf_ptr] == '\r') { + if (sci_rx_buf_ptr == 0) return; /* we've read a blank packet in */ sci_rx_buf[sci_rx_buf_ptr] = '\0'; sci_have_packet = 1; sci_rx_buf_ptr = 0; @@ -68,15 +70,11 @@ void msg_clr() { } void send_ack() { - sci_tx_buf[0] = '!'; - sci_tx_buf[1] = '\n'; - sci_tx_buf[2] = '\0'; + my_strncpy(sci_tx_buf, "!\n", BUFFER_LEN); send_packet(); } void send_nack() { - sci_tx_buf[0] = '?'; - sci_tx_buf[1] = '\n'; - sci_tx_buf[2] = '\0'; + my_strncpy(sci_tx_buf, "?\n", BUFFER_LEN); send_packet(); }