Command specific macros. More...

Macros

#define GOS_CMD_CREATE_COMMAND(component, name, key, shortcut, min, max, retval)   _GOS_CMD_CREATE_COMMAND(component, name, key, shortcut, min, max, retval)
 
#define GOS_CMD_CREATE_GETTER(component, name, key, shortcut, argc)   _GOS_CMD_CREATE_GETTER(component, name, key, MACRO_NO_EXPAND_ARG(shortcut), argc)
 
#define GOS_CMD_CREATE_SETTER(component, name, key, shortcut, argc)   _GOS_CMD_CREATE_SETTER(component, name, key, MACRO_NO_EXPAND_ARG(shortcut), argc)
 
#define GOS_CMD_CREATE_GETTER_SETTER(component, name, key, shortcut, get_argc, set_argc)   _GOS_CMD_CREATE_GETTER_SETTER(component, name, key, MACRO_NO_EXPAND_ARG(shortcut), get_argc, set_argc)
 
#define GOS_DEFINE_COMMAND(component, name)   gos_cmd_result_t component ## _ ## name ## _command(int argc, char **argv)
 
#define GOS_DEFINE_GETTER(component, name)   gos_cmd_result_t component ## _get_ ## name ## _command(int argc, char **argv)
 
#define GOS_DEFINE_SETTER(component, name)   gos_cmd_result_t component ## _set_ ## name ## _command(int argc, char **argv)
 
#define SC2(a1, a2, b)   GOS_CMD_SHORTCUT_ID2(a1, a2, b)
 
#define SC3(a1, a2, b, c)   GOS_CMD_SHORTCUT_ID3(a1, a2, b, c)
 
#define GOS_CMD_RESULT(gos_result)   ((gos_result) == GOS_SUCCESS) ? GOS_CMD_SUCCESS : GOS_CMD_FAILED
 
#define GOS_CMD_VERIFY(gos_result)   if((gos_result) != GOS_SUCCESS) return GOS_CMD_FAILED
 
#define GOS_CMD_FAILED(result, func)   ((result = func) != GOS_CMD_SUCCESS)
 
#define GOS_CMD_SET_FAILED(result, func)   ((result = func) != GOS_CMD_SET_OK)
 
#define GOS_CMD_EXECUTE_OK(gos_result)   (gos_result == GOS_SUCCESS) ? GOS_CMD_EXECUTE_AOK : GOS_CMD_FAILED
 
#define GOS_CMD_PARSE_INT_ARG_WITH_VAR(type, var, str, min, max)
 Utility macro to parse an integer argument and store in supplied variable. More...
 
#define GOS_CMD_PARSE_INT_ARG(type, name, str, min, max)
 Utility macro to parse an integer argument and store in created variable. More...
 
#define GOS_CMD_PARSE_HEX_ARG_WITH_VAR(type, var, str, min, max)
 Utility macro to parse an hexadecimal argument and store in supplied variable. More...
 
#define GOS_CMD_PARSE_HEX_ARG(type, name, str, min, max)
 Utility macro to parse an hexadecimal argument and store in created variable. More...
 

Detailed Description

Command specific macros.

Macro Definition Documentation

◆ GOS_CMD_CREATE_COMMAND

#define GOS_CMD_CREATE_COMMAND (   component,
  name,
  key,
  shortcut,
  min,
  max,
  retval 
)    _GOS_CMD_CREATE_COMMAND(component, name, key, shortcut, min, max, retval)

Define a Gecko OS Command

This automatically adds a command line command. The command implementation should be defined in the same file as the definition, e.g.

GOS_CMD_CREATE_COMMAND(my_app, start_polling, "start_polling", "start", 0, 1, true);
...
gos_cmd_result_t my_app_start_polling_command(int argc, char **argv)
{
gos_cmd_format_response(CMD_SUCCESS, "Polling started");
return CMD_SUCCESS;
}
...
Parameters
componentThe name of the component that this command belows, e.g. my_app
nameThe name of the command, e.g. start_polling
keyThe command-line command key, e.g. start_polling
shortcutThe command-line command shortcut, e.g. sp
minThe minimum number of arguments this command accepts
maxThe maximum number of arguments this commands accepts
retvaltrue if the command prints its own response, false else
Examples:
cloud/coap_demo/commands.c, cloud/mqtt_demo/mqtt_cli_commands.c, demo/uart_blaster/commands.c, system/application_nvm/main.c, system/custom_commands/main.c, and utility/buffer_dump/main.c.

◆ GOS_CMD_CREATE_GETTER

#define GOS_CMD_CREATE_GETTER (   component,
  name,
  key,
  shortcut,
  argc 
)    _GOS_CMD_CREATE_GETTER(component, name, key, MACRO_NO_EXPAND_ARG(shortcut), argc)

Define a Gecko OS settings 'getter'

This automatically adds a setting to the available 'get' command line options. The 'getter' implementation should be defined in the same file as the definition, e.g.

GOS_CMD_CREATE_GETTER(my_app, polling_period, "my_app.polling_period", SC2('m','a','p'), 0);
...
gos_cmd_result_t my_app_get_polling_period_command(int argc, char **argv)
{
gos_cmd_format_response(CMD_SUCCESS, "%d", context->polling_period);
return CMD_SUCCESS;
}
...
Note
This only creates a 'getter'. Use GOS_CMD_CREATE_GETTER_SETTER to create both a 'getter' and 'setter'.
Parameters
componentThe name of the component that this command belows, e.g. my_app
nameThe name of the getter command, e.g. polling_period
keyThe command-line 'get' command option key, e.g. get my_app.polling_period
shortcutThe command-line 'get' command options shortcut, e.g. get ma p
argcThe minimum number of arguments this 'getter' accepts, typically this value is 0.

◆ GOS_CMD_CREATE_GETTER_SETTER

#define GOS_CMD_CREATE_GETTER_SETTER (   component,
  name,
  key,
  shortcut,
  get_argc,
  set_argc 
)    _GOS_CMD_CREATE_GETTER_SETTER(component, name, key, MACRO_NO_EXPAND_ARG(shortcut), get_argc, set_argc)

Define a Gecko OS settings 'getter' and 'setter'

This automatically adds a setting to the available 'get' and 'set' command line options. The 'getter' and 'setter' implementations should be defined in the same file as the definition, e.g.

GOS_CMD_CREATE_GETTER_SETTER(my_app, polling_period, "my_app.polling_period", SC2('m','a','p'), 0, 1);
...
gos_cmd_result_t my_app_get_polling_period_command(int argc, char **argv)
{
gos_cmd_format_response(CMD_SUCCESS, "%d", context->polling_period);
return CMD_SUCCESS;
}
gos_cmd_result_t my_app_set_polling_period_command(int argc, char **argv)
{
GOS_CMD_PARSE_INT_ARG(uint32_t, period, argv[1], 10, 1000);
context->polling_period = period
return CMD_SET_OK;
}
...
Parameters
componentThe name of the component that this command belows, e.g. my_app
nameThe name of the getter/setter commands, e.g. polling_period
keyThe command-line 'get' and 'set' command option key, e.g. get my_app.polling_period and set my_app.polling_period
shortcutThe command-line 'get' command options shortcut, e.g. get ma p and set ma p
get_argcThe minimum number of arguments this 'getter' accepts, typically this value is 0
set_argcThe minimum number of arguments this 'setter' accepts, typically this value is 1
Examples:
cloud/coap_demo/commands.c, cloud/mqtt_demo/mqtt_cli_variables.c, demo/uart_blaster/commands.c, network/uart_tcp_client/variables.c, system/custom_commands/main.c, and system/settings_file/main.c.

◆ GOS_CMD_CREATE_SETTER

#define GOS_CMD_CREATE_SETTER (   component,
  name,
  key,
  shortcut,
  argc 
)    _GOS_CMD_CREATE_SETTER(component, name, key, MACRO_NO_EXPAND_ARG(shortcut), argc)

Define a Gecko OS settings 'setter'

This automatically adds a setting to the available 'set' command line options. The 'setter' implementation should be defined in the same file as the definition, e.g.

GOS_CMD_CREATE_SETTER(my_app, polling_period, "my_app.polling_period", SC2('m','a','p'), 1);
...
gos_cmd_result_t my_app_set_polling_period_command(int argc, char **argv)
{
GOS_CMD_PARSE_INT_ARG(uint32_t, period, argv[1], 10, 1000);
context->polling_period = period
return CMD_SET_OK;
}
...
Note
This only creates a 'setter'. Use GOS_CMD_CREATE_GETTER_SETTER to create both a 'getter' and 'setter'.
Parameters
componentThe name of the component that this command belows, e.g. my_app
nameThe name of the setter command, e.g. polling_period
keyThe command-line 'set' command option key, e.g. set my_app.polling_period
shortcutThe command-line 'set' command options shortcut, e.g. set ma p
argcThe minimum number of arguments this 'setter' accepts, typically this value is 1.
Examples:
system/custom_commands/main.c.

◆ GOS_CMD_EXECUTE_OK

#define GOS_CMD_EXECUTE_OK (   gos_result)    (gos_result == GOS_SUCCESS) ? GOS_CMD_EXECUTE_AOK : GOS_CMD_FAILED

Helper macro to return GOS_CMD_EXECUTE_AOK on GOS_SUCCESS else GOS_CMD_FAILED

◆ GOS_CMD_FAILED

#define GOS_CMD_FAILED (   result,
  func 
)    ((result = func) != GOS_CMD_SUCCESS)

Store the result of command util API call, return TRUE if API was successful, FALSE else

◆ GOS_CMD_PARSE_HEX_ARG

#define GOS_CMD_PARSE_HEX_ARG (   type,
  name,
  str,
  min,
  max 
)
Value:
type name;\
GOS_CMD_PARSE_HEX_ARG_WITH_VAR(type, name, str, min, max)

Utility macro to parse an hexadecimal argument and store in created variable.

Note
If parsing fails then then function returns with the value GOS_CMD_BAD_ARGS
Parameters
typeThe datatype of variable to create(e.g. uint32_t)
nameThe name of the variable to create
strHex string to parse
minMinimum value of the integer
maxMaximum value of the integer

◆ GOS_CMD_PARSE_HEX_ARG_WITH_VAR

#define GOS_CMD_PARSE_HEX_ARG_WITH_VAR (   type,
  var,
  str,
  min,
  max 
)
Value:
do {\
intmax_t __value;\
if(str_parse_hex(str, &__value, min, max) != GOS_SUCCESS) return GOS_CMD_BAD_ARGS;\
var = (type)__value;\
} while (0)
gos_result_t str_parse_hex(const char *s, intmax_t *result, intmax_t min, intmax_t max)
! Invalid command arguments
Definition: gos_cmd.h:214
Definition: gos_result.h:22

Utility macro to parse an hexadecimal argument and store in supplied variable.

Note
If parsing fails then then function returns with the value GOS_CMD_BAD_ARGS
Parameters
typeThe argument datatype (e.g. uint32_t)
varThe name of existing variable
strHex string to parse
minMinumum value of the integer
maxMaximum value of the integer

◆ GOS_CMD_PARSE_INT_ARG

#define GOS_CMD_PARSE_INT_ARG (   type,
  name,
  str,
  min,
  max 
)
Value:
type name;\
GOS_CMD_PARSE_INT_ARG_WITH_VAR(type, name, str, min, max)

Utility macro to parse an integer argument and store in created variable.

Note
If parsing fails then then function returns with the value GOS_CMD_BAD_ARGS
If the supplied string starts with 0x it will be parsed as HEX.
Parameters
typeThe datatype of variable to create(e.g. uint32_t)
nameThe name of the variable to create
strInteger string to parse
minMinumum value of the integer
maxMaximum value of the integer
Examples:
utility/buffer_dump/main.c.

◆ GOS_CMD_PARSE_INT_ARG_WITH_VAR

#define GOS_CMD_PARSE_INT_ARG_WITH_VAR (   type,
  var,
  str,
  min,
  max 
)
Value:
do {\
intmax_t __value;\
if(str_parse_int(str, &__value, min, max) != GOS_SUCCESS) return GOS_CMD_BAD_ARGS;\
var = (type)__value;\
} while (0)
gos_result_t str_parse_int(const char *s, intmax_t *result, intmax_t min, intmax_t max)
! Invalid command arguments
Definition: gos_cmd.h:214
Definition: gos_result.h:22

Utility macro to parse an integer argument and store in supplied variable.

Note
If parsing fails then then function returns with the value GOS_CMD_BAD_ARGS
If the supplied string starts with 0x it will be parsed as HEX.
Parameters
typeThe argument datatype (e.g. uint32_t)
varThe name of existing variable
strInteger string to parse
minMinumum value of the integer
maxMaximum value of the integer
Examples:
cloud/coap_demo/commands.c, cloud/mqtt_demo/mqtt_cli_commands.c, cloud/mqtt_demo/mqtt_cli_variables.c, demo/uart_blaster/commands.c, network/uart_tcp_client/variables.c, system/custom_commands/main.c, system/settings_file/main.c, and utility/buffer_dump/main.c.

◆ GOS_CMD_RESULT

#define GOS_CMD_RESULT (   gos_result)    ((gos_result) == GOS_SUCCESS) ? GOS_CMD_SUCCESS : GOS_CMD_FAILED

Helper macro to convert a gos_result_t to a gos_cmd_result_t

◆ GOS_CMD_SET_FAILED

#define GOS_CMD_SET_FAILED (   result,
  func 
)    ((result = func) != GOS_CMD_SET_OK)

Store the result of SET API call, return TRUE if API was successful, FALSE else

Examples:
demo/uart_blaster/commands.c.

◆ GOS_CMD_VERIFY

#define GOS_CMD_VERIFY (   gos_result)    if((gos_result) != GOS_SUCCESS) return GOS_CMD_FAILED

Helper macro to return GOS_CMD_FAILED if the Gecko OS API fails

◆ GOS_DEFINE_COMMAND

#define GOS_DEFINE_COMMAND (   component,
  name 
)    gos_cmd_result_t component ## _ ## name ## _command(int argc, char **argv)

◆ GOS_DEFINE_GETTER

#define GOS_DEFINE_GETTER (   component,
  name 
)    gos_cmd_result_t component ## _get_ ## name ## _command(int argc, char **argv)

Helper macro to define a getter's implementation

Examples:
cloud/mqtt_demo/mqtt_cli_variables.c, demo/uart_blaster/commands.c, and network/uart_tcp_client/variables.c.

◆ GOS_DEFINE_SETTER

#define GOS_DEFINE_SETTER (   component,
  name 
)    gos_cmd_result_t component ## _set_ ## name ## _command(int argc, char **argv)

Helper macro to define a getter's implementation

Examples:
cloud/mqtt_demo/mqtt_cli_variables.c, demo/uart_blaster/commands.c, and network/uart_tcp_client/variables.c.

◆ SC2

#define SC2 (   a1,
  a2,
 
)    GOS_CMD_SHORTCUT_ID2(a1, a2, b)

Helper function for creating a two item short, e.g.

get wlan.ssid -> get wl s -> SC2('w', 'l', 's')
Examples:
demo/uart_blaster/commands.c, network/uart_tcp_client/variables.c, system/custom_commands/main.c, and system/settings_file/main.c.

◆ SC3

#define SC3 (   a1,
  a2,
  b,
 
)    GOS_CMD_SHORTCUT_ID3(a1, a2, b, c)

Helper function for creating a three item short, e.g.

get wlan.powersave.mode -> get wl p m -> SC3('w', 'l', 'p','m')
Examples:
cloud/coap_demo/commands.c, cloud/mqtt_demo/mqtt_cli_variables.c, demo/uart_blaster/commands.c, network/uart_tcp_client/variables.c, and system/custom_commands/main.c.