Wirepas SDK
state.h
Go to the documentation of this file.
1 /* Copyright 2017 Wirepas Ltd. All Rights Reserved.
2  *
3  * See file LICENSE.txt for full license details.
4  *
5  */
6 
15 #ifndef APP_LIB_STATE_H_
16 #define APP_LIB_STATE_H_
17 
18 #include <stdlib.h>
19 #include <stdint.h>
20 #include <stdbool.h>
21 #include <limits.h>
22 
23 #include "app/app.h"
24 #include "settings.h" // For app_lib_settings_net_channel_t
25 
27 #define APP_LIB_STATE_NAME 0x02f9c165
28 
29 
30 #define APP_LIB_STATE_VERSION 0x20A
31 
37 #define APP_LIB_STATE_INVALID_ROUTE_COST UINT8_MAX
38 
44 #define APP_LIB_STATE_COST_UNKNOWN 0
45 
51 #define APP_LIB_STATE_LINKREL_UNKNOWN 0
52 
58 #define APP_LIB_STATE_DEFAULT_SCAN 0
59 
65 typedef enum
66 {
75 
80 typedef enum
81 {
89 
93 typedef enum
94 {
101 
105 typedef struct
106 {
108  uint32_t address;
110  uint16_t last_update;
125  int8_t norm_rssi;
130  uint8_t cost;
132  uint8_t channel;
134  uint8_t type;
140  int8_t tx_power;
146  int8_t rx_power;
148  uint8_t diradv_support;
150 
154 typedef struct
155 {
159  uint32_t number_nbors;
163 
167 typedef enum
168 {
179 
183 typedef enum
184 {
189 
193 typedef enum
194 {
198 
202 typedef struct
203 {
205 
216  int8_t rssi;
222  int8_t txpower;
223  bool is_sink;
224  bool is_ll;
225  uint8_t cost;
226  uint8_t type;
227 
232 
236 typedef struct
237 {
241  uint8_t hops_left;
243 
247 typedef struct
248 {
258  uint8_t cost;
260 
265 typedef enum
266 {
276 
287 typedef struct
288 {
293  uint8_t quality;
295  uint8_t error_codes;
297 
301 typedef void (*app_lib_state_on_scan_nbors_cb_f)(void);
302 
308 typedef void (*app_lib_state_on_beacon_cb_f)
309  (const app_lib_state_beacon_rx_t * beacon);
310 
340 
358 
372 typedef uint8_t (*app_lib_state_get_stack_state_f)(void);
373 
388 typedef uint8_t (*app_lib_state_get_route_count_f)(size_t * count_p);
389 
394 typedef uint16_t (*app_lib_state_get_diag_interval_f)(void);
395 
404 typedef app_res_e (*app_lib_state_get_access_cycle_f)(uint16_t * ac_value_p);
405 
430 
449 
475 
482 typedef app_res_e
484 
494 typedef app_res_e (*app_lib_state_get_energy_f)(uint8_t * energy_p);
495 
509 typedef app_res_e (*app_lib_state_set_energy_f)(uint8_t energy);
510 
525 typedef app_res_e (*app_lib_state_get_sink_cost_f)(uint8_t * cost_p);
526 
546 typedef app_res_e (*app_lib_state_set_sink_cost_f)(const uint8_t cost);
547 
558 typedef void (*app_lib_state_route_changed_cb_f)(void);
559 
568 
581  (const app_lib_state_route_changed_cb_f cb, uint32_t unused);
582 
595 typedef uint8_t (*app_lib_state_adjust_hops_cb_f)
597 
662 
695 typedef app_res_e (*app_lib_state_set_scan_dur_f)(uint32_t duration_us);
696 
709 
718 
722 typedef struct
723 {
745 
746 #endif /* APP_LIB_STATE_H_ */
app_lib_state_nbor_list_t::number_nbors
uint32_t number_nbors
Definition: state.h:159
app_lib_state_t::setEnergy
app_lib_state_set_energy_f setEnergy
Definition: state.h:735
app_lib_state_on_scan_nbors_cb_f
void(* app_lib_state_on_scan_nbors_cb_f)(void)
Function type for a neighbor scan completion callback.
Definition: state.h:301
app_lib_state_nbor_info_t::rx_power
int8_t rx_power
Definition: state.h:146
app_lib_state_get_access_cycle_f
app_res_e(* app_lib_state_get_access_cycle_f)(uint16_t *ac_value_p)
Get current access cycle.
Definition: state.h:404
APP_LIB_STATE_NEIGHBOR_IS_CLUSTER
@ APP_LIB_STATE_NEIGHBOR_IS_CLUSTER
Definition: state.h:73
APP_LIB_STATE_NETWORK_ADDRESS_NOT_SET
@ APP_LIB_STATE_NETWORK_ADDRESS_NOT_SET
Network address is not set.
Definition: state.h:172
app_lib_state_set_on_scan_nbors_with_type_cb_f
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.
Definition: state.h:429
app_lib_state_t::setHopsLeftCb
app_lib_state_set_adjust_hops_cb_f setHopsLeftCb
Definition: state.h:740
app_lib_state_t::setRouteCb
app_lib_state_set_route_cb_f setRouteCb
Definition: state.h:739
settings.h
app_lib_state_get_route_count_f
uint8_t(* app_lib_state_get_route_count_f)(size_t *count_p)
Get the number of routes this node has to a sink.
Definition: state.h:388
app_lib_state_beacon_rx_t::txpower
int8_t txpower
Tx power in dB This equals maximum transmission power that sender can transmit (which is used when tr...
Definition: state.h:222
app_lib_state_t::setScanDuration
app_lib_state_set_scan_dur_f setScanDuration
Definition: state.h:741
app_lib_state_hops_adjust_t::hops_left
uint8_t hops_left
Amount of hops left in this data packet.
Definition: state.h:241
app_lib_state_get_nbors_f
app_res_e(* app_lib_state_get_nbors_f)(app_lib_state_nbor_list_t *nbors_list)
Get list of neighbors.
Definition: state.h:474
APP_LIB_STATE_SCAN_NBORS_ALL
@ APP_LIB_STATE_SCAN_NBORS_ALL
Definition: state.h:96
app_lib_state_start_stack_f
app_res_e(* app_lib_state_start_stack_f)(void)
Start the stack.
Definition: state.h:339
app_lib_state_beacon_rx_t
Structure to hold the information about received beacons.
Definition: state.h:202
APP_LIB_STATE_DIRADV_NOT_SUPPORTED
@ APP_LIB_STATE_DIRADV_NOT_SUPPORTED
Definition: state.h:85
app_lib_state_on_beacon_cb_f
void(* app_lib_state_on_beacon_cb_f)(const app_lib_state_beacon_rx_t *beacon)
Function type for a beacon reception callback.
Definition: state.h:309
app_lib_state_set_sink_cost_f
app_res_e(* app_lib_state_set_sink_cost_f)(const uint8_t cost)
Set additional penalty for the sink usage.
Definition: state.h:546
app_lib_state_route_state_e
app_lib_state_route_state_e
Route state.
Definition: state.h:183
app_lib_state_install_quality_t::quality
uint8_t quality
Definition: state.h:293
APP_LIB_STATE_DIRADV_UNKNOWN
@ APP_LIB_STATE_DIRADV_UNKNOWN
Definition: state.h:87
app_lib_state_route_changed_cb_f
void(* app_lib_state_route_changed_cb_f)(void)
Callback when route is changed.
Definition: state.h:558
app_lib_state_get_install_quality_f
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.
Definition: state.h:717
APP_LIB_STATE_NODE_ADDRESS_NOT_SET
@ APP_LIB_STATE_NODE_ADDRESS_NOT_SET
Node address is not set.
Definition: state.h:171
app_lib_state_t::getRouteCount
app_lib_state_get_route_count_f getRouteCount
Definition: state.h:727
APP_LIB_STATE_ACCESS_DENIED
@ APP_LIB_STATE_ACCESS_DENIED
Operation is not allowed.
Definition: state.h:177
install_quality_error_code_e
install_quality_error_code_e
Error codes for installation quality, if an error code is active, corrective action regarding the ins...
Definition: state.h:265
app_lib_state_nbor_list_t::nbors
app_lib_state_nbor_info_t * nbors
Definition: state.h:161
app_lib_state_t::startScanNbors
app_lib_state_start_scan_nbors_f startScanNbors
Definition: state.h:731
app_lib_state_t::stopScanNbors
app_lib_state_scan_stop_f stopScanNbors
Definition: state.h:742
app_lib_state_hops_adjust_t
Structure for adjusting hops.
Definition: state.h:236
app_lib_state_route_info_t
Structure for route information.
Definition: state.h:247
APP_LIB_STATE_BEACON_TYPE_NB
@ APP_LIB_STATE_BEACON_TYPE_NB
Network beacon.
Definition: state.h:195
app_lib_state_nbor_info_t::diradv_support
uint8_t diradv_support
Definition: state.h:148
app_lib_state_nbor_info_t::last_update
uint16_t last_update
Definition: state.h:110
app_lib_state_beacon_rx_t::rssi
int8_t rssi
RSSI in dBm.
Definition: state.h:216
app_lib_state_nbor_info_t::cost
uint8_t cost
Definition: state.h:130
app_lib_state_t::setOnBeaconCb
app_lib_state_set_on_beacon_cb_f setOnBeaconCb
Definition: state.h:733
APP_LIB_STATE_INSTALL_QUALITY_ERROR_NOROUTE
@ APP_LIB_STATE_INSTALL_QUALITY_ERROR_NOROUTE
Definition: state.h:270
APP_LIB_STATE_ROUTE_STATE_INVALID
@ APP_LIB_STATE_ROUTE_STATE_INVALID
No next hop / route.
Definition: state.h:185
app_addr_t
uint32_t app_addr_t
Definition: app.h:228
APP_LIB_STATE_DIRADV_SUPPORTED
@ APP_LIB_STATE_DIRADV_SUPPORTED
Definition: state.h:83
app_lib_state_nbor_info_t::norm_rssi
int8_t norm_rssi
Definition: state.h:125
app_lib_state_beacon_rx_t::address
app_addr_t address
Address of the beacon sender.
Definition: state.h:204
app_lib_state_nbor_info_t::type
uint8_t type
Definition: state.h:134
APP_LIB_STATE_ROLE_NOT_SET
@ APP_LIB_STATE_ROLE_NOT_SET
Node role is not set.
Definition: state.h:174
APP_LIB_STATE_SCAN_NBORS_ONLY_REQUESTED
@ APP_LIB_STATE_SCAN_NBORS_ONLY_REQUESTED
Definition: state.h:99
app_lib_state_get_route_f
app_res_e(* app_lib_state_get_route_f)(app_lib_state_route_info_t *info)
Get route information.
Definition: state.h:567
app_lib_state_beacon_rx_t::is_ll
bool is_ll
Device is LL.
Definition: state.h:224
APP_LIB_STATE_STOPPED
@ APP_LIB_STATE_STOPPED
Stack is stopped.
Definition: state.h:170
app_lib_state_route_info_t::sink
app_addr_t sink
Definition: state.h:252
app_lib_state_get_sink_cost_f
app_res_e(* app_lib_state_get_sink_cost_f)(uint8_t *cost_p)
Query the currently set additional penalty for the sink usage.
Definition: state.h:525
app_lib_state_t::getNbors
app_lib_state_get_nbors_f getNbors
Definition: state.h:732
app_lib_state_set_adjust_hops_cb_f
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....
Definition: state.h:661
app_lib_state_t::getAccessCycle
app_lib_state_get_access_cycle_f getAccessCycle
Definition: state.h:729
app_lib_state_nbor_list_t
Neighbors list definition.
Definition: state.h:154
app_lib_state_t::getEnergy
app_lib_state_get_energy_f getEnergy
Definition: state.h:734
app_lib_state_route_info_t::next_hop
app_addr_t next_hop
Definition: state.h:254
APP_LIB_STATE_APP_CONFIG_DATA_NOT_SET
@ APP_LIB_STATE_APP_CONFIG_DATA_NOT_SET
Definition: state.h:175
app_lib_state_route_info_t::channel
app_lib_settings_net_channel_t channel
Definition: state.h:256
app_lib_state_install_quality_t::error_codes
uint8_t error_codes
Definition: state.h:295
app_lib_state_t::setSinkCost
app_lib_state_set_sink_cost_f setSinkCost
Definition: state.h:737
app_lib_state_t::stopStack
app_lib_state_stop_stack_f stopStack
Definition: state.h:725
app_lib_state_set_energy_f
app_res_e(* app_lib_state_set_energy_f)(uint8_t energy)
Set available energy.
Definition: state.h:509
app_lib_state_stop_stack_f
app_res_e(* app_lib_state_stop_stack_f)(void)
Stop the stack.
Definition: state.h:357
app.h
APP_LIB_STATE_INSTALL_QUALITY_ERROR_NONE
@ APP_LIB_STATE_INSTALL_QUALITY_ERROR_NONE
Definition: state.h:268
app_lib_state_set_scan_dur_f
app_res_e(* app_lib_state_set_scan_dur_f)(uint32_t duration_us)
Set scan duration to be used.
Definition: state.h:695
APP_LIB_STATE_ROUTE_STATE_VALID
@ APP_LIB_STATE_ROUTE_STATE_VALID
Valid next hop / route.
Definition: state.h:187
app_lib_state_scan_nbors_type_e
app_lib_state_scan_nbors_type_e
Scan neighbor type to specify the scans that trigger the callback.
Definition: state.h:93
app_lib_state_get_diag_interval_f
uint16_t(* app_lib_state_get_diag_interval_f)(void)
Get diagnostics interval.
Definition: state.h:394
app_lib_state_scan_stop_f
app_res_e(* app_lib_state_scan_stop_f)(void)
Stops ongoing scan operation before ended.
Definition: state.h:708
app_lib_state_t
List of library functions of v3 version (0x202)
Definition: state.h:722
app_lib_state_t::startStack
app_lib_state_start_stack_f startStack
Definition: state.h:724
app_lib_state_t::getSinkCost
app_lib_state_get_sink_cost_f getSinkCost
Definition: state.h:736
app_lib_state_beacon_rx_t::is_sink
bool is_sink
Device is sink.
Definition: state.h:223
app_lib_state_nbor_info_t::tx_power
int8_t tx_power
Definition: state.h:140
app_lib_state_stack_state_e
app_lib_state_stack_state_e
Stack state flags.
Definition: state.h:167
app_lib_state_install_quality_t
Installation quality information. Contains information about the nodes installation location i....
Definition: state.h:287
APP_LIB_STATE_INSTALL_QUALITY_ERROR_BADRSSI
@ APP_LIB_STATE_INSTALL_QUALITY_ERROR_BADRSSI
Definition: state.h:274
app_lib_state_set_route_cb_f
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.
Definition: state.h:581
app_lib_state_set_on_beacon_cb_f
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.
Definition: state.h:483
app_lib_state_nbor_info_t::channel
uint8_t channel
Definition: state.h:132
app_lib_state_t::getDiagInterval
app_lib_state_get_diag_interval_f getDiagInterval
Definition: state.h:728
APP_LIB_STATE_ROUTE_STATE_PENDING
@ APP_LIB_STATE_ROUTE_STATE_PENDING
Acquiring next hop / route.
Definition: state.h:186
app_lib_state_get_stack_state_f
uint8_t(* app_lib_state_get_stack_state_f)(void)
Get the stack state.
Definition: state.h:372
app_lib_state_nbor_info_t
Neighbors info definition.
Definition: state.h:105
app_lib_state_get_energy_f
app_res_e(* app_lib_state_get_energy_f)(uint8_t *energy_p)
Get available energy.
Definition: state.h:494
app_lib_state_t::getRouteInfo
app_lib_state_get_route_f getRouteInfo
Definition: state.h:738
app_lib_state_beacon_rx_t::is_da_support
bool is_da_support
Sender supports Directed Advertiser sending packets to it.
Definition: state.h:230
APP_LIB_STATE_NEIGHBOR_IS_NEXT_HOP
@ APP_LIB_STATE_NEIGHBOR_IS_NEXT_HOP
Definition: state.h:69
app_lib_state_nbor_type_e
app_lib_state_nbor_type_e
Neighbor type.
Definition: state.h:65
app_lib_state_t::getInstallQual
app_lib_state_get_install_quality_f getInstallQual
Definition: state.h:743
app_lib_state_diradv_support_e
app_lib_state_diradv_support_e
Support type for directed advertiser, i.e. does neighbor support sending directed advertiser packets ...
Definition: state.h:80
APP_LIB_STATE_INSTALL_QUALITY_ERROR_NONBORS
@ APP_LIB_STATE_INSTALL_QUALITY_ERROR_NONBORS
Definition: state.h:272
APP_LIB_STATE_NEIGHBOR_IS_MEMBER
@ APP_LIB_STATE_NEIGHBOR_IS_MEMBER
Definition: state.h:71
app_lib_state_t::setOnScanNborsCb
app_lib_state_set_on_scan_nbors_with_type_cb_f setOnScanNborsCb
Definition: state.h:730
app_lib_state_nbor_info_t::link_reliability
uint8_t link_reliability
Definition: state.h:114
app_lib_state_beacon_type_e
app_lib_state_beacon_type_e
Type for beacons, passed in app_lib_state_beacon_rx_t.
Definition: state.h:193
app_lib_state_nbor_info_t::address
uint32_t address
Definition: state.h:108
app_res_e
app_res_e
Definition: app.h:201
app_lib_joining_received_beacon_s::type
uint32_t type
Definition: joining.h:139
APP_LIB_STATE_STARTED
@ APP_LIB_STATE_STARTED
Stack is started.
Definition: state.h:169
app_lib_state_adjust_hops_cb_f
uint8_t(* app_lib_state_adjust_hops_cb_f)(const app_lib_state_hops_adjust_t *info)
Function type for a adjusting hops left.
Definition: state.h:596
APP_LIB_STATE_NETWORK_CHANNEL_NOT_SET
@ APP_LIB_STATE_NETWORK_CHANNEL_NOT_SET
Network channel is not set.
Definition: state.h:173
app_lib_state_start_scan_nbors_f
app_res_e(* app_lib_state_start_scan_nbors_f)(void)
Start neighbor scan.
Definition: state.h:448
app_lib_settings_net_channel_t
uint8_t app_lib_settings_net_channel_t
Network channel type definition.
Definition: settings.h:60
app_lib_state_route_info_t::state
app_lib_state_route_state_e state
Definition: state.h:250
app_lib_state_t::getStackState
app_lib_state_get_stack_state_f getStackState
Definition: state.h:726
APP_LIB_STATE_BEACON_TYPE_CB
@ APP_LIB_STATE_BEACON_TYPE_CB
Cluster beacon.
Definition: state.h:196