This library provides a framework to add command console support to your application. Support for Wi-Fi, Ethernet, iPerf and Bluetooth Low Energy (BLE) commands is bundled with this library.
MTB AnyCloud Wi-Fi Bluetooth Tester application is built over this library for Wi-Fi kits.
This library is supported on ModusToolbox™ frameworks. See the following section to build the library in those frameworks.
These code snippets demonstrate the initialization and usage of Command Console library APIs.
Initializes Command Console library and adds/removes commands.
#define CONSOLE_COMMAND_MAX_PARAMS (32)
#define CONSOLE_COMMAND_MAX_LENGTH (85)
#define CONSOLE_COMMAND_HISTORY_LENGTH (10)
const char* console_delimiter_string_doxygen = " ";
static char command_buffer[CONSOLE_COMMAND_MAX_LENGTH];
static char command_history_buffer[CONSOLE_COMMAND_MAX_LENGTH * CONSOLE_COMMAND_HISTORY_LENGTH];
int test_console_command_doxygen(
int argc,
char *argv[],
tlv_buffer_t** data)
{
printf (" test_console_command is called , argc = %d , argv = %s \n", argc, argv[1]);
return 0;
}
#define TEST_CONSOLE_COMMANDS \
{ (char*) "test_console_command", test_console_command_doxygen, 1, NULL, NULL, (char *)"", (char *)"sample command with 1 argument" }, \
{
TEST_CONSOLE_COMMANDS
CMD_TABLE_END
};
int snippet_add_remove_command_table(void)
{
uint16_t wait_time = 0;
cy_rslt_t result = CY_RSLT_SUCCESS;
printf("Executing add-remove command snippet\n");
console_cfg.
serial = (
void *)&cy_retarget_io_uart_obj;
console_cfg.
line_len =
sizeof(command_buffer);
console_cfg.
buffer = command_buffer;
console_cfg.
history_len = CONSOLE_COMMAND_HISTORY_LENGTH;
console_cfg.
params_num = CONSOLE_COMMAND_MAX_PARAMS;
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in initializing command console library : %lu \n", (unsigned long)result);
goto error;
}
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in adding command console table : %lu \n", (unsigned long)result);
goto error;
}
while(1)
{
cy_rtos_delay_milliseconds(500);
wait_time += 500;
if(wait_time == 5000)
{
break;
}
}
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in removing command console table : %lu \n", (unsigned long)result);
goto error;
}
if ( result != CY_RSLT_SUCCESS )
{
printf ("command console deinit failed : %lu \n", (unsigned long)result);
goto error;
}
return 0;
error:
return -1;
}
cy_rslt_t cy_command_console_delete_table(const cy_command_console_cmd_t *commands)
De-registers the cy_command_console_cmd_t table.
cy_rslt_t cy_command_console_deinit(void)
De-initializes the command console framework and terminates the thread.
cy_rslt_t cy_command_console_add_table(const cy_command_console_cmd_t *commands)
Invoked to register a table of cy_command_console_cmd_t entries.
cy_rslt_t cy_command_console_init(cy_command_console_cfg_t *cfg)
Initializes the Command console framework and spawns a thread that listens on the console for command...
Structure to configure the command console framework.
Definition: command_console.h:174
uint32_t history_len
Size of the buffer to store the command history.
Definition: command_console.h:179
const char * delimiter_string
Delimiter string which separates out the command line arguments.
Definition: command_console.h:181
void * serial
Pointer to the serial object.
Definition: command_console.h:176
uint32_t line_len
Size of buffer to store command.
Definition: command_console.h:177
char * history_buffer_ptr
Pointer pointing to the buffer provided by the application to store the command history.
Definition: command_console.h:180
char * buffer
Pointer pointing to the buffer provided by the application to store the command given from the consol...
Definition: command_console.h:178
uint8_t params_num
Maximum parameters allowed.
Definition: command_console.h:183
cy_thread_priority_t thread_priority
Command console UART thread priority.
Definition: command_console.h:182
Structure to hold the information for each console command.
Definition: command_console.h:154
Command console Type-Length-Value buffer.
Definition: command_console.h:121
Initializes Command Console library and adds the Wi-Fi and BT utility commands provided by the library.
#include "command_console.h"
#include "iperf_utility.h"
#include "bt_utility.h"
#include "wifi_utility.h"
static cy_wcm_config_t wcm_config;
int snippet_command_console_utility(void) {
cy_rslt_t result = CY_RSLT_SUCCESS;
wcm_config.interface = CY_WCM_INTERFACE_TYPE_STA;
result = cy_wcm_init(&wcm_config);
if(result != CY_RSLT_SUCCESS)
{
printf("cy_wcm_init failed with error: %lu\n", (unsigned long)result);
return -1;
}
printf("WCM Initialized\n");
printf("Executing command console utility snippet \n");
console_cfg.
serial = (
void *)&cy_retarget_io_uart_obj;
console_cfg.
line_len =
sizeof(command_buffer);
console_cfg.
buffer = command_buffer;
console_cfg.
history_len = CONSOLE_COMMAND_HISTORY_LENGTH;
console_cfg.
params_num = CONSOLE_COMMAND_MAX_PARAMS;
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in initializing command console library : %lu \n", (unsigned long)result);
goto error;
}
result = wifi_utility_init();
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in initializing command console library : %lu \n", (unsigned long)result);
goto error;
}
iperf_utility_init(&wcm_config.interface);
bt_utility_init();
return 0;
error:
return -1;
}