Custom Commands

This contains all functionality needed to add/override commands to the ZentriOS Command API. More...

Modules

Types
Command types.
 
Macros
Command specific macros.
 

Functions

void zn_cmd_set_console_enabled (zos_bool_t enabled)
 Enable/disable the command serial console. More...
 
zos_result_t zn_cmd_register_commands (zos_cmd_lists_t *cmd_lists)
 Register commands::getters/setters serial commands. More...
 
zos_result_t zn_cmd_unregister_commands (zos_cmd_list_t *cmd_list)
 Unregister any previously registered command, getter or setter. More...
 
zos_result_t zn_cmd_start_response (zos_cmd_result_t cmd_result, size_t size)
 Begin printing a command response. More...
 
zos_result_t zn_cmd_write_response_data (const void *data, size_t data_size)
 Write the command response body. More...
 
zos_result_t zn_cmd_write_response (zos_cmd_result_t cmd_result, const void *data, size_t data_size)
 Write a complete command response. More...
 
zos_result_t zn_cmd_format_response (zos_cmd_result_t cmd_result, const char *fmt,...)
 Write formatted command response. More...
 
zos_result_t zn_cmd_format_vresponse (zos_cmd_result_t cmd_result, const char *fmt, va_list args)
 Write formatted command response. More...
 
zos_cmd_result_t zn_cmd_set_bool (int argc, char **argv, zos_bool_t *bool_val)
 Utility to parse a boolean argument and store to given pointer.
 
zos_cmd_result_t zn_cmd_set_flag (int argc, char **argv, uint32_t flag_mask, void *flag_ptr, uint8_t flag_width)
 Utility to parse flag argument and store to given pointer. More...
 
zos_cmd_result_t zn_cmd_set_int (int argc, char **argv, intmax_t *int_val, intmax_t min, intmax_t max)
 Utility to parse integer argument and store to given pointer. More...
 
zos_cmd_result_t zn_cmd_set_hex (int argc, char **argv, intmax_t *int_val, intmax_t min, intmax_t max)
 Utility to parse hex string and store to given pointer. More...
 
zos_cmd_result_t zn_cmd_set_encoded_str (int argc, char **argv, void *buffer, size_t max_len, size_t *saved_len)
 Utility to parse encoded string and save to given buffer.
 
zos_cmd_result_t zn_cmd_set_str (int argc, char **argv, char *buffer, size_t max_len)
 Utility to parse string and save to given buffer.
 
zos_result_t zn_cmd_read_write_data (size_t size, uint32_t read_timeout, void *user, zos_cmd_writer_t writer)
 Utility to read command bus and write data to writer argument. More...
 
zos_result_t zn_cmd_read_write_data_with_poll (size_t size, uint32_t read_timeout, void *user, zos_cmd_writer_t writer, zos_cmd_write_poller_t poller)
 Utility to read command bus and write data to writer argument. More...
 
zos_result_t zn_cmd_update_system_monitor (void)
 Update the system thread's system monitor. More...
 

Detailed Description

This contains all functionality needed to add/override commands to the ZentriOS Command API.

Function Documentation

zos_result_t zn_cmd_format_response ( zos_cmd_result_t  cmd_result,
const char *  fmt,
  ... 
)

Write formatted command response.

This will print the command header and supplied format string

Returns
zos_result_t result of api call
Examples:
cloud/cloud_filesystem/cloud_filesystem.c, cloud/mqttdemo/commands.c, cloud/s2cdemo/commands.c, demo/pong/commands.c, and demo/uart_blaster/commands.c.
zos_result_t zn_cmd_format_vresponse ( zos_cmd_result_t  cmd_result,
const char *  fmt,
va_list  args 
)

Write formatted command response.

This will print the command header and supplied format string

Returns
zos_result_t result of api call
zos_result_t zn_cmd_read_write_data ( size_t  size,
uint32_t  read_timeout,
void *  user,
zos_cmd_writer_t  writer 
)

Utility to read command bus and write data to writer argument.

If system.cmd.echo = 1 then characters are echoed to the command bus.

zos_result_t zn_cmd_read_write_data_with_poll ( size_t  size,
uint32_t  read_timeout,
void *  user,
zos_cmd_writer_t  writer,
zos_cmd_write_poller_t  poller 
)

Utility to read command bus and write data to writer argument.

If system.cmd.echo = 1 then characters are echoed to the command bus.

This has the same functionality as zn_cmd_read_write_data() with the additional option to poll the available write TX buffer before writing the data.

zos_result_t zn_cmd_register_commands ( zos_cmd_lists_t cmd_lists)

Register commands::getters/setters serial commands.

Note
Any duplicate command/getter/setter name overrides any previously registered name
Parameters
[in]cmd_listsLists of commands::getters/setters
Returns
zos_result_t result of api call
void zn_cmd_set_console_enabled ( zos_bool_t  enabled)

Enable/disable the command serial console.

When the command serial console is disabled, ZentriOS will not listen on the command bus for commands.

Parameters
[in]enabledEnable/disable serial command processing
Examples:
basic/ftp_upload/ftp_upload.c, basic/http_methods/main.c, and basic/uart/uart.c.
zos_cmd_result_t zn_cmd_set_flag ( int  argc,
char **  argv,
uint32_t  flag_mask,
void *  flag_ptr,
uint8_t  flag_width 
)

Utility to parse flag argument and store to given pointer.

zos_cmd_result_t zn_cmd_set_hex ( int  argc,
char **  argv,
intmax_t *  int_val,
intmax_t  min,
intmax_t  max 
)

Utility to parse hex string and store to given pointer.

zos_cmd_result_t zn_cmd_set_int ( int  argc,
char **  argv,
intmax_t *  int_val,
intmax_t  min,
intmax_t  max 
)

Utility to parse integer argument and store to given pointer.

zos_result_t zn_cmd_start_response ( zos_cmd_result_t  cmd_result,
size_t  size 
)

Begin printing a command response.

This will print a serial command response header.

Parameters
[in]cmd_resultThe result of the command
[in]sizeThe size in bytes of the command response
Returns
zos_result_t result of api call
zos_result_t zn_cmd_unregister_commands ( zos_cmd_list_t cmd_list)

Unregister any previously registered command, getter or setter.

Note
The address of cmd_list must be the same as the one specified in the pointers in cmd_lists
Parameters
[in]cmd_listList of commands::getter/setters
Returns
zos_result_t result of api call
zos_result_t zn_cmd_update_system_monitor ( void  )

Update the system thread's system monitor.

For long running commands, this should be periodically invoked so the system thread's system monitor does not trigger.

Note
The system thread's system monitor has a timeout of 30s so this should be invoke ~every 15s.
Returns
zos_result_t result of api call
zos_result_t zn_cmd_write_response ( zos_cmd_result_t  cmd_result,
const void *  data,
size_t  data_size 
)

Write a complete command response.

This will print the command header and supplied response data

Parameters
[in]cmd_resultThe result of the command
[in]dataResponse data
[in]data_sizeThe size in bytes of the command response
Returns
zos_result_t result of api call
zos_result_t zn_cmd_write_response_data ( const void *  data,
size_t  data_size 
)

Write the command response body.

This will print the supplied response data. This should be called until the specified number of bytes from zn_cmd_start_response() have been written. e.g.:

1 zn_cmd_start_response(CMD_SUCCESS, 20);
2 zn_cmd_write_response_data(data1, 10);
3 zn_cmd_write_response_data(data2, 10);
Parameters
[in]dataResponse data
[in]data_sizeThe size of command data to be written
Returns
zos_result_t result of api call