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
  * M110: Set Current Line Number
27
  * M110: Set Current Line Number
28
  */
28
  */
29
 void GcodeSuite::M110() {
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
  * sending commands to Marlin, and lines will be checked for sequentiality.
52
  * sending commands to Marlin, and lines will be checked for sequentiality.
53
  * M110 N<int> sets the current line number.
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
  * GCode Command Queue
58
  * GCode Command Queue
277
  */
277
  */
278
 void GCodeQueue::ok_to_send() {
278
 void GCodeQueue::ok_to_send() {
279
   #if NUM_SERIAL > 1
279
   #if NUM_SERIAL > 1
280
-    const int16_t pn = port[index_r];
280
+    const int16_t pn = command_port();
281
     if (pn < 0) return;
281
     if (pn < 0) return;
282
     PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
282
     PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
283
   #endif
283
   #endif
302
  * indicate that a command needs to be re-sent.
302
  * indicate that a command needs to be re-sent.
303
  */
303
  */
304
 void GCodeQueue::flush_and_request_resend() {
304
 void GCodeQueue::flush_and_request_resend() {
305
+  const int16_t pn = command_port();
305
   #if NUM_SERIAL > 1
306
   #if NUM_SERIAL > 1
306
-    const int16_t pn = port[index_r];
307
     if (pn < 0) return;
307
     if (pn < 0) return;
308
     PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
308
     PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
309
   #endif
309
   #endif
310
   SERIAL_FLUSH();
310
   SERIAL_FLUSH();
311
   SERIAL_ECHOPGM(STR_RESEND);
311
   SERIAL_ECHOPGM(STR_RESEND);
312
-  SERIAL_ECHOLN(last_N + 1);
312
+  
313
+  SERIAL_ECHOLN(last_N[pn] + 1);  
313
   ok_to_send();
314
   ok_to_send();
314
 }
315
 }
315
 
316
 
336
   PORT_REDIRECT(pn);                      // Reply to the serial port that sent the command
337
   PORT_REDIRECT(pn);                      // Reply to the serial port that sent the command
337
   SERIAL_ERROR_START();
338
   SERIAL_ERROR_START();
338
   serialprintPGM(err);
339
   serialprintPGM(err);
339
-  SERIAL_ECHOLN(last_N);
340
+  SERIAL_ECHOLN(last_N[pn]);
340
   while (read_serial(pn) != -1);          // Clear out the RX buffer
341
   while (read_serial(pn) != -1);          // Clear out the RX buffer
341
   flush_and_request_resend();
342
   flush_and_request_resend();
342
   serial_count[pn] = 0;
343
   serial_count[pn] = 0;
475
             if (n2pos) npos = n2pos;
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
             return gcode_line_error(PSTR(STR_ERR_LINE_NO), i);
482
             return gcode_line_error(PSTR(STR_ERR_LINE_NO), i);
482
 
483
 
483
           char *apos = strrchr(command, '*');
484
           char *apos = strrchr(command, '*');
490
           else
491
           else
491
             return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
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
         #if ENABLED(SDSUPPORT)
496
         #if ENABLED(SDSUPPORT)
496
           // Pronterface "M29" and "M29 " has no line number
497
           // Pronterface "M29" and "M29 " has no line number

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

35
    * commands to Marlin, and lines will be checked for sequentiality.
35
    * commands to Marlin, and lines will be checked for sequentiality.
36
    * M110 N<int> sets the current line number.
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
    * GCode Command Queue
42
    * GCode Command Queue
51
 
52
 
52
   static char command_buffer[BUFSIZE][MAX_CMD_SIZE];
53
   static char command_buffer[BUFSIZE][MAX_CMD_SIZE];
53
 
54
 
54
-  /*
55
+  /**
55
    * The port that the command was received on
56
    * The port that the command was received on
56
    */
57
    */
57
   #if NUM_SERIAL > 1
58
   #if NUM_SERIAL > 1
58
     static int16_t port[BUFSIZE];
59
     static int16_t port[BUFSIZE];
59
   #endif
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
   GCodeQueue();
70
   GCodeQueue();
62
 
71
 
63
   /**
72
   /**

Loading…
Cancel
Save