Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
pru_adv.c
Go to the documentation of this file.
1 /* Copyright (c) Nordic Semiconductor. All Rights Reserved.
2  *
3  * The information contained herein is property of Nordic Semiconductor ASA.
4  * Terms and conditions of usage are described in detail in NORDIC
5  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
6  *
7  * Licensees are granted free, non-transferable use of the information. NO
8  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
9  * the file.
10  *
11  */
12 
15 #include "pru_adv.h"
16 #include "ble_advdata.h"
17 #include "pru_sensors.h"
18 #include "ble_wpts.h"
19 #include "pru_hw_config.h"
20 #include "pru_config.h"
21 
22 /******************************************************************************/
25 /******************************************************************************/
26 
27 uint32_t pru_advdata_set(ble_wpts_t * p_wpts)
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  {
71  }
72 
73  // Set PRU TX power field.
75  {
80  }
81  else
82  {
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
96  BLE_WPTS_BITFIELD_WRITE(service_data_array[BLE_WPTS_ADV_FLAGS_POS], BLE_WPTS_ADV_FLAG_OVP_STATUS_BITMSK, BLE_WPTS_ADV_FLAG_OVP_STATUS_BITPOS, ovp_status);
98 
99  err_code = ble_advdata_set(&advdata, NULL);
100  return err_code;
101 }
102 
#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
uint32_t pru_advdata_set(ble_wpts_t *p_wpts)
Advertising functionality initialization.
Definition: pru_adv.c:27
#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
WPT Service status structure.
Definition: ble_wpts.h:71
#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