diff --git a/config.h b/config.h index c0bffa4..aa427e7 100644 --- a/config.h +++ b/config.h @@ -185,11 +185,11 @@ // each of the startup blocks, as they are each stored as a string of this size. Make sure // to account for the available EEPROM at the defined memory address in settings.h and for // the number of desired startup blocks. -// NOTE: 50 characters is not a problem except for extreme cases, but the line buffer size +// NOTE: 70 characters is not a problem except for extreme cases, but the line buffer size // can be too small and g-code blocks can get truncated. Officially, the g-code standards // support up to 256 characters. In future versions, this default will be increased, when // we know how much extra memory space we can re-invest into this. -// #define LINE_BUFFER_SIZE 50 // Uncomment to override default in protocol.h +// #define LINE_BUFFER_SIZE 70 // Uncomment to override default in protocol.h // Serial send and receive buffer size. The receive buffer is often used as another streaming // buffer to store incoming blocks to be processed by Grbl when its ready. Most streaming diff --git a/protocol.c b/protocol.c index c97770a..c797036 100644 --- a/protocol.c +++ b/protocol.c @@ -37,10 +37,16 @@ static uint8_t char_counter; // Last character counter in line variable. static uint8_t iscomment; // Comment/block delete flag for processor to ignore comment characters. -void protocol_init() +static void protocol_reset_line_buffer() { char_counter = 0; // Reset line input iscomment = false; +} + + +void protocol_init() +{ + protocol_reset_line_buffer(); report_init_message(); // Welcome message PINOUT_DDR &= ~(PINOUT_MASK); // Set as input pins @@ -303,9 +309,8 @@ void protocol_process() // Empty or comment line. Skip block. report_status_message(STATUS_OK); // Send status message for syncing purposes. } - char_counter = 0; // Reset line buffer index - iscomment = false; // Reset comment flag - + protocol_reset_line_buffer(); + } else { if (iscomment) { // Throw away all comment characters @@ -322,7 +327,9 @@ void protocol_process() // Enable comments flag and ignore all characters until ')' or EOL. iscomment = true; } else if (char_counter >= LINE_BUFFER_SIZE-1) { - // Throw away any characters beyond the end of the line buffer + // Report line buffer overflow and reset + report_status_message(STATUS_OVERFLOW); + protocol_reset_line_buffer(); } else if (c >= 'a' && c <= 'z') { // Upcase lowercase line[char_counter++] = c-'a'+'A'; } else { diff --git a/protocol.h b/protocol.h index 209d19d..4d90c1c 100644 --- a/protocol.h +++ b/protocol.h @@ -30,7 +30,7 @@ // memory space we can invest into here or we re-write the g-code parser not to have his // buffer. #ifndef LINE_BUFFER_SIZE - #define LINE_BUFFER_SIZE 50 + #define LINE_BUFFER_SIZE 70 #endif // Initialize the serial protocol diff --git a/report.c b/report.c index a2602f4..35cb2be 100644 --- a/report.c +++ b/report.c @@ -74,6 +74,8 @@ void report_status_message(uint8_t status_code) printPgmString(PSTR("Busy or queued")); break; case STATUS_ALARM_LOCK: printPgmString(PSTR("Alarm lock")); break; + case STATUS_OVERFLOW: + printPgmString(PSTR("Line overflow")); break; } printPgmString(PSTR("\r\n")); } diff --git a/report.h b/report.h index 8f1555c..e3583fc 100644 --- a/report.h +++ b/report.h @@ -35,6 +35,7 @@ #define STATUS_SETTING_READ_FAIL 10 #define STATUS_IDLE_ERROR 11 #define STATUS_ALARM_LOCK 12 +#define STATUS_OVERFLOW 13 // Define Grbl alarm codes. Less than zero to distinguish alarm error from status error. #define ALARM_HARD_LIMIT -1