Fixed in-line comments and escaping

* "G1 X1 ; test" was not executing "G1 X1" due to never leaving comment mode.
  * "M117 Hello \;)" printed "Hello \" to the display due to not replacing serial_char properly.

Tested with the following commands:
    * M117 Hello ; test => displays "Hello" on display, ignores "test"
    * G1 X1 ; foo => moves 1mm in X, ignores "foo"
    * ; test => completely ignored, not even acknowledged
    * M117 Hello \;) => displays "Hello ;)" on display
    * M117 Hello \\;) => displays "Hello \" on display, ignores ")"
This commit is contained in:
Gina Häußge 2015-03-05 23:30:34 +01:00
parent 99fb1bc3e8
commit 63b62d8d4e
2 changed files with 96 additions and 71 deletions

View File

@ -101,3 +101,25 @@
* M908 - Control digital trimpot directly. * M908 - Control digital trimpot directly.
* M928 - Start SD logging (M928 filename.g) - ended by M29 * M928 - Start SD logging (M928 filename.g) - ended by M29
* M999 - Restart after being stopped by error * M999 - Restart after being stopped by error
# Comments
Comments start at a `;` (semicolon) and end with the end of the line:
N3 T0*57 ; This is a comment
N4 G92 E0*67
; So is this
N5 G28*22
(example taken from the [RepRap wiki](http://reprap.org/wiki/Gcode#Comments))
If you need to use a literal `;` somewhere (for example within `M117`), you can escape semicolons with a `\`
(backslash):
M117 Hello \;)
`\` can also be used to escape `\` itself, if you need a literal `\` in front of a `;`:
M117 backslash: \\;and a comment
Please note that hosts should strip any comments before sending GCODE to the printer in order to save bandwidth.

View File

@ -732,12 +732,15 @@ void get_command()
serial_char == '\r' || serial_char == '\r' ||
serial_count >= (MAX_CMD_SIZE - 1) ) serial_count >= (MAX_CMD_SIZE - 1) )
{ {
if(!serial_count) { //if empty line // end of line == end of comment
comment_mode = false; //for new command comment_mode = false;
if(!serial_count) {
// short cut for empty lines
return; return;
} }
cmdbuffer[bufindw][serial_count] = 0; //terminate string cmdbuffer[bufindw][serial_count] = 0; //terminate string
if(!comment_mode){
fromsd[bufindw] = false; fromsd[bufindw] = false;
if(strchr(cmdbuffer[bufindw], 'N') != NULL) if(strchr(cmdbuffer[bufindw], 'N') != NULL)
{ {
@ -818,14 +821,14 @@ void get_command()
bufindw = (bufindw + 1)%BUFSIZE; bufindw = (bufindw + 1)%BUFSIZE;
buflen += 1; buflen += 1;
}
serial_count = 0; //clear buffer serial_count = 0; //clear buffer
} }
else if(serial_char == '\\') { //Handle escapes else if(serial_char == '\\') { //Handle escapes
if(MYSERIAL.available() > 0 && buflen < BUFSIZE) { if(MYSERIAL.available() > 0 && buflen < BUFSIZE) {
// if we have one more character, copy it over // if we have one more character, copy it over
MYSERIAL.read(); serial_char = MYSERIAL.read();
cmdbuffer[bufindw][serial_count++] = serial_char; cmdbuffer[bufindw][serial_count++] = serial_char;
} }