Command Console Library
Overview

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.

Please refer Readme for more information.

Features and Functionality

  • Supports Wi-Fi commands to perform network operations such as scan, join, etc.
  • Supports Ethernet commands to perform network operations such as ethernet interface up and ethernet interface down.
  • Integrates iPerf 2.0 commands. iPerf is a tool for active measurements of the maximum achievable bandwidth on IP networks.
  • Supports TCP client/server and UDP client/server on IPv4. IPv6 support will be added in the future.
  • Supports Bluetooth LE commands including Tx/Rx for measuring BLE throughput

    Note
    While iPerf provides several other commands, only a subset of commands that are relevant to embedded connectivity use cases is enabled in this library.

Supported Platforms

ModusToolbox™

Supported Frameworks

  • ModusToolbox™ environment: In this environment the command-console Library uses the abstraction-rtos library that provides the RTOS abstraction API and uses the secure-sockets library for implementing socket functions. For the BLE functionality, this library uses BT stack Integration.

Dependent Libraries

ModusToolbox™

Quick Start

This library is supported on ModusToolbox™ frameworks. See the following section to build the library in those frameworks.

ModusToolbox™

  • For Wi-Fi kits,

    Note
    For CYW955913EVK-01, to include wifi-connection-manager library, the application should pull wifi-core-freertos-lwip-mbedtls library which will internally pull wifi-connection-manager and other dependent modules.
  • For Ethernet kits,
  • To pull BT stack Integration create the following *.mtb* file in deps folder. btstack-integration.mtb: https://github.com/Infineon/btstack-integration#latest-v4.X#$$ASSET_REPO$$/btstack-integration/latest-v4.X
    Note
    BT stack Integration should not be included for CYW955913EVK-01.
  • Review and make the required changes to the pre-defined configuration files and Makefile COMPONENTS in the application.
    • The configuration files are bundled with the Wi-Fi core freertos lwip mbedtls library/Ethernet core freertos lwip mbedtls library for FreeRTOS, lwIP, and Mbed TLS.
      • See README.md of Wi-Fi core freertos lwip mbedtls library for Wi-Fi kits.
      • See README.md of Ethernet core freertos lwip mbedtls library for Ethernet kits.
    • If the application is using bundle library then the configuration files are in the bundle library. For example if the application is using Wi-Fi core freertos lwip mbedtls bundle library, the configuration files are in wifi-core-freertos-lwip-mbedtls/configs folder. Similarly if the application is using Ethernet Core FreeRTOS lwIP mbedtls library, the configuration files are in ethernet-core-freertos-lwip-mbedtls/configs folder.
  • A set of COMPONENTS must be defined in the code example project's Makefile for this library. See the Quick Start section in README.md.
    COMPONENTS=FREERTOS MBEDTLS LWIP
    Note
    For CYW955913EVK-01 the above defines are not applicable.
  • For Wi-Fi kits, to enable the Wi-Fi functionality, add WCM to the COMPONENTS section in the application's Makefile:
    COMPONENTS=WCM
  • For Ethernet kits, to enable the ethernet functionality, add ECM to the COMPONENTS section in the application's Makefile:
    COMPONENTS=ECM
  • To enable BLE functionality, add WICED_BLE to the COMPONENTS section in the application's Makefile:
    COMPONENTS=WICED_BLE
  • Add the following compiler directives to the DEFINES section in the application's Makefile:
    DEFINES=HAVE_SNPRINTF
  • Tune the lwIP configuration parameters listed in application's lwipopts.h file, depending on the required Wi-Fi throughput and use case.
    Note
    For CYW955913EVK-01 the above configuration is not applicable.

ModusToolbox™

These code snippets demonstrate the initialization and usage of Command Console library APIs.

Code Snippet 1: Addition and deletion of commands

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" }, \
const cy_command_console_cmd_t test_command_table_doxygen[] =
{
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.history_buffer_ptr = command_history_buffer;
console_cfg.delimiter_string = console_delimiter_string_doxygen;
console_cfg.params_num = CONSOLE_COMMAND_MAX_PARAMS;
console_cfg.thread_priority = CY_RTOS_PRIORITY_NORMAL;
/* Initialize the Command Console library. */
result = cy_command_console_init(&console_cfg);
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in initializing command console library : %lu \n", (unsigned long)result);
goto error;
}
/* Add the command table. */
result = cy_command_console_add_table ( test_command_table_doxygen );
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in adding command console table : %lu \n", (unsigned long)result);
goto error;
}
/* Wait for a while to use the commands. */
while(1)
{
cy_rtos_delay_milliseconds(500);
wait_time += 500;
if(wait_time == 5000)
{
break;
}
}
/* Delete the command table. */
result = cy_command_console_delete_table ( test_command_table_doxygen );
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in removing command console table : %lu \n", (unsigned long)result);
goto error;
}
/* De-initialize the Command Console library. */
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

Code Snippet 2: Initialization and addition of Utility commands

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"
/* WCM parameters. */
static cy_wcm_config_t wcm_config;
int snippet_command_console_utility(void) {
cy_rslt_t result = CY_RSLT_SUCCESS;
/* Initialize WCM. */
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.history_buffer_ptr = command_history_buffer;
console_cfg.delimiter_string = console_delimiter_string_doxygen;
console_cfg.params_num = CONSOLE_COMMAND_MAX_PARAMS;
console_cfg.thread_priority = CY_RTOS_PRIORITY_NORMAL;
/* Initialize the Command Console library. */
result = cy_command_console_init(&console_cfg);
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in initializing command console library : %lu \n", (unsigned long)result);
goto error;
}
/* Initialize the Wi-Fi utility and add Wi-Fi commands. */
result = wifi_utility_init();
if ( result != CY_RSLT_SUCCESS )
{
printf ("Error in initializing command console library : %lu \n", (unsigned long)result);
goto error;
}
/* Initialize the iPerf utility and add iPerf commands. */
iperf_utility_init(&wcm_config.interface);
/* Initialize the Bluetooth utility and add BT commands. */
bt_utility_init();
return 0;
error:
return -1;
}