Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ble_wpts_c.c
Go to the documentation of this file.
1 /* Copyright (c) 2013 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 <stdint.h>
16 #include <string.h>
17 
18 #include "ble_wpts_c.h"
19 #include "ble_srv_common.h"
20 
21 /******************************************************************************/
24 /******************************************************************************/
25 
28 static uint16_t m_pending_write_conn_handle;
31 //lint -save -e415 -e416 -e661 -e662 // Possible out-of-bounds errors.
37 static void proc_pru_dynamic_read_rsp(ble_wpts_c_t * p_wpts_c, ble_evt_t * p_ble_evt)
38 {
39  ble_wpts_c_evt_t evt;
40  uint8_t * p_data;
41  uint16_t len;
42 
43  p_data = p_ble_evt->evt.gattc_evt.params.read_rsp.data;
44  len = p_ble_evt->evt.gattc_evt.params.read_rsp.len;
45  evt.gatt_status = p_ble_evt->evt.gattc_evt.gatt_status;
46  memset(&evt.data.pru_dynamic, 0, sizeof(pru_dynamic_t));
47 
48  if(evt.gatt_status == BLE_GATT_STATUS_SUCCESS)
49  {
50  if (len == BLE_WPTS_PRU_DYNAMIC_LEN)
51  {
53  evt.data.pru_dynamic.vrect = uint16_decode(&p_data[BLE_WPTS_PRU_DYNAMIC_VRECT_POS]);
54  evt.data.pru_dynamic.irect = uint16_decode(&p_data[BLE_WPTS_PRU_DYNAMIC_IRECT_POS]);
55  evt.data.pru_dynamic.vout = uint16_decode(&p_data[BLE_WPTS_PRU_DYNAMIC_VOUT_POS]);
56  evt.data.pru_dynamic.iout = uint16_decode(&p_data[BLE_WPTS_PRU_DYNAMIC_IOUT_POS]);
61 
65 
66  evt.data.pru_dynamic.alerts.pru_over_current = BLE_WPTS_BITFIELD_READ( p_data[BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS], \
69 
70  evt.data.pru_dynamic.alerts.pru_over_temperature = BLE_WPTS_BITFIELD_READ( p_data[BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS], \
73 
74  evt.data.pru_dynamic.alerts.pru_self_protection = BLE_WPTS_BITFIELD_READ( p_data[BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS], \
77 
78  evt.data.pru_dynamic.alerts.charge_complete = BLE_WPTS_BITFIELD_READ( p_data[BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS], \
81 
82  evt.data.pru_dynamic.alerts.wired_charge_detect = BLE_WPTS_BITFIELD_READ( p_data[BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS], \
85 
86  evt.data.pru_dynamic.pru_charge_port = BLE_WPTS_BITFIELD_READ( p_data[BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS], \
89 
90  evt.data.pru_dynamic.adjust_power_response = BLE_WPTS_BITFIELD_READ( p_data[BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS], \
93 
95 
96  }
97  else
98  {
99  // Invalid length, report error to application
100  evt.gatt_status = BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE;
101  }
102  }
104  m_wpts_c_evt_handler(p_wpts_c, &evt);
105 }
106 //lint -restore
107 
108 //lint -save -e415 -e416 -e661 -e662 // Possible out-of-bounds errors.
114 static void proc_pru_static_read_rsp(ble_wpts_c_t * p_wpts_c, ble_evt_t * p_ble_evt)
115 {
116  ble_wpts_c_evt_t evt;
117  uint8_t * p_data;
118  uint16_t len;
119 
120  p_data = p_ble_evt->evt.gattc_evt.params.read_rsp.data;
121  len = p_ble_evt->evt.gattc_evt.params.read_rsp.len;
122  evt.gatt_status = p_ble_evt->evt.gattc_evt.gatt_status;
123 
124  if (evt.gatt_status == BLE_GATT_STATUS_SUCCESS)
125  {
126  if (len == BLE_WPTS_PRU_STATIC_LEN )
127  {
135  evt.data.pru_static.vrect_set = uint16_decode(&p_data[BLE_WPTS_PRU_STATIC_VRECT_SET_POS]);
136  evt.data.pru_static.delta_r1 = uint16_decode(&p_data[BLE_WPTS_PRU_STATIC_DELTA_R1_POS]);
137 
141 
145 
146  evt.data.pru_static.info_sep_btle_radio = BLE_WPTS_BITFIELD_READ(p_data[BLE_WPTS_PRU_STATIC_PRU_INFORMATION_POS], \
149 
150  evt.data.pru_static.info_pc_alg_pref = BLE_WPTS_BITFIELD_READ(p_data[BLE_WPTS_PRU_STATIC_PRU_INFORMATION_POS], \
153 
154 
155  evt.data.pru_static.info_adj_power_capability = BLE_WPTS_BITFIELD_READ(p_data[BLE_WPTS_PRU_STATIC_PRU_INFORMATION_POS], \
158 
159  evt.data.pru_static.info_ccp_connected_mode = BLE_WPTS_BITFIELD_READ(p_data[BLE_WPTS_PRU_STATIC_PRU_INFORMATION_POS], \
162 
163  evt.data.pru_static.info_ptu_test_mode = BLE_WPTS_BITFIELD_READ(p_data[BLE_WPTS_PRU_STATIC_PRU_INFORMATION_POS], \
166  }
167  else
168  {
169  // Invalid length, report error to application
170  evt.gatt_status = BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE;
171  }
173  m_wpts_c_evt_handler(p_wpts_c, &evt);
174  }
175 }
176 //lint -restore
177 
178 
184 static void on_read_rsp(ble_wpts_c_t * p_wpts_c, ble_evt_t * p_ble_evt)
185 {
186  if(p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_SUCCESS)
187  {
188  if (p_ble_evt->evt.gattc_evt.params.read_rsp.handle == p_wpts_c->prudp_handle)
189  {
190  proc_pru_dynamic_read_rsp(p_wpts_c, p_ble_evt);
191  }
192  else if (p_ble_evt->evt.gattc_evt.params.read_rsp.handle == p_wpts_c->prusp_handle)
193  {
194  proc_pru_static_read_rsp(p_wpts_c, p_ble_evt);
195  }
196  }
197 }
198 
204 static void on_write_rsp(ble_wpts_c_t * p_wpts_c, ble_evt_t * p_ble_evt)
205 {
206  ble_wpts_c_evt_t evt;
207  evt.gatt_status = p_ble_evt->evt.gattc_evt.gatt_status;
208 
209  if(p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_SUCCESS)
210  {
211  if (p_ble_evt->evt.gattc_evt.params.write_rsp.handle == p_wpts_c->prua_cccd_handle)
212  {
214  m_wpts_c_evt_handler(p_wpts_c, &evt);
215  }
216  }
217 }
218 
224 static void on_tx_complete(ble_wpts_c_t * p_wpts_c, ble_evt_t * p_ble_evt)
225 {
226  ble_wpts_c_evt_t evt;
227 
228  // Here, we always assume success, even though we didn't get a response
229  evt.gatt_status = BLE_GATT_STATUS_SUCCESS;
230 
231  // Here we use a local variable as char handle is not included in the
232  // TX_COMPLETE event
234  {
236  m_wpts_c_evt_handler(p_wpts_c, &evt);
237  }
239  {
241  m_wpts_c_evt_handler(p_wpts_c, &evt);
242  }
243 }
244 
250 static void on_hvx(ble_wpts_c_t * p_wpts_c, ble_evt_t * p_ble_evt)
251 {
252  ble_wpts_c_evt_t evt;
253 
254 
255  evt.gatt_status = p_ble_evt->evt.gattc_evt.gatt_status;
256 
257  if ((p_ble_evt->evt.gattc_evt.params.hvx.handle == p_wpts_c->prua_handle) &&
258  ( (p_ble_evt->evt.gattc_evt.params.hvx.type == BLE_GATT_HVX_NOTIFICATION) ||
259  (p_ble_evt->evt.gattc_evt.params.hvx.type == BLE_GATT_HVX_INDICATION))
260  )
261  {
262 
263  uint8_t data = p_ble_evt->evt.gattc_evt.params.hvx.data[0];
264 
266 
267  memset(&evt.data.pru_alert,0,sizeof(pru_alert_t));
268 
276 
278  {
279  if(p_ble_evt->evt.gattc_evt.params.hvx.len == (BLE_GAP_ADDR_LEN + 1))
280  {
281  //lint -save -e420
282  memcpy(evt.data.pru_alert.device_address,&p_ble_evt->evt.gattc_evt.params.hvx.data[1],BLE_GAP_ADDR_LEN);
283  //lint -restore
284  }
285  }
286 
287  if(p_ble_evt->evt.gattc_evt.params.hvx.type == BLE_GATT_HVX_NOTIFICATION)
288  {
290  m_wpts_c_evt_handler(p_wpts_c, &evt);
291  }
292  else if (p_ble_evt->evt.gattc_evt.params.hvx.type == BLE_GATT_HVX_INDICATION)
293  {
295 
296  if(sd_ble_gattc_hv_confirm(p_wpts_c->conn_handle, p_wpts_c->prua_handle) == NRF_SUCCESS)
297  {
298  m_wpts_c_evt_handler(p_wpts_c, &evt);
299  }
300  }
301  }
302 }
303 
306 /******************************************************************************/
309 /******************************************************************************/
310 
311 void ble_wpts_c_on_ble_evt(ble_wpts_c_t * p_wpts_c, ble_evt_t * p_ble_evt)
312 {
313  switch (p_ble_evt->header.evt_id)
314  {
315  case BLE_GAP_EVT_CONNECTED:
316  // Handled on profile level outside service
317  break;
318 
319  case BLE_GAP_EVT_DISCONNECTED:
320  // Handled on profile level outside service
321  break;
322 
323  case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
324  //on_prim_srvc_disc_rsp(p_wpts_c, p_ble_evt);
325  break;
326 
327  case BLE_GATTC_EVT_CHAR_DISC_RSP:
328  //on_char_disc_rsp(p_wpts_c, p_ble_evt);
329  break;
330 
331  case BLE_GATTC_EVT_DESC_DISC_RSP:
332  // on_desc_disc_rsp(p_wpts_c, p_ble_evt);
333  break;
334 
335  case BLE_GATTC_EVT_READ_RSP:
336  on_read_rsp(p_wpts_c, p_ble_evt);
337  break;
338 
339  case BLE_GATTC_EVT_WRITE_RSP:
340  on_write_rsp(p_wpts_c, p_ble_evt);
341  break;
342  case BLE_EVT_TX_COMPLETE: // Used for Write Without Response
343  on_tx_complete(p_wpts_c, p_ble_evt);
344  break;
345  case BLE_GATTC_EVT_HVX:
346  on_hvx(p_wpts_c, p_ble_evt);
347  break;
348 
349  default:
350  break;
351  }
352 }
353 
354 uint32_t ble_wpts_c_init(const ble_wpts_c_init_t * p_wpts_c_init)
355 {
356  if (p_wpts_c_init->evt_handler == NULL)
357  {
358  return NRF_ERROR_INVALID_PARAM;
359  }
360  m_wpts_c_evt_handler = p_wpts_c_init->evt_handler;
361  m_pending_write_cmd_char_handle = BLE_GATT_HANDLE_INVALID;
362  m_pending_write_conn_handle = BLE_CONN_HANDLE_INVALID;
363  return NRF_SUCCESS;
364 }
365 
366 uint32_t ble_wpts_c_send_pru_control(ble_wpts_c_t * p_wpts_c, pru_control_t * p_wpts_pru_control)
367 {
368  ble_gattc_write_params_t params;
369  uint8_t buf[BLE_WPTS_PRU_CONTROL_LEN];
370  memset(buf, 0, BLE_WPTS_PRU_CONTROL_LEN);
371 
372  // Encode control data
376  p_wpts_pru_control->enable_pru_output);
377 
378  BLE_WPTS_BITFIELD_WRITE(buf[BLE_WPTS_PRU_CONTROL_ENABLES_POS], \
381  p_wpts_pru_control->enable_pru_charge_indicator);
382 
383  BLE_WPTS_BITFIELD_WRITE(buf[BLE_WPTS_PRU_CONTROL_ENABLES_POS], \
386  p_wpts_pru_control->adj_power);
387 
388  buf[BLE_WPTS_PRU_CONTROL_PERMISSION_POS] = p_wpts_pru_control->permissions;
389  buf[BLE_WPTS_PRU_CONTROL_TIME_SET_POS] = p_wpts_pru_control->time_set;
390 
391  // Initiate write without response
392  params.write_op = BLE_GATT_OP_WRITE_CMD;
395 
396  params.handle = p_wpts_c->pruc_handle;
397  params.offset = 0;
398  params.len = BLE_WPTS_PRU_CONTROL_LEN;
399  params.p_value = buf;
400  return sd_ble_gattc_write(p_wpts_c->conn_handle, &params);
401 }
402 
404 {
405  return sd_ble_gattc_read(p_wpts_c->conn_handle, p_wpts_c->prusp_handle, 0);
406 }
407 
409 {
410  return sd_ble_gattc_read(p_wpts_c->conn_handle, p_wpts_c->prudp_handle, 0);
411 }
412 
413 uint32_t ble_wpts_c_write_ptu_static(ble_wpts_c_t * p_wpts_c, ptu_static_t * p_wpts_ptu_static)
414 {
415  ble_gattc_write_params_t params;
416  uint8_t buf[BLE_WPTS_PTU_STATIC_LEN];
417 
418  memset(buf, 0, BLE_WPTS_PTU_STATIC_LEN);
419 
420  // Encode data
421 
425  p_wpts_ptu_static->option_valid_max_imp);
426 
427  BLE_WPTS_BITFIELD_WRITE(buf[BLE_WPTS_PTU_STATIC_OPTIONAL_FIELDS_POS], \
430  p_wpts_ptu_static->option_valid_max_res);
431 
435  p_wpts_ptu_static->ptu_max_source_impedance);
436 
440  p_wpts_ptu_static->ptu_max_load_resistance);
441 
445  p_wpts_ptu_static->devices_supported_bitval);
446 
447  buf[BLE_WPTS_PTU_STATIC_PTU_POWER_POS] = p_wpts_ptu_static->ptu_power;
448  buf[BLE_WPTS_PTU_STATIC_PTU_CLASS_POS] = p_wpts_ptu_static->ptu_class;
449  buf[BLE_WPTS_PTU_STATIC_HW_REV_POS] = p_wpts_ptu_static->hardware_rev;
450  buf[BLE_WPTS_PTU_STATIC_FW_REV_POS] = p_wpts_ptu_static->firmware_rev;
451  buf[BLE_WPTS_PTU_STATIC_PROTOCOL_REV_POS] = p_wpts_ptu_static->protocol_rev;
452 
453  // Initiate write without response
454  params.write_op = BLE_GATT_OP_WRITE_CMD;
457 
458  params.handle = p_wpts_c->ptusp_handle;
459  params.offset = 0;
460  params.len = BLE_WPTS_PTU_STATIC_LEN;
461  params.p_value = buf;
462  return sd_ble_gattc_write(p_wpts_c->conn_handle, &params);
463 }
464 
466 {
467  ble_gattc_write_params_t params;
468  uint8_t buf[2];
469 
470  //lint -save -e534 // Function always returns '2'. Ignoring.
471  uint16_encode(BLE_GATT_HVX_NOTIFICATION | BLE_GATT_HVX_INDICATION, buf);
472  //lint -restore
473 
474  params.write_op = BLE_GATT_OP_WRITE_REQ;
475 
476  params.handle = p_wpts_c->prua_cccd_handle;
477  params.offset = 0;
478  params.len = sizeof(buf);
479  params.p_value = buf;
480  return sd_ble_gattc_write(p_wpts_c->conn_handle, &params);
481 }
482 
483 uint32_t ble_wpts_service_data_read(ble_gap_evt_adv_report_t * p_adv_report, ble_wpts_service_data_t * p_service_data)
484 {
485  uint8_t i = 0;
486  uint8_t len;
487  uint8_t * p_adv_service_data;
488 
489  while (i < p_adv_report->dlen)
490  {
491  if (p_adv_report->data[i] == 0)
492  {
493  return NRF_ERROR_INTERNAL;
494  }
495 
496  if (p_adv_report->data[i + 1] == BLE_GAP_AD_TYPE_SERVICE_DATA)
497  {
498  len = p_adv_report->data[i];
500  {
501  p_service_data -> uuid16 = uint16_decode(&p_adv_report->data[i + 2]);
502 
503  p_adv_service_data = &p_adv_report->data[i + 4];
504  p_service_data -> gatt_prim_srv_handle = uint16_decode(&p_adv_service_data[BLE_WPTS_ADV_SERVICE_HANDLE_POS]);
505 
507  if(p_service_data -> pru_pwr != (int8_t)BLE_WPTS_ADV_POWER_UNKNOWN_VAL)
508  {
509  p_service_data -> pru_pwr -= BLE_WPTS_ADV_PRU_TX_POWER_LEVEL_OFFSET;
510  }
511 
512  p_service_data -> pru_gain = BLE_WPTS_BITFIELD_READ(p_adv_service_data[BLE_WPTS_ADV_PRU_RSSI_PARAMS_POS], BLE_WPTS_ADV_PRU_RSSI_PRU_GAIN_BITMSK, BLE_WPTS_ADV_PRU_RSSI_PRU_GAIN_BITPOS);
513  if(p_service_data -> pru_gain != (int8_t)BLE_WPTS_ADV_ANTENNA_GAIN_UNKNOWN_VAL)
514  {
515  p_service_data -> pru_gain -= BLE_WPTS_ADV_ANTENNA_GAIN_OFFSET;
516  }
517 
518  p_service_data -> adv_flags = p_adv_service_data[BLE_WPTS_ADV_FLAGS_POS];
519  return NRF_SUCCESS;
520  }
521  }
522 
523  i += (p_adv_report->data[i] + 1);
524  }
525 
526  return NRF_ERROR_INTERNAL;
527 }
528 
529 void ble_wpts_char_handles_update(uint16_t prim_service_handle, ble_wpts_c_t * wpts_c)
530 {
531  wpts_c -> pruc_handle = prim_service_handle + BLE_WPTS_HANDLE_OFFSET_PRU_CONTROL;
532  wpts_c -> ptusp_handle = prim_service_handle + BLE_WPTS_HANDLE_OFFSET_PTU_STATIC;
533  wpts_c -> prua_handle = prim_service_handle + BLE_WPTS_HANDLE_OFFSET_PRU_ALERT;
534  wpts_c -> prua_cccd_handle = prim_service_handle + BLE_WPTS_HANDLE_OFFSET_PRU_ALERT_CCCD;
535  wpts_c -> prusp_handle = prim_service_handle + BLE_WPTS_HANDLE_OFFSET_PRU_STATIC;
536  wpts_c -> prudp_handle = prim_service_handle + BLE_WPTS_HANDLE_OFFSET_PRU_DYNAMIC;
537  wpts_c -> service_handle_range.start_handle = prim_service_handle + BLE_WPTS_HANDLE_OFFSET_MIN;
538  wpts_c -> service_handle_range.end_handle = prim_service_handle + BLE_WPTS_HANDLE_OFFSET_MAX;
539 }
540 
543 //lint -restore
uint16_t irect
Definition: wpt.h:168
ble_wpts_c_evt_handler_t evt_handler
Definition: ble_wpts_c.h:76
uint8_t protocol_rev
Definition: wpt.h:120
uint8_t info_ccp_connected_mode
Definition: wpt.h:105
PTU Static Parameter structure.
Definition: wpt.h:110
uint8_t info_adj_power_capability
Definition: wpt.h:104
#define BLE_WPTS_ADV_ANTENNA_GAIN_UNKNOWN_VAL
#define BLE_WPTS_ADV_PRU_RSSI_PRU_PWR_BITMSK
#define BLE_WPTS_PRU_DYNAMIC_ALERT_ADJ_POWER_RESP_BITPOS
static void on_tx_complete(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
Handle TX complete event.
Definition: ble_wpts_c.c:224
uint32_t ble_wpts_service_data_read(ble_gap_evt_adv_report_t *p_adv_report, ble_wpts_service_data_t *p_service_data)
Definition: ble_wpts_c.c:483
#define BLE_WPTS_ADV_PRU_RSSI_PRU_GAIN_BITMSK
#define BLE_WPTS_PRU_INFO_ADJUST_POWER_BITPOS
#define BLE_WPTS_PRU_CONTROL_LEN
Characteristic value lengths.
#define BLE_WPTS_PRU_DYNAMIC_TEMPERATURE_POS
pru_alert_bits_t alerts
Definition: wpt.h:175
#define BLE_WPTS_PRU_DYNAMIC_OPTIONAL_FIELDS_POS
PRU dynamic characteristic byte positions.
#define BLE_WPTS_PTU_STATIC_PTU_MAX_LOAD_RES_POS
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_RESISTANCE_BITPOS
#define BLE_WPTS_PRU_ALERT_OVER_CURRENT_BITMSK
union ble_wpts_c_evt_t::@1 data
#define BLE_WPTS_PRU_STATIC_OPTION_DELTA_R1_BITPOS
PRU Static characteristic Option field.
#define BLE_WPTS_PRU_INFO_CHARGE_COMPLETE_CONN_MODE_BITMSK
#define BLE_WPTS_PRU_INFO_PTU_TEST_MODE_BITPOS
uint16_t conn_handle
Definition: ble_wpts_c.h:66
uint8_t wired_charge_detect
Definition: wpt.h:139
uint8_t pru_category
Definition: wpt.h:92
uint8_t mode_transition
Definition: wpt.h:148
WPT Service Client structure. This contains various status information for the service.
Definition: ble_wpts_c.h:57
#define BLE_WPTS_PRU_ALERT_MODE_NO_MODE_TRANSITION_VAL
PRU Alert Mode transition.
#define BLE_WPTS_PTU_STATIC_PTU_MAX_SRC_IMPED_POS
static void proc_pru_static_read_rsp(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
Process a PRU Static Parameter read response.
Definition: ble_wpts_c.c:114
#define BLE_WPTS_PTU_STATIC_HW_REV_POS
uint16_t vout
Definition: wpt.h:169
uint8_t adjust_power_response
Definition: wpt.h:177
#define BLE_WPTS_PRU_INFO_CHARGE_COMPLETE_CONN_MODE_BITPOS
#define BLE_WPTS_PTU_STATIC_MAX_LOAD_RESISTANCE_BITMSK
#define BLE_WPTS_PRU_DYNAMIC_LEN
#define BLE_WPTS_ADV_SERVICE_HANDLE_POS
Advertising Service Data.
PRU Control structure.
Definition: wpt.h:79
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_BITMSK
#define BLE_WPTS_ENABLE_PRU_ADJ_POWER_BITPOS
uint16_t gatt_status
Definition: ble_wpts_c.h:47
#define BLE_WPTS_ADV_PRU_RSSI_PRU_GAIN_BITPOS
uint32_t ble_wpts_c_enable_pru_alert_notification(ble_wpts_c_t *p_wpts_c)
Enable alert notifications to be sent from PRU.
Definition: ble_wpts_c.c:465
#define BLE_WPTS_PRU_INFO_BLE_BITMSK
uint8_t protocol_rev
Definition: wpt.h:91
pru_alert_type_t type
Definition: wpt.h:150
#define BLE_WPTS_PTU_STATIC_MAX_SOURCE_IMPEDANCE_BITPOS
PTU Static characteristic PTU Max Source Impedance bitfield.
#define BLE_WPTS_PRU_ALERT_WIRED_CHARGER_DETECT_BITPOS
uint32_t ble_wpts_c_read_pru_static(ble_wpts_c_t *p_wpts_c)
Read the PRU Static Parameter characterisic value from the PRU server.
Definition: ble_wpts_c.c:403
uint32_t ble_wpts_c_write_ptu_static(ble_wpts_c_t *p_wpts_c, ptu_static_t *p_wpts_ptu_static)
Write the PTU Static characteristic to the PRU server.
Definition: ble_wpts_c.c:413
uint16_t vrect
Definition: wpt.h:167
uint8_t info_pc_alg_pref
Definition: wpt.h:103
#define BLE_WPTS_PRU_DYNAMIC_VRECT_HIGH_DYN_POS
uint16_t vrect_set_dyn
Definition: wpt.h:173
uint8_t enable_pru_output
Definition: wpt.h:81
#define BLE_WPTS_PRU_DYNAMIC_IRECT_POS
int16_t temperature
Definition: wpt.h:171
uint32_t ble_wpts_c_init(const ble_wpts_c_init_t *p_wpts_c_init)
Initialize the WPT Service Client.
Definition: ble_wpts_c.c:354
#define BLE_WPTS_ADV_PRU_TX_POWER_LEVEL_OFFSET
uint8_t ptu_max_source_impedance
Definition: wpt.h:115
uint16_t iout
Definition: wpt.h:170
#define BLE_WPTS_PRU_DYNAMIC_PTU_TESTER_COMMAND_POS
pru_alert_t pru_alert
Definition: ble_wpts_c.h:52
PRU Alert Parameter structure.
Definition: wpt.h:145
#define BLE_WPTS_PRU_ALERT_CHARGE_COMPLETE_BITMSK
uint16_t vrect_high_dyn
Definition: wpt.h:174
#define BLE_WPTS_PTU_STATIC_OPTIONAL_FIELDS_POS
PTU Static Parameter characteristic byte positions.
#define BLE_WPTS_PRU_CONTROL_PERMISSION_POS
void ble_wpts_char_handles_update(uint16_t prim_service_handle, ble_wpts_c_t *wpts_c)
Definition: ble_wpts_c.c:529
static void on_read_rsp(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
Handle read response events.
Definition: ble_wpts_c.c:184
uint16_t pruc_handle
Definition: ble_wpts_c.h:60
#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 fw_revision
Definition: wpt.h:94
uint8_t ptu_power
Definition: wpt.h:114
#define BLE_WPTS_PRU_ALERT_MODE_TRANSITION_BITPOS
void(* ble_wpts_c_evt_handler_t)(ble_wpts_c_t *p_wpts_c, ble_wpts_c_evt_t *p_evt)
WPT Service Client event handler type.
Definition: ble_wpts_c.h:70
Struct holding contents of "Service data AD type".
#define BLE_WPTS_PRU_STATIC_VRECT_MIN_STATIC_POS
uint32_t ble_wpts_c_read_pru_dynamic(ble_wpts_c_t *p_wpts_c)
Read the PRU Dynamic characterisic value from the PRU server.
Definition: ble_wpts_c.c:408
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_RESISTANCE_BITMSK
#define BLE_WPTS_PRU_DYNAMIC_VRECT_SET_DYN_POS
uint16_t prua_cccd_handle
Definition: ble_wpts_c.h:63
#define BLE_WPTS_PTU_STATIC_FW_REV_POS
ctl_time_set_t time_set
Definition: wpt.h:85
#define BLE_WPTS_PTU_STATIC_MAX_SOURCE_IMPEDANCE_BITMSK
uint8_t devices_supported_bitval
Definition: wpt.h:121
#define BLE_WPTS_HANDLE_OFFSET_MAX
ptu_tester_command_t tester_command
Definition: wpt.h:180
#define BLE_WPTS_PRU_DYNAMIC_ALERT_CHARGE_PORT_BITPOS
PRU dynamic characteristic Alert bitfield. Remaining bitifields is the same as PRU Alert characterist...
#define BLE_WPTS_BITFIELD_WRITE(bitfield, msk, pos, val)
Write bitfield.
uint16_t vrect_min_dyn
Definition: wpt.h:172
#define BLE_WPTS_PRU_STATIC_HW_REV_POS
#define BLE_WPTS_PRU_STATIC_OPTION_DELTA_R1_BITMSK
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_BITPOS
PTU Static characteristic PTU MAx Number of Devices Supported field.
#define BLE_WPTS_PRU_STATIC_VRECT_SET_POS
uint8_t info_sep_btle_radio
Definition: wpt.h:102
#define BLE_WPTS_PRU_ALERT_MODE_TRANSITION_BITMSK
uint8_t option_fields_r1_valid
Definition: wpt.h:100
uint16_t vrect_high_static
Definition: wpt.h:97
#define BLE_WPTS_PRU_STATIC_FW_REV_POS
#define BLE_WPTS_PRU_ALERT_OVER_VOLTAGE_BITPOS
PRU Alert characteristic value bitfield.
#define BLE_WPTS_HANDLE_OFFSET_PRU_ALERT
pru_static_t pru_static
Definition: ble_wpts_c.h:50
#define BLE_WPTS_PRU_DYNAMIC_ALERT_CHARGE_PORT_BITMSK
#define BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS
uint8_t hw_revision
Definition: wpt.h:93
uint8_t ptu_max_load_resistance
Definition: wpt.h:116
uint8_t pru_charge_port
Definition: wpt.h:176
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_IMPEDANCE_BITMSK
ble_wpts_c_evt_type_t type
Definition: ble_wpts_c.h:46
#define BLE_WPTS_PRU_DYNAMIC_VOUT_POS
#define BLE_WPTS_ENABLE_PRU_CHARGE_INDICATOR_BITMSK
#define BLE_WPTS_HANDLE_OFFSET_MIN
#define BLE_WPTS_ENABLE_PRU_ADJ_POWER_BITMSK
uint8_t hardware_rev
Definition: wpt.h:118
uint8_t pru_over_voltage
Definition: wpt.h:134
ctl_perm_t permissions
Definition: wpt.h:84
#define BLE_WPTS_PTU_STATIC_LEN
uint8_t option_valid_max_imp
Definition: wpt.h:112
#define BLE_WPTS_PRU_ALERT_OVER_VOLTAGE_BITMSK
#define BLE_WPTS_PRU_STATIC_LEN
#define BLE_WPTS_PRU_ALERT_SELF_PROTECTION_BITPOS
uint16_t prua_handle
Definition: ble_wpts_c.h:62
WPT Service Client init structure. This contains all options and data needed for initialization of th...
Definition: ble_wpts_c.h:74
uint8_t pru_over_current
Definition: wpt.h:135
#define BLE_WPTS_PRU_STATIC_PROTOCOL_REV_POS
uint8_t pru_over_temperature
Definition: wpt.h:136
#define BLE_WPTS_ADV_PRU_RSSI_PARAMS_POS
#define BLE_WPTS_PRU_CONTROL_TIME_SET_POS
WPT Service Client event.
Definition: ble_wpts_c.h:44
#define BLE_WPTS_PRU_STATIC_VRECT_HIGH_STATIC_POS
static void on_hvx(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
Handle value indication/notification events.
Definition: ble_wpts_c.c:250
#define BLE_WPTS_ADV_ANTENNA_GAIN_OFFSET
uint16_t delta_r1
Definition: wpt.h:99
void ble_wpts_c_on_ble_evt(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
WPT Service Client BLE stack event handler.
Definition: ble_wpts_c.c:311
#define BLE_WPTS_PRU_INFO_POWER_CONTROL_PREF_BITMSK
#define BLE_WPTS_PRU_ALERT_OVER_TEMPERATURE_BITMSK
#define BLE_WPTS_PRU_DYNAMIC_IOUT_POS
#define BLE_WPTS_PRU_ALERT_OVER_CURRENT_BITPOS
#define BLE_WPTS_PTU_STATIC_MAX_LOAD_RESISTANCE_BITPOS
PTU Static characteristic PTU Max Load Resistance bitfield.
uint16_t ptusp_handle
Definition: ble_wpts_c.h:61
#define BLE_WPTS_PRU_STATIC_PRU_INFORMATION_POS
#define BLE_WPTS_HANDLE_OFFSET_PRU_ALERT_CCCD
uint8_t ptu_class
Definition: wpt.h:117
#define BLE_WPTS_ADV_SERVICE_DATA_LENGTH
#define BLE_WPTS_ENABLE_PRU_OUTPUT_BITMSK
uint8_t firmware_rev
Definition: wpt.h:119
#define BLE_WPTS_PRU_STATIC_PRECT_MAX_POS
uint8_t option_valid_max_res
Definition: wpt.h:113
uint8_t info_nfc_receiver
Definition: wpt.h:101
uint8_t device_address[BLE_GAP_ADDR_LEN]
Definition: wpt.h:149
uint16_t vrect_min_static
Definition: wpt.h:96
#define BLE_WPTS_HANDLE_OFFSET_PTU_STATIC
#define BLE_WPTS_PRU_INFO_POWER_CONTROL_PREF_BITPOS
uint8_t optional_fields
Definition: wpt.h:166
#define BLE_WPTS_HANDLE_OFFSET_PRU_STATIC
#define BLE_WPTS_PRU_DYNAMIC_ALERT_ADJ_POWER_RESP_BITMSK
uint16_t prusp_handle
Definition: ble_wpts_c.h:64
#define BLE_WPTS_PRU_CONTROL_ENABLES_POS
PRU Control characteristic fields byte positions.
uint16_t vrect_set
Definition: wpt.h:98
uint8_t enable_pru_charge_indicator
Definition: wpt.h:82
#define BLE_WPTS_ENABLE_PRU_OUTPUT_BITPOS
PRU Control characteristic Enables bit field definitions.
static uint16_t m_pending_write_conn_handle
Definition: ble_wpts_c.c:28
#define BLE_WPTS_PRU_INFO_ADJUST_POWER_BITMSK
pru_dynamic_t pru_dynamic
Definition: ble_wpts_c.h:51
#define BLE_WPTS_PRU_ALERT_SELF_PROTECTION_BITMSK
static ble_wpts_c_evt_handler_t m_wpts_c_evt_handler
Definition: ble_wpts_c.c:26
static void on_write_rsp(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
Handle write response events.
Definition: ble_wpts_c.c:204
#define BLE_WPTS_PRU_DYNAMIC_VRECT_MIN_DYN_POS
#define BLE_WPTS_PTU_STATIC_PROTOCOL_REV_POS
uint8_t info_ptu_test_mode
Definition: wpt.h:106
static uint16_t m_pending_write_cmd_char_handle
Definition: ble_wpts_c.c:27
uint8_t pru_self_protection
Definition: wpt.h:137
#define BLE_WPTS_PRU_ALERT_WIRED_CHARGER_DETECT_BITMSK
#define BLE_WPTS_ENABLE_PRU_CHARGE_INDICATOR_BITPOS
ptu_tester_command_t
PTU Tester commands.
Definition: wpt.h:155
uint16_t prudp_handle
Definition: ble_wpts_c.h:65
#define BLE_WPTS_ADV_FLAGS_POS
#define BLE_WPTS_PRU_INFO_NFC_BITMSK
#define BLE_WPTS_PRU_INFO_NFC_BITPOS
PRU Static characteristic PRU Information field.
#define BLE_WPTS_PRU_ALERT_OVER_TEMPERATURE_BITPOS
#define BLE_WPTS_BITFIELD_READ(bitfield, msk, pos)
Read bitfield.
uint32_t ble_wpts_c_send_pru_control(ble_wpts_c_t *p_wpts_c, pru_control_t *p_wpts_pru_control)
Send a PRU Control message to the PRU server.
Definition: ble_wpts_c.c:366
#define BLE_WPTS_ADV_PRU_RSSI_PRU_PWR_BITPOS
#define BLE_WPTS_PRU_INFO_PTU_TEST_MODE_BITMSK
ctl_adj_power_t adj_power
Definition: wpt.h:83
#define BLE_WPTS_PRU_STATIC_DELTA_R1_POS
#define BLE_WPTS_HANDLE_OFFSET_PRU_CONTROL
WPT Service Characteristic value handles offset relative to primary service handle.
pru_alert_bits_t alerts
Definition: wpt.h:147
#define BLE_WPTS_HANDLE_OFFSET_PRU_DYNAMIC
#define BLE_WPTS_ADV_POWER_UNKNOWN_VAL
static void proc_pru_dynamic_read_rsp(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
Process a PRU Dynamic Parameter read response.
Definition: ble_wpts_c.c:37
#define BLE_WPTS_PTU_STATIC_PTU_POWER_POS
uint8_t charge_complete
Definition: wpt.h:138
PRU Dynamic Parameter structure.
Definition: wpt.h:164
#define BLE_WPTS_PRU_DYNAMIC_VRECT_POS
#define BLE_WPTS_PRU_INFO_BLE_BITPOS
#define BLE_WPTS_PRU_ALERT_CHARGE_COMPLETE_BITPOS
uint8_t prect_max
Definition: wpt.h:95
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_SUPPORTED_POS
#define BLE_WPTS_PRU_STATIC_PRU_CATEGORY_POS