Pārlūkot izejas kodu

Fix MeatPack with per-serial-port instances (#21306)

X-Ryl669 3 gadus atpakaļ
vecāks
revīzija
f147a8990a
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam

+ 3
- 1
Marlin/Configuration_adv.h Parādīt failu

@@ -3373,7 +3373,9 @@
3373 3373
   //#define GCODE_QUOTED_STRINGS  // Support for quoted string parameters
3374 3374
 #endif
3375 3375
 
3376
-//#define MEATPACK                // Support for MeatPack G-code compression (https://github.com/scottmudge/OctoPrint-MeatPack)
3376
+// Support for MeatPack G-code compression (https://github.com/scottmudge/OctoPrint-MeatPack)
3377
+//#define MEATPACK_ON_SERIAL_PORT_1
3378
+//#define MEATPACK_ON_SERIAL_PORT_2
3377 3379
 
3378 3380
 //#define GCODE_CASE_INSENSITIVE  // Accept G-code sent to the firmware in lowercase
3379 3381
 

+ 13
- 14
Marlin/src/core/serial.cpp Parādīt failu

@@ -37,23 +37,22 @@ PGMSTR(SP_A_STR, " A");  PGMSTR(SP_B_STR, " B");  PGMSTR(SP_C_STR, " C");
37 37
 PGMSTR(SP_X_STR, " X");  PGMSTR(SP_Y_STR, " Y");  PGMSTR(SP_Z_STR, " Z");  PGMSTR(SP_E_STR, " E");
38 38
 PGMSTR(SP_X_LBL, " X:"); PGMSTR(SP_Y_LBL, " Y:"); PGMSTR(SP_Z_LBL, " Z:"); PGMSTR(SP_E_LBL, " E:");
39 39
 
40
+// Hook Meatpack if it's enabled on the first leaf
41
+#if ENABLED(MEATPACK_ON_SERIAL_PORT_1)
42
+  SerialLeafT1 mpSerial1(false, _SERIAL_LEAF_1);
43
+#endif
44
+#if ENABLED(MEATPACK_ON_SERIAL_PORT_2)
45
+  SerialLeafT2 mpSerial2(false, _SERIAL_LEAF_2);
46
+#endif
47
+
48
+// Step 2: For multiserial, handle the second serial port as well
40 49
 #if HAS_MULTI_SERIAL
41
-  #ifdef SERIAL_CATCHALL
42
-    SerialOutputT multiSerial(MYSERIAL, SERIAL_CATCHALL);
43
-  #else
44
-    #if HAS_ETHERNET
45
-      // Runtime checking of the condition variable
46
-      ConditionalSerial<decltype(MYSERIAL2)> serialOut2(ethernet.have_telnet_client, MYSERIAL2, false); // Takes reference here
47
-    #else
48
-      // Don't pay for runtime checking a true variable, instead use the output directly
49
-      #define serialOut2 MYSERIAL2
50
-    #endif
51
-    SerialOutputT multiSerial(MYSERIAL1, serialOut2);
50
+  #if HAS_ETHERNET
51
+    // We need a definition here
52
+    SerialLeafT2 msSerial2(ethernet.have_telnet_client, MYSERIAL2, false);
52 53
   #endif
53
-#endif
54 54
 
55
-#if ENABLED(MEATPACK)
56
-  MeatpackSerial<decltype(_SERIAL_IMPL)> mpSerial(false, _SERIAL_IMPL);
55
+  SerialOutputT multiSerial(SERIAL_LEAF_1, SERIAL_LEAF_2);
57 56
 #endif
58 57
 
59 58
 void serialprintPGM(PGM_P str) {

+ 43
- 13
Marlin/src/core/serial.h Parādīt failu

@@ -24,7 +24,7 @@
24 24
 #include "../inc/MarlinConfig.h"
25 25
 #include "serial_hook.h"
26 26
 
27
-#if ENABLED(MEATPACK)
27
+#if HAS_MEATPACK
28 28
   #include "../feature/meatpack.h"
29 29
 #endif
30 30
 
@@ -62,29 +62,59 @@ extern uint8_t marlin_debug_flags;
62 62
 //
63 63
 // Serial redirection
64 64
 //
65
+// Step 1: Find what's the first serial leaf
66
+#if BOTH(HAS_MULTI_SERIAL, SERIAL_CATCHALL)
67
+  #define _SERIAL_LEAF_1  MYSERIAL
68
+#else
69
+  #define _SERIAL_LEAF_1  MYSERIAL1
70
+#endif
71
+
72
+// Hook Meatpack if it's enabled on the first leaf
73
+#if ENABLED(MEATPACK_ON_SERIAL_PORT_1)
74
+  typedef MeatpackSerial<decltype(_SERIAL_LEAF_1)> SerialLeafT1;
75
+  extern SerialLeafT1 mpSerial1;
76
+  #define SERIAL_LEAF_1 mpSerial1
77
+#else
78
+  #define SERIAL_LEAF_1 _SERIAL_LEAF_1
79
+#endif
80
+
81
+// Step 2: For multiserial, handle the second serial port as well
65 82
 #if HAS_MULTI_SERIAL
66 83
   #define _PORT_REDIRECT(n,p) REMEMBER(n,multiSerial.portMask,p)
67 84
   #define _PORT_RESTORE(n,p)  RESTORE(n)
68 85
   #define SERIAL_ASSERT(P)    if(multiSerial.portMask!=(P)){ debugger(); }
86
+  // If we have a catchall, use that directly
69 87
   #ifdef SERIAL_CATCHALL
70
-    typedef MultiSerial<decltype(MYSERIAL), decltype(SERIAL_CATCHALL), 0> SerialOutputT;
88
+    #define _SERIAL_LEAF_2 SERIAL_CATCHALL
71 89
   #else
72
-    typedef MultiSerial<decltype(MYSERIAL1), TERN(HAS_ETHERNET, ConditionalSerial<decltype(MYSERIAL2)>, decltype(MYSERIAL2)), 0> SerialOutputT;
90
+    #if HAS_ETHERNET
91
+      // We need to create an instance here
92
+      typedef ConditionalSerial<decltype(MYSERIAL2)> SerialLeafT2;
93
+      extern SerialLeafT2 msSerial2;
94
+      #define _SERIAL_LEAF_2 msSerial2
95
+    #else
96
+      // Don't create a useless instance here, directly use the existing instance
97
+      #define _SERIAL_LEAF_2 MYSERIAL2
98
+    #endif
73 99
   #endif
74
-  extern SerialOutputT multiSerial;
75
-  #define _SERIAL_IMPL multiSerial
100
+
101
+  // Hook Meatpack if it's enabled on the second leaf
102
+  #if ENABLED(MEATPACK_ON_SERIAL_PORT_2)
103
+    typedef MeatpackSerial<decltype(_SERIAL_LEAF_2)> SerialLeafT2;
104
+    extern SerialLeafT2 mpSerial2;
105
+    #define SERIAL_LEAF_2 mpSerial2
106
+  #else
107
+    #define SERIAL_LEAF_2 _SERIAL_LEAF_2
108
+  #endif
109
+
110
+  typedef MultiSerial<decltype(SERIAL_LEAF_1), decltype(SERIAL_LEAF_2), 0> SerialOutputT;
111
+  extern SerialOutputT        multiSerial;
112
+  #define SERIAL_IMPL         multiSerial
76 113
 #else
77 114
   #define _PORT_REDIRECT(n,p) NOOP
78 115
   #define _PORT_RESTORE(n)    NOOP
79 116
   #define SERIAL_ASSERT(P)    NOOP
80
-  #define _SERIAL_IMPL MYSERIAL1
81
-#endif
82
-
83
-#if ENABLED(MEATPACK)
84
-  extern MeatpackSerial<decltype(_SERIAL_IMPL)> mpSerial;
85
-  #define SERIAL_IMPL mpSerial
86
-#else
87
-  #define SERIAL_IMPL _SERIAL_IMPL
117
+  #define SERIAL_IMPL         SERIAL_LEAF_1
88 118
 #endif
89 119
 
90 120
 #define SERIAL_OUT(WHAT, V...)  (void)SERIAL_IMPL.WHAT(V)

+ 2
- 10
Marlin/src/feature/meatpack.cpp Parādīt failu

@@ -39,7 +39,7 @@
39 39
 
40 40
 #include "../inc/MarlinConfig.h"
41 41
 
42
-#if ENABLED(MEATPACK)
42
+#if HAS_MEATPACK
43 43
 
44 44
 #include "meatpack.h"
45 45
 MeatPack meatpack;
@@ -50,14 +50,6 @@ MeatPack meatpack;
50 50
 #define DEBUG_OUT ENABLED(MP_DEBUG)
51 51
 #include "../core/debug_out.h"
52 52
 
53
-bool MeatPack::cmd_is_next = false;       // A command is pending
54
-uint8_t MeatPack::state = 0;              // Configuration state OFF
55
-uint8_t MeatPack::second_char = 0;        // The unpacked 2nd character from an out-of-sequence packed pair
56
-uint8_t MeatPack::cmd_count = 0,          // Counts how many command bytes are received (need 2)
57
-        MeatPack::full_char_count = 0,    // Counts how many full-width characters are to be received
58
-        MeatPack::char_out_count = 0;     // Stores number of characters to be read out.
59
-uint8_t MeatPack::char_out_buf[2];        // Output buffer for caching up to 2 characters
60
-
61 53
 // The 15 most-common characters used in G-code, ~90-95% of all G-code uses these characters
62 54
 // Stored in SRAM for performance.
63 55
 uint8_t meatPackLookupTable[16] = {
@@ -223,4 +215,4 @@ uint8_t MeatPack::get_result_char(char* const __restrict out) {
223 215
   return res;
224 216
 }
225 217
 
226
-#endif // MEATPACK
218
+#endif // HAS_MEATPACK

+ 19
- 22
Marlin/src/feature/meatpack.h Parādīt failu

@@ -90,18 +90,18 @@ class MeatPack {
90 90
   static const uint8_t kSpaceCharIdx = 11;
91 91
   static const char kSpaceCharReplace = 'E';
92 92
 
93
-  static bool cmd_is_next;        // A command is pending
94
-  static uint8_t state;           // Configuration state
95
-  static uint8_t second_char;     // Buffers a character if dealing with out-of-sequence pairs
96
-  static uint8_t cmd_count,       // Counter of command bytes received (need 2)
97
-                 full_char_count, // Counter for full-width characters to be received
98
-                 char_out_count;  // Stores number of characters to be read out.
99
-  static uint8_t char_out_buf[2]; // Output buffer for caching up to 2 characters
93
+  bool cmd_is_next;        // A command is pending
94
+  uint8_t state;           // Configuration state
95
+  uint8_t second_char;     // Buffers a character if dealing with out-of-sequence pairs
96
+  uint8_t cmd_count,       // Counter of command bytes received (need 2)
97
+          full_char_count, // Counter for full-width characters to be received
98
+          char_out_count;  // Stores number of characters to be read out.
99
+  uint8_t char_out_buf[2]; // Output buffer for caching up to 2 characters
100 100
 
101 101
 public:
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, const serial_index_t serial_ind);
104
+  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.
@@ -109,17 +109,17 @@ public:
109 109
    * @param out [in] Output pointer for unpacked/processed data.
110 110
    * @return Number of characters returned. Range from 0 to 2.
111 111
    */
112
-  static uint8_t get_result_char(char* const __restrict out);
113
-
114
-  static void reset_state();
115
-  static void report_state();
116
-  static uint8_t unpack_chars(const uint8_t pk, uint8_t* __restrict const chars_out);
117
-  static void handle_command(const MeatPack_Command c);
118
-  static void handle_output_char(const uint8_t c);
119
-  static void handle_rx_char_inner(const uint8_t c);
120
-};
112
+  uint8_t get_result_char(char* const __restrict out);
113
+
114
+  void reset_state();
115
+  void report_state();
116
+  uint8_t unpack_chars(const uint8_t pk, uint8_t* __restrict const chars_out);
117
+  void handle_command(const MeatPack_Command c);
118
+  void handle_output_char(const uint8_t c);
119
+  void handle_rx_char_inner(const uint8_t c);
121 120
 
122
-extern MeatPack meatpack;
121
+  MeatPack() : cmd_is_next(false), state(0), second_char(0), cmd_count(0), full_char_count(0), char_out_count(0) {}
122
+};
123 123
 
124 124
 // Implement the MeatPack serial class so it's transparent to rest of the code
125 125
 template <typename SerialT>
@@ -127,6 +127,7 @@ struct MeatpackSerial : public SerialBase <MeatpackSerial < SerialT >> {
127 127
   typedef SerialBase< MeatpackSerial<SerialT> > BaseClassT;
128 128
 
129 129
   SerialT & out;
130
+  MeatPack meatpack;
130 131
 
131 132
   char serialBuffer[2];
132 133
   uint8_t charCount;
@@ -143,10 +144,6 @@ struct MeatpackSerial : public SerialBase <MeatpackSerial < SerialT >> {
143 144
   void flushTX()                      { CALL_IF_EXISTS(void, &out, flushTX); }
144 145
 
145 146
   int available(serial_index_t index) {
146
-    // There is a potential issue here with multiserial, since it'll return its decoded buffer whatever the serial index here.
147
-    // So, instead of doing MeatpackSerial<MultiSerial<...>> we should do MultiSerial<MeatpackSerial<...>, MeatpackSerial<...>>
148
-    // TODO, let's fix this later on
149
-
150 147
     if (charCount) return charCount;          // The buffer still has data
151 148
     if (out.available(index) <= 0) return 0;  // No data to read
152 149
 

+ 1
- 1
Marlin/src/gcode/host/M115.cpp Parādīt failu

@@ -145,7 +145,7 @@ void GcodeSuite::M115() {
145 145
     cap_line(PSTR("COOLER_TEMPERATURE"), ENABLED(HAS_COOLER));
146 146
 
147 147
     // MEATPACK Compression
148
-    cap_line(PSTR("MEATPACK"), ENABLED(MEATPACK));
148
+    cap_line(PSTR("MEATPACK"), ENABLED(HAS_MEATPACK));
149 149
 
150 150
     // Machine Geometry
151 151
     #if ENABLED(M115_GEOMETRY_REPORT)

+ 4
- 0
Marlin/src/inc/Conditionals_post.h Parādīt failu

@@ -2912,3 +2912,7 @@
2912 2912
 #elif NUM_SERIAL > 1
2913 2913
   #define HAS_MULTI_SERIAL 1
2914 2914
 #endif
2915
+
2916
+#if ENABLED(MEATPACK_ON_SERIAL_PORT_1) || BOTH(HAS_MULTI_SERIAL, MEATPACK_ON_SERIAL_PORT_2)
2917
+  #define HAS_MEATPACK 1
2918
+#endif

+ 4
- 2
Marlin/src/inc/SanityCheck.h Parādīt failu

@@ -551,6 +551,8 @@
551 551
   #error "UNKNOWN_Z_NO_RAISE is replaced by setting Z_IDLE_HEIGHT to Z_MAX_POS."
552 552
 #elif defined(Z_AFTER_DEACTIVATE)
553 553
   #error "Z_AFTER_DEACTIVATE is replaced by Z_IDLE_HEIGHT."
554
+#elif defined(MEATPACK)
555
+  #error "MEATPACK is now enabled with MEATPACK_ON_SERIAL_PORT_1, MEATPACK_ON_SERIAL_PORT_2, etc."
554 556
 #endif
555 557
 
556 558
 /**
@@ -3340,8 +3342,8 @@ static_assert(   _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
3340 3342
 /**
3341 3343
  * Sanity Check for MEATPACK and BINARY_FILE_TRANSFER Features
3342 3344
  */
3343
-#if BOTH(MEATPACK, BINARY_FILE_TRANSFER)
3344
-  #error "Either enable MEATPACK or BINARY_FILE_TRANSFER, not both."
3345
+#if BOTH(HAS_MEATPACK, BINARY_FILE_TRANSFER)
3346
+  #error "Either enable MEATPACK_ON_SERIAL_PORT_* or BINARY_FILE_TRANSFER, not both."
3345 3347
 #endif
3346 3348
 
3347 3349
 /**

+ 1
- 1
platformio.ini Parādīt failu

@@ -332,7 +332,7 @@ PCA9632                 = src_filter=+<src/feature/leds/pca9632.cpp>
332 332
 PRINTER_EVENT_LEDS      = src_filter=+<src/feature/leds/printer_event_leds.cpp>
333 333
 TEMP_STAT_LEDS          = src_filter=+<src/feature/leds/tempstat.cpp>
334 334
 MAX7219_DEBUG           = src_filter=+<src/feature/max7219.cpp> +<src/gcode/feature/leds/M7219.cpp>
335
-MEATPACK                = src_filter=+<src/feature/meatpack.cpp>
335
+HAS_MEATPACK            = src_filter=+<src/feature/meatpack.cpp>
336 336
 MIXING_EXTRUDER         = src_filter=+<src/feature/mixing.cpp> +<src/gcode/feature/mixing/M163-M165.cpp>
337 337
 HAS_PRUSA_MMU1          = src_filter=+<src/feature/mmu/mmu.cpp>
338 338
 HAS_PRUSA_MMU2          = src_filter=+<src/feature/mmu/mmu2.cpp> +<src/gcode/feature/prusa_MMU2>

Notiek ielāde…
Atcelt
Saglabāt