![]() |
Wirepas SDK
|
Application library for viewing and controlling stack runtime state
Library services are accessed via lib_state handle.
Definition in file state.h.
Go to the source code of this file.
Typedefs | |
| typedef void(* | app_lib_state_on_scan_nbors_cb_f) (void) |
| Function type for a neighbor scan completion callback. More... | |
| typedef void(* | app_lib_state_on_beacon_cb_f) (const app_lib_state_beacon_rx_t *beacon) |
| Function type for a beacon reception callback. More... | |
| typedef app_res_e(* | app_lib_state_start_stack_f) (void) |
| Start the stack. More... | |
| typedef app_res_e(* | app_lib_state_stop_stack_f) (void) |
| Stop the stack. More... | |
| typedef uint8_t(* | app_lib_state_get_stack_state_f) (void) |
| Get the stack state. More... | |
| typedef uint8_t(* | app_lib_state_get_route_count_f) (size_t *count_p) |
| Get the number of routes this node has to a sink. More... | |
| typedef uint16_t(* | app_lib_state_get_diag_interval_f) (void) |
| Get diagnostics interval. More... | |
| typedef app_res_e(* | app_lib_state_get_access_cycle_f) (uint16_t *ac_value_p) |
| Get current access cycle. More... | |
| typedef app_res_e(* | app_lib_state_set_on_scan_nbors_with_type_cb_f) (app_lib_state_on_scan_nbors_cb_f cb, app_lib_state_scan_nbors_type_e type) |
| Set a callback to be called when neighbor scan is complete. More... | |
| typedef app_res_e(* | app_lib_state_start_scan_nbors_f) (void) |
| Start neighbor scan. More... | |
| typedef app_res_e(* | app_lib_state_get_nbors_f) (app_lib_state_nbor_list_t *nbors_list) |
| Get list of neighbors. More... | |
| typedef app_res_e(* | app_lib_state_set_on_beacon_cb_f) (app_lib_state_on_beacon_cb_f cb) |
| Set a callback to be called when a beacon is received. More... | |
| typedef app_res_e(* | app_lib_state_get_energy_f) (uint8_t *energy_p) |
| Get available energy. More... | |
| typedef app_res_e(* | app_lib_state_set_energy_f) (uint8_t energy) |
| Set available energy. More... | |
| typedef app_res_e(* | app_lib_state_get_sink_cost_f) (uint8_t *cost_p) |
| Query the currently set additional penalty for the sink usage. More... | |
| typedef app_res_e(* | app_lib_state_set_sink_cost_f) (const uint8_t cost) |
| Set additional penalty for the sink usage. More... | |
| typedef void(* | app_lib_state_route_changed_cb_f) (void) |
| Callback when route is changed. More... | |
| typedef app_res_e(* | app_lib_state_get_route_f) (app_lib_state_route_info_t *info) |
| Get route information. More... | |
| typedef app_res_e(* | app_lib_state_set_route_cb_f) (const app_lib_state_route_changed_cb_f cb, uint32_t unused) |
| Set callback for route change notification. More... | |
| typedef uint8_t(* | app_lib_state_adjust_hops_cb_f) (const app_lib_state_hops_adjust_t *info) |
| Function type for a adjusting hops left. More... | |
| typedef app_res_e(* | app_lib_state_set_adjust_hops_cb_f) (app_lib_state_adjust_hops_cb_f cb) |
| Set a callback to be called when rerouting packet and querying if 'hops left' should be modified (i.e. limiting the propagation of packet further) More... | |
| typedef app_res_e(* | app_lib_state_set_scan_dur_f) (uint32_t duration_us) |
| Set scan duration to be used. More... | |
| typedef app_res_e(* | app_lib_state_scan_stop_f) (void) |
| Stops ongoing scan operation before ended. More... | |
| typedef app_res_e(* | app_lib_state_get_install_quality_f) (app_lib_state_install_quality_t *qual_out) |
| Read installation quality, app_lib_state_install_quality_t. More... | |
Data Structures | |
| struct | app_lib_state_nbor_info_t |
| Neighbors info definition. More... | |
| struct | app_lib_state_nbor_list_t |
| Neighbors list definition. More... | |
| struct | app_lib_state_beacon_rx_t |
| Structure to hold the information about received beacons. More... | |
| struct | app_lib_state_hops_adjust_t |
| Structure for adjusting hops. More... | |
| struct | app_lib_state_route_info_t |
| Structure for route information. More... | |
| struct | app_lib_state_install_quality_t |
| Installation quality information. Contains information about the nodes installation location i.e. its quality indicated by a numeric value, as well as error codes if something is wrong with the location. More... | |
| struct | app_lib_state_t |
| List of library functions of v3 version (0x202) More... | |
Macros | |
| #define | APP_LIB_STATE_NAME 0x02f9c165 |
| Library symbolic name. More... | |
| #define | APP_LIB_STATE_VERSION 0x20A |
| Maximum supported library version. More... | |
| #define | APP_LIB_STATE_INVALID_ROUTE_COST UINT8_MAX |
| Macro for cost indicating "no route". Used in cost component in lib_state->getNbors() service. More... | |
| #define | APP_LIB_STATE_COST_UNKNOWN 0 |
| Macro for cost being unknown. Used in cost component in lib_state->getNbors() service. More... | |
| #define | APP_LIB_STATE_LINKREL_UNKNOWN 0 |
| Macro for link reliability being unknown. Used in link reliability component in lib_state->getNbors() service. More... | |
| #define | APP_LIB_STATE_DEFAULT_SCAN 0 |
| Macro for using with lib_state->setScanDuration() to disable custom scan duration and use stack default scan duration. More... | |
| typedef uint8_t(* app_lib_state_adjust_hops_cb_f) (const app_lib_state_hops_adjust_t *info) |
Function type for a adjusting hops left.
| info | Info about packet that is rerouted |
Usage: see documentation on lib_state->setHopsLeftCb() on how to use this callback.
| typedef app_res_e(* app_lib_state_get_access_cycle_f) (uint16_t *ac_value_p) |
Get current access cycle.
| ac_value_p | Pointer to store the current access cycle value in milliseconds Updated if return code is APP_RES_OK |
| typedef uint16_t(* app_lib_state_get_diag_interval_f) (void) |
| typedef app_res_e(* app_lib_state_get_energy_f) (uint8_t *energy_p) |
Get available energy.
| energy_p | Pointer to store the available energy as a proportional value from 0 to 255 |
| typedef app_res_e(* app_lib_state_get_install_quality_f) (app_lib_state_install_quality_t *qual_out) |
Read installation quality, app_lib_state_install_quality_t.
| qual_out | [out] The installation quality information is copied to this pointer |
| typedef app_res_e(* app_lib_state_get_nbors_f) (app_lib_state_nbor_list_t *nbors_list) |
Get list of neighbors.
| nbors_list | Pointer to store the information of list of neighbors. |
This service can be used to tell the status of a node's neighbors. This information may be used for various purposes, for example to estimate where a node is located.
Example:
| typedef uint8_t(* app_lib_state_get_route_count_f) (size_t *count_p) |
Get the number of routes this node has to a sink.
| count_p | Pointer to store the result. Whenever there is a route to sink, value is 1, otherwise 0. |
Example:
| typedef app_res_e(* app_lib_state_get_route_f) (app_lib_state_route_info_t *info) |
Get route information.
| info | [out] Route information is provided here |
| typedef app_res_e(* app_lib_state_get_sink_cost_f) (uint8_t *cost_p) |
Query the currently set additional penalty for the sink usage.
| cost_p | Pointer to store the current initial cost |
cost_p is NULLExample:
| typedef uint8_t(* app_lib_state_get_stack_state_f) (void) |
Get the stack state.
Service indicates whether the stack is running or not, and whether it can be started.
Example:
| typedef void(* app_lib_state_on_beacon_cb_f) (const app_lib_state_beacon_rx_t *beacon) |
| typedef void(* app_lib_state_on_scan_nbors_cb_f) (void) |
| typedef void(* app_lib_state_route_changed_cb_f) (void) |
Callback when route is changed.
Used with app_lib_state_set_route_cb_f Function prototype for a route information changed callback. The stack invokes this callback whenever anything in the route information structure has changed. This can be utilized to wake up the application to reach such information. Do not read the route information directly in this callback's context.
| typedef app_res_e(* app_lib_state_scan_stop_f) (void) |
Stops ongoing scan operation before ended.
This service aborts ongoing scan operation started with lib_state->startScanNbors().
| typedef app_res_e(* app_lib_state_set_adjust_hops_cb_f) (app_lib_state_adjust_hops_cb_f cb) |
Set a callback to be called when rerouting packet and querying if 'hops left' should be modified (i.e. limiting the propagation of packet further)
| cb | Callback function to be called when querying hops left adjusting. NULL to disable callback function. |
The mechanism is intended to be used with 'local multicast groups'. Then, the propagation of packet is limited to the edge of the multicast group. If following assumptions apply, this can be done: 1) Multicast group X is 'concise', i.e. ALL devices that belong to multicast group X are close to each other. 2) There are no devices that do not belong to multicast group X 'in middle' of multicast group X 3) Originator of the command is close to multicast group X.
If these apply, then following can be done:
If packet is transmitted to group X but routing device does NOT belong to this group, decrease hops left value. Note: do not set it immediately to 0 because that would lead to reliability problems at the edge of the group
Example:
| typedef app_res_e(* app_lib_state_set_energy_f) (uint8_t energy) |
Set available energy.
| energy | Available energy as a proportional value from 0 to 255
|
| typedef app_res_e(* app_lib_state_set_on_beacon_cb_f) (app_lib_state_on_beacon_cb_f cb) |
Set a callback to be called when a beacon is received.
| cb | The function to be executed, or NULL to unset |
| typedef app_res_e(* app_lib_state_set_on_scan_nbors_with_type_cb_f) (app_lib_state_on_scan_nbors_cb_f cb, app_lib_state_scan_nbors_type_e type) |
Set a callback to be called when neighbor scan is complete.
| cb | The function to be executed, or NULL to unset |
| type | The type of scan event app is interested (Unused if cb is NULL) |
Example:
| typedef app_res_e(* app_lib_state_set_route_cb_f) (const app_lib_state_route_changed_cb_f cb, uint32_t unused) |
Set callback for route change notification.
When route information changes, the application is notified via this handle.
| cb | Callback called on route change |
| unused | Unused parameter, always set to 0 |
| typedef app_res_e(* app_lib_state_set_scan_dur_f) (uint32_t duration_us) |
Set scan duration to be used.
| duration_us | Scan duration in microseconds. If duration_us is APP_LIB_STATE_DEFAULT_SCAN, use default-length value and perform similar length as standard stack scan operation |
Example:
| typedef app_res_e(* app_lib_state_set_sink_cost_f) (const uint8_t cost) |
Set additional penalty for the sink usage.
This service can be used to inform the sink that the backend communication has problems. In order to keep the entire network operational, other nodes can be forced to use other sinks with working backend communication
| cost | Value of 0 means that connection is good and no additional penalty is sent to sink usage. Value of 254 includes maximum penalty |
Example on use:
| typedef app_res_e(* app_lib_state_start_scan_nbors_f) (void) |
Start neighbor scan.
This service can be used by the application to get fresh information about neighbors. Application can trigger to measurement all neighbors and once the measurement is done, application is informed it over API (see lib_state->setOnScanNborsCb service).
Example:
| typedef app_res_e(* app_lib_state_start_stack_f) (void) |
Start the stack.
This is most commonly used in the end of the App_init() function to start the radio operation.
Example:
In order to start, the stack needs minimum of four following attributes to be configured: device role, device address, network address and network channel. These attributes can be set by the application thanks to the Single-MCU API during the initialization step. Device role, network address and network channel can be hardcoded in the application image.
| typedef app_res_e(* app_lib_state_stop_stack_f) (void) |
Stop the stack.
Example:
| struct app_lib_state_nbor_info_t |
| Data Fields | ||
|---|---|---|
| uint32_t | address |
Address of the neighbor node |
| uint8_t | channel |
Radio channel used by the neighbor |
| uint8_t | cost |
Route cost to the sink via this neighbor. Value of APP_LIB_STATE_INVALID_ROUTE_COST indicates that a neighbor has no route to a sink. Value of APP_LIB_STATE_COST_UNKNOWN states that cost is unknown for this neighbor. |
| uint8_t | diradv_support |
Is directed advertiser supported, app_lib_state_diradv_support_e |
| uint16_t | last_update |
Aount of seconds since these values were last updated. |
| uint8_t | link_reliability |
Link reliability to the neighboring node. Scaled so that 0 = 0 %, 255 = 100 %. Value of APP_LIB_STATE_LINKREL_UNKNOWN tells that link reliability to this neighbor is unknown. |
| int8_t | norm_rssi |
Received signal strength, compensated with transmission power, i.e. this value answers the question "what would the RSSI be, if the neighbor transmits with its maximum TX power". Larger value means better signal.
|
| int8_t | rx_power |
Transmission power used when neighbor sending to this device
|
| int8_t | tx_power |
Transmission power used when sending to neighbor.
|
| uint8_t | type |
Type of the neighbor. app_lib_state_nbor_type_e |
| struct app_lib_state_nbor_list_t |
| Data Fields | ||
|---|---|---|
| app_lib_state_nbor_info_t * | nbors |
Information of neighbors received |
| uint32_t | number_nbors |
Input: Maximum amount of neighbors in nbors field. Output: Amount of neighbors filled |
| struct app_lib_state_beacon_rx_t |
Structure to hold the information about received beacons.
| Data Fields | ||
|---|---|---|
| app_addr_t | address | Address of the beacon sender. |
| uint8_t | cost | Cost of the device. 255==no route. |
| bool | is_da_support | Sender supports Directed Advertiser sending packets to it. |
| bool | is_ll | Device is LL. |
| bool | is_sink | Device is sink. |
| int8_t | rssi |
RSSI in dBm. Larger value means better signal.
|
| int8_t | txpower | Tx power in dB This equals maximum transmission power that sender can transmit (which is used when transmitting beacons) |
| uint8_t | type | Type of beacon app_lib_state_nbor_type_e. |
| struct app_lib_state_hops_adjust_t |
| Data Fields | ||
|---|---|---|
| app_addr_t | address |
Target address of the packet (multicast group, with APP_ADDR_MULTICAST bitmask set) |
| uint8_t | hops_left | Amount of hops left in this data packet. |
| struct app_lib_state_route_info_t |
| Data Fields | ||
|---|---|---|
| app_lib_settings_net_channel_t | channel |
Next hop's (logical) data (cluster) channel or 0 if no valid route |
| uint8_t | cost |
Route cost or APP_LIB_STATE_INVALID_ROUTE_COST if no valid route |
| app_addr_t | next_hop |
Next hop's unicast address or 0 if no valid route |
| app_addr_t | sink |
Sink's unicast address or 0 if no valid route |
| app_lib_state_route_state_e | state |
Route state: invalid, pending or valid |
| struct app_lib_state_install_quality_t |
Installation quality information. Contains information about the nodes installation location i.e. its quality indicated by a numeric value, as well as error codes if something is wrong with the location.
For more detailed information about the value(s) presented here, see application note about installation quality API, document reference: AN-XXX
| Data Fields | ||
|---|---|---|
| uint8_t | error_codes |
Error codes, install_quality_error_code_e |
| uint8_t | quality |
Quality reported as u8. Limits are as follows: Quality >= 127 : Good installation 127 > Quality > 63 : Average installation Quality <= 63 : Bad installation |
| struct app_lib_state_t |
| Data Fields | ||
|---|---|---|
| app_lib_state_get_access_cycle_f | getAccessCycle | |
| app_lib_state_get_diag_interval_f | getDiagInterval | |
| app_lib_state_get_energy_f | getEnergy | |
| app_lib_state_get_install_quality_f | getInstallQual | |
| app_lib_state_get_nbors_f | getNbors | |
| app_lib_state_get_route_count_f | getRouteCount | |
| app_lib_state_get_route_f | getRouteInfo | |
| app_lib_state_get_sink_cost_f | getSinkCost | |
| app_lib_state_get_stack_state_f | getStackState | |
| app_lib_state_set_energy_f | setEnergy | |
| app_lib_state_set_adjust_hops_cb_f | setHopsLeftCb | |
| app_lib_state_set_on_beacon_cb_f | setOnBeaconCb | |
| app_lib_state_set_on_scan_nbors_with_type_cb_f | setOnScanNborsCb | |
| app_lib_state_set_route_cb_f | setRouteCb | |
| app_lib_state_set_scan_dur_f | setScanDuration | |
| app_lib_state_set_sink_cost_f | setSinkCost | |
| app_lib_state_start_scan_nbors_f | startScanNbors | |
| app_lib_state_start_stack_f | startStack | |
| app_lib_state_scan_stop_f | stopScanNbors | |
| app_lib_state_stop_stack_f | stopStack | |
Type for beacons, passed in app_lib_state_beacon_rx_t.
| Enumerator | |
|---|---|
| APP_LIB_STATE_BEACON_TYPE_NB | Network beacon. |
| APP_LIB_STATE_BEACON_TYPE_CB | Cluster beacon. |
Definition at line 193 of file state.h.
Support type for directed advertiser, i.e. does neighbor support sending directed advertiser packets to it.
Definition at line 80 of file state.h.
Neighbor type.
Definition at line 65 of file state.h.
Scan neighbor type to specify the scans that trigger the callback.
Definition at line 93 of file state.h.
Stack state flags.
Definition at line 167 of file state.h.
Error codes for installation quality, if an error code is active, corrective action regarding the installation location is required.
Definition at line 265 of file state.h.
| #define APP_LIB_STATE_COST_UNKNOWN 0 |
Macro for cost being unknown. Used in cost component in lib_state->getNbors() service.
| #define APP_LIB_STATE_DEFAULT_SCAN 0 |
Macro for using with lib_state->setScanDuration() to disable custom scan duration and use stack default scan duration.
| #define APP_LIB_STATE_INVALID_ROUTE_COST UINT8_MAX |
Macro for cost indicating "no route". Used in cost component in lib_state->getNbors() service.
| #define APP_LIB_STATE_LINKREL_UNKNOWN 0 |
Macro for link reliability being unknown. Used in link reliability component in lib_state->getNbors() service.
| #define APP_LIB_STATE_NAME 0x02f9c165 |