45 #if defined( ARDUINO ) && defined( __AVR__ )
47 dbgResponse -> print( F(
"API tree attached with " ) );
53 dbgResponse -> print( (
const char*)
"API tree attached with " );
82 #if defined( ARDUINO ) && defined( __AVR__ )
84 dbgResponse -> println( F(
"Commander init start" ) );
88 dbgResponse -> println( (
const char*)
"Commander init start" );
93 #if defined( ARDUINO ) && defined( __AVR__ )
95 dbgResponse -> print( F(
"\tCreating alphabetical order... " ) );
99 dbgResponse -> print( (
const char*)
"\tCreating alphabetical order... " );
127 #if defined( ARDUINO ) && defined( __AVR__ )
141 #if defined( ARDUINO ) && defined( __AVR__ )
143 dbgResponse -> print( F(
"\tCreate balanced binary structure... " ) );
147 dbgResponse -> print( (
const char*)
"\tCreate balanced binary structure... " );
152 #if defined( ARDUINO ) && defined( __AVR__ )
155 dbgResponse -> println( F(
"Commander init finished!" ) );
160 dbgResponse -> println( (
const char*)
"Commander init finished!" );
195 uint16_t current_index;
242 (comp_res > 0) ? (next = (prev->
left)) : ( next = (prev->
right));
244 while( next != NULL ){
248 (comp_res > 0) ? (next = (prev->
left)) : ( next = (prev->
right));
265 if( start_index > stop_index ){
272 mid = ( start_index + stop_index ) / 2;
291 uint32_t cmd_name_cntr;
295 uint8_t show_description = 0;
298 API_t *commandData_ptr;
314 #ifdef COMMANDER_ENABLE_PIPE_MODULE
320 response -> println( F(
"Piping not available on this device!" ) );
322 response -> println( (
const char*)
"Piping not available on this device!" );
341 while( ( *arg !=
'\0' ) && ( *arg !=
' ' ) && ( *arg !=
'?' ) ){
360 else if( *arg ==
'?' ){
364 show_description = 1;
369 commandData_ptr = (*this)[
tempBuff ];
372 if( commandData_ptr ){
377 if( show_description ){
382 response -> print( commandData_ptr -> name );
385 response -> println( commandData_ptr -> desc );
394 response -> print( commandData_ptr -> name_P );
397 response -> println( commandData_ptr -> desc_P );
409 #ifdef COMMANDER_ENABLE_PIPE_MODULE
457 (commandData_ptr -> func)( arg,
response );
464 while(
tempBuff[ pipePos + 1 ] ==
' ' ){
475 (commandData_ptr -> func)( arg,
response );
485 else if( strcmp(
tempBuff, (
const char*)
"help" ) == 0 ){
488 if( strcmp( arg, (
const char*)
"-d" ) == 0 ){
506 #if defined( ARDUINO ) && defined( __AVR__ )
508 response -> print( F(
"Command \'" ) );
510 response -> println( F(
"\' not found!" ) );
514 response -> print( (
const char*)
"Command \'" );
516 response -> println( (
const char*)
"\' not found!" );
520 #ifdef COMMANDER_ENABLE_PIPE_MODULE
622 (comp_res > 0) ? (next = (prev->
left)) : ( next = (prev->
right));
626 while( ( comp_res !=0 ) && ( next != NULL ) ){
630 (comp_res > 0) ? (next = (prev->
left)) : ( next = (prev->
right));
649 return (*
this)[ (
char*)name ];
666 #if defined( ARDUINO ) && defined( __AVR__ )
668 out -> println( F(
"\033[1;31m----\033[1;32m Available commands \033[1;31m----\033[0;37m\r\n" ) );
672 out -> println( (
const char*)
"\033[1;31m----\033[1;32m Available commands \033[1;31m----\033[0;37m\r\n" );
680 #if defined( ARDUINO ) && defined( __AVR__ )
682 out -> println( F(
"---- Available commands ----\r\n" ) );
686 out -> println( (
const char*)
"---- Available commands ----\r\n" );
706 out -> print( (
const char*)
"\033[1;32m" );
708 out -> print( (
const char*)
"\033[0;37m" );
720 out -> print( F(
"\033[1;32m" ) );
721 out -> print(
API_tree[ j ].name_P );
722 out -> print( F(
"\033[0;37m" ) );
725 out -> print(
API_tree[ j ].desc_P );
740 out -> println(
':' );
741 out -> print(
'\t' );
752 out -> print(
API_tree[ j ].name_P );
753 out -> println(
':' );
754 out -> print(
'\t' );
755 out -> print(
API_tree[ j ].desc_P );
771 out -> println(
API_tree[ j ].name );
779 out -> println(
API_tree[ j ].name_P );
801 while( str[ cntr ] ){
803 if( str[ cntr ] == c ){
825 return strcmp( element1 -> name, element2 -> name );
831 return strcmp( element1 -> name, element2 );
840 return strcmp_P(
progmemBuffer, ( PGM_P )element2 -> name_P );
846 return strcmp_P( element2, (PGM_P)element1 -> name_P ) * -1;
#define COMMANDER_API_VERSION
#define COMMANDER_MAX_COMMAND_SIZE
API_t * operator[](int i)
Array index operator overload for int type.
void swap_api_elements(uint16_t index, uint16_t place)
Swap two API elements in the tree.
memoryType_t memoryType
Flag for memory type.
void disableDebug()
Disables debug messages.
API_t * API_tree
Starting address of the API-tree.
int commander_strcmp_tree_ram_progmem(API_t *element1, char *element2)
Compare an API-tree element's name with a regular string.
uint32_t API_tree_size
Number of elements in the API-tree.
int(Commander::* commander_strcmp)(API_t *element1, API_t *element2)
Function pointer to an internal strcmp like function.
char tempBuff[COMMANDER_MAX_COMMAND_SIZE]
Internal command buffer.
void executeCommand(char *cmd)
Command execution.
commandResponse defaultResponse
Default response handler class.
uint32_t elementCounter
Internal variable for counting purpose.
int(Commander::* commander_strcmp_tree_ram)(API_t *element1, char *element2)
Function pointer to an internal strcmp like function.
int commander_strcmp_progmem(API_t *element1, API_t *element2)
Compare two API-tree element's name.
Stream * response
Pointer to response class.
char progmemBuffer[COMMANDER_MAX_COMMAND_SIZE]
With the PROGMEM implementation we need to copy the data from the PROGMEM area to a buffer for comper...
static const char * version
Library version string.
void helpFunction(bool description=false)
Help function.
void printHelp(Stream *out)
Prints out the help string to the specified Stream.
int32_t hasChar(char *str, char c)
Search for a character in a string.
void recursive_optimizer(int32_t start_index, int32_t stop_index)
Recursive function optimize a section in the tree.
Stream * dbgResponse
Pointer to response class.
int commander_strcmp_tree_ram_regular(API_t *element1, char *element2)
Compare an API-tree element's name with a regular string.
char pipeArgBuffer[COMMANDER_MAX_COMMAND_SIZE]
If piping happenes the output of the first command will be copied to this buffer.
bool debugEnabled
Flag to enable or disable debug messages.
void attachDebugChannel(Stream *resp)
Debug channel for Serial.
void execute(char *cmd)
Default execution function.
int commander_strcmp_regular(API_t *element1, API_t *element2)
Compare two API-tree element's name.
void optimize_api_tree()
Optimizes the tree to make it balanced.
void enableDebug()
Enables debug messages.
uint16_t find_api_index_by_place(uint16_t place)
Find an API element in the tree by alphabetical place.
commanderPipeChannel pipeChannel
Channel for the internal piping.
void attachTreeFunction(API_t *API_tree_p, uint32_t API_tree_size_p)
Attach API-tree to the object.
@ MEMORY_PROGMEM
Progmem memory implementation.
@ MEMORY_REGULAR
Regular memory implementation.
int read() override
Read one byte form the channel.
int available() override
Available bytes in the channel.
Structure for command data.