Sfoglia il codice sorgente

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 ")"
Gina Häußge 9 anni fa
parent
commit
63b62d8d4e
2 ha cambiato i file con 94 aggiunte e 69 eliminazioni
  1. 22
    0
      Documentation/GCodes.md
  2. 72
    69
      Marlin/Marlin_main.cpp

+ 22
- 0
Documentation/GCodes.md Vedi File

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

+ 72
- 69
Marlin/Marlin_main.cpp Vedi File

@@ -732,100 +732,103 @@ void get_command()
732 732
        serial_char == '\r' ||
733 733
        serial_count >= (MAX_CMD_SIZE - 1) )
734 734
     {
735
-      if(!serial_count) { //if empty line
736
-        comment_mode = false; //for new command
735
+      // end of line == end of comment
736
+      comment_mode = false;
737
+
738
+      if(!serial_count) {
739
+        // short cut for empty lines
737 740
         return;
738 741
       }
739 742
       cmdbuffer[bufindw][serial_count] = 0; //terminate string
740
-      if(!comment_mode){
741
-        fromsd[bufindw] = false;
742
-        if(strchr(cmdbuffer[bufindw], 'N') != NULL)
743
+
744
+      fromsd[bufindw] = false;
745
+      if(strchr(cmdbuffer[bufindw], 'N') != NULL)
746
+      {
747
+        strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
748
+        gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
749
+        if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
750
+          SERIAL_ERROR_START;
751
+          SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
752
+          SERIAL_ERRORLN(gcode_LastN);
753
+          //Serial.println(gcode_N);
754
+          FlushSerialRequestResend();
755
+          serial_count = 0;
756
+          return;
757
+        }
758
+
759
+        if(strchr(cmdbuffer[bufindw], '*') != NULL)
743 760
         {
744
-          strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
745
-          gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
746
-          if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
747
-            SERIAL_ERROR_START;
748
-            SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
749
-            SERIAL_ERRORLN(gcode_LastN);
750
-            //Serial.println(gcode_N);
751
-            FlushSerialRequestResend();
752
-            serial_count = 0;
753
-            return;
754
-          }
761
+          byte checksum = 0;
762
+          byte count = 0;
763
+          while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
764
+          strchr_pointer = strchr(cmdbuffer[bufindw], '*');
755 765
 
756
-          if(strchr(cmdbuffer[bufindw], '*') != NULL)
757
-          {
758
-            byte checksum = 0;
759
-            byte count = 0;
760
-            while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
761
-            strchr_pointer = strchr(cmdbuffer[bufindw], '*');
762
-
763
-            if( (int)(strtod(strchr_pointer + 1, NULL)) != checksum) {
764
-              SERIAL_ERROR_START;
765
-              SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
766
-              SERIAL_ERRORLN(gcode_LastN);
767
-              FlushSerialRequestResend();
768
-              serial_count = 0;
769
-              return;
770
-            }
771
-            //if no errors, continue parsing
772
-          }
773
-          else
774
-          {
766
+          if( (int)(strtod(strchr_pointer + 1, NULL)) != checksum) {
775 767
             SERIAL_ERROR_START;
776
-            SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
768
+            SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
777 769
             SERIAL_ERRORLN(gcode_LastN);
778 770
             FlushSerialRequestResend();
779 771
             serial_count = 0;
780 772
             return;
781 773
           }
782
-
783
-          gcode_LastN = gcode_N;
784 774
           //if no errors, continue parsing
785 775
         }
786
-        else  // if we don't receive 'N' but still see '*'
776
+        else
787 777
         {
788
-          if((strchr(cmdbuffer[bufindw], '*') != NULL))
789
-          {
790
-            SERIAL_ERROR_START;
791
-            SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
792
-            SERIAL_ERRORLN(gcode_LastN);
793
-            serial_count = 0;
794
-            return;
795
-          }
778
+          SERIAL_ERROR_START;
779
+          SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
780
+          SERIAL_ERRORLN(gcode_LastN);
781
+          FlushSerialRequestResend();
782
+          serial_count = 0;
783
+          return;
796 784
         }
797
-        if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
798
-          strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
799
-          switch((int)((strtod(strchr_pointer + 1, NULL)))){
800
-          case 0:
801
-          case 1:
802
-          case 2:
803
-          case 3:
804
-            if (Stopped == true) {
805
-              SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
806
-              LCD_MESSAGEPGM(MSG_STOPPED);
807
-            }
808
-            break;
809
-          default:
810
-            break;
811
-          }
812 785
 
786
+        gcode_LastN = gcode_N;
787
+        //if no errors, continue parsing
788
+      }
789
+      else  // if we don't receive 'N' but still see '*'
790
+      {
791
+        if((strchr(cmdbuffer[bufindw], '*') != NULL))
792
+        {
793
+          SERIAL_ERROR_START;
794
+          SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
795
+          SERIAL_ERRORLN(gcode_LastN);
796
+          serial_count = 0;
797
+          return;
798
+        }
799
+      }
800
+      if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
801
+        strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
802
+        switch((int)((strtod(strchr_pointer + 1, NULL)))){
803
+        case 0:
804
+        case 1:
805
+        case 2:
806
+        case 3:
807
+          if (Stopped == true) {
808
+            SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
809
+            LCD_MESSAGEPGM(MSG_STOPPED);
810
+          }
811
+          break;
812
+        default:
813
+          break;
813 814
         }
814 815
 
815
-        //If command was e-stop process now
816
-        if(strcmp(cmdbuffer[bufindw], "M112") == 0)
817
-          kill();
818
-        
819
-        bufindw = (bufindw + 1)%BUFSIZE;
820
-        buflen += 1;
821 816
       }
817
+
818
+      //If command was e-stop process now
819
+      if(strcmp(cmdbuffer[bufindw], "M112") == 0)
820
+        kill();
821
+
822
+      bufindw = (bufindw + 1)%BUFSIZE;
823
+      buflen += 1;
824
+
822 825
       serial_count = 0; //clear buffer
823 826
     }
824 827
     else if(serial_char == '\\') {  //Handle escapes
825 828
        
826 829
         if(MYSERIAL.available() > 0  && buflen < BUFSIZE) {
827 830
             // if we have one more character, copy it over
828
-            MYSERIAL.read();
831
+            serial_char = MYSERIAL.read();
829 832
             cmdbuffer[bufindw][serial_count++] = serial_char;
830 833
         }
831 834
 

Loading…
Annulla
Salva