Bläddra i källkod

Simplify emergency parser (only parse initial command)

Scott Lahteine 8 år sedan
förälder
incheckning
ea47803ae2
1 ändrade filer med 39 tillägg och 103 borttagningar
  1. 39
    103
      Marlin/MarlinSerial.cpp

+ 39
- 103
Marlin/MarlinSerial.cpp Visa fil

@@ -325,12 +325,11 @@ MarlinSerial customizedSerial;
325 325
 
326 326
     enum e_parser_state {
327 327
       state_RESET,
328
+      state_N,
328 329
       state_M,
329 330
       state_M1,
330 331
       state_M10,
331 332
       state_M11,
332
-      state_M2,
333
-      state_M3,
334 333
       state_M4,
335 334
       state_M41,
336 335
       state_IGNORE // to '\n'
@@ -338,131 +337,68 @@ MarlinSerial customizedSerial;
338 337
 
339 338
     static e_parser_state state = state_RESET;
340 339
 
340
+    if (c == '\n') state = state_IGNORE;
341
+
341 342
     switch (state) {
342 343
       case state_RESET:
343 344
         switch (c) {
344
-          case 'M':
345
-            state = state_M;
346
-            break;
347
-          case ';':
348
-            state = state_IGNORE;
349
-            break;
350
-          default: state = state_RESET;
351
-        }
352
-      break;
353
-
354
-      case state_M:
355
-        switch (c) {
356
-          case '1':
357
-            state = state_M1;
358
-            break;
359
-          case '2':
360
-            state = state_M2;
361
-            break;
362
-          case '3':
363
-            state = state_M3;
364
-            break;
365
-          case '4':
366
-            state = state_M4;
367
-            break;
368
-          case ';':
369
-            state = state_IGNORE;
370
-            break;
371
-          default: state = state_RESET;
345
+          case ' ': break;
346
+          case 'N': state = state_N;      break;
347
+          case 'M': state = state_M;      break;
348
+          default: state = state_IGNORE;
372 349
         }
373
-      break;
350
+        break;
374 351
 
375
-      case state_M1:
352
+      case state_N:
376 353
         switch (c) {
377
-          case '0':
378
-            state = state_M10;
379
-            break;
380
-          case '1':
381
-            state = state_M11;
382
-            break;
383
-          case ';':
384
-            state = state_IGNORE;
385
-            break;
386
-          default: state = state_RESET;
354
+          case '0': case '1': case '2':
355
+          case '3': case '4': case '5':
356
+          case '6': case '7': case '8':
357
+          case '9': case '-': case ' ':   break;
358
+          case 'M': state = state_M;      break;
359
+          default:  state = state_IGNORE;
387 360
         }
388
-      break;
361
+        break;
389 362
 
390
-      case state_M2:
363
+      case state_M:
391 364
         switch (c) {
392
-          case '3': // M23
393
-          case '8': // M28
394
-          case ';':
395
-            state = state_IGNORE;
396
-            break;
397
-          default: state = state_RESET;
365
+          case ' ': break;
366
+          case '1': state = state_M1;     break;
367
+          case '4': state = state_M4;     break;
368
+          default: state = state_IGNORE;
398 369
         }
399
-      break;
370
+        break;
400 371
 
401
-      case state_M3:
372
+      case state_M1:
402 373
         switch (c) {
403
-          case '0': // M30
404
-          case '2': // M32
405
-          case '3': // M33
406
-          case ';':
407
-            state = state_IGNORE;
408
-            break;
409
-          default: state = state_RESET;
374
+          case '0': state = state_M10;    break;
375
+          case '1': state = state_M11;    break;
376
+          default: state = state_IGNORE;
410 377
         }
411
-      break;
378
+        break;
412 379
 
413 380
       case state_M10:
414
-        switch (c) {
415
-          case '8': // M108
416
-            { state = state_RESET; wait_for_heatup = false; }
417
-            break;
418
-          case ';':
419
-            state = state_IGNORE;
420
-            break;
421
-          default: state = state_RESET;
422
-        }
423
-      break;
381
+        if (c == '8') wait_for_heatup = false; // M108
382
+        state = state_IGNORE;
383
+        break;
424 384
 
425 385
       case state_M11:
426
-        switch (c) {
427
-          case '2': // M112
428
-            state = state_RESET; kill(PSTR(MSG_KILLED));
429
-            break;
430
-          case '7': // M117
431
-          case ';':
432
-            state = state_IGNORE;
433
-            break;
434
-          default: state = state_RESET;
435
-        }
436
-      break;
386
+        if (c == '2') kill(PSTR(MSG_KILLED));  // M112
387
+        state = state_IGNORE;
388
+        break;
437 389
 
438 390
       case state_M4:
439
-        switch (c) {
440
-          case '1':
441
-            state = state_M41;
442
-            break;
443
-          case ';':
444
-            state = state_IGNORE;
445
-            break;
446
-          default: state = state_RESET;
447
-        }
448
-      break;
391
+        state = (c == '1') ? state_M41 : state_IGNORE;
392
+        break;
449 393
 
450 394
       case state_M41:
451
-        switch (c) {
452
-          case '0':
453
-            state = state_RESET;
454
-            quickstop_stepper();
455
-            break;
456
-          case ';':
457
-            state = state_IGNORE;
458
-            break;
459
-          default: state = state_RESET;
460
-        }
461
-      break;
395
+        if (c == '0') quickstop_stepper();     // M410
396
+        state = state_IGNORE;
397
+        break;
462 398
 
463 399
       case state_IGNORE:
464 400
         if (c == '\n') state = state_RESET;
465
-      break;
401
+        break;
466 402
 
467 403
       default:
468 404
         state = state_RESET;

Laddar…
Avbryt
Spara