Moved comment and block delete handling to be done in protocol.c rather than gcode.c. Prevents these from being held in memory. Also, fixes bug when comments and block delete character are mixed with g-code.
This commit is contained in:
parent
517a0f659a
commit
ea5b8942db
45
protocol.c
45
protocol.c
@ -72,20 +72,41 @@ uint8_t protocol_execute_line(char *line) {
|
|||||||
void protocol_process()
|
void protocol_process()
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
uint8_t iscomment = false;
|
||||||
while((c = serial_read()) != SERIAL_NO_DATA)
|
while((c = serial_read()) != SERIAL_NO_DATA)
|
||||||
{
|
{
|
||||||
if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute!
|
if (iscomment) {
|
||||||
line[char_counter] = 0; // treminate string
|
// While in comment, skip all characters until ')', '\n', or '\r'
|
||||||
status_message(protocol_execute_line(line));
|
if ((c == ')') || (c == '\n') || (c == '\r')) {
|
||||||
char_counter = 0; // reset line buffer index
|
iscomment = false;
|
||||||
} else if (c <= ' ') {
|
}
|
||||||
// Throw away whitepace and control characters
|
}
|
||||||
} else if (char_counter >= LINE_BUFFER_SIZE-1) {
|
if (!iscomment) { // Seperate if-statement to process '\n' or '\r' at end of comment
|
||||||
// Throw away any characters beyond the end of the line buffer
|
if ((c == '\n') || (c == '\r')) { // End of block reached
|
||||||
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
if (char_counter > 0) {// Line is complete. Then execute!
|
||||||
line[char_counter++] = c-'a'+'A';
|
line[char_counter] = 0; // terminate string
|
||||||
} else {
|
status_message(protocol_execute_line(line));
|
||||||
line[char_counter++] = c;
|
char_counter = 0; // reset line buffer index
|
||||||
|
} else {
|
||||||
|
// Empty or comment line. Skip block.
|
||||||
|
status_message(STATUS_OK); // Send status message for syncing purposes.
|
||||||
|
}
|
||||||
|
} else if (c <= ' ') {
|
||||||
|
// Throw away whitepace and control characters
|
||||||
|
} else if (c == '/') {
|
||||||
|
// Disable block delete and throw away character
|
||||||
|
// To enable block delete, uncomment following line
|
||||||
|
// iscomment = true;
|
||||||
|
} else if (c == '(') {
|
||||||
|
// Enable comments and ignore all characters until ')' or '\n'
|
||||||
|
iscomment = true;
|
||||||
|
} else if (char_counter >= LINE_BUFFER_SIZE-1) {
|
||||||
|
// Throw away any characters beyond the end of the line buffer
|
||||||
|
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
||||||
|
line[char_counter++] = c-'a'+'A';
|
||||||
|
} else {
|
||||||
|
line[char_counter++] = c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user