Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
PRU Advertisement helper

Functions

uint32_t pru_advdata_set (ble_wpts_t *p_wpts)
 Advertising functionality initialization. More...
 

Detailed Description

Function Documentation

uint32_t pru_advdata_set ( ble_wpts_t p_wpts)

Advertising functionality initialization.

Parameters
p_wptsPointer to WPT Service.

Encodes the required advertising data and passes it to the stack. Also builds a structure to be passed to the stack when starting advertising.

Returns
NRF_SUCCESS on success, otherwise an error code.

Definition at line 27 of file pru_adv.c.

28 {
29  uint32_t err_code;
30  ble_advdata_t advdata;
31  uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
32  uint8_t service_data_array[BLE_WPTS_ADV_SERVICE_DATA_LEN];
33  bool ovp_status;
34  const pru_sensor_data_t * p_pru_sensor_data;
35 
36  ble_advdata_service_data_t service_data;
37 
38  // Build and set advertising data
39  memset(&advdata, 0, sizeof(advdata));
40 
41  advdata.name_type = BLE_ADVDATA_NO_NAME;
42  advdata.include_appearance = false;
43  advdata.flags = flags;
44  advdata.service_data_count = 1;
45  advdata.p_service_data_array = &service_data;
46 
47  // Set Service data
48  service_data.service_uuid = BLE_WPTS_UUID16;
49  service_data.data.size = BLE_WPTS_ADV_SERVICE_DATA_LEN;
50  service_data.data.p_data = service_data_array;
51  memset(service_data_array, 0, BLE_WPTS_ADV_SERVICE_DATA_LEN);
52 
53  // Set GATT primary service handle.
54  (void)uint16_encode(p_wpts->service_handle, &service_data_array[BLE_WPTS_ADV_SERVICE_HANDLE_POS]);
55 
56  // Set PRU RSSI parameters. We do not check whether the values are in bounds.
57  // Set PRU antenna gain field.
59  {
64  }
65  else
66  {
67  BLE_WPTS_BITFIELD_WRITE(service_data_array[BLE_WPTS_ADV_PRU_RSSI_PARAMS_POS], \
71  }
72 
73  // Set PRU TX power field.
75  {
76  BLE_WPTS_BITFIELD_WRITE(service_data_array[BLE_WPTS_ADV_PRU_RSSI_PARAMS_POS], \
80  }
81  else
82  {
83  BLE_WPTS_BITFIELD_WRITE(service_data_array[BLE_WPTS_ADV_PRU_RSSI_PARAMS_POS], \
87  }
88 
89  // Get OVP status
90  p_pru_sensor_data = pru_sensors_data_get();
91  ovp_status = p_pru_sensor_data->over_voltage;
92 
93  // Set advertising flags
98 
99  err_code = ble_advdata_set(&advdata, NULL);
100  return err_code;
101 }
#define BLE_WPTS_ADV_FLAG_OVP_STATUS_BITMSK
#define BLE_WPTS_ADV_ANTENNA_GAIN_UNKNOWN_VAL
#define BLE_WPTS_ADV_PRU_RSSI_PRU_PWR_BITMSK
#define BLE_WPTS_ADV_PRU_RSSI_PRU_GAIN_BITMSK
#define PRU_TX_POWER_KNOWN
Definition: pru_hw_config.h:37
#define BLE_WPTS_UUID16
WPT Service UUIDs.
uint8_t over_voltage
Definition: pru_sensors.h:33
#define BLE_WPTS_ADV_FLAG_REBOOT_INDICATOR_BITMSK
#define BLE_WPTS_ADV_SERVICE_HANDLE_POS
Advertising Service Data.
#define BLE_WPTS_ADV_PRU_RSSI_PRU_GAIN_BITPOS
#define PRU_TIME_SET_SUPPORT
Definition: pru_config.h:32
#define BLE_WPTS_ADV_FLAG_IMPEDANCE_SHIFT_BITPOS
uint16_t service_handle
Definition: ble_wpts.h:74
#define BLE_WPTS_ADV_PRU_TX_POWER_LEVEL_OFFSET
#define PRU_ANTENNA_GAIN_KNOWN
Definition: pru_hw_config.h:35
#define PRU_TX_POWER_LEVEL
Definition: pru_hw_config.h:38
const pru_sensor_data_t * pru_sensors_data_get(void)
Get the latest data from the PRU sensors.
Definition: pru_sensors.c:146
Definition of PRU reporting data.
Definition: pru_sensors.h:26
#define BLE_WPTS_BITFIELD_WRITE(bitfield, msk, pos, val)
Write bitfield.
#define PRU_ANTENNA_GAIN
Definition: pru_hw_config.h:36
#define BLE_WPTS_ADV_SERVICE_DATA_LEN
#define BLE_WPTS_ADV_FLAG_REBOOT_INDICATOR_BITPOS
#define BLE_WPTS_ADV_PRU_RSSI_PARAMS_POS
#define BLE_WPTS_ADV_ANTENNA_GAIN_OFFSET
uint8_t reboot_bit
Definition: ble_wpts.h:81
#define BLE_WPTS_ADV_FLAG_OVP_STATUS_BITPOS
#define BLE_WPTS_ADV_FLAG_IMPEDANCE_SHIFT_BITMSK
#define BLE_WPTS_ADV_FLAGS_POS
#define PRU_CATEGORY
Definition: pru_hw_config.h:34
#define BLE_WPTS_ADV_PRU_RSSI_PRU_PWR_BITPOS
#define BLE_WPTS_ADV_POWER_UNKNOWN_VAL
#define BLE_WPTS_ADV_FLAG_TIME_SET_SUPPORT_BITMSK
#define BLE_WPTS_ADV_FLAG_TIME_SET_SUPPORT_BITPOS