we now have a working nRFGattClient::write()
parent
3bea28cfae
commit
16137b5897
|
@ -65,6 +65,19 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
DiscoveredCharacteristic::onDataReadCallback(&response);
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GATTC_EVT_WRITE_RSP:
|
||||
if (DiscoveredCharacteristic::onDataWriteCallback != NULL) {
|
||||
GattWriteCallbackParams response = {
|
||||
.handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
|
||||
.writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
|
||||
.offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
|
||||
.len = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
|
||||
.data = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
|
||||
};
|
||||
DiscoveredCharacteristic::onDataWriteCallback(&response);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
sdSingleton.progressCharacteristicDiscovery();
|
||||
|
|
|
@ -115,8 +115,31 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
virtual ble_error_t write(GattClient::WriteOp_t cmd, Gap::Handle_t connHandle, size_t length, const uint8_t *value) const {
|
||||
return BLE_ERROR_NONE;
|
||||
virtual ble_error_t write(GattClient::WriteOp_t cmd, Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, size_t length, const uint8_t *value) const {
|
||||
ble_gattc_write_params_t writeParams = {
|
||||
.write_op = cmd,
|
||||
// .flags = 0,
|
||||
.handle = attributeHandle,
|
||||
.offset = 0,
|
||||
.len = length,
|
||||
.p_value = const_cast<uint8_t *>(value),
|
||||
};
|
||||
|
||||
uint32_t rc = sd_ble_gattc_write(connHandle, &writeParams);
|
||||
if (rc == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
switch (rc) {
|
||||
case NRF_ERROR_BUSY:
|
||||
return BLE_STACK_BUSY;
|
||||
case BLE_ERROR_NO_TX_BUFFERS:
|
||||
return BLE_ERROR_NO_MEM;
|
||||
case BLE_ERROR_INVALID_CONN_HANDLE:
|
||||
case NRF_ERROR_INVALID_STATE:
|
||||
case NRF_ERROR_INVALID_ADDR:
|
||||
default:
|
||||
return BLE_ERROR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue