Browse Source

Allow asterisks in G-Code commands

Addressing #6655
Scott Lahteine 7 years ago
parent
commit
4bf0e15653
2 changed files with 9 additions and 17 deletions
  1. 9
    16
      Marlin/Marlin_main.cpp
  2. 0
    1
      Marlin/language.h

+ 9
- 16
Marlin/Marlin_main.cpp View File

1138
      */
1138
      */
1139
     if (serial_char == '\n' || serial_char == '\r') {
1139
     if (serial_char == '\n' || serial_char == '\r') {
1140
 
1140
 
1141
-      serial_comment_mode = false; // end of line == end of comment
1141
+      serial_comment_mode = false;                      // end of line == end of comment
1142
 
1142
 
1143
-      if (!serial_count) continue; // skip empty lines
1143
+      if (!serial_count) continue;                      // Skip empty lines
1144
 
1144
 
1145
-      serial_line_buffer[serial_count] = 0; // terminate string
1146
-      serial_count = 0; //reset buffer
1145
+      serial_line_buffer[serial_count] = 0;             // Terminate string
1146
+      serial_count = 0;                                 // Reset buffer
1147
 
1147
 
1148
       char* command = serial_line_buffer;
1148
       char* command = serial_line_buffer;
1149
 
1149
 
1150
-      while (*command == ' ') command++; // skip any leading spaces
1151
-      char *npos = (*command == 'N') ? command : NULL, // Require the N parameter to start the line
1152
-           *apos = strchr(command, '*');
1150
+      while (*command == ' ') command++;                // Skip leading spaces
1151
+      char *npos = (*command == 'N') ? command : NULL;  // Require the N parameter to start the line
1153
 
1152
 
1154
       if (npos) {
1153
       if (npos) {
1155
 
1154
 
1167
           return;
1166
           return;
1168
         }
1167
         }
1169
 
1168
 
1169
+        char *apos = strrchr(command, '*');
1170
         if (apos) {
1170
         if (apos) {
1171
-          byte checksum = 0, count = 0;
1172
-          while (command[count] != '*') checksum ^= command[count++];
1173
-
1171
+          uint8_t checksum = 0, count = uint8_t(apos - command);
1172
+          while (count) checksum ^= command[--count];
1174
           if (strtol(apos + 1, NULL, 10) != checksum) {
1173
           if (strtol(apos + 1, NULL, 10) != checksum) {
1175
             gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH));
1174
             gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH));
1176
             return;
1175
             return;
1177
           }
1176
           }
1178
-          // if no errors, continue parsing
1179
         }
1177
         }
1180
         else {
1178
         else {
1181
           gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM));
1179
           gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM));
1183
         }
1181
         }
1184
 
1182
 
1185
         gcode_LastN = gcode_N;
1183
         gcode_LastN = gcode_N;
1186
-        // if no errors, continue parsing
1187
-      }
1188
-      else if (apos) { // No '*' without 'N'
1189
-        gcode_line_error(PSTR(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM), false);
1190
-        return;
1191
       }
1184
       }
1192
 
1185
 
1193
       // Movement commands alert when stopped
1186
       // Movement commands alert when stopped

+ 0
- 1
Marlin/language.h View File

130
 #define MSG_ERR_LINE_NO                     "Line Number is not Last Line Number+1, Last Line: "
130
 #define MSG_ERR_LINE_NO                     "Line Number is not Last Line Number+1, Last Line: "
131
 #define MSG_ERR_CHECKSUM_MISMATCH           "checksum mismatch, Last Line: "
131
 #define MSG_ERR_CHECKSUM_MISMATCH           "checksum mismatch, Last Line: "
132
 #define MSG_ERR_NO_CHECKSUM                 "No Checksum with line number, Last Line: "
132
 #define MSG_ERR_NO_CHECKSUM                 "No Checksum with line number, Last Line: "
133
-#define MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM "No Line Number with checksum, Last Line: "
134
 #define MSG_FILE_PRINTED                    "Done printing file"
133
 #define MSG_FILE_PRINTED                    "Done printing file"
135
 #define MSG_BEGIN_FILE_LIST                 "Begin file list"
134
 #define MSG_BEGIN_FILE_LIST                 "Begin file list"
136
 #define MSG_END_FILE_LIST                   "End file list"
135
 #define MSG_END_FILE_LIST                   "End file list"

Loading…
Cancel
Save