Browse Source

G-code line number for each serial port (for TFTs) (#18165)

Mark Scammacca 4 years ago
parent
commit
7119596170
No account linked to committer's email address
3 changed files with 24 additions and 11 deletions
  1. 4
    1
      Marlin/src/gcode/host/M110.cpp
  2. 9
    8
      Marlin/src/gcode/queue.cpp
  3. 11
    2
      Marlin/src/gcode/queue.h

+ 4
- 1
Marlin/src/gcode/host/M110.cpp View File

@@ -27,5 +27,8 @@
27 27
  * M110: Set Current Line Number
28 28
  */
29 29
 void GcodeSuite::M110() {
30
-  if (parser.seenval('N')) queue.last_N = parser.value_long();
30
+
31
+  if (parser.seenval('N'))
32
+    queue.last_N[queue.command_port()] = parser.value_long();
33
+
31 34
 }

+ 9
- 8
Marlin/src/gcode/queue.cpp View File

@@ -52,7 +52,7 @@ GCodeQueue queue;
52 52
  * sending commands to Marlin, and lines will be checked for sequentiality.
53 53
  * M110 N<int> sets the current line number.
54 54
  */
55
-long gcode_N, GCodeQueue::last_N;
55
+long GCodeQueue::last_N[NUM_SERIAL];
56 56
 
57 57
 /**
58 58
  * GCode Command Queue
@@ -277,7 +277,7 @@ void GCodeQueue::enqueue_now_P(PGM_P const pgcode) {
277 277
  */
278 278
 void GCodeQueue::ok_to_send() {
279 279
   #if NUM_SERIAL > 1
280
-    const int16_t pn = port[index_r];
280
+    const int16_t pn = command_port();
281 281
     if (pn < 0) return;
282 282
     PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
283 283
   #endif
@@ -302,14 +302,15 @@ void GCodeQueue::ok_to_send() {
302 302
  * indicate that a command needs to be re-sent.
303 303
  */
304 304
 void GCodeQueue::flush_and_request_resend() {
305
+  const int16_t pn = command_port();
305 306
   #if NUM_SERIAL > 1
306
-    const int16_t pn = port[index_r];
307 307
     if (pn < 0) return;
308 308
     PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
309 309
   #endif
310 310
   SERIAL_FLUSH();
311 311
   SERIAL_ECHOPGM(STR_RESEND);
312
-  SERIAL_ECHOLN(last_N + 1);
312
+  
313
+  SERIAL_ECHOLN(last_N[pn] + 1);  
313 314
   ok_to_send();
314 315
 }
315 316
 
@@ -336,7 +337,7 @@ void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t pn) {
336 337
   PORT_REDIRECT(pn);                      // Reply to the serial port that sent the command
337 338
   SERIAL_ERROR_START();
338 339
   serialprintPGM(err);
339
-  SERIAL_ECHOLN(last_N);
340
+  SERIAL_ECHOLN(last_N[pn]);
340 341
   while (read_serial(pn) != -1);          // Clear out the RX buffer
341 342
   flush_and_request_resend();
342 343
   serial_count[pn] = 0;
@@ -475,9 +476,9 @@ void GCodeQueue::get_serial_commands() {
475 476
             if (n2pos) npos = n2pos;
476 477
           }
477 478
 
478
-          gcode_N = strtol(npos + 1, nullptr, 10);
479
+          const long gcode_N = strtol(npos + 1, nullptr, 10);
479 480
 
480
-          if (gcode_N != last_N + 1 && !M110)
481
+          if (gcode_N != last_N[i] + 1 && !M110)
481 482
             return gcode_line_error(PSTR(STR_ERR_LINE_NO), i);
482 483
 
483 484
           char *apos = strrchr(command, '*');
@@ -490,7 +491,7 @@ void GCodeQueue::get_serial_commands() {
490 491
           else
491 492
             return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
492 493
 
493
-          last_N = gcode_N;
494
+          last_N[i] = gcode_N;
494 495
         }
495 496
         #if ENABLED(SDSUPPORT)
496 497
           // Pronterface "M29" and "M29 " has no line number

+ 11
- 2
Marlin/src/gcode/queue.h View File

@@ -35,7 +35,8 @@ public:
35 35
    * commands to Marlin, and lines will be checked for sequentiality.
36 36
    * M110 N<int> sets the current line number.
37 37
    */
38
-  static long last_N;
38
+
39
+  static long last_N[NUM_SERIAL];
39 40
 
40 41
   /**
41 42
    * GCode Command Queue
@@ -51,13 +52,21 @@ public:
51 52
 
52 53
   static char command_buffer[BUFSIZE][MAX_CMD_SIZE];
53 54
 
54
-  /*
55
+  /**
55 56
    * The port that the command was received on
56 57
    */
57 58
   #if NUM_SERIAL > 1
58 59
     static int16_t port[BUFSIZE];
59 60
   #endif
60 61
 
62
+  static int16_t command_port() {
63
+    return (0
64
+      #if NUM_SERIAL > 1
65
+        + port[index_r]
66
+      #endif
67
+    );
68
+  }
69
+
61 70
   GCodeQueue();
62 71
 
63 72
   /**

Loading…
Cancel
Save