49
49
#define XIO_H_ONCE
50
50
51
51
// #include "g2core.h" // not required if used in g2core project
52
- #include "config.h" // required for nvObj typedef
52
+ #include " config.h" // required for nvObj typedef
53
+ #include " canonical_machine.h" // needed for cm_has_hold()
53
54
54
55
/* *** Defines, Macros, and Assorted Parameters ****/
55
56
@@ -97,6 +98,7 @@ enum xioDeviceEnum { // reconfigure this enum as you add
97
98
DEV_USB1, // must be 1
98
99
DEV_UART1, // must be 2
99
100
// DEV_SPI0, // We can't have it here until we actually define it
101
+ DEV_FLASH_FILE, // must be 0
100
102
DEV_MAX
101
103
};
102
104
@@ -106,7 +108,7 @@ enum xioSPIMode {
106
108
};
107
109
108
110
109
- /**** readline stuff -- TODO *****/
111
+ /* *** readline stuff *****/
110
112
111
113
#define RX_BUFFER_MIN_SIZE 256 // minimum requested buffer size (they are usually larger)
112
114
@@ -161,6 +163,71 @@ extern "C" {
161
163
#define CHAR_QUEUE_FLUSH (char )' %'
162
164
// #define CHAR_BOOTLOADER ESC
163
165
166
+
167
+ /* *** xio_flash_file - object to hold in-flash (compiled-in) "files" to run ****/
168
+
169
+ struct xio_flash_file {
170
+ const char * const _data;
171
+ const int32_t _length;
172
+
173
+ int32_t _read_offset = 0 ;
174
+
175
+ xio_flash_file (const char * const data, int32_t length) : _data{data}, _length{length} {};
176
+
177
+ void reset () {
178
+ _read_offset = 0 ;
179
+ };
180
+
181
+ const char *readline (bool control_only, uint16_t &line_size) {
182
+ line_size = 0 ;
183
+ if (_read_offset == _length) { return nullptr ; }
184
+
185
+ if (control_only) {
186
+ char c = _data[_read_offset];
187
+ if (!
188
+ ((c == ' !' ) ||
189
+ (c == ' ~' ) ||
190
+ (c == ENQ) || // request ENQ/ack
191
+ (c == CHAR_RESET) || // ^X - reset (aka cancel, terminate)
192
+ (c == CHAR_ALARM) || // ^D - request job kill (end of transmission)
193
+ (c == ' %' && cm_has_hold ()) // flush (only in feedhold or part of control header)
194
+ ))
195
+ {
196
+ return nullptr ;
197
+ }
198
+ }
199
+
200
+ const char *line_start = _data + _read_offset;
201
+
202
+ while (_read_offset < _length) {
203
+ char c = _data[_read_offset++];
204
+
205
+ if (c == ' \n ' ) {
206
+ break ;
207
+ }
208
+
209
+ line_size++;
210
+ }
211
+
212
+ return line_start;
213
+ };
214
+
215
+ bool isDone () {
216
+ return _read_offset == _length;
217
+ }
218
+ };
219
+
220
+ /* *** convenience function to construct a xio_flash_file ****/
221
+
222
+ template <int32_t length>
223
+ constexpr xio_flash_file make_xio_flash_file (const char (&data)[length]) {
224
+ return {data, length};
225
+ }
226
+
227
+ /* *** function prototype for file-sending ****/
228
+
229
+ bool xio_send_file (xio_flash_file &file);
230
+
164
231
#ifdef __TEXT_MODE
165
232
166
233
void xio_print_spi (nvObj_t *nv);
0 commit comments