Browse Source

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

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
ellensp 4 years ago
parent
commit
c929fb52dd
No account linked to committer's email address

+ 1
- 1
Marlin/src/core/serial.cpp View File

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

+ 3
- 1
Marlin/src/core/serial.h View File

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

+ 2
- 2
Marlin/src/feature/meatpack.cpp View File

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

+ 1
- 1
Marlin/src/feature/meatpack.h View File

101
 
101
 
102
   // Pass in a character rx'd by SD card or serial. Automatically parses command/ctrl sequences,
102
   // Pass in a character rx'd by SD card or serial. Automatically parses command/ctrl sequences,
103
   // and will control state internally.
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
    * After passing in rx'd char using above method, call this to get characters out.
107
    * After passing in rx'd char using above method, call this to get characters out.

+ 1
- 1
Marlin/src/feature/spindle_laser.h View File

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

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

53
   }
53
   }
54
 
54
 
55
   #if HAS_MULTI_SERIAL
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
     if (WITHIN(port, 0, NUM_SERIAL))
57
     if (WITHIN(port, 0, NUM_SERIAL))
58
       serial_port_index = (
58
       serial_port_index = (
59
         port == 0 ? SERIAL_BOTH
59
         port == 0 ? SERIAL_BOTH

+ 32
- 32
Marlin/src/gcode/queue.cpp View File

89
  * The port that the command was received on
89
  * The port that the command was received on
90
  */
90
  */
91
 #if HAS_MULTI_SERIAL
91
 #if HAS_MULTI_SERIAL
92
-  int16_t GCodeQueue::port[BUFSIZE];
92
+  serial_index_t GCodeQueue::port[BUFSIZE];
93
 #endif
93
 #endif
94
 
94
 
95
 /**
95
 /**
136
  */
136
  */
137
 void GCodeQueue::_commit_command(bool say_ok
137
 void GCodeQueue::_commit_command(bool say_ok
138
   #if HAS_MULTI_SERIAL
138
   #if HAS_MULTI_SERIAL
139
-    , int16_t p/*=-1*/
139
+    , serial_index_t serial_ind/*=-1*/
140
   #endif
140
   #endif
141
 ) {
141
 ) {
142
   send_ok[index_w] = say_ok;
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
   TERN_(POWER_LOSS_RECOVERY, recovery.commit_sdpos(index_w));
144
   TERN_(POWER_LOSS_RECOVERY, recovery.commit_sdpos(index_w));
145
   if (++index_w >= BUFSIZE) index_w = 0;
145
   if (++index_w >= BUFSIZE) index_w = 0;
146
   length++;
146
   length++;
153
  */
153
  */
154
 bool GCodeQueue::_enqueue(const char* cmd, bool say_ok/*=false*/
154
 bool GCodeQueue::_enqueue(const char* cmd, bool say_ok/*=false*/
155
   #if HAS_MULTI_SERIAL
155
   #if HAS_MULTI_SERIAL
156
-    , int16_t pn/*=-1*/
156
+    , serial_index_t serial_ind/*=-1*/
157
   #endif
157
   #endif
158
 ) {
158
 ) {
159
   if (*cmd == ';' || length >= BUFSIZE) return false;
159
   if (*cmd == ';' || length >= BUFSIZE) return false;
160
   strcpy(command_buffer[index_w], cmd);
160
   strcpy(command_buffer[index_w], cmd);
161
   _commit_command(say_ok
161
   _commit_command(say_ok
162
     #if HAS_MULTI_SERIAL
162
     #if HAS_MULTI_SERIAL
163
-      , pn
163
+      , serial_ind
164
     #endif
164
     #endif
165
   );
165
   );
166
   return true;
166
   return true;
289
  */
289
  */
290
 void GCodeQueue::ok_to_send() {
290
 void GCodeQueue::ok_to_send() {
291
   #if HAS_MULTI_SERIAL
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
   #endif
295
   #endif
296
   if (!send_ok[index_r]) return;
296
   if (!send_ok[index_r]) return;
297
   SERIAL_ECHOPGM(STR_OK);
297
   SERIAL_ECHOPGM(STR_OK);
314
  * indicate that a command needs to be re-sent.
314
  * indicate that a command needs to be re-sent.
315
  */
315
  */
316
 void GCodeQueue::flush_and_request_resend() {
316
 void GCodeQueue::flush_and_request_resend() {
317
-  const int16_t pn = command_port();
317
+  const serial_index_t serial_ind = command_port();
318
   #if HAS_MULTI_SERIAL
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
   #endif
321
   #endif
322
   SERIAL_FLUSH();
322
   SERIAL_FLUSH();
323
   SERIAL_ECHOPGM(STR_RESEND);
323
   SERIAL_ECHOPGM(STR_RESEND);
324
-  SERIAL_ECHOLN(last_N[pn] + 1);
324
+  SERIAL_ECHOLN(last_N[serial_ind] + 1);
325
   ok_to_send();
325
   ok_to_send();
326
 }
326
 }
327
 
327
 
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
   SERIAL_ERROR_START();
353
   SERIAL_ERROR_START();
354
   serialprintPGM(err);
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
   flush_and_request_resend();
357
   flush_and_request_resend();
358
-  serial_count[pn] = 0;
358
+  serial_count[serial_ind] = 0;
359
 }
359
 }
360
 
360
 
361
 FORCE_INLINE bool is_M29(const char * const cmd) {  // matches "M29" & "M29 ", but not "M290", etc
361
 FORCE_INLINE bool is_M29(const char * const cmd) {  // matches "M29" & "M29 ", but not "M290", etc
473
    * Loop while serial characters are incoming and the queue is not full
473
    * Loop while serial characters are incoming and the queue is not full
474
    */
474
    */
475
   while (length < BUFSIZE && serial_data_available()) {
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
       if (c < 0) continue;
479
       if (c < 0) continue;
480
 
480
 
481
       #if ENABLED(MEATPACK)
481
       #if ENABLED(MEATPACK)
482
-        meatpack.handle_rx_char(uint8_t(c));
482
+        meatpack.handle_rx_char(uint8_t(c), p);
483
         char c_res[2] = { 0, 0 };
483
         char c_res[2] = { 0, 0 };
484
         const uint8_t char_count = meatpack.get_result_char(c_res);
484
         const uint8_t char_count = meatpack.get_result_char(c_res);
485
       #else
485
       #else
492
         if (ISEOL(serial_char)) {
492
         if (ISEOL(serial_char)) {
493
 
493
 
494
           // Reset our state, continue if the line was empty
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
             continue;
496
             continue;
497
 
497
 
498
-          char* command = serial_line_buffer[i];
498
+          char* command = serial_line_buffer[p];
499
 
499
 
500
           while (*command == ' ') command++;                   // Skip leading spaces
500
           while (*command == ' ') command++;                   // Skip leading spaces
501
           char *npos = (*command == 'N') ? command : nullptr;  // Require the N parameter to start the line
501
           char *npos = (*command == 'N') ? command : nullptr;  // Require the N parameter to start the line
511
 
511
 
512
             const long gcode_N = strtol(npos + 1, nullptr, 10);
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
             char *apos = strrchr(command, '*');
517
             char *apos = strrchr(command, '*');
518
             if (apos) {
518
             if (apos) {
519
               uint8_t checksum = 0, count = uint8_t(apos - command);
519
               uint8_t checksum = 0, count = uint8_t(apos - command);
520
               while (count) checksum ^= command[--count];
520
               while (count) checksum ^= command[--count];
521
               if (strtol(apos + 1, nullptr, 10) != checksum)
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
             else
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
           #if ENABLED(SDSUPPORT)
529
           #if ENABLED(SDSUPPORT)
530
             // Pronterface "M29" and "M29 " has no line number
530
             // Pronterface "M29" and "M29 " has no line number
531
             else if (card.flag.saving && !is_M29(command))
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
           #endif
533
           #endif
534
 
534
 
535
           //
535
           //
547
                 #if ENABLED(BEZIER_CURVE_SUPPORT)
547
                 #if ENABLED(BEZIER_CURVE_SUPPORT)
548
                   case 5:
548
                   case 5:
549
                 #endif
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
                   SERIAL_ECHOLNPGM(STR_ERR_STOPPED);
551
                   SERIAL_ECHOLNPGM(STR_ERR_STOPPED);
552
                   LCD_MESSAGEPGM(MSG_STOPPED);
552
                   LCD_MESSAGEPGM(MSG_STOPPED);
553
                   break;
553
                   break;
569
           #endif
569
           #endif
570
 
570
 
571
           // Add the command to the queue
571
           // Add the command to the queue
572
-          _enqueue(serial_line_buffer[i], true
572
+          _enqueue(serial_line_buffer[p], true
573
             #if HAS_MULTI_SERIAL
573
             #if HAS_MULTI_SERIAL
574
-              , i
574
+              , p
575
             #endif
575
             #endif
576
           );
576
           );
577
         }
577
         }
578
         else
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
       } // char_count loop
581
       } // char_count loop
582
 
582
 

+ 5
- 8
Marlin/src/gcode/queue.h View File

56
    * The port that the command was received on
56
    * The port that the command was received on
57
    */
57
    */
58
   #if HAS_MULTI_SERIAL
58
   #if HAS_MULTI_SERIAL
59
-    static int16_t port[BUFSIZE];
59
+    static serial_index_t port[BUFSIZE];
60
   #endif
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
   GCodeQueue();
63
   GCodeQueue();
67
 
64
 
159
 
156
 
160
   static void _commit_command(bool say_ok
157
   static void _commit_command(bool say_ok
161
     #if HAS_MULTI_SERIAL
158
     #if HAS_MULTI_SERIAL
162
-      , int16_t p=-1
159
+      , serial_index_t serial_ind=-1
163
     #endif
160
     #endif
164
   );
161
   );
165
 
162
 
166
   static bool _enqueue(const char* cmd, bool say_ok=false
163
   static bool _enqueue(const char* cmd, bool say_ok=false
167
     #if HAS_MULTI_SERIAL
164
     #if HAS_MULTI_SERIAL
168
-      , int16_t p=-1
165
+      , serial_index_t serial_ind=-1
169
     #endif
166
     #endif
170
   );
167
   );
171
 
168
 
181
    */
178
    */
182
   static bool enqueue_one(const char* cmd);
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 View File

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

+ 1
- 1
Marlin/src/sd/cardreader.h View File

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

Loading…
Cancel
Save