Increased g-code parser line buffer. Added line overflow feedback.

- Increased g-code parser line buffer from 50 to 70 characters. Should
fix most all issues with long arc statements, provided that they are 8
digits(float) long only.

- Added a line buffer overflow feedback error to let the user know when
it encounters this problem. Resets the line whenever this occurs.
(Thanks @BHSPitMonkey!)
This commit is contained in:
Sonny Jeon 2013-04-05 09:29:07 -06:00
parent 33c6659523
commit ca563cf423
5 changed files with 18 additions and 8 deletions

View File

@ -185,11 +185,11 @@
// each of the startup blocks, as they are each stored as a string of this size. Make sure // 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 // to account for the available EEPROM at the defined memory address in settings.h and for
// the number of desired startup blocks. // 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 // 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 // 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. // 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 // 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 // buffer to store incoming blocks to be processed by Grbl when its ready. Most streaming

View File

@ -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. 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 char_counter = 0; // Reset line input
iscomment = false; iscomment = false;
}
void protocol_init()
{
protocol_reset_line_buffer();
report_init_message(); // Welcome message report_init_message(); // Welcome message
PINOUT_DDR &= ~(PINOUT_MASK); // Set as input pins PINOUT_DDR &= ~(PINOUT_MASK); // Set as input pins
@ -303,8 +309,7 @@ void protocol_process()
// Empty or comment line. Skip block. // Empty or comment line. Skip block.
report_status_message(STATUS_OK); // Send status message for syncing purposes. report_status_message(STATUS_OK); // Send status message for syncing purposes.
} }
char_counter = 0; // Reset line buffer index protocol_reset_line_buffer();
iscomment = false; // Reset comment flag
} else { } else {
if (iscomment) { if (iscomment) {
@ -322,7 +327,9 @@ void protocol_process()
// Enable comments flag and ignore all characters until ')' or EOL. // Enable comments flag and ignore all characters until ')' or EOL.
iscomment = true; iscomment = true;
} else if (char_counter >= LINE_BUFFER_SIZE-1) { } 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 } else if (c >= 'a' && c <= 'z') { // Upcase lowercase
line[char_counter++] = c-'a'+'A'; line[char_counter++] = c-'a'+'A';
} else { } else {

View File

@ -30,7 +30,7 @@
// memory space we can invest into here or we re-write the g-code parser not to have his // memory space we can invest into here or we re-write the g-code parser not to have his
// buffer. // buffer.
#ifndef LINE_BUFFER_SIZE #ifndef LINE_BUFFER_SIZE
#define LINE_BUFFER_SIZE 50 #define LINE_BUFFER_SIZE 70
#endif #endif
// Initialize the serial protocol // Initialize the serial protocol

View File

@ -74,6 +74,8 @@ void report_status_message(uint8_t status_code)
printPgmString(PSTR("Busy or queued")); break; printPgmString(PSTR("Busy or queued")); break;
case STATUS_ALARM_LOCK: case STATUS_ALARM_LOCK:
printPgmString(PSTR("Alarm lock")); break; printPgmString(PSTR("Alarm lock")); break;
case STATUS_OVERFLOW:
printPgmString(PSTR("Line overflow")); break;
} }
printPgmString(PSTR("\r\n")); printPgmString(PSTR("\r\n"));
} }

View File

@ -35,6 +35,7 @@
#define STATUS_SETTING_READ_FAIL 10 #define STATUS_SETTING_READ_FAIL 10
#define STATUS_IDLE_ERROR 11 #define STATUS_IDLE_ERROR 11
#define STATUS_ALARM_LOCK 12 #define STATUS_ALARM_LOCK 12
#define STATUS_OVERFLOW 13
// Define Grbl alarm codes. Less than zero to distinguish alarm error from status error. // Define Grbl alarm codes. Less than zero to distinguish alarm error from status error.
#define ALARM_HARD_LIMIT -1 #define ALARM_HARD_LIMIT -1