The Connect stack provides an extensible CLI (Command Line Interface) implementation. By default all Connect example project has more or less already implemented CLI commands to interact with the application through the device's UART interface.
The example project to explain how additional CLI command can be added described through Connect (SoC): Wire-Replacement application. Create the project by going through the example application project wizard.
To add new CLI command first open AppBuilder (it opens automatically when new project created) and switch to the Printing tab.
In the Command Line Configuration frame click on the Add New button which will insert a new line at the end of the command line list (since it will be inserted at the end maybe scrolling down to the bottom of the list is necessary for the new line to appear).
There are three column for a command:
Command
Arglist
Callback
The Command is the command name as it will be available on the UART console, Arglist is the list of the type of the arguments which will be accepted by the command and Callback is the function which will be called on execution of the command from the command line.
Command and Callback are straightforward but Arglist may require detailed explanation. The following argument types are accepted:
u: one-byte unsigned integer
v: two-byte unsigned integer
w: four-byte unsigned integer
s: one-byte signed integer
b: string
The string argument can be entered in ASCII by using quotes, for example: "string". It can also be entered in hexadecimal values by using curly braces, for example: { 48 45 58 0A }.
This description of parameters can be find also in command-interpreter2.h file in the command-interpreter folder of the project at declaration of EmberCommandEntry.
Modify the Command field to printParams, the Callback field to printParamsCommand and the Arglist to bu (a string and a 8-bit value) and click on the Generate button.
The generate action will create the prototype of the callback in flex-cli.c
void printParamsCommand(void);
and add the newly created command to the emberCommandTable[] - the corresponding line should look like
The last parameter is an empty string which could be the help for the command but the AppBuilder does not provide way to specify it and making changes in AppBuilder will overwrite the modifications made manually in flex-cli.c.
The next step is to implement the callback - flex-callbacks.c is a suitable place for that purpose.
The file command-interpreter2-util.c contains the helper functions for retrieving values of the command line arguments, the most often used functions are:
emberUnsignedCommandArgument()
emberSignedCommandArgument()
emberStringCommandArgument()
In all cases the first parameter of the call is the spot of the argument in the argument list (zero based index value). In case of emberStringCommandArgument() the second parameter is a pointer to the value of the string length.
If the project successfully compiled, the new command should be appear in the help:
Executing the command should print the arguments' values on the console:
How to Add CLI command to Connect applications
The Connect stack provides an extensible CLI (Command Line Interface) implementation. By default all Connect example project has more or less already implemented CLI commands to interact with the application through the device's UART interface.
The example project to explain how additional CLI command can be added described through
Connect (SoC): Wire-Replacement
application. Create the project by going through the example application project wizard.To add new CLI command first open AppBuilder (it opens automatically when new project created) and switch to the Printing tab.
In the Command Line Configuration frame click on the Add New button which will insert a new line at the end of the command line list (since it will be inserted at the end maybe scrolling down to the bottom of the list is necessary for the new line to appear).
There are three column for a command:
The Command is the command name as it will be available on the UART console, Arglist is the list of the type of the arguments which will be accepted by the command and Callback is the function which will be called on execution of the command from the command line.
Command and Callback are straightforward but Arglist may require detailed explanation. The following argument types are accepted:
The string argument can be entered in ASCII by using quotes, for example: "string". It can also be entered in hexadecimal values by using curly braces, for example: { 48 45 58 0A }.
This description of parameters can be find also in
command-interpreter2.h
file in thecommand-interpreter
folder of the project at declaration ofEmberCommandEntry
.Modify the Command field to
printParams
, the Callback field toprintParamsCommand
and the Arglist tobu
(a string and a 8-bit value) and click on the Generate button.The generate action will create the prototype of the callback in
flex-cli.c
and add the newly created command to the
emberCommandTable[]
- the corresponding line should look likeThe last parameter is an empty string which could be the help for the command but the AppBuilder does not provide way to specify it and making changes in AppBuilder will overwrite the modifications made manually in
flex-cli.c
.The next step is to implement the callback -
flex-callbacks.c
is a suitable place for that purpose.The file
command-interpreter2-util.c
contains the helper functions for retrieving values of the command line arguments, the most often used functions are:In all cases the first parameter of the call is the spot of the argument in the argument list (zero based index value). In case of
emberStringCommandArgument()
the second parameter is a pointer to the value of the string length.If the project successfully compiled, the new command should be appear in the help:
Executing the command should print the arguments' values on the console: