Explorar el Código

Meatpack::report_state on serial port init (#20903)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
ellensp hace 3 años
padre
commit
c929fb52dd
No account linked to committer's email address

+ 1
- 1
Marlin/src/core/serial.cpp Ver fichero

@@ -34,7 +34,7 @@ PGMSTR(SP_X_STR, " X");  PGMSTR(SP_Y_STR, " Y");  PGMSTR(SP_Z_STR, " Z");  PGMST
34 34
 PGMSTR(SP_X_LBL, " X:"); PGMSTR(SP_Y_LBL, " Y:"); PGMSTR(SP_Z_LBL, " Z:"); PGMSTR(SP_E_LBL, " E:");
35 35
 
36 36
 #if HAS_MULTI_SERIAL
37
-  int8_t serial_port_index = 0;
37
+  serial_index_t serial_port_index = 0;
38 38
 #endif
39 39
 
40 40
 void serialprintPGM(PGM_P str) {

+ 3
- 1
Marlin/src/core/serial.h Ver fichero

@@ -61,9 +61,11 @@ extern uint8_t marlin_debug_flags;
61 61
 //
62 62
 // Serial redirection
63 63
 //
64
+typedef int8_t serial_index_t;
64 65
 #define SERIAL_BOTH 0x7F
66
+
65 67
 #if HAS_MULTI_SERIAL
66
-  extern int8_t serial_port_index;
68
+  extern serial_index_t serial_port_index;
67 69
   #define _PORT_REDIRECT(n,p)   REMEMBER(n,serial_port_index,p)
68 70
   #define _PORT_RESTORE(n)      RESTORE(n)
69 71
 

+ 2
- 2
Marlin/src/feature/meatpack.cpp Ver fichero

@@ -74,7 +74,6 @@ void MeatPack::reset_state() {
74 74
   second_char = 0;
75 75
   cmd_count = full_char_count = char_out_count = 0;
76 76
   TERN_(MP_DEBUG, chars_decoded = 0);
77
-  report_state();
78 77
 }
79 78
 
80 79
 /**
@@ -189,7 +188,7 @@ void MeatPack::report_state() {
189 188
  * Interpret a single character received from serial
190 189
  * according to the current meatpack state.
191 190
  */
192
-void MeatPack::handle_rx_char(const uint8_t c) {
191
+void MeatPack::handle_rx_char(const uint8_t c, const serial_index_t serial_ind) {
193 192
   if (c == kCommandByte) {                // A command (0xFF) byte?
194 193
     if (cmd_count) {                      // In fact, two in a row?
195 194
       cmd_is_next = true;                 // Then a MeatPack command follows
@@ -201,6 +200,7 @@ void MeatPack::handle_rx_char(const uint8_t c) {
201 200
   }
202 201
 
203 202
   if (cmd_is_next) {                      // Were two command bytes received?
203
+    PORT_REDIRECT(serial_ind);
204 204
     handle_command((MeatPack_Command)c);  // Then the byte is a MeatPack command
205 205
     cmd_is_next = false;
206 206
     return;

+ 1
- 1
Marlin/src/feature/meatpack.h Ver fichero

@@ -101,7 +101,7 @@ private:
101 101
 
102 102
   // Pass in a character rx'd by SD card or serial. Automatically parses command/ctrl sequences,
103 103
   // and will control state internally.
104
-  static void handle_rx_char(const uint8_t c);
104
+  static void handle_rx_char(const uint8_t c, const serial_index_t serial_ind);
105 105
 
106 106
   /**
107 107
    * After passing in rx'd char using above method, call this to get characters out.

+ 1
- 1
Marlin/src/feature/spindle_laser.h Ver fichero

@@ -157,7 +157,7 @@ public:
157 157
         #elif CUTTER_UNIT_IS(RPM)
158 158
           2
159 159
         #else
160
-          #error "CUTTER_UNIT_IS(???)"
160
+          #error "CUTTER_UNIT_IS(unknown)"
161 161
         #endif
162 162
       ));
163 163
     }

+ 1
- 1
Marlin/src/gcode/host/M118.cpp Ver fichero

@@ -53,7 +53,7 @@ void GcodeSuite::M118() {
53 53
   }
54 54
 
55 55
   #if HAS_MULTI_SERIAL
56
-    const int8_t old_serial = serial_port_index;
56
+    const serial_index_t old_serial = serial_port_index;
57 57
     if (WITHIN(port, 0, NUM_SERIAL))
58 58
       serial_port_index = (
59 59
         port == 0 ? SERIAL_BOTH

+ 32
- 32
Marlin/src/gcode/queue.cpp Ver fichero

@@ -89,7 +89,7 @@ char GCodeQueue::command_buffer[BUFSIZE][MAX_CMD_SIZE];
89 89
  * The port that the command was received on
90 90
  */
91 91
 #if HAS_MULTI_SERIAL
92
-  int16_t GCodeQueue::port[BUFSIZE];
92
+  serial_index_t GCodeQueue::port[BUFSIZE];
93 93
 #endif
94 94
 
95 95
 /**
@@ -136,11 +136,11 @@ void GCodeQueue::clear() {
136 136
  */
137 137
 void GCodeQueue::_commit_command(bool say_ok
138 138
   #if HAS_MULTI_SERIAL
139
-    , int16_t p/*=-1*/
139
+    , serial_index_t serial_ind/*=-1*/
140 140
   #endif
141 141
 ) {
142 142
   send_ok[index_w] = say_ok;
143
-  TERN_(HAS_MULTI_SERIAL, port[index_w] = p);
143
+  TERN_(HAS_MULTI_SERIAL, port[index_w] = serial_ind);
144 144
   TERN_(POWER_LOSS_RECOVERY, recovery.commit_sdpos(index_w));
145 145
   if (++index_w >= BUFSIZE) index_w = 0;
146 146
   length++;
@@ -153,14 +153,14 @@ void GCodeQueue::_commit_command(bool say_ok
153 153
  */
154 154
 bool GCodeQueue::_enqueue(const char* cmd, bool say_ok/*=false*/
155 155
   #if HAS_MULTI_SERIAL
156
-    , int16_t pn/*=-1*/
156
+    , serial_index_t serial_ind/*=-1*/
157 157
   #endif
158 158
 ) {
159 159
   if (*cmd == ';' || length >= BUFSIZE) return false;
160 160
   strcpy(command_buffer[index_w], cmd);
161 161
   _commit_command(say_ok
162 162
     #if HAS_MULTI_SERIAL
163
-      , pn
163
+      , serial_ind
164 164
     #endif
165 165
   );
166 166
   return true;
@@ -289,9 +289,9 @@ void GCodeQueue::enqueue_now_P(PGM_P const pgcode) {
289 289
  */
290 290
 void GCodeQueue::ok_to_send() {
291 291
   #if HAS_MULTI_SERIAL
292
-    const int16_t pn = command_port();
293
-    if (pn < 0) return;
294
-    PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
292
+    const serial_index_t serial_ind = command_port();
293
+    if (serial_ind < 0) return;                   // Never mind. Command came from SD or Flash Drive
294
+    PORT_REDIRECT(serial_ind);                    // Reply to the serial port that sent the command
295 295
   #endif
296 296
   if (!send_ok[index_r]) return;
297 297
   SERIAL_ECHOPGM(STR_OK);
@@ -314,14 +314,14 @@ void GCodeQueue::ok_to_send() {
314 314
  * indicate that a command needs to be re-sent.
315 315
  */
316 316
 void GCodeQueue::flush_and_request_resend() {
317
-  const int16_t pn = command_port();
317
+  const serial_index_t serial_ind = command_port();
318 318
   #if HAS_MULTI_SERIAL
319
-    if (pn < 0) return;
320
-    PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
319
+    if (serial_ind < 0) return;                   // Never mind. Command came from SD or Flash Drive
320
+    PORT_REDIRECT(serial_ind);                    // Reply to the serial port that sent the command
321 321
   #endif
322 322
   SERIAL_FLUSH();
323 323
   SERIAL_ECHOPGM(STR_RESEND);
324
-  SERIAL_ECHOLN(last_N[pn] + 1);
324
+  SERIAL_ECHOLN(last_N[serial_ind] + 1);
325 325
   ok_to_send();
326 326
 }
327 327
 
@@ -348,14 +348,14 @@ inline int read_serial(const uint8_t index) {
348 348
   }
349 349
 }
350 350
 
351
-void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t pn) {
352
-  PORT_REDIRECT(pn);                      // Reply to the serial port that sent the command
351
+void GCodeQueue::gcode_line_error(PGM_P const err, const serial_index_t serial_ind) {
352
+  PORT_REDIRECT(serial_ind);                      // Reply to the serial port that sent the command
353 353
   SERIAL_ERROR_START();
354 354
   serialprintPGM(err);
355
-  SERIAL_ECHOLN(last_N[pn]);
356
-  while (read_serial(pn) != -1);          // Clear out the RX buffer
355
+  SERIAL_ECHOLN(last_N[serial_ind]);
356
+  while (read_serial(serial_ind) != -1);          // Clear out the RX buffer
357 357
   flush_and_request_resend();
358
-  serial_count[pn] = 0;
358
+  serial_count[serial_ind] = 0;
359 359
 }
360 360
 
361 361
 FORCE_INLINE bool is_M29(const char * const cmd) {  // matches "M29" & "M29 ", but not "M290", etc
@@ -473,13 +473,13 @@ void GCodeQueue::get_serial_commands() {
473 473
    * Loop while serial characters are incoming and the queue is not full
474 474
    */
475 475
   while (length < BUFSIZE && serial_data_available()) {
476
-    LOOP_L_N(i, NUM_SERIAL) {
476
+    LOOP_L_N(p, NUM_SERIAL) {
477 477
 
478
-      const int c = read_serial(i);
478
+      const int c = read_serial(p);
479 479
       if (c < 0) continue;
480 480
 
481 481
       #if ENABLED(MEATPACK)
482
-        meatpack.handle_rx_char(uint8_t(c));
482
+        meatpack.handle_rx_char(uint8_t(c), p);
483 483
         char c_res[2] = { 0, 0 };
484 484
         const uint8_t char_count = meatpack.get_result_char(c_res);
485 485
       #else
@@ -492,10 +492,10 @@ void GCodeQueue::get_serial_commands() {
492 492
         if (ISEOL(serial_char)) {
493 493
 
494 494
           // Reset our state, continue if the line was empty
495
-          if (process_line_done(serial_input_state[i], serial_line_buffer[i], serial_count[i]))
495
+          if (process_line_done(serial_input_state[p], serial_line_buffer[p], serial_count[p]))
496 496
             continue;
497 497
 
498
-          char* command = serial_line_buffer[i];
498
+          char* command = serial_line_buffer[p];
499 499
 
500 500
           while (*command == ' ') command++;                   // Skip leading spaces
501 501
           char *npos = (*command == 'N') ? command : nullptr;  // Require the N parameter to start the line
@@ -511,25 +511,25 @@ void GCodeQueue::get_serial_commands() {
511 511
 
512 512
             const long gcode_N = strtol(npos + 1, nullptr, 10);
513 513
 
514
-            if (gcode_N != last_N[i] + 1 && !M110)
515
-              return gcode_line_error(PSTR(STR_ERR_LINE_NO), i);
514
+            if (gcode_N != last_N[p] + 1 && !M110)
515
+              return gcode_line_error(PSTR(STR_ERR_LINE_NO), p);
516 516
 
517 517
             char *apos = strrchr(command, '*');
518 518
             if (apos) {
519 519
               uint8_t checksum = 0, count = uint8_t(apos - command);
520 520
               while (count) checksum ^= command[--count];
521 521
               if (strtol(apos + 1, nullptr, 10) != checksum)
522
-                return gcode_line_error(PSTR(STR_ERR_CHECKSUM_MISMATCH), i);
522
+                return gcode_line_error(PSTR(STR_ERR_CHECKSUM_MISMATCH), p);
523 523
             }
524 524
             else
525
-              return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
525
+              return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), p);
526 526
 
527
-            last_N[i] = gcode_N;
527
+            last_N[p] = gcode_N;
528 528
           }
529 529
           #if ENABLED(SDSUPPORT)
530 530
             // Pronterface "M29" and "M29 " has no line number
531 531
             else if (card.flag.saving && !is_M29(command))
532
-              return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
532
+              return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), p);
533 533
           #endif
534 534
 
535 535
           //
@@ -547,7 +547,7 @@ void GCodeQueue::get_serial_commands() {
547 547
                 #if ENABLED(BEZIER_CURVE_SUPPORT)
548 548
                   case 5:
549 549
                 #endif
550
-                  PORT_REDIRECT(i);                      // Reply to the serial port that sent the command
550
+                  PORT_REDIRECT(p);                      // Reply to the serial port that sent the command
551 551
                   SERIAL_ECHOLNPGM(STR_ERR_STOPPED);
552 552
                   LCD_MESSAGEPGM(MSG_STOPPED);
553 553
                   break;
@@ -569,14 +569,14 @@ void GCodeQueue::get_serial_commands() {
569 569
           #endif
570 570
 
571 571
           // Add the command to the queue
572
-          _enqueue(serial_line_buffer[i], true
572
+          _enqueue(serial_line_buffer[p], true
573 573
             #if HAS_MULTI_SERIAL
574
-              , i
574
+              , p
575 575
             #endif
576 576
           );
577 577
         }
578 578
         else
579
-          process_stream_char(serial_char, serial_input_state[i], serial_line_buffer[i], serial_count[i]);
579
+          process_stream_char(serial_char, serial_input_state[p], serial_line_buffer[p], serial_count[p]);
580 580
 
581 581
       } // char_count loop
582 582
 

+ 5
- 8
Marlin/src/gcode/queue.h Ver fichero

@@ -56,12 +56,9 @@ public:
56 56
    * The port that the command was received on
57 57
    */
58 58
   #if HAS_MULTI_SERIAL
59
-    static int16_t port[BUFSIZE];
59
+    static serial_index_t port[BUFSIZE];
60 60
   #endif
61
-
62
-  static int16_t command_port() {
63
-    return TERN0(HAS_MULTI_SERIAL, port[index_r]);
64
-  }
61
+  static inline serial_index_t command_port() { return TERN0(HAS_MULTI_SERIAL, port[index_r]); }
65 62
 
66 63
   GCodeQueue();
67 64
 
@@ -159,13 +156,13 @@ private:
159 156
 
160 157
   static void _commit_command(bool say_ok
161 158
     #if HAS_MULTI_SERIAL
162
-      , int16_t p=-1
159
+      , serial_index_t serial_ind=-1
163 160
     #endif
164 161
   );
165 162
 
166 163
   static bool _enqueue(const char* cmd, bool say_ok=false
167 164
     #if HAS_MULTI_SERIAL
168
-      , int16_t p=-1
165
+      , serial_index_t serial_ind=-1
169 166
     #endif
170 167
   );
171 168
 
@@ -181,7 +178,7 @@ private:
181 178
    */
182 179
   static bool enqueue_one(const char* cmd);
183 180
 
184
-  static void gcode_line_error(PGM_P const err, const int8_t pn);
181
+  static void gcode_line_error(PGM_P const err, const serial_index_t serial_ind);
185 182
 
186 183
 };
187 184
 

+ 1
- 1
Marlin/src/sd/cardreader.cpp Ver fichero

@@ -1229,7 +1229,7 @@ void CardReader::fileHasFinished() {
1229 1229
   uint8_t CardReader::auto_report_sd_interval = 0;
1230 1230
   millis_t CardReader::next_sd_report_ms;
1231 1231
   #if HAS_MULTI_SERIAL
1232
-    int8_t CardReader::auto_report_port;
1232
+    serial_index_t CardReader::auto_report_port;
1233 1233
   #endif
1234 1234
 
1235 1235
   void CardReader::auto_report_sd_status() {

+ 1
- 1
Marlin/src/sd/cardreader.h Ver fichero

@@ -267,7 +267,7 @@ private:
267 267
     static uint8_t auto_report_sd_interval;
268 268
     static millis_t next_sd_report_ms;
269 269
     #if HAS_MULTI_SERIAL
270
-      static int8_t auto_report_port;
270
+      static serial_index_t auto_report_port;
271 271
     #endif
272 272
   #endif
273 273
 

Loading…
Cancelar
Guardar