Settings interface
Interface files for utilising auto-generated settings files from the main thread and firmware modules.
Initialisation
Function int init_settings(void)
, initialises the settings module. It first initialises nvs storage system by calling int nvs_storage_init()
and upon success updates all values and settings from nvs storage by calling int update_all_from_nvs()
.
Settings are updated only if previousy stored in the nvs storage and if stored type is compatible with setting variable.
Parsing BLE and LoRa messages
Upon receiving new BLE or LoRa message in the main thread, message is parsed by calling int parse_message(uint8_t *message, uint8_t message_length)
function that takes message and its length as input parameters, then replaces message with response, if there is one, and returns response length. Upon error, negative error code is returned.
Message can consist of several stacked messages, however all need to be sent on the same port. In both BLE and LoRa messages, first message entry is sent port, based on which messages are parsed later on.
New message begins with ID, the length and number of bytes define by length. If length is 0, only message ID is needed for execution. Once new message is red, it is executed by passing it to int execute_message(uint8_t port, uint8_t id, uint8_t len, uint8_t data, uint8_t *response_message)
function.
Executing messages
Based on port number, message is treated as:
setting -
{setting_id, setting_len, setting[setting_len]}
if ID is valid, new value is stored to nvs and replaced in theMain_settings
structurevalues - currently only outgoing value messages are supported
command - commands are executed in
int execute_command_message(uint8_t port, uint8_t id, uint8_t len, uint8_t data, uint8_t *response_message)
function.
Command messages
execute_command_message
function, executes commands, based on theirs ID number, which are defined in commands_def.h auto-generated file. Currently the following are supported:
CMD_RESET - system reboot
CMD_SEND_SINGLE_VAL - returns response message of the form
{val_id, val_len, val[val_len]}
.CMD_SEND_ALL_VAL - return a string of single values, containing all supported values, of total max message length
CMD_SEND_STATUS - returns status message. See Status chapter for detailed description.
CMD_SEND_POSITION - returns gps coordinates values.
Response message
After execute_message
returns length of the response, non-zero responses are stacked in single response message, thath is returend via approprite port, determined in execute_message
function. New port is stored as a first entry of final response. parse_message
returns length of the response message or negative error code.
Last updated