@@ -13,9 +13,11 @@ const char INT_CHARS[] = "0123456789";
13
13
const char STR_NONE[] PROGMEM = " None" ;
14
14
const char STR_ILLEGAL[] PROGMEM = " Illegal" ;
15
15
16
- const char STR_CONFIG_SENSOR_ID_SWAP[] PROGMEM = " swap" ;
17
- const char STR_CONFIG_SENSOR_ID_CLR[] PROGMEM = " clr" ;
18
- const char STR_CONFIG_SENSOR_ID_ACK[] PROGMEM = " ack" ;
16
+ const char STR_CONFIG_SET_VALUES[] PROGMEM = " set" ;
17
+ const char STR_CONFIG_RESET_VALUES[] PROGMEM = " reset" ;
18
+ const char STR_CONFIG_SENSOR_ID_SWAP[] PROGMEM = " swap ids" ;
19
+ const char STR_CONFIG_SENSOR_ID_CLR[] PROGMEM = " clr ids" ;
20
+ const char STR_CONFIG_SENSOR_ID_ACK[] PROGMEM = " ack ids" ;
19
21
20
22
/*
21
23
* CONFIG PARAM NAMES
@@ -171,28 +173,27 @@ const __FlashStringHelper *getEventName(EventEnum literal) {
171
173
/*
172
174
* COMMANDS
173
175
*/
174
- const char STR_CMD_SET_CONFIG[] PROGMEM = " set config" ;
175
- const char STR_CMD_REC_ON[] PROGMEM = " rec on" ;
176
- const char STR_CMD_REC_OFF[] PROGMEM = " rec off" ;
177
- const char STR_CMD_HELP[] PROGMEM = " help" ;
178
- const char STR_CMD_GET_LOG[] PROGMEM = " get log" ;
179
- const char STR_CMD_GET_CONFIG[] PROGMEM = " get config" ;
180
- const char STR_CMD_GET_STAT[] PROGMEM = " get stat" ;
181
- const char STR_CMD_HEAT_ON[] PROGMEM = " heat on" ;
176
+ const char STR_CMD_CONFIG[] PROGMEM = " config" ;
177
+ const char STR_CMD_REC_ON[] PROGMEM = " rec on" ;
178
+ const char STR_CMD_REC_OFF[] PROGMEM = " rec off" ;
179
+ const char STR_CMD_HELP[] PROGMEM = " help" ;
180
+ const char STR_CMD_GET_LOG[] PROGMEM = " log" ;
181
+ const char STR_CMD_GET_STAT[] PROGMEM = " stat" ;
182
+ const char STR_CMD_HEAT_ON[] PROGMEM = " heat on" ;
182
183
const char STR_CMD_HEAT_OFF[] PROGMEM = " heat off" ;
183
- const char STR_CMD_RESET[] PROGMEM = " reset" ;
184
+ const char STR_CMD_RESET[] PROGMEM = " reset" ;
184
185
185
186
#define MAX_CMD_NAME_LEN 12
186
187
187
188
PGM_P getUserCommandNamePtr (UserCommandEnum literal) {
188
189
switch (literal) {
189
190
case CMD_NONE: return STR_NONE;
190
- case CMD_SET_CONFIG: return STR_CMD_SET_CONFIG;
191
+ case CMD_HELP: return STR_CMD_HELP;
192
+ case CMD_SET_CONFIG: return STR_CMD_CONFIG;
193
+ case CMD_GET_CONFIG: return STR_CMD_CONFIG;
191
194
case CMD_REC_ON: return STR_CMD_REC_ON;
192
195
case CMD_REC_OFF: return STR_CMD_REC_OFF;
193
- case CMD_HELP: return STR_CMD_HELP;
194
196
case CMD_GET_LOG: return STR_CMD_GET_LOG;
195
- case CMD_GET_CONFIG: return STR_CMD_GET_CONFIG;
196
197
case CMD_GET_STAT: return STR_CMD_GET_STAT;
197
198
case CMD_HEAT_ON: return STR_CMD_HEAT_ON;
198
199
case CMD_HEAT_OFF: return STR_CMD_HEAT_OFF;
@@ -223,51 +224,53 @@ const __FlashStringHelper *getSensorStatusName(SensorStatusEnum literal) {
223
224
/*
224
225
* USER COMMANDS
225
226
*/
226
- UserCommandEnum parseUserCommand (char buf [], uint8_t bufSize ) {
227
- switch (bufSize ) {
227
+ UserCommandEnum parseUserCommand (char cmd [], uint8_t cmdLen, char args[] ) {
228
+ switch (cmdLen ) {
228
229
case 1 :
229
- if (!strcmp (buf , " ?" )) {
230
+ if (!strcmp (cmd , " ?" )) {
230
231
return CMD_HELP;
231
232
}
232
233
break ;
234
+ case 3 :
235
+ if (!strcmp_P (cmd, STR_CMD_GET_LOG)) {
236
+ return CMD_GET_LOG;
237
+ }
238
+ break ;
233
239
case 4 :
234
- if (!strcmp_P (buf , STR_CMD_HELP)) {
240
+ if (!strcmp_P (cmd , STR_CMD_HELP)) {
235
241
return CMD_HELP;
242
+ } else if (!strcmp_P (cmd, STR_CMD_GET_STAT)) {
243
+ return CMD_GET_STAT;
236
244
}
237
245
break ;
238
246
case 5 :
239
- if (!strcmp_P (buf , STR_CMD_RESET)) {
247
+ if (!strcmp_P (cmd , STR_CMD_RESET)) {
240
248
return CMD_RESET;
241
249
}
242
250
break ;
243
251
case 6 :
244
- if (!strcmp_P (buf , STR_CMD_REC_ON)) {
252
+ if (!strcmp_P (cmd , STR_CMD_REC_ON)) {
245
253
return CMD_REC_ON;
254
+ } else if (!strcmp_P (cmd, STR_CMD_CONFIG)) {
255
+ if (strlen (args) > 0 ) {
256
+ return CMD_GET_CONFIG;
257
+ } else {
258
+ return CMD_SET_CONFIG;
259
+ }
246
260
}
247
261
break ;
248
262
case 7 :
249
- if (!strcmp_P (buf , STR_CMD_REC_OFF)) {
263
+ if (!strcmp_P (cmd , STR_CMD_REC_OFF)) {
250
264
return CMD_REC_OFF;
251
- } else if (!strcmp_P (buf , STR_CMD_HEAT_ON)) {
265
+ } else if (!strcmp_P (cmd , STR_CMD_HEAT_ON)) {
252
266
return CMD_HEAT_ON;
253
- } else if (!strcmp_P (buf, STR_CMD_GET_LOG)) {
254
- return CMD_GET_LOG;
255
267
}
256
268
break ;
257
269
case 8 :
258
- if (!strcmp_P (buf , STR_CMD_HEAT_OFF)) {
270
+ if (!strcmp_P (cmd , STR_CMD_HEAT_OFF)) {
259
271
return CMD_HEAT_OFF;
260
- } else if (!strcmp_P (buf, STR_CMD_GET_STAT)) {
261
- return CMD_GET_STAT;
262
272
}
263
273
break ;
264
- case 10 :
265
- if (!strcmp_P (buf, STR_CMD_SET_CONFIG)) {
266
- return CMD_SET_CONFIG;
267
- } if (!strcmp_P (buf, STR_CMD_GET_CONFIG)) {
268
- return CMD_GET_CONFIG;
269
- }
270
- break ;
271
274
default :
272
275
break ;
273
276
}
@@ -287,22 +290,22 @@ void SerialUI::setup() {
287
290
}
288
291
289
292
void SerialUI::readUserCommand () {
290
- char buf [COMMAND_BUF_SIZE+1 ];
293
+ char cmd [COMMAND_BUF_SIZE+1 ];
291
294
// fill buffer with 0's => always \0-terminated!
292
- memset (buf , 0 , COMMAND_BUF_SIZE);
295
+ memset (cmd , 0 , COMMAND_BUF_SIZE);
293
296
if ( Serial.peek () < 0 ) {
294
297
return ;
295
298
}
296
299
delay (2 );
297
300
298
301
uint8_t count = 0 ;
299
302
do {
300
- count += Serial.readBytes (&buf [count], COMMAND_BUF_SIZE);
303
+ count += Serial.readBytes (&cmd [count], COMMAND_BUF_SIZE);
301
304
delay (2 );
302
305
} while ( (count < COMMAND_BUF_SIZE) && !(Serial.peek () < 0 ) );
303
306
#ifdef DEBUG_UI
304
307
Serial.print (F (" DEBUG_UI: read cmd string: '" ));
305
- Serial.print (buf );
308
+ Serial.print (cmd );
306
309
Serial.print (F (" ', len: " ));
307
310
Serial.println (count);
308
311
#endif
@@ -311,30 +314,30 @@ void SerialUI::readUserCommand() {
311
314
uint8_t len = 0 ;
312
315
boolean prevSpace = false ;
313
316
for (uint8_t i = 0 ; i< count; i++) {
314
- if (isspace (buf [i]) && prevSpace) {
317
+ if (isspace (cmd [i]) && prevSpace) {
315
318
// skip
316
319
} else {
317
- buf [len++] = buf [i];
320
+ cmd [len++] = cmd [i];
318
321
}
319
- prevSpace = isspace (buf [i]);
322
+ prevSpace = isspace (cmd [i]);
320
323
}
321
- buf [len] = ' \0 ' ;
324
+ cmd [len] = ' \0 ' ;
322
325
323
326
// convert to lower case:
324
- char *lower = strlwr (buf );
327
+ char *lower = strlwr (cmd );
325
328
326
329
OperationalParams *op = context->op ;
327
330
// count the command characters up to the trailing numeric arguments (if any):
328
- uint8_t commandLength = strspn (lower, COMMAND_CHARS);
329
- if (len > commandLength ) {
330
- strcpy (op->command ->args , &lower[commandLength ]);
331
+ uint8_t cmdLen = strspn (lower, COMMAND_CHARS);
332
+ if (len > cmdLen ) {
333
+ strcpy (op->command ->args , &lower[cmdLen ]);
331
334
}
332
335
333
- if (isspace (lower[commandLength - 1 ])) {
334
- commandLength --;
336
+ if (isspace (lower[cmdLen - 1 ])) {
337
+ cmdLen --;
335
338
}
336
- lower[commandLength ] = ' \0 ' ;
337
- op->command ->command = parseUserCommand (buf, commandLength );
339
+ lower[cmdLen ] = ' \0 ' ;
340
+ op->command ->command = parseUserCommand (cmd, cmdLen, op-> command -> args );
338
341
339
342
#ifdef DEBUG_UI
340
343
Serial.print (F (" DEBUG_UI: parsed cmd: 0x" ));
@@ -434,7 +437,11 @@ void SerialUI::processReadWriteRequests(ReadWriteRequests requests, BoilerStateA
434
437
for (uint8_t i=0 ; i< NUM_USER_COMMANDS; i++) {
435
438
if (commands & cmd) {
436
439
Serial.print (" - " );
437
- Serial.println (getUserCommandName ((UserCommandEnum) cmd, buf));
440
+ Serial.print (getUserCommandName ((UserCommandEnum) cmd, buf));
441
+ if (cmd == CMD_SET_CONFIG) {
442
+ Serial.print (F (" <modifiers>" ));
443
+ }
444
+ Serial.println ();
438
445
}
439
446
cmd = cmd << 1 ;
440
447
}
0 commit comments