19 #include "ble_srv_common.h"
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;
100 evt.
gatt_status = BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE;
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;
170 evt.
gatt_status = BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE;
186 if(p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_SUCCESS)
188 if (p_ble_evt->evt.gattc_evt.params.read_rsp.handle == p_wpts_c->
prudp_handle)
192 else if (p_ble_evt->evt.gattc_evt.params.read_rsp.handle == p_wpts_c->
prusp_handle)
207 evt.
gatt_status = p_ble_evt->evt.gattc_evt.gatt_status;
209 if(p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_SUCCESS)
211 if (p_ble_evt->evt.gattc_evt.params.write_rsp.handle == p_wpts_c->
prua_cccd_handle)
255 evt.
gatt_status = p_ble_evt->evt.gattc_evt.gatt_status;
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))
263 uint8_t data = p_ble_evt->evt.gattc_evt.params.hvx.data[0];
279 if(p_ble_evt->evt.gattc_evt.params.hvx.len == (BLE_GAP_ADDR_LEN + 1))
287 if(p_ble_evt->evt.gattc_evt.params.hvx.type == BLE_GATT_HVX_NOTIFICATION)
292 else if (p_ble_evt->evt.gattc_evt.params.hvx.type == BLE_GATT_HVX_INDICATION)
313 switch (p_ble_evt->header.evt_id)
315 case BLE_GAP_EVT_CONNECTED:
319 case BLE_GAP_EVT_DISCONNECTED:
323 case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
327 case BLE_GATTC_EVT_CHAR_DISC_RSP:
331 case BLE_GATTC_EVT_DESC_DISC_RSP:
335 case BLE_GATTC_EVT_READ_RSP:
339 case BLE_GATTC_EVT_WRITE_RSP:
342 case BLE_EVT_TX_COMPLETE:
345 case BLE_GATTC_EVT_HVX:
346 on_hvx(p_wpts_c, p_ble_evt);
358 return NRF_ERROR_INVALID_PARAM;
368 ble_gattc_write_params_t params;
392 params.write_op = BLE_GATT_OP_WRITE_CMD;
399 params.p_value = buf;
400 return sd_ble_gattc_write(p_wpts_c->
conn_handle, ¶ms);
415 ble_gattc_write_params_t params;
454 params.write_op = BLE_GATT_OP_WRITE_CMD;
461 params.p_value = buf;
462 return sd_ble_gattc_write(p_wpts_c->
conn_handle, ¶ms);
467 ble_gattc_write_params_t params;
471 uint16_encode(BLE_GATT_HVX_NOTIFICATION | BLE_GATT_HVX_INDICATION, buf);
474 params.write_op = BLE_GATT_OP_WRITE_REQ;
478 params.len =
sizeof(buf);
479 params.p_value = buf;
480 return sd_ble_gattc_write(p_wpts_c->
conn_handle, ¶ms);
487 uint8_t * p_adv_service_data;
489 while (i < p_adv_report->dlen)
491 if (p_adv_report->data[i] == 0)
493 return NRF_ERROR_INTERNAL;
496 if (p_adv_report->data[i + 1] == BLE_GAP_AD_TYPE_SERVICE_DATA)
498 len = p_adv_report->data[i];
501 p_service_data -> uuid16 = uint16_decode(&p_adv_report->data[i + 2]);
503 p_adv_service_data = &p_adv_report->data[i + 4];
523 i += (p_adv_report->data[i] + 1);
526 return NRF_ERROR_INTERNAL;
ble_wpts_c_evt_handler_t evt_handler
uint8_t info_ccp_connected_mode
PTU Static Parameter structure.
uint8_t info_adj_power_capability
#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.
uint32_t ble_wpts_service_data_read(ble_gap_evt_adv_report_t *p_adv_report, ble_wpts_service_data_t *p_service_data)
#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
#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
uint8_t wired_charge_detect
WPT Service Client structure. This contains various status information for the service.
#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.
#define BLE_WPTS_PTU_STATIC_HW_REV_POS
uint8_t adjust_power_response
#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.
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_BITMSK
#define BLE_WPTS_ENABLE_PRU_ADJ_POWER_BITPOS
#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.
#define BLE_WPTS_PRU_INFO_BLE_BITMSK
#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.
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.
#define BLE_WPTS_PRU_DYNAMIC_VRECT_HIGH_DYN_POS
uint8_t enable_pru_output
#define BLE_WPTS_PRU_DYNAMIC_IRECT_POS
uint32_t ble_wpts_c_init(const ble_wpts_c_init_t *p_wpts_c_init)
Initialize the WPT Service Client.
#define BLE_WPTS_ADV_PRU_TX_POWER_LEVEL_OFFSET
uint8_t ptu_max_source_impedance
#define BLE_WPTS_PRU_DYNAMIC_PTU_TESTER_COMMAND_POS
PRU Alert Parameter structure.
#define BLE_WPTS_PRU_ALERT_CHARGE_COMPLETE_BITMSK
#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)
static void on_read_rsp(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
Handle read response events.
#define BLE_WPTS_PTU_STATIC_PTU_CLASS_POS
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_IMPEDANCE_BITPOS
PTU Static characteristic Option bitfield definitions.
#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.
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.
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_RESISTANCE_BITMSK
#define BLE_WPTS_PRU_DYNAMIC_VRECT_SET_DYN_POS
uint16_t prua_cccd_handle
#define BLE_WPTS_PTU_STATIC_FW_REV_POS
#define BLE_WPTS_PTU_STATIC_MAX_SOURCE_IMPEDANCE_BITMSK
uint8_t devices_supported_bitval
#define BLE_WPTS_HANDLE_OFFSET_MAX
ptu_tester_command_t tester_command
#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.
#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
#define BLE_WPTS_PRU_ALERT_MODE_TRANSITION_BITMSK
uint8_t option_fields_r1_valid
uint16_t vrect_high_static
#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
#define BLE_WPTS_PRU_DYNAMIC_ALERT_CHARGE_PORT_BITMSK
#define BLE_WPTS_PRU_DYNAMIC_PRU_ALERT_POS
uint8_t ptu_max_load_resistance
#define BLE_WPTS_PTU_STATIC_OPTION_MAX_IMPEDANCE_BITMSK
ble_wpts_c_evt_type_t type
#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
#define BLE_WPTS_PTU_STATIC_LEN
uint8_t option_valid_max_imp
#define BLE_WPTS_PRU_ALERT_OVER_VOLTAGE_BITMSK
#define BLE_WPTS_PRU_STATIC_LEN
#define BLE_WPTS_PRU_ALERT_SELF_PROTECTION_BITPOS
WPT Service Client init structure. This contains all options and data needed for initialization of th...
#define BLE_WPTS_PRU_STATIC_PROTOCOL_REV_POS
uint8_t pru_over_temperature
#define BLE_WPTS_ADV_PRU_RSSI_PARAMS_POS
#define BLE_WPTS_PRU_CONTROL_TIME_SET_POS
WPT Service Client event.
#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.
#define BLE_WPTS_ADV_ANTENNA_GAIN_OFFSET
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.
#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.
#define BLE_WPTS_PRU_STATIC_PRU_INFORMATION_POS
#define BLE_WPTS_HANDLE_OFFSET_PRU_ALERT_CCCD
#define BLE_WPTS_ADV_SERVICE_DATA_LENGTH
#define BLE_WPTS_ENABLE_PRU_OUTPUT_BITMSK
#define BLE_WPTS_PRU_STATIC_PRECT_MAX_POS
uint8_t option_valid_max_res
uint8_t info_nfc_receiver
uint8_t device_address[BLE_GAP_ADDR_LEN]
uint16_t vrect_min_static
#define BLE_WPTS_HANDLE_OFFSET_PTU_STATIC
#define BLE_WPTS_PRU_INFO_POWER_CONTROL_PREF_BITPOS
#define BLE_WPTS_HANDLE_OFFSET_PRU_STATIC
#define BLE_WPTS_PRU_DYNAMIC_ALERT_ADJ_POWER_RESP_BITMSK
#define BLE_WPTS_PRU_CONTROL_ENABLES_POS
PRU Control characteristic fields byte positions.
uint8_t enable_pru_charge_indicator
#define BLE_WPTS_ENABLE_PRU_OUTPUT_BITPOS
PRU Control characteristic Enables bit field definitions.
static uint16_t m_pending_write_conn_handle
#define BLE_WPTS_PRU_INFO_ADJUST_POWER_BITMSK
pru_dynamic_t pru_dynamic
#define BLE_WPTS_PRU_ALERT_SELF_PROTECTION_BITMSK
static ble_wpts_c_evt_handler_t m_wpts_c_evt_handler
static void on_write_rsp(ble_wpts_c_t *p_wpts_c, ble_evt_t *p_ble_evt)
Handle write response events.
#define BLE_WPTS_PRU_DYNAMIC_VRECT_MIN_DYN_POS
#define BLE_WPTS_PTU_STATIC_PROTOCOL_REV_POS
uint8_t info_ptu_test_mode
static uint16_t m_pending_write_cmd_char_handle
uint8_t pru_self_protection
#define BLE_WPTS_PRU_ALERT_WIRED_CHARGER_DETECT_BITMSK
#define BLE_WPTS_ENABLE_PRU_CHARGE_INDICATOR_BITPOS
ptu_tester_command_t
PTU Tester commands.
#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.
#define BLE_WPTS_ADV_PRU_RSSI_PRU_PWR_BITPOS
#define BLE_WPTS_PRU_INFO_PTU_TEST_MODE_BITMSK
ctl_adj_power_t adj_power
#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.
#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.
#define BLE_WPTS_PTU_STATIC_PTU_POWER_POS
PRU Dynamic Parameter structure.
#define BLE_WPTS_PRU_DYNAMIC_VRECT_POS
#define BLE_WPTS_PRU_INFO_BLE_BITPOS
#define BLE_WPTS_PRU_ALERT_CHARGE_COMPLETE_BITPOS
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_SUPPORTED_POS
#define BLE_WPTS_PRU_STATIC_PRU_CATEGORY_POS