samples: mesh: boards: nrf52: randomize publishers TID on boot
Now on reboot, NODE as client do not start message publishing with TID = 1. Instead of that it would start with any random value from 0 to 255. Signed-off-by: Vikrant More <vikrant8051@gmail.com>
This commit is contained in:
parent
06f69b5c64
commit
2708ce561d
|
@ -143,4 +143,6 @@ void main(void)
|
|||
if (err) {
|
||||
printk("Bluetooth init failed (err %d)\n", err);
|
||||
}
|
||||
|
||||
randomize_publishers_TID();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,28 @@
|
|||
|
||||
#define GENERIC_LEVEL
|
||||
|
||||
static bool is_randomization_of_TIDs_done;
|
||||
static u8_t tid_level;
|
||||
|
||||
#ifndef VND_MODEL_TEST
|
||||
static u8_t tid_onoff;
|
||||
#else
|
||||
static u8_t tid_vnd;
|
||||
#endif
|
||||
|
||||
void randomize_publishers_TID(void)
|
||||
{
|
||||
bt_rand(&tid_level, sizeof(tid_level));
|
||||
|
||||
#ifndef VND_MODEL_TEST
|
||||
bt_rand(&tid_onoff, sizeof(tid_onoff));
|
||||
#else
|
||||
bt_rand(&tid_vnd, sizeof(tid_vnd));
|
||||
#endif
|
||||
|
||||
is_randomization_of_TIDs_done = true;
|
||||
}
|
||||
|
||||
static u32_t button_read(struct device *port, u32_t pin)
|
||||
{
|
||||
u32_t val = 0;
|
||||
|
@ -26,13 +48,10 @@ static u32_t button_read(struct device *port, u32_t pin)
|
|||
void publish(struct k_work *work)
|
||||
{
|
||||
int err = 0;
|
||||
static u8_t tid_level;
|
||||
|
||||
#ifndef VND_MODEL_TEST
|
||||
static u8_t tid_onoff;
|
||||
#else
|
||||
static u8_t tid_vnd;
|
||||
#endif
|
||||
if (is_randomization_of_TIDs_done == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (button_read(button_device[0], SW0_GPIO_PIN) == 0) {
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define LEVEL_U75 49152
|
||||
#define LEVEL_U100 65535
|
||||
|
||||
void randomize_publishers_TID(void);
|
||||
void publish(struct k_work *work);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue