Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ble_wpts.c File Reference
#include <stdint.h>
#include <string.h>
#include "ble_wpts.h"
#include "ble_wpts_common.h"
#include "nordic_common.h"

Go to the source code of this file.

Functions

API implementation
void ble_wpts_on_ble_evt (ble_wpts_t *p_wpt, ble_evt_t *p_ble_evt)
 WPT Service BLE stack event handler. More...
 
static void pru_static_encode (ble_wpts_t *p_wpt, const pru_static_t *p_pru_static, uint8_t *p_encoded_buffer)
 Encode PRU Static Parameter structure. More...
 
static void pru_dynamic_encode (ble_wpts_t *p_wpt, const pru_dynamic_t *p_pru_dynamic, uint8_t *p_encoded_buffer)
 Encode PRU Dynamic Parameter structure. More...
 
static uint32_t pru_control_char_add (ble_wpts_t *p_wpt, const ble_wpts_init_t *p_wpts_init)
 Add PRU Control characteristic. More...
 
static uint32_t ptu_static_char_add (ble_wpts_t *p_wpt, const ble_wpts_init_t *p_wpts_init)
 Add PTU Static Parameter characteristic. More...
 
static uint32_t pru_alert_char_add (ble_wpts_t *p_wpt, const ble_wpts_init_t *p_wpts_init)
 Add PRU Alert characteristic. More...
 
static uint32_t pru_static_char_add (ble_wpts_t *p_wpt, const ble_wpts_init_t *p_wpts_init)
 Add PRU Static Parameter characteristic. More...
 
static uint32_t pru_dynamic_char_add (ble_wpts_t *p_wpt, const ble_wpts_init_t *p_wpts_init)
 Add PRU Dynamic Parameter characteristic. More...
 
uint32_t ble_wpts_init (ble_wpts_t *p_wpt, const ble_wpts_init_t *p_wpts_init)
 Initialize the WPT Service. More...
 
uint32_t ble_wpts_alert_send (ble_wpts_t *p_wpt, pru_alert_t *p_alert)
 Sends PRU alert if notification has been enabled. More...
 
uint32_t ble_wpts_pru_static_set (ble_wpts_t *p_wpt, pru_static_t *p_pru_static)
 Sets value of the PRU Static Parameter characteristic. More...
 
uint32_t ble_wpts_pru_dynamic_set (ble_wpts_t *p_wpts, pru_dynamic_t *p_pru_dynamic)
 Transfer latest read sensor data to characteristic attributes. More...
 

Static functions and variables

const ble_gatts_rw_authorize_reply_params_t m_auth_reply
 
static void on_connect (ble_wpts_t *p_wpt, ble_evt_t *p_ble_evt)
 Connect event handler. More...
 
static void on_disconnect (ble_wpts_t *p_wpt, ble_evt_t *p_ble_evt)
 Disconnect event handler. More...
 
static void on_pru_control_write (ble_wpts_t *p_wpts, ble_gatts_evt_write_t *p_evt_write)
 Handle write events to the PRU Control characteristic. More...
 
static void on_ptu_static_parameter_write (ble_wpts_t *p_wpts, ble_gatts_evt_write_t *p_evt_write)
 Handle write events to the PTU Static Parameter characteristic. More...
 
static void on_pru_alert_cccd_write (ble_wpts_t *p_wpts, ble_gatts_evt_write_t *p_evt_write)
 Handle write events to the PRU Alert CCCD. More...
 
static void on_write (ble_wpts_t *p_wpt, ble_evt_t *p_ble_evt)
 Write event handler. More...
 

Function Documentation

static void on_connect ( ble_wpts_t p_wpt,
ble_evt_t *  p_ble_evt 
)
static

Connect event handler.

Parameters
[in]p_wptPRU Service structure.
[in]p_ble_evtEvent received from the BLE stack.

Definition at line 45 of file ble_wpts.c.

46 {
47  p_wpt->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
48 }
uint16_t conn_handle
Definition: ble_wpts.h:80
static void on_disconnect ( ble_wpts_t p_wpt,
ble_evt_t *  p_ble_evt 
)
static

Disconnect event handler.

Parameters
[in]p_wptPRU Service structure.
[in]p_ble_evtEvent received from the BLE stack.

Definition at line 55 of file ble_wpts.c.

56 {
57  UNUSED_PARAMETER(p_ble_evt);
58  p_wpt->conn_handle = BLE_CONN_HANDLE_INVALID;
59 }
uint16_t conn_handle
Definition: ble_wpts.h:80
static void on_pru_control_write ( ble_wpts_t p_wpts,
ble_gatts_evt_write_t *  p_evt_write 
)
static

Handle write events to the PRU Control characteristic.

Parameters
[in]p_wptsPRU Service structure.
[in]p_evt_writeWrite event received from the BLE stack.

Definition at line 66 of file ble_wpts.c.

67 {
68  if (p_evt_write->len == BLE_WPTS_PRU_CONTROL_LEN)
69  {
70  ble_wpts_evt_t evt;
71 
72  // Decode/parse control data
84 
85  // Generate service event
87  p_wpts->evt_handler(p_wpts, &evt);
88  }
89 }
ctl_time_set_t
Time set field in control packet.
Definition: wpt.h:65
#define BLE_WPTS_PRU_CONTROL_LEN
Characteristic value lengths.
#define BLE_WPTS_ENABLE_PRU_ADJ_POWER_BITPOS
uint8_t enable_pru_output
Definition: wpt.h:81
ctl_perm_t
Permissions fields in control packet.
Definition: wpt.h:52
#define BLE_WPTS_PRU_CONTROL_PERMISSION_POS
ctl_time_set_t time_set
Definition: wpt.h:85
ble_wpts_evt_type_t evt_type
Definition: ble_wpts.h:43
#define BLE_WPTS_ENABLE_PRU_CHARGE_INDICATOR_BITMSK
#define BLE_WPTS_ENABLE_PRU_ADJ_POWER_BITMSK
ctl_perm_t permissions
Definition: wpt.h:84
WPT Service event.
Definition: ble_wpts.h:41
#define BLE_WPTS_PRU_CONTROL_TIME_SET_POS
union ble_wpts_evt_t::@0 data
#define BLE_WPTS_ENABLE_PRU_OUTPUT_BITMSK
pru_control_t pru_control
Definition: ble_wpts.h:46
ctl_adj_power_t
Power adjust settings in control packet.
Definition: wpt.h:42
#define BLE_WPTS_PRU_CONTROL_ENABLES_POS
PRU Control characteristic fields byte positions.
uint8_t enable_pru_charge_indicator
Definition: wpt.h:82
#define BLE_WPTS_ENABLE_PRU_OUTPUT_BITPOS
PRU Control characteristic Enables bit field definitions.
#define BLE_WPTS_ENABLE_PRU_CHARGE_INDICATOR_BITPOS
ble_wpts_evt_handler_t evt_handler
Definition: ble_wpts.h:73
#define BLE_WPTS_BITFIELD_READ(bitfield, msk, pos)
Read bitfield.
ctl_adj_power_t adj_power
Definition: wpt.h:83
static void on_ptu_static_parameter_write ( ble_wpts_t p_wpts,
ble_gatts_evt_write_t *  p_evt_write 
)
static

Handle write events to the PTU Static Parameter characteristic.

Parameters
[in]p_wptsPRU Service structure.
[in]p_evt_writeWrite event received from the BLE stack.

Definition at line 96 of file ble_wpts.c.

97 {
98  if (p_evt_write->len == BLE_WPTS_PTU_STATIC_LEN)
99  {
100  ble_wpts_evt_t evt;
101  uint8_t * p = p_evt_write->data;
102 
106 
110 
114 
118 
122 
128 
129 
131  p_wpts->evt_handler(p_wpts, &evt);
132  }
133 }
uint8_t protocol_rev
Definition: wpt.h:120
#define BLE_WPTS_PTU_STATIC_PTU_MAX_LOAD_RES_POS
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_RESISTANCE_BITPOS
#define BLE_WPTS_PTU_STATIC_PTU_MAX_SRC_IMPED_POS
#define BLE_WPTS_PTU_STATIC_HW_REV_POS
#define BLE_WPTS_PTU_STATIC_MAX_LOAD_RESISTANCE_BITMSK
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_BITMSK
#define BLE_WPTS_PTU_STATIC_MAX_SOURCE_IMPEDANCE_BITPOS
PTU Static characteristic PTU Max Source Impedance bitfield.
uint8_t ptu_max_source_impedance
Definition: wpt.h:115
#define BLE_WPTS_PTU_STATIC_OPTIONAL_FIELDS_POS
PTU Static Parameter characteristic byte positions.
#define BLE_WPTS_PTU_STATIC_PTU_CLASS_POS
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_IMPEDANCE_BITPOS
PTU Static characteristic Option bitfield definitions.
uint8_t ptu_power
Definition: wpt.h:114
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_RESISTANCE_BITMSK
#define BLE_WPTS_PTU_STATIC_FW_REV_POS
#define BLE_WPTS_PTU_STATIC_MAX_SOURCE_IMPEDANCE_BITMSK
uint8_t devices_supported_bitval
Definition: wpt.h:121
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_BITPOS
PTU Static characteristic PTU MAx Number of Devices Supported field.
ble_wpts_evt_type_t evt_type
Definition: ble_wpts.h:43
uint8_t ptu_max_load_resistance
Definition: wpt.h:116
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_IMPEDANCE_BITMSK
uint8_t hardware_rev
Definition: wpt.h:118
#define BLE_WPTS_PTU_STATIC_LEN
uint8_t option_valid_max_imp
Definition: wpt.h:112
WPT Service event.
Definition: ble_wpts.h:41
#define BLE_WPTS_PTU_STATIC_MAX_LOAD_RESISTANCE_BITPOS
PTU Static characteristic PTU Max Load Resistance bitfield.
union ble_wpts_evt_t::@0 data
uint8_t ptu_class
Definition: wpt.h:117
uint8_t firmware_rev
Definition: wpt.h:119
uint8_t option_valid_max_res
Definition: wpt.h:113
#define BLE_WPTS_PTU_STATIC_PROTOCOL_REV_POS
ble_wpts_evt_handler_t evt_handler
Definition: ble_wpts.h:73
#define BLE_WPTS_BITFIELD_READ(bitfield, msk, pos)
Read bitfield.
#define BLE_WPTS_PTU_STATIC_PTU_POWER_POS
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_SUPPORTED_POS
ptu_static_t ptu_static
Definition: ble_wpts.h:47
static void on_pru_alert_cccd_write ( ble_wpts_t p_wpts,
ble_gatts_evt_write_t *  p_evt_write 
)
static

Handle write events to the PRU Alert CCCD.

Parameters
[in]p_wptsPRU Service structure.
[in]p_evt_writeWrite event received from the BLE stack.

Definition at line 140 of file ble_wpts.c.

141 {
142  // Ensure that CCCD data length is at least 16 bit
143  //(Needed for ble_srv_is_notification_enabled())
144  if (p_evt_write->len >= 2)
145  {
146  // CCCD written, update notification state
147  if (p_wpts->evt_handler != NULL)
148  {
149  ble_wpts_evt_t evt;
150 
151  if (ble_srv_is_notification_enabled(p_evt_write->data))
152  {
154  }
155  else
156  {
158  }
159 
160  p_wpts->evt_handler(p_wpts, &evt);
161  }
162  }
163 }
ble_wpts_evt_type_t evt_type
Definition: ble_wpts.h:43
WPT Service event.
Definition: ble_wpts.h:41
ble_wpts_evt_handler_t evt_handler
Definition: ble_wpts.h:73
static void on_write ( ble_wpts_t p_wpt,
ble_evt_t *  p_ble_evt 
)
static

Write event handler.

Parameters
[in]p_wptPRU Service structure.
[in]p_ble_evtEvent received from the BLE stack.

Definition at line 171 of file ble_wpts.c.

172 {
173  ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
174 
175  if (p_evt_write->handle == p_wpt->pru_control_handles.value_handle)
176  {
177  on_pru_control_write(p_wpt, p_evt_write);
178  }
179  else if (p_evt_write->handle == p_wpt->ptu_static_handles.value_handle)
180  {
181  on_ptu_static_parameter_write(p_wpt, p_evt_write);
182  }
183  else if (p_evt_write->handle == p_wpt->pru_alert_handles.cccd_handle)
184  {
185  on_pru_alert_cccd_write(p_wpt, p_evt_write);
186  }
187 }
static void on_pru_control_write(ble_wpts_t *p_wpts, ble_gatts_evt_write_t *p_evt_write)
Handle write events to the PRU Control characteristic.
Definition: ble_wpts.c:66
static void on_ptu_static_parameter_write(ble_wpts_t *p_wpts, ble_gatts_evt_write_t *p_evt_write)
Handle write events to the PTU Static Parameter characteristic.
Definition: ble_wpts.c:96
ble_gatts_char_handles_t pru_control_handles
Definition: ble_wpts.h:75
ble_gatts_char_handles_t pru_alert_handles
Definition: ble_wpts.h:77
static void on_pru_alert_cccd_write(ble_wpts_t *p_wpts, ble_gatts_evt_write_t *p_evt_write)
Handle write events to the PRU Alert CCCD.
Definition: ble_wpts.c:140
ble_gatts_char_handles_t ptu_static_handles
Definition: ble_wpts.h:76

Variable Documentation

const ble_gatts_rw_authorize_reply_params_t m_auth_reply
Initial value:
=
{.type = BLE_GATTS_AUTHORIZE_TYPE_READ,
.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS,
.params.read.update = 0}

Constant authorize response, we only need authorization to get a hold of the read event.

Definition at line 34 of file ble_wpts.c.