Release 0.4.6
============= Enhancements ~~~~~~~~~~~~ * Add connection handle to GATT callback parameters. This paves the way for applications requiring multiple concurrent connections: read/write/HVX callbacks will be able to distinguish between peripherals by comparing per- device connection handles. * nRFGattClient: move the allocation of the singleton to within the getInstance() method. This saves memory when nRFGattClient isn't instantiated. * Disable GattClient features when using S110 SoftDevice. This is controlled by the pre-processor macros: MCU_NORDIC_16K_S110 or MCU_NORDIC_16K_S110.master
commit
c9a77b8253
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ble-nrf51822",
|
||||
"version": "0.4.5",
|
||||
"version": "0.4.6",
|
||||
"description": "Nordic stack and drivers for the mbed BLE API.",
|
||||
"keywords": [
|
||||
"Bluetooth",
|
||||
|
@ -19,7 +19,7 @@
|
|||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"ble": "~0.4.5"
|
||||
"ble": "~0.4.6"
|
||||
},
|
||||
"extraIncludes": [
|
||||
"source/btle",
|
||||
|
|
|
@ -52,11 +52,13 @@ static void sys_evt_dispatch(uint32_t sys_evt)
|
|||
|
||||
error_t btle_init(void)
|
||||
{
|
||||
nrf_clock_lfclksrc_t clockSource;
|
||||
if (NRF_CLOCK->LFCLKSRC & (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos)) {
|
||||
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);
|
||||
clockSource = NRF_CLOCK_LFCLKSRC_XTAL_20_PPM;
|
||||
} else {
|
||||
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, NULL);
|
||||
clockSource = NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION;
|
||||
}
|
||||
SOFTDEVICE_HANDLER_INIT(clockSource, NULL);
|
||||
|
||||
// Enable BLE stack
|
||||
/**
|
||||
|
@ -107,7 +109,9 @@ static void btle_handler(ble_evt_t *p_ble_evt)
|
|||
|
||||
dm_ble_evt_handler(p_ble_evt);
|
||||
|
||||
#if !defined(MCU_NORDIC_16K_S110) && !defined(MCU_NORDIC_32K_S110)
|
||||
bleGattcEventHandler(p_ble_evt);
|
||||
#endif
|
||||
|
||||
/* Custom event handler */
|
||||
switch (p_ble_evt->header.evt_id) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "nRF5xServiceDiscovery.h"
|
||||
#include "nRF5xGattClient.h"
|
||||
|
||||
#if !defined(MCU_NORDIC_16K_S110) && !defined(MCU_NORDIC_32K_S110)
|
||||
void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
||||
{
|
||||
nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery;
|
||||
|
@ -56,10 +57,11 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_READ_RSP: {
|
||||
GattReadCallbackParams response = {
|
||||
.handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
|
||||
.offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
|
||||
.len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
|
||||
.data = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
|
||||
.connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
.handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
|
||||
.offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
|
||||
.len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
|
||||
.data = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
|
||||
};
|
||||
nRF5xGattClient::getInstance().processReadResponse(&response);
|
||||
}
|
||||
|
@ -67,11 +69,12 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_WRITE_RSP: {
|
||||
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,
|
||||
.connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
.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,
|
||||
};
|
||||
nRF5xGattClient::getInstance().processWriteResponse(&response);
|
||||
}
|
||||
|
@ -79,10 +82,11 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_HVX: {
|
||||
GattHVXCallbackParams params;
|
||||
params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle;
|
||||
params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
|
||||
params.len = p_ble_evt->evt.gattc_evt.params.hvx.len;
|
||||
params.data = p_ble_evt->evt.gattc_evt.params.hvx.data;
|
||||
params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle;
|
||||
params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle;
|
||||
params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
|
||||
params.len = p_ble_evt->evt.gattc_evt.params.hvx.len;
|
||||
params.data = p_ble_evt->evt.gattc_evt.params.hvx.data;
|
||||
|
||||
nRF5xGattClient::getInstance().processHVXEvent(¶ms);
|
||||
}
|
||||
|
@ -92,4 +96,5 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
sdSingleton.progressCharacteristicDiscovery();
|
||||
sdSingleton.progressServiceDiscovery();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -80,6 +80,8 @@ public:
|
|||
return BLE_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
/* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
|
||||
#if !defined(MCU_NORDIC_16K_S110) && !defined(MCU_NORDIC_32K_S110)
|
||||
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) {
|
||||
ble_gap_scan_params_t scanParams = {
|
||||
.active = scanningParams.getActiveScanning(), /**< If 1, perform active scanning (scan requests). */
|
||||
|
@ -104,6 +106,7 @@ public:
|
|||
|
||||
return BLE_STACK_BUSY;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
#include "nRF5xGattClient.h"
|
||||
|
||||
nRF5xGattClient nRFGattClientSingleton;
|
||||
|
||||
nRF5xGattClient &
|
||||
nRF5xGattClient::getInstance(void) {
|
||||
static nRF5xGattClient nRFGattClientSingleton;
|
||||
return nRFGattClientSingleton;
|
||||
}
|
||||
|
||||
#if !defined(MCU_NORDIC_16K_S110) && !defined(MCU_NORDIC_32K_S110)
|
||||
ble_error_t
|
||||
nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
|
||||
ServiceDiscovery::ServiceCallback_t sc,
|
||||
|
@ -32,3 +32,4 @@ nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t
|
|||
{
|
||||
return discovery.launch(connectionHandle, sc, cc, matchingServiceUUIDIn, matchingCharacteristicUUIDIn);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -25,6 +25,12 @@ class nRF5xGattClient : public GattClient
|
|||
public:
|
||||
static nRF5xGattClient &getInstance();
|
||||
|
||||
/**
|
||||
* When using S110, all Gatt client features will return
|
||||
* BLE_ERROR_NOT_IMPLEMENTED
|
||||
*/
|
||||
#if !defined(MCU_NORDIC_16K_S110) && !defined(MCU_NORDIC_32K_S110)
|
||||
|
||||
/**
|
||||
* Launch service discovery. Once launched, service discovery will remain
|
||||
* active with callbacks being issued back into the application for matching
|
||||
|
@ -152,6 +158,8 @@ private:
|
|||
|
||||
private:
|
||||
nRF5xServiceDiscovery discovery;
|
||||
|
||||
#endif // if !S110
|
||||
};
|
||||
|
||||
#endif // ifndef __NRF51822_GATT_CLIENT_H__
|
||||
|
|
|
@ -375,21 +375,23 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
switch (eventType) {
|
||||
case GattServerEvents::GATT_EVENT_DATA_WRITTEN: {
|
||||
GattWriteCallbackParams cbParams = {
|
||||
.handle = handle_value,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.write.op),
|
||||
.offset = gattsEventP->params.write.offset,
|
||||
.len = gattsEventP->params.write.len,
|
||||
.data = gattsEventP->params.write.data
|
||||
.connHandle = gattsEventP->conn_handle,
|
||||
.handle = handle_value,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.write.op),
|
||||
.offset = gattsEventP->params.write.offset,
|
||||
.len = gattsEventP->params.write.len,
|
||||
.data = gattsEventP->params.write.data
|
||||
};
|
||||
handleDataWrittenEvent(&cbParams);
|
||||
break;
|
||||
}
|
||||
case GattServerEvents::GATT_EVENT_WRITE_AUTHORIZATION_REQ: {
|
||||
GattWriteAuthCallbackParams cbParams = {
|
||||
.handle = handle_value,
|
||||
.offset = gattsEventP->params.authorize_request.request.write.offset,
|
||||
.len = gattsEventP->params.authorize_request.request.write.len,
|
||||
.data = gattsEventP->params.authorize_request.request.write.data,
|
||||
.connHandle = gattsEventP->conn_handle,
|
||||
.handle = handle_value,
|
||||
.offset = gattsEventP->params.authorize_request.request.write.offset,
|
||||
.len = gattsEventP->params.authorize_request.request.write.len,
|
||||
.data = gattsEventP->params.authorize_request.request.write.data,
|
||||
};
|
||||
ble_gatts_rw_authorize_reply_params_t reply = {
|
||||
.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE,
|
||||
|
@ -410,11 +412,12 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
*/
|
||||
if (reply.params.write.gatt_status == BLE_GATT_STATUS_SUCCESS) {
|
||||
GattWriteCallbackParams cbParams = {
|
||||
.handle = handle_value,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.authorize_request.request.write.op),
|
||||
.offset = gattsEventP->params.authorize_request.request.write.offset,
|
||||
.len = gattsEventP->params.authorize_request.request.write.len,
|
||||
.data = gattsEventP->params.authorize_request.request.write.data,
|
||||
.connHandle = gattsEventP->conn_handle,
|
||||
.handle = handle_value,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.authorize_request.request.write.op),
|
||||
.offset = gattsEventP->params.authorize_request.request.write.offset,
|
||||
.len = gattsEventP->params.authorize_request.request.write.len,
|
||||
.data = gattsEventP->params.authorize_request.request.write.data,
|
||||
};
|
||||
handleDataWrittenEvent(&cbParams);
|
||||
}
|
||||
|
@ -422,10 +425,11 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
}
|
||||
case GattServerEvents::GATT_EVENT_READ_AUTHORIZATION_REQ: {
|
||||
GattReadAuthCallbackParams cbParams = {
|
||||
.handle = handle_value,
|
||||
.offset = gattsEventP->params.authorize_request.request.read.offset,
|
||||
.len = 0,
|
||||
.data = NULL
|
||||
.connHandle = gattsEventP->conn_handle,
|
||||
.handle = handle_value,
|
||||
.offset = gattsEventP->params.authorize_request.request.read.offset,
|
||||
.len = 0,
|
||||
.data = NULL
|
||||
};
|
||||
|
||||
ble_gatts_rw_authorize_reply_params_t reply = {
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "compiler_abstraction.h"
|
||||
#include "nordic_common.h"
|
||||
#ifdef DEBUG
|
||||
#include "bsp.h"
|
||||
|
||||
/* global error variables - in order to prevent removal by optimizers */
|
||||
uint32_t m_error_code;
|
||||
|
|
Loading…
Reference in New Issue