Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
PTU BLE Service API (client)

Data Structures

struct  ble_wpts_c_evt_t
 WPT Service Client event. More...
 
struct  ble_wpts_c_t
 WPT Service Client structure. This contains various status information for the service. More...
 
struct  ble_wpts_c_init_t
 WPT Service Client init structure. This contains all options and data needed for initialization of the service. More...
 

Typedefs

typedef 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.
 

Enumerations

enum  ble_wpts_c_evt_type_t {
  BLE_WPTS_C_EVT_DISCOVERY_OK, BLE_WPTS_C_EVT_DISCOVERY_FAILED, BLE_WPTS_C_EVT_PRU_CONTROL_WRITE_RESP, BLE_WPTS_C_EVT_PTU_STATIC_WRITE_RESP,
  BLE_WPTS_C_EVT_PRU_STATIC_READ_RESP, BLE_WPTS_C_EVT_PRU_DYNAMIC_READ_RESP, BLE_WPTS_C_EVT_PRU_ALERT_ENABLE_WRITE_RESP, BLE_WPTS_C_EVT_PRU_ALERT
}
 WPT Service Client event type. More...
 

Functions

uint32_t ble_wpts_c_init (const ble_wpts_c_init_t *p_wpts_c_init)
 Initialize the WPT Service Client. More...
 
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. More...
 
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. More...
 
uint32_t ble_wpts_c_enable_pru_alert_notification (ble_wpts_c_t *p_wpts_c)
 Enable alert notifications to be sent from PRU. More...
 
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. More...
 
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. More...
 
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. More...
 
uint32_t ble_wpts_service_data_read (ble_gap_evt_adv_report_t *p_adv_report, ble_wpts_service_data_t *p_service_data)
 
void ble_wpts_char_handles_update (uint16_t prim_service_handle, ble_wpts_c_t *p_wpts_c)
 

Detailed Description

Enumeration Type Documentation

WPT Service Client event type.

Enumerator
BLE_WPTS_C_EVT_DISCOVERY_OK 

PRU characteristic and service discovery successful.

BLE_WPTS_C_EVT_DISCOVERY_FAILED 

PRU characteristic or service discovery failed.

BLE_WPTS_C_EVT_PRU_CONTROL_WRITE_RESP 

PRU Control write response received.

BLE_WPTS_C_EVT_PTU_STATIC_WRITE_RESP 

PTU Static Parameter write response received.

BLE_WPTS_C_EVT_PRU_STATIC_READ_RESP 

PRU Static Parameter read response received.

BLE_WPTS_C_EVT_PRU_DYNAMIC_READ_RESP 

PRU Dynamic Parameter read response received.

BLE_WPTS_C_EVT_PRU_ALERT_ENABLE_WRITE_RESP 

PRU Alert enable write response.

BLE_WPTS_C_EVT_PRU_ALERT 

PRU Alert received.

Definition at line 31 of file ble_wpts_c.h.

Function Documentation

uint32_t ble_wpts_c_init ( const ble_wpts_c_init_t p_wpts_c_init)

Initialize the WPT Service Client.

Parameters
[in]p_wpts_c_initInformation needed to initialize the service.
Returns
NRF_SUCCESS on successful initialization of service, otherwise an error code.

Definition at line 354 of file ble_wpts_c.c.

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 }
ble_wpts_c_evt_handler_t evt_handler
Definition: ble_wpts_c.h:76
static uint16_t m_pending_write_conn_handle
Definition: ble_wpts_c.c:28
static ble_wpts_c_evt_handler_t m_wpts_c_evt_handler
Definition: ble_wpts_c.c:26
static uint16_t m_pending_write_cmd_char_handle
Definition: ble_wpts_c.c:27
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.

Handles all events from the BLE stack of interest to the WPT Service Client.

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

Definition at line 311 of file ble_wpts_c.c.

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 }
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
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
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
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
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.

The application calls this function to send a PRU Control message to the PRU server.

Parameters
[in]p_wpts_cWPT Service Client structure.
[in]p_wpts_pru_controlPRU control value.
Returns
NRF_SUCCESS on success, otherwise an error code.

Definition at line 366 of file ble_wpts_c.c.

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 
381  p_wpts_pru_control->enable_pru_charge_indicator);
382 
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 }
#define BLE_WPTS_PRU_CONTROL_LEN
Characteristic value lengths.
uint16_t conn_handle
Definition: ble_wpts_c.h:66
#define BLE_WPTS_ENABLE_PRU_ADJ_POWER_BITPOS
uint8_t enable_pru_output
Definition: wpt.h:81
#define BLE_WPTS_PRU_CONTROL_PERMISSION_POS
uint16_t pruc_handle
Definition: ble_wpts_c.h:60
ctl_time_set_t time_set
Definition: wpt.h:85
#define BLE_WPTS_BITFIELD_WRITE(bitfield, msk, pos, val)
Write bitfield.
#define BLE_WPTS_ENABLE_PRU_CHARGE_INDICATOR_BITMSK
#define BLE_WPTS_ENABLE_PRU_ADJ_POWER_BITMSK
ctl_perm_t permissions
Definition: wpt.h:84
#define BLE_WPTS_PRU_CONTROL_TIME_SET_POS
#define BLE_WPTS_ENABLE_PRU_OUTPUT_BITMSK
#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.
static uint16_t m_pending_write_conn_handle
Definition: ble_wpts_c.c:28
static uint16_t m_pending_write_cmd_char_handle
Definition: ble_wpts_c.c:27
#define BLE_WPTS_ENABLE_PRU_CHARGE_INDICATOR_BITPOS
ctl_adj_power_t adj_power
Definition: wpt.h:83
uint32_t ble_wpts_c_enable_pru_alert_notification ( ble_wpts_c_t p_wpts_c)

Enable alert notifications to be sent from PRU.

Parameters
[in]p_wpts_cWPT Service Client structure.
Returns
NRF_SUCCESS on success, otherwise an error code.

Definition at line 465 of file ble_wpts_c.c.

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 }
uint16_t conn_handle
Definition: ble_wpts_c.h:66
uint16_t prua_cccd_handle
Definition: ble_wpts_c.h:63
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.

The application calls this function to read the PRU Static Parameter characterisic value from the PRU server.

Parameters
[in]p_wpts_cWPT Service Client structure.
Returns
NRF_SUCCESS on success, otherwise an error code.

Definition at line 403 of file ble_wpts_c.c.

404 {
405  return sd_ble_gattc_read(p_wpts_c->conn_handle, p_wpts_c->prusp_handle, 0);
406 }
uint16_t conn_handle
Definition: ble_wpts_c.h:66
uint16_t prusp_handle
Definition: ble_wpts_c.h:64
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.

The application calls this function to read the PRU Dynamic Parameter characterisic value from the PRU server.

Parameters
[in]p_wpts_cWPT Service Client structure.
Returns
NRF_SUCCESS on success, otherwise an error code.

Definition at line 408 of file ble_wpts_c.c.

409 {
410  return sd_ble_gattc_read(p_wpts_c->conn_handle, p_wpts_c->prudp_handle, 0);
411 }
uint16_t conn_handle
Definition: ble_wpts_c.h:66
uint16_t prudp_handle
Definition: ble_wpts_c.h:65
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.

The application calls this function to write the PTU Static Parameter characteristic to the PRU server.

Parameters
[in]p_wpts_cWPT Service Client structure.
[in]p_wpts_ptu_staticPTU Static characteristic value.
Returns
NRF_SUCCESS on success, otherwise an error code.

Definition at line 413 of file ble_wpts_c.c.

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 
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 }
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
uint16_t conn_handle
Definition: ble_wpts_c.h:66
#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_BITFIELD_WRITE(bitfield, msk, pos, val)
Write bitfield.
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_BITPOS
PTU Static characteristic PTU MAx Number of Devices Supported field.
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
#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
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
static uint16_t m_pending_write_conn_handle
Definition: ble_wpts_c.c:28
#define BLE_WPTS_PTU_STATIC_PROTOCOL_REV_POS
static uint16_t m_pending_write_cmd_char_handle
Definition: ble_wpts_c.c:27
#define BLE_WPTS_PTU_STATIC_PTU_POWER_POS
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_SUPPORTED_POS
uint32_t ble_wpts_service_data_read ( ble_gap_evt_adv_report_t *  p_adv_report,
ble_wpts_service_data_t p_service_data 
)

Read advertising packet, search for Service Data AD Type and return contents

Parameters
[in]p_adv_reportAdvertising report to parse.
[out]p_service_dataStruct in which to return service data contents.
Returns
NRF_SUCCESS if advertising packet contained Service Name AD Type and value was written.

Definition at line 483 of file ble_wpts_c.c.

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 
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 }
#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 BLE_WPTS_ADV_SERVICE_HANDLE_POS
Advertising Service Data.
#define BLE_WPTS_ADV_PRU_RSSI_PRU_GAIN_BITPOS
#define BLE_WPTS_ADV_PRU_TX_POWER_LEVEL_OFFSET
#define BLE_WPTS_ADV_PRU_RSSI_PARAMS_POS
#define BLE_WPTS_ADV_ANTENNA_GAIN_OFFSET
#define BLE_WPTS_ADV_SERVICE_DATA_LENGTH
#define BLE_WPTS_ADV_FLAGS_POS
#define BLE_WPTS_BITFIELD_READ(bitfield, msk, pos)
Read bitfield.
#define BLE_WPTS_ADV_PRU_RSSI_PRU_PWR_BITPOS
#define BLE_WPTS_ADV_POWER_UNKNOWN_VAL
void ble_wpts_char_handles_update ( uint16_t  prim_service_handle,
ble_wpts_c_t p_wpts_c 
)

Derive and update characteristic handles from WPT primary service handle.

Parameters
[in]prim_service_handlePrimary service handle from which to derive characteristic handles.
[out]p_wpts_cStruct holding handles to be updated. Only the characteristic handles in this struct will be updated.

Definition at line 529 of file ble_wpts_c.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 }
#define BLE_WPTS_HANDLE_OFFSET_MAX
#define BLE_WPTS_HANDLE_OFFSET_PRU_ALERT
#define BLE_WPTS_HANDLE_OFFSET_MIN
#define BLE_WPTS_HANDLE_OFFSET_PRU_ALERT_CCCD
#define BLE_WPTS_HANDLE_OFFSET_PTU_STATIC
#define BLE_WPTS_HANDLE_OFFSET_PRU_STATIC
#define BLE_WPTS_HANDLE_OFFSET_PRU_CONTROL
WPT Service Characteristic value handles offset relative to primary service handle.
#define BLE_WPTS_HANDLE_OFFSET_PRU_DYNAMIC