From 682e23eb7b1fc46fb9d9e99b96f780ab398cd571 Mon Sep 17 00:00:00 2001 From: Simen Svale Skogsrud Date: Sat, 5 Feb 2011 00:39:34 +0100 Subject: [PATCH] added error messages and dropped echoing of command input --- gcode.h | 3 +-- serial_protocol.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gcode.h b/gcode.h index d00fcbb..8adb836 100644 --- a/gcode.h +++ b/gcode.h @@ -27,8 +27,7 @@ #define GCSTATUS_BAD_NUMBER_FORMAT 1 #define GCSTATUS_EXPECTED_COMMAND_LETTER 2 #define GCSTATUS_UNSUPPORTED_STATEMENT 3 -#define GCSTATUS_MOTION_CONTROL_ERROR 4 -#define GCSTATUS_FLOATING_POINT_ERROR 5 +#define GCSTATUS_FLOATING_POINT_ERROR 4 // Initialize the parser void gc_init(); diff --git a/serial_protocol.c b/serial_protocol.c index a294963..319d8bf 100644 --- a/serial_protocol.c +++ b/serial_protocol.c @@ -31,6 +31,21 @@ static char line[LINE_BUFFER_SIZE]; static uint8_t char_counter; +void status_message(int status_code) { + if (status_code) { + switch(status_code) { + case GCSTATUS_BAD_NUMBER_FORMAT: + printPgmString(PSTR("error: Bad number format\n\r")); break; + case GCSTATUS_EXPECTED_COMMAND_LETTER: + printPgmString(PSTR("error: Expected command letter\n\r")); break; + case GCSTATUS_UNSUPPORTED_STATEMENT: + printPgmString(PSTR("error: Unsupported statement\n\r")); break; + case GCSTATUS_FLOATING_POINT_ERROR: + printPgmString(PSTR("error: Floating point error\n\r")); break; + } + } +} + void prompt() { printPgmString(PSTR("ok\r\n")); } @@ -50,10 +65,9 @@ void sp_process() while((c = serialRead()) != -1) { if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute! - line[char_counter] = 0; - printString(line); printPgmString(PSTR("\r\n")); - gc_execute_line(line); - char_counter = 0; + line[char_counter] = 0; // treminate string + status_message(gc_execute_line(line)); + char_counter = 0; // reset line buffer index prompt(); } else if (c <= ' ') { // Throw away whitepace and control characters } else if (c >= 'a' && c <= 'z') { // Upcase lowercase