Bläddra i källkod

Fix serial port redirection (index ≠ port num) (#16687)

Robby Candra 5 år sedan
förälder
incheckning
a0a93e35ae
3 ändrade filer med 10 tillägg och 11 borttagningar
  1. 1
    1
      Marlin/src/core/serial.cpp
  2. 8
    9
      Marlin/src/gcode/queue.cpp
  3. 1
    1
      Marlin/src/gcode/queue.h

+ 1
- 1
Marlin/src/core/serial.cpp Visa fil

29
 static const char echomagic[]  PROGMEM = "echo:";
29
 static const char echomagic[]  PROGMEM = "echo:";
30
 
30
 
31
 #if NUM_SERIAL > 1
31
 #if NUM_SERIAL > 1
32
-  int8_t serial_port_index = SERIAL_PORT;
32
+  int8_t serial_port_index = 0;
33
 #endif
33
 #endif
34
 
34
 
35
 void serialprintPGM(PGM_P str) {
35
 void serialprintPGM(PGM_P str) {

+ 8
- 9
Marlin/src/gcode/queue.cpp Visa fil

191
   // Execute command if non-blank
191
   // Execute command if non-blank
192
   if (i) {
192
   if (i) {
193
     parser.parse(cmd);
193
     parser.parse(cmd);
194
-    PORT_REDIRECT(SERIAL_PORT);
195
     gcode.process_parsed_command();
194
     gcode.process_parsed_command();
196
   }
195
   }
197
   return true;
196
   return true;
243
   #if NUM_SERIAL > 1
242
   #if NUM_SERIAL > 1
244
     const int16_t pn = port[index_r];
243
     const int16_t pn = port[index_r];
245
     if (pn < 0) return;
244
     if (pn < 0) return;
246
-    PORT_REDIRECT(pn);
245
+    PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
247
   #endif
246
   #endif
248
   if (!send_ok[index_r]) return;
247
   if (!send_ok[index_r]) return;
249
   SERIAL_ECHOPGM(MSG_OK);
248
   SERIAL_ECHOPGM(MSG_OK);
267
  */
266
  */
268
 void GCodeQueue::flush_and_request_resend() {
267
 void GCodeQueue::flush_and_request_resend() {
269
   #if NUM_SERIAL > 1
268
   #if NUM_SERIAL > 1
270
-    const int16_t p = port[index_r];
271
-    if (p < 0) return;
272
-    PORT_REDIRECT(p);
269
+    const int16_t pn = port[index_r];
270
+    if (pn < 0) return;
271
+    PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
273
   #endif
272
   #endif
274
   SERIAL_FLUSH();
273
   SERIAL_FLUSH();
275
   SERIAL_ECHOPGM(MSG_RESEND);
274
   SERIAL_ECHOPGM(MSG_RESEND);
296
   }
295
   }
297
 }
296
 }
298
 
297
 
299
-void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t port) {
300
-  PORT_REDIRECT(port);
298
+void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t pn) {
299
+  PORT_REDIRECT(pn);                      // Reply to the serial port that sent the command
301
   SERIAL_ERROR_START();
300
   SERIAL_ERROR_START();
302
   serialprintPGM(err);
301
   serialprintPGM(err);
303
   SERIAL_ECHOLN(last_N);
302
   SERIAL_ECHOLN(last_N);
304
-  while (read_serial(port) != -1);           // clear out the RX buffer
303
+  while (read_serial(pn) != -1);          // Clear out the RX buffer
305
   flush_and_request_resend();
304
   flush_and_request_resend();
306
-  serial_count[port] = 0;
305
+  serial_count[pn] = 0;
307
 }
306
 }
308
 
307
 
309
 FORCE_INLINE bool is_M29(const char * const cmd) {  // matches "M29" & "M29 ", but not "M290", etc
308
 FORCE_INLINE bool is_M29(const char * const cmd) {  // matches "M29" & "M29 ", but not "M290", etc

+ 1
- 1
Marlin/src/gcode/queue.h Visa fil

150
    */
150
    */
151
   static bool enqueue_one(const char* cmd);
151
   static bool enqueue_one(const char* cmd);
152
 
152
 
153
-  static void gcode_line_error(PGM_P const err, const int8_t port);
153
+  static void gcode_line_error(PGM_P const err, const int8_t pn);
154
 
154
 
155
 };
155
 };
156
 
156
 

Laddar…
Avbryt
Spara