@@ -42,7 +42,9 @@ void Commander::attachTreeFunction( API_t *API_tree_p, uint32_t API_tree_size_p
42
42
API_tree = API_tree_p;
43
43
API_tree_size = API_tree_size_p;
44
44
45
- dbgResponse -> printf ( (const char *)" API tree attached with %d commands.\r\n " , API_tree_size );
45
+ dbgResponse -> print ( (const char *)" API tree attached with " );
46
+ dbgResponse -> print ( API_tree_size );
47
+ dbgResponse -> println ( " commands." );
46
48
47
49
}
48
50
@@ -55,10 +57,10 @@ void Commander::init(){
55
57
// Temporary variable, used to flip elements.
56
58
API_t temp;
57
59
58
- dbgResponse -> printf ( (const char *)" Commander init start\r\n " );
60
+ dbgResponse -> println ( (const char *)" Commander init start" );
59
61
60
62
// Make the tree ordered by alphabet.
61
- dbgResponse -> printf ( (const char *)" \t Creating alphabetical order... " );
63
+ dbgResponse -> print ( (const char *)" \t Creating alphabetical order... " );
62
64
for ( i = 0 ; i < API_tree_size; i++ ){
63
65
64
66
for ( j = i + 1 ; j < API_tree_size; j++ ){
@@ -82,16 +84,16 @@ void Commander::init(){
82
84
API_tree[ i ].place = i;
83
85
84
86
}
85
- dbgResponse -> printf ( (const char *)" [ OK ]\r\n " );
87
+ dbgResponse -> println ( (const char *)" [ OK ]" );
86
88
87
89
// Optimize the tree to make it balanced.
88
90
// It is necessary to speed up the command
89
91
// search phase.
90
- dbgResponse -> printf ( (const char *)" \t Create balanced binary structure... " );
92
+ dbgResponse -> print ( (const char *)" \t Create balanced binary structure... " );
91
93
optimize_api_tree ();
92
- dbgResponse -> printf ( (const char *)" [ OK ]\r\n " );
94
+ dbgResponse -> println ( (const char *)" [ OK ]" );
93
95
94
- dbgResponse -> printf ( (const char *)" Commander init finished!\r\n " );
96
+ dbgResponse -> println ( (const char *)" Commander init finished!" );
95
97
96
98
}
97
99
@@ -236,19 +238,8 @@ void Commander::executeCommand( char *cmd ){
236
238
// get a bus-fault error without a buffer.
237
239
strncpy ( tempBuff, cmd, COMMANDER_MAX_COMMAND_SIZE );
238
240
239
- // Remove whitespaces at the beginning.
240
- while ( *tempBuff == ' ' ){
241
- tempBuff++;
242
- }
243
-
244
241
pipePos = hasChar ( tempBuff, ' |' );
245
242
246
- if ( pipePos > 0 ){
247
-
248
- tempBuff[ pipePos ] = ' \0 ' ;
249
-
250
- }
251
-
252
243
// tempBuff is the address of the first character of the incoming command.
253
244
// If we give arg variable the value stored in tempBuff means arg will point to
254
245
// the first character of the command as well.
@@ -305,42 +296,27 @@ void Commander::executeCommand( char *cmd ){
305
296
if ( show_description ){
306
297
307
298
// Print the description text to the output channel.
308
- response -> printf ( " %s: %s\r\n " , commandData_ptr -> name, commandData_ptr -> desc );
299
+ response -> print ( commandData_ptr -> name );
300
+ response -> print ( " : " );
301
+ response -> println ( commandData_ptr -> desc );
309
302
310
303
311
304
}
312
305
313
- // Example: random 0 180 | setServo
314
-
315
306
// If show_description flag is not set, than we have to execute the commands function.
316
307
else {
317
308
318
309
if ( pipePos > 0 ){
319
310
320
- // TODO Switch response to pipe response.
321
- response = &pipeResponse;
311
+ // TODO Switch response to internal buffer.
322
312
323
313
}
324
314
325
- // TODO if the internal buffer has data, the arg has to be replaced with that.
326
- if ( pipeResponse.available () ){
327
-
328
- arg = pipeResponse.getData ();
329
-
330
- }
315
+ // TODO if the internal buffer has data, the arg has to be replaced to that.
331
316
332
317
// Execute commands function.
333
318
(commandData_ptr -> func)( arg, response );
334
319
335
- pipeResponse.flush ();
336
-
337
- // TODO recursive function call.
338
- if ( pipePos > 0 ){
339
-
340
- executeCommand ( cmd + pipePos );
341
-
342
- }
343
-
344
320
}
345
321
346
322
}
@@ -368,7 +344,9 @@ void Commander::executeCommand( char *cmd ){
368
344
369
345
// If we went through the whole tree and we did not found the command in it,
370
346
// we have to notice the user abut the problem. Maybe a Type-O
371
- response -> printf ( (const char *)" Command \' %s\' not found!!!\r\n " , tempBuff );
347
+ response -> print ( (const char *)" Command \' " );
348
+ response -> print ( tempBuff );
349
+ response -> println ( " \' not found!" );
372
350
373
351
}
374
352
@@ -394,174 +372,33 @@ void Commander::execute( const char *cmd ){
394
372
395
373
}
396
374
397
- #ifdef COMMANDER_USE_SERIAL_RESPONSE
398
-
399
- void Commander::execute ( char *cmd, Serial *resp ){
400
-
401
- // Serial execute handler, so the Serial response will be chosen.
402
- response = &serialResponse;
403
-
404
- // Select the right Serial object in the response class.
405
- serialResponse.select ( resp );
406
-
407
- // Execute the command.
408
- executeCommand ( cmd );
409
-
410
- }
411
-
412
- void Commander::execute ( const char *cmd, Serial *resp ){
413
-
414
- // Serial execute handler, so the Serial response will be chosen.
415
- response = &serialResponse;
416
-
417
- // Select the right Serial object in the response class.
418
- serialResponse.select ( resp );
419
-
420
- // Execute the command.
421
- executeCommand ( (char *)cmd );
422
-
423
- }
424
-
425
- void Commander::attachDebugChannel ( Serial *resp ){
426
-
427
- dbgResponse = &serialDebugResponse;
428
-
429
- // Select the right Serial object in the response class.
430
- serialDebugResponse.select ( resp );
375
+ void Commander::execute ( char *cmd, Stream *resp ){
431
376
432
- // Enable debug messages.
433
- debugEnabled = true ;
434
-
435
- }
436
-
437
- #endif
438
-
439
- #ifdef COMMANDER_USE_ARDUINO_SERIAL_RESPONSE
440
-
441
- void Commander::execute ( char *cmd, HardwareSerial *resp ){
442
-
443
- // Arduino Serial execute handler, so the Arduino Serial response will be chosen.
444
- response = &arduinoSerialResponse;
445
-
446
- // Select the right HardwareSerial object in the response class.
447
- arduinoSerialResponse.select ( resp );
377
+ response = resp;
448
378
449
379
// Execute the command.
450
380
executeCommand ( cmd );
451
381
452
382
}
453
383
454
- void Commander::execute ( const char *cmd, HardwareSerial *resp ){
384
+ void Commander::execute ( const char *cmd, Stream *resp ){
455
385
456
- // Arduino Serial execute handler, so the Arduino Serial response will be chosen.
457
- response = &arduinoSerialResponse;
458
-
459
- // Select the right HardwareSerial object in the response class.
460
- arduinoSerialResponse.select ( resp );
386
+ response = resp;
461
387
462
388
// Execute the command.
463
389
executeCommand ( (char *)cmd );
464
390
465
391
}
466
392
467
- void Commander::attachDebugChannel ( HardwareSerial *resp ){
468
-
469
- dbgResponse = &arduinoSerialDebugResponse;
393
+ void Commander::attachDebugChannel ( Stream *resp ){
470
394
471
- // Select the right HardwareSerial object in the response class.
472
- arduinoSerialDebugResponse.select ( resp );
395
+ dbgResponse = resp;
473
396
474
397
// Enable debug messages.
475
398
debugEnabled = true ;
476
399
477
400
}
478
401
479
- #endif
480
-
481
- #ifdef COMMANDER_USE_ARDUINO_32U4_SERIAL_RESPONSE
482
-
483
- void Commander::execute ( char *cmd, Serial_ *resp ){
484
-
485
- // Arduino Serial execute handler, so the Arduino Serial response will be chosen.
486
- response = &arduino32U4SerialResponse;
487
-
488
- // Select the right HardwareSerial object in the response class.
489
- arduino32U4SerialResponse.select ( resp );
490
-
491
- // Execute the command.
492
- executeCommand ( cmd );
493
-
494
- }
495
-
496
- void Commander::execute ( const char *cmd, Serial_ *resp ){
497
-
498
- // Arduino Serial execute handler, so the Arduino Serial response will be chosen.
499
- response = &arduino32U4SerialResponse;
500
-
501
- // Select the right HardwareSerial object in the response class.
502
- arduino32U4SerialResponse.select ( resp );
503
-
504
- // Execute the command.
505
- executeCommand ( (char *)cmd );
506
-
507
- }
508
-
509
- void Commander::attachDebugChannel ( Serial_ *resp ){
510
-
511
- dbgResponse = &arduino32U4SerialResponse;
512
-
513
- // Select the right HardwareSerial object in the response class.
514
- arduino32U4SerialResponse.select ( resp );
515
-
516
- // Enable debug messages.
517
- debugEnabled = true ;
518
-
519
- }
520
-
521
- #endif
522
-
523
- #ifdef COMMANDER_USE_WIFI_CLIENT_RESPONSE
524
-
525
- void Commander::execute ( char *cmd, WiFiClient *resp ){
526
-
527
- // Arduino Serial execute handler, so the Arduino Serial response will be chosen.
528
- response = &WiFiClientResponse;
529
-
530
- // Select the right HardwareSerial object in the response class.
531
- WiFiClientResponse.select ( resp );
532
-
533
- // Execute the command.
534
- executeCommand ( cmd );
535
-
536
- }
537
-
538
- void Commander::execute ( const char *cmd, WiFiClient *resp ){
539
-
540
- // Arduino Serial execute handler, so the Arduino Serial response will be chosen.
541
- response = &WiFiClientResponse;
542
-
543
- // Select the right HardwareSerial object in the response class.
544
- WiFiClientResponse.select ( resp );
545
-
546
- // Execute the command.
547
- executeCommand ( (char *)cmd );
548
-
549
- }
550
-
551
- void Commander::attachDebugChannel ( WiFiClient *resp ){
552
-
553
- dbgResponse = &WiFiClientDebugResponse;
554
-
555
- // Select the right HardwareSerial object in the response class.
556
- WiFiClientDebugResponse.select ( resp );
557
-
558
- // Enable debug messages.
559
- debugEnabled = true ;
560
-
561
- }
562
-
563
- #endif
564
-
565
402
void Commander::enableDebug (){
566
403
567
404
debugEnabled = true ;
@@ -638,7 +475,7 @@ void Commander::helpFunction( bool description ){
638
475
uint32_t i;
639
476
uint32_t j;
640
477
641
- response -> printf ( (const char *)" ---- Available commands ----\r\n " );
478
+ response -> println ( (const char *)" ---- Available commands ----" );
642
479
for ( i = 0 ; i < API_tree_size; i++ ){
643
480
644
481
for ( j = 0 ; j < API_tree_size; j++ ){
@@ -647,14 +484,18 @@ void Commander::helpFunction( bool description ){
647
484
648
485
if ( description ){
649
486
650
- response -> printf ( (const char *)" %s:\r\n " , API_tree[ j ].name );
651
- response -> printf ( (const char *)" \t %s\r\n\r\n " , API_tree[ j ].desc );
487
+ response -> print ( API_tree[ j ].name );
488
+ response -> println ( ' :' );
489
+ response -> print ( ' \t ' );
490
+ response -> print ( API_tree[ j ].desc );
491
+ response -> println ();
492
+ response -> println ();
652
493
653
494
}
654
495
655
496
else {
656
497
657
- response -> printf ( ( const char *) " %s \r\n " , API_tree[ j ].name );
498
+ response -> println ( API_tree[ j ].name );
658
499
659
500
}
660
501
0 commit comments