mesh: prefix with mesh and move heartbeat helper functions to mesh_node [a2593]

This commit is contained in:
Milanka Ringwald 2020-01-31 11:15:59 +01:00
parent 4f44739eea
commit 12d66e05f4
2 changed files with 31 additions and 3 deletions

View File

@ -262,3 +262,25 @@ const uint8_t * mesh_node_get_device_uuid(void){
return mesh_node_device_uuid;
}
// Heartbeat (helper)
uint16_t mesh_heartbeat_pwr2(uint8_t value){
if (value == 0 ) return 0x0000;
if (value == 0xff || value == 0x11) return 0xffff;
return 1 << (value-1);
}
uint8_t mesh_heartbeat_count_log(uint16_t value){
if (value == 0) return 0x00;
if (value == 0xffff) return 0xff;
// count leading zeros, supported by clang and gcc
// note: CountLog(8) == CountLog(7) = 3
return 33 - __builtin_clz(value - 1);
}
uint8_t mesh_heartbeat_period_log(uint16_t value){
if (value == 0) return 0x00;
// count leading zeros, supported by clang and gcc
// note: PeriodLog(8) == PeriodLog(7) = 3
return 33 - __builtin_clz(value - 1);
}

View File

@ -106,11 +106,11 @@ typedef struct {
typedef struct {
uint16_t destination;
uint8_t count_log; // Number of Heartbeat messages to be sent
uint8_t period_log; // Period for sending Heartbeat messages
uint8_t ttl; // TTL to be used when sending Heartbeat messages
uint16_t count_log; // Number of Heartbeat messages to be sent
uint16_t period_log; // Period for sending Heartbeat messages in seconds
uint16_t features; // Bit field indicating features that trigger Heartbeat messages when changed
uint16_t netkey_index;
uint8_t ttl; // TTL to be used when sending Heartbeat messages
} mesh_heartbeat_publication_state_t;
typedef struct {
@ -330,6 +330,12 @@ uint16_t mesh_node_get_product_id(void);
*/
uint16_t mesh_node_get_product_version_id(void);
// Heartbeat (helper)
uint16_t mesh_heartbeat_pwr2(uint8_t value);
uint8_t mesh_heartbeat_count_log(uint16_t value);
uint8_t mesh_heartbeat_period_log(uint16_t value);
#if defined __cplusplus
}
#endif