Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ptu_distant_list_handler.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include "ble.h"
#include "ble_gap.h"

Go to the source code of this file.

Data Structures

struct  ptu_dlh_init_t
 

Functions

void ptu_dlh_notify_beacon_active (void)
 Notify distant list handler that the beacon is now active. More...
 
void ptu_dlh_notify_beacon_disabled (void)
 Notify distant list handler that the beacon is now disabled. More...
 
void ptu_dlh_on_wpt_adv_report (ble_gap_addr_t const *p_addr, uint8_t adv_flags)
 Distance list handler WPT Advertisement report handler. More...
 
bool ptu_dlh_device_is_in_distant_list (ble_gap_addr_t const *p_addr)
 Check if device with provided address is in the distant list. More...
 
uint32_t ptu_dlh_init (ptu_dlh_init_t const *p_init)
 Check if device with provided address is in the distant list. More...
 

Function Documentation

void ptu_dlh_notify_beacon_active ( void  )

Notify distant list handler that the beacon is now active.

When this function is called, the distant list handler will not add new devices discovered to the distant list.

Definition at line 104 of file ptu_distant_list_handler.c.

105 {
106  uint32_t err_code;
107 
108  err_code = TIMER_START(m_ignore_latency_timer_id, m_ignore_latency_ms, NULL);
109  APP_ERROR_CHECK(err_code);
110 }
static uint32_t m_ignore_latency_ms
#define TIMER_START(timer_id, ms, p_ctx)
Definition: wpt.h:32
void ptu_dlh_notify_beacon_disabled ( void  )

Notify distant list handler that the beacon is now disabled.

When this function is called, the distant list handler will not add new devices discovered to the distant list.

Definition at line 112 of file ptu_distant_list_handler.c.

113 {
114  m_ignoring_devices = true;
115 }
static bool m_ignoring_devices
void ptu_dlh_on_wpt_adv_report ( ble_gap_addr_t const *  p_addr,
uint8_t  adv_flags 
)

Distance list handler WPT Advertisement report handler.

Will check address of advertisement and depending on the current state of the beacon, it will either add it to the distant list, or not.

Parameters
p_addrAddress of device advertising
adv_flagsWPT Advertisement Flags found in advertisement

Definition at line 117 of file ptu_distant_list_handler.c.

118 {
119  // Check reboot bit and remove device if reboot bit is set, and the device is currently in the distance list
120  if(BLE_WPTS_BITFIELD_READ( adv_flags,
123  {
124  if(m_address_in_distant_list(p_addr))
125  {
126  m_remove_device(p_addr);
127  }
128  }
129 
130  else if(m_ignoring_devices && !m_address_in_distant_list(p_addr))
131  {
133  memcpy(&m_distant_list[m_distant_list_index], p_addr, sizeof(ble_gap_addr_t));
134  }
135 }
#define BLE_WPTS_ADV_FLAG_REBOOT_INDICATOR_BITMSK
static ble_gap_addr_t m_distant_list[PTU_DISTANT_LIST_LEN]
static bool m_ignoring_devices
static bool m_address_in_distant_list(ble_gap_addr_t const *p_addr)
Check if given address is in the distant list.
static void m_remove_device(ble_gap_addr_t const *p_addr)
Removes given address from distant list.
#define BLE_WPTS_ADV_FLAG_REBOOT_INDICATOR_BITPOS
static uint8_t m_next_index(uint8_t current_index)
Get next index in distant list array.
#define BLE_WPTS_BITFIELD_READ(bitfield, msk, pos)
Read bitfield.
static uint8_t m_distant_list_index
bool ptu_dlh_device_is_in_distant_list ( ble_gap_addr_t const *  p_addr)

Check if device with provided address is in the distant list.

Will check address of advertisement and depending on the current state of the beacon, it will either add it to the distant list, or not.

Parameters
p_addrAddress to check
Returns
true if given address is in distant list, false otherwise

Definition at line 137 of file ptu_distant_list_handler.c.

138 {
139  APP_ERROR_CHECK_BOOL(p_addr != NULL);
140 
141  return m_address_in_distant_list(p_addr);
142 }
static bool m_address_in_distant_list(ble_gap_addr_t const *p_addr)
Check if given address is in the distant list.
uint32_t ptu_dlh_init ( ptu_dlh_init_t const *  p_init)

Check if device with provided address is in the distant list.

Parameters
p_initInitializing parameters
Returns
NRF_SUCCESS if success, otherwise error code.

Definition at line 144 of file ptu_distant_list_handler.c.

145 {
146  uint32_t err_code;
147 
148  if(p_init == NULL)
149  {
150  return NRF_ERROR_INVALID_PARAM;
151  }
152 
153  m_ignore_latency_ms = p_init->ignore_latency_ms;
154 
156 
157  m_ignoring_devices = true;
158 
159  memset(m_distant_list, 0, sizeof(m_distant_list));
160 
161  err_code = app_timer_create(&m_ignore_latency_timer_id, APP_TIMER_MODE_SINGLE_SHOT, m_ignore_latency_timer_id_handler);
162  if(err_code != NRF_SUCCESS)
163  {
164  return err_code;
165  }
166 
167  return NRF_SUCCESS;
168 }
static ble_gap_addr_t m_distant_list[PTU_DISTANT_LIST_LEN]
static bool m_ignoring_devices
static uint32_t m_ignore_latency_ms
static void m_ignore_latency_timer_id_handler(void *p_context)
Hander for the ignore latency timer id.
static uint8_t m_distant_list_index