App Utility#

The App BT Mesh Utility provides collection of stateless utility functions and macros to solve recurring tasks in the BT Mesh components and examples. This component supports logging of missing application key binding and missing model publication data configuration errors. The logging level of these errors are configurable. This component is suitable for use in both NCP and SOC applications.

Functions#

sl_status_t
sl_status_t
app_btmesh_nvm_read(uint16_t key, void *buf, size_t *len)
sl_status_t
app_btmesh_nvm_write(uint16_t key, const void *buf, size_t len)
sl_status_t
app_btmesh_nvm_erase(uint16_t key)
sl_status_t
const char *
app_btmesh_uuid_64_to_string(char *buffer, uint32_t buffer_size, const sl_bt_uuid_64_t *uuid_64, char separator, bool uppercase)
const char *
app_btmesh_bytes_to_hex(char *buffer, uint32_t buffer_size, const uint8_t *bytes, uint32_t bytes_size, char separator, bool uppercase)

Macros#

#define
app_btmesh_util_log_status_f (sc, ...)

Logs the btmesh API failures.

#define
APP_BTMESH_UTIL_COMPONENT_LOGGING undefined

This macro calculates the number of precompile logging enable request in the specific c file where the this header file is included from

#define
log_nl ()
#define
log (...)
#define
log_level (level, ...)
#define
log_debug (...)
#define
log_info (...)
#define
log_warning (...)
#define
log_error (...)
#define
log_critical (...)
#define
log_append (...)
#define
log_append_level (level, ...)
#define
log_append_debug (...)
#define
log_append_info (...)
#define
log_append_warning (...)
#define
log_append_error (...)
#define
log_append_critical (...)
#define
log_status_debug (sc)
#define
log_status_info (sc)
#define
log_status_warning (sc)
#define
log_status_error (sc)
#define
log_status_critical (sc)
#define
log_status_debug_f (sc, ...)
#define
log_status_info_f (sc, ...)
#define
log_status_warning_f (sc, ...)
#define
log_status_error_f (sc, ...)
#define
log_status_critical_f (sc, ...)
#define
log_status (sc)
#define
log_status_level (level, sc)
#define
log_status_f (sc, ...)
#define
log_status_level_f (level, sc, ...)
#define
log_btmesh_status_f (sc, ...)
#define
log_hexdump_debug (p_data, len)
#define
log_hexdump_info (p_data, len)
#define
log_hexdump_warning (p_data, len)
#define
log_hexdump_error (p_data, len)
#define
log_hexdump_critical (p_data, len)
#define
log_hexdump_level (level, p_data, len)
#define
log_hexdump_debug_s (separator, p_data, len)
#define
log_hexdump_info_s (separator, p_data, len)
#define
log_hexdump_warning_s (separator, p_data, len)
#define
log_hexdump_error_s (separator, p_data, len)
#define
log_hexdump_critical_s (separator, p_data, len)
#define
log_hexdump_level_s (level, separator, p_data, len)
#define
APP_BTMESH_UUID_64_STR_MAX_SIZE 24

Maximum size of UUID64 string representation with separators (including null char)

#define
NL APP_LOG_NL
#define
APP_BTMESH_UUID_64_TO_STRING (uuid_64, separator, uppercase)

Provides string representation of UUID64 in a compound literal

It is guaranteed that this macro returns a valid string even in case of invalid parameters.

Warnings

  • This macro calls app_btmesh_uuid_64_to_string function with a compound literal which means the lifetime of returned string representation is the same as the enclosing block so the return value shall not be referenced outside of the most enclosing block where this macro is called from. For example the macro value shall not be returned from the caller function.

This macro can be used in printf-like calls (e.g. log calls) directly because it returns a string under every circumstances and the lifetime of compound literal is not problematic if the value is passed as a parameter directly to another function.

Returns

  • String representation of UUID64 which has enclosing block lifetime

#define
SL_PROG_TO_PCT (_target, _progress)

Convert progress into percentage, based on target and current values

#define
SL_PROG_TO_PCT_INT (_target, _progress)

Convert progress into percentage, based on target and current values

#define
SL_ARRAY_LENGTH (array)

Calculates how many elements an array contains

#define
SLI_SILABS_CID_INT 0x02FF

Silicon Laboratories Company ID as integer

#define
SLI_SILABS_CID_STR_LE "\xFF\x02"

Silicon Laboratories Company ID as little-endian string

#define
SLI_SILABS_CID_STR_BE "\x02\xFF"

Silicon Laboratories Company ID as big-endian string

Function Documentation#

app_btmesh_nvm_init#

sl_status_t app_btmesh_nvm_init (void )
Parameters
TypeDirectionArgument NameDescription
voidN/A

Initializes the NVM interface.

Calls the default initializer of NVM3.

Returns

  • Status code

Return values

  • SL_STATUS_OK: In case of success

  • SL_STATUS_ALREADY_INITIALIZED: In case it was initialized earlier with parameters different from default


app_btmesh_nvm_read#

sl_status_t app_btmesh_nvm_read (uint16_t key, void * buf, size_t * len)
Parameters
TypeDirectionArgument NameDescription
uint16_t[in]key

Identifier of the data.

void *[out]buf

Buffer to the data to read.

size_t *[inout]len

Pointer to the length of the read data. As in input it takes the length of buffer. As an output it contains the length of the read data.

Reads data from NVM.

Returns

  • Status code

Return values

  • SL_STATUS_OK: In case of success

  • SL_STATUS_INVALID_STATE: In case NVM has not been initialized

  • SL_STATUS_INVALID_KEY: In case key is invalid

  • SL_STATUS_NOT_FOUND: In case key has not been found

  • SL_STATUS_INVALID_PARAMETER: In case any of the input parameters is invalid


app_btmesh_nvm_write#

sl_status_t app_btmesh_nvm_write (uint16_t key, const void * buf, size_t len)
Parameters
TypeDirectionArgument NameDescription
uint16_t[in]key

Identifier of the data.

const void *[in]buf

Buffer to the data to write.

size_t[in]len

Length of the data in the buffer.

Writes data into the NVM.

Returns

  • Status code

Return values

  • SL_STATUS_OK: In case of success

  • SL_STATUS_INVALID_STATE: In case NVM has not been initialized

  • SL_STATUS_FULL: In case NVM is full

  • SL_STATUS_NO_MORE_RESOURCE: In case NVM doesn't have the resources to store the data

  • SL_STATUS_FLASH_PROGRAM_FAILED: In case writing to NVM has failed

  • SL_STATUS_INVALID_PARAMETER: In case any of the input parameters is invalid


app_btmesh_nvm_erase#

sl_status_t app_btmesh_nvm_erase (uint16_t key)
Parameters
TypeDirectionArgument NameDescription
uint16_t[in]key

Identifier of the data.

Erases data from NVM.

Returns

  • Status code

Return values

  • SL_STATUS_OK: In case of success

  • SL_STATUS_INVALID_STATE: In case NVM has not been initialized

  • SL_STATUS_INVALID_KEY: In case key is invalid

  • SL_STATUS_NOT_FOUND: In case key has not been found

  • SL_STATUS_FLASH_PROGRAM_FAILED: In case writing to NVM has failed

  • SL_STATUS_INVALID_PARAMETER: In case any of the input parameters is invalid


app_btmesh_nvm_erase_all#

sl_status_t app_btmesh_nvm_erase_all (void )
Parameters
TypeDirectionArgument NameDescription
voidN/A

Erases all NVM data.

Returns

  • Status code

Return values

  • SL_STATUS_OK: In case of success

  • SL_STATUS_INVALID_STATE: In case NVM has not been initialized

  • SL_STATUS_INVALID_PARAMETER: In case any of the input parameters is invalid


app_btmesh_uuid_64_to_string#

const char * app_btmesh_uuid_64_to_string (char * buffer, uint32_t buffer_size, const sl_bt_uuid_64_t * uuid_64, char separator, bool uppercase)
Parameters
TypeDirectionArgument NameDescription
char *[out]buffer

Output buffer where the string representation is written

uint32_t[in]buffer_size

Size of output buffer

const sl_bt_uuid_64_t *[in]uuid_64

Input UUID64 which shall be converted to string

char[in]separator

Separator character to be used between two hex characters. If the separator is the null character then no separator is used.

bool[in]uppercase

If true hex characters are upper case otherwise lower case

Provides string representation of UUID64

It is guaranteed that this function returns a valid string even in case of invalid parameters.

Returns

  • Output buffer which contains the string representation of UUID64

Return values

  • INVALID: if an error occurs due to invalid parameters


app_btmesh_bytes_to_hex#

const char * app_btmesh_bytes_to_hex (char * buffer, uint32_t buffer_size, const uint8_t * bytes, uint32_t bytes_size, char separator, bool uppercase)
Parameters
TypeDirectionArgument NameDescription
char *[out]buffer

Output buffer where the hex representation is written

uint32_t[in]buffer_size

Size of output buffer

const uint8_t *[in]bytes

Input byte array which shall be converted to hex

uint32_t[in]bytes_size

Size of input byte array

char[in]separator

Separator character to be used between two hex characters. If the separator is the null character then no separator is used.

bool[in]uppercase

If true hex characters are upper case otherwise lower case

Provides hex representation of byte array as a string

It is guaranteed that this function returns a valid string even in case of invalid parameters.

Returns

  • Output buffer which contains the hex representation of byte array

Return values

  • INVALID: if an error occurs due to invalid parameters