|
@@ -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
|
|