Release 0.4.3

=============

This is a minor release.

Enhancements
~~~~~~~~~~~~

* Rename nRF51... to nRF5x... This prepares for the arrival of nRF52.
* Switch Github repository URL to ARMmbed organization.

* Add support to handle radio-notification callback as a FuncionPointer so that
  we can have <object, member> pairs for callbacks.

Bugfixes
~~~~~~~~

none.
This commit is contained in:
Rohit Grover 2015-07-21 13:09:56 +01:00
commit ec744cbd62
19 changed files with 181 additions and 162 deletions

View file

@ -1,6 +1,6 @@
{
"name": "ble-nrf51822",
"version": "0.4.2",
"version": "0.4.3",
"description": "Nordic stack and drivers for the mbed BLE API.",
"keywords": [
"Bluetooth",
@ -8,7 +8,7 @@
],
"author": "Rohit Grover",
"repository": {
"url": "git@github.com:mbedmicro/nRF51822.git",
"url": "git@github.com:ARMmbed/nRF51822.git",
"type": "git"
},
"homepage": "https://developer.mbed.org/teams/Nordic-Semiconductor/",
@ -19,7 +19,7 @@
}
],
"dependencies": {
"ble": "~0.4.2"
"ble": "~0.4.3"
},
"extraIncludes": [
"source/btle",

View file

@ -31,9 +31,9 @@
#include "pstorage.h"
#include "ble/GapEvents.h"
#include "nRF51Gap.h"
#include "nRF51GattServer.h"
#include "nRF51SecurityManager.h"
#include "nRF5xGap.h"
#include "nRF5xGattServer.h"
#include "nRF5xSecurityManager.h"
#include "device_manager.h"
@ -113,11 +113,11 @@ static void btle_handler(ble_evt_t *p_ble_evt)
switch (p_ble_evt->header.evt_id) {
case BLE_GAP_EVT_CONNECTED: {
Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
nRF51Gap::getInstance().setConnectionHandle(handle);
nRF5xGap::getInstance().setConnectionHandle(handle);
const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params));
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
nRF51Gap::getInstance().processConnectionEvent(handle,
nRF5xGap::getInstance().processConnectionEvent(handle,
static_cast<Gap::Role_t>(p_ble_evt->evt.gap_evt.params.connected.role),
static_cast<Gap::AddressType_t>(peer->addr_type), peer->addr,
static_cast<Gap::AddressType_t>(own->addr_type), own->addr,
@ -129,7 +129,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
// Since we are not in a connection and have not started advertising,
// store bonds
nRF51Gap::getInstance().setConnectionHandle (BLE_CONN_HANDLE_INVALID);
nRF5xGap::getInstance().setConnectionHandle (BLE_CONN_HANDLE_INVALID);
Gap::DisconnectionReason_t reason;
switch (p_ble_evt->evt.gap_evt.params.disconnected.reason) {
@ -148,16 +148,16 @@ static void btle_handler(ble_evt_t *p_ble_evt)
reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason);
break;
}
nRF51Gap::getInstance().processDisconnectionEvent(handle, reason);
nRF5xGap::getInstance().processDisconnectionEvent(handle, reason);
break;
}
case BLE_GAP_EVT_PASSKEY_DISPLAY:
nRF51SecurityManager::getInstance().processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey);
nRF5xSecurityManager::getInstance().processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey);
break;
case BLE_GAP_EVT_TIMEOUT:
nRF51Gap::getInstance().processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src));
nRF5xGap::getInstance().processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src));
break;
case BLE_GATTC_EVT_TIMEOUT:
@ -169,7 +169,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
case BLE_GAP_EVT_ADV_REPORT: {
const ble_gap_evt_adv_report_t *advReport = &p_ble_evt->evt.gap_evt.params.adv_report;
nRF51Gap::getInstance().processAdvertisementReport(advReport->peer_addr.addr,
nRF5xGap::getInstance().processAdvertisementReport(advReport->peer_addr.addr,
advReport->rssi,
advReport->scan_rsp,
static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type),
@ -182,7 +182,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
break;
}
nRF51GattServer::getInstance().hwCallback(p_ble_evt);
nRF5xGattServer::getInstance().hwCallback(p_ble_evt);
}
/*! @brief Callback when an error occurs inside the SoftDevice */

View file

@ -14,12 +14,12 @@
* limitations under the License.
*/
#include "nRF51ServiceDiscovery.h"
#include "nRF51GattClient.h"
#include "nRF5xServiceDiscovery.h"
#include "nRF5xGattClient.h"
void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
{
nRF51ServiceDiscovery &sdSingleton = nRF51GattClient::getInstance().discovery;
nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery;
switch (p_ble_evt->header.evt_id) {
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
@ -61,7 +61,7 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
.len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
.data = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
};
nRF51GattClient::getInstance().processReadResponse(&response);
nRF5xGattClient::getInstance().processReadResponse(&response);
}
break;
@ -73,7 +73,7 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
.len = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
.data = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
};
nRF51GattClient::getInstance().processWriteResponse(&response);
nRF5xGattClient::getInstance().processWriteResponse(&response);
}
break;
@ -84,7 +84,7 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
params.len = p_ble_evt->evt.gattc_evt.params.hvx.len;
params.data = p_ble_evt->evt.gattc_evt.params.hvx.data;
nRF51GattClient::getInstance().processHVXEvent(&params);
nRF5xGattClient::getInstance().processHVXEvent(&params);
}
break;
}

View file

@ -17,8 +17,8 @@
#include "btle.h"
#include "pstorage.h"
#include "nRF51Gap.h"
#include "nRF51SecurityManager.h"
#include "nRF5xGap.h"
#include "nRF5xSecurityManager.h"
#include "device_manager.h"
#include "btle_security.h"
@ -154,14 +154,14 @@ dm_handler(dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t ev
switch (p_event->event_id) {
case DM_EVT_SECURITY_SETUP: /* started */ {
const ble_gap_sec_params_t *peerParams = &p_event->event_param.p_gap_param->params.sec_params_request.peer_params;
nRF51SecurityManager::getInstance().processSecuritySetupInitiatedEvent(p_event->event_param.p_gap_param->conn_handle,
nRF5xSecurityManager::getInstance().processSecuritySetupInitiatedEvent(p_event->event_param.p_gap_param->conn_handle,
peerParams->bond,
peerParams->mitm,
(SecurityManager::SecurityIOCapabilities_t)peerParams->io_caps);
break;
}
case DM_EVT_SECURITY_SETUP_COMPLETE:
nRF51SecurityManager::getInstance().
nRF5xSecurityManager::getInstance().
processSecuritySetupCompletedEvent(p_event->event_param.p_gap_param->conn_handle,
(SecurityManager::SecurityCompletionStatus_t)(p_event->event_param.p_gap_param->params.auth_status.auth_status));
break;
@ -195,11 +195,11 @@ dm_handler(dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t ev
break;
}
nRF51SecurityManager::getInstance().processLinkSecuredEvent(p_event->event_param.p_gap_param->conn_handle, resolvedSecurityMode);
nRF5xSecurityManager::getInstance().processLinkSecuredEvent(p_event->event_param.p_gap_param->conn_handle, resolvedSecurityMode);
break;
}
case DM_EVT_DEVICE_CONTEXT_STORED:
nRF51SecurityManager::getInstance().processSecurityContextStoredEvent(p_event->event_param.p_gap_param->conn_handle);
nRF5xSecurityManager::getInstance().processSecurityContextStoredEvent(p_event->event_param.p_gap_param->conn_handle);
break;
default:
break;

View file

@ -14,16 +14,16 @@
* limitations under the License.
*/
#include "nRF51DiscoveredCharacteristic.h"
#include "nRF51GattClient.h"
#include "nRF5xDiscoveredCharacteristic.h"
#include "nRF5xGattClient.h"
#include "ble_gatt.h"
void
nRF51DiscoveredCharacteristic::setup(nRF51GattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn)
nRF5xDiscoveredCharacteristic::setup(nRF5xGattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn)
{
gattc = gattcIn;
connHandle = connectionHandleIn;
@ -40,12 +40,12 @@ nRF51DiscoveredCharacteristic::setup(nRF51GattClient *gattcIn,
}
void
nRF51DiscoveredCharacteristic::setup(nRF51GattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
UUID::ShortUUIDBytes_t uuidIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn)
nRF5xDiscoveredCharacteristic::setup(nRF5xGattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
UUID::ShortUUIDBytes_t uuidIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn)
{
gattc = gattcIn;
connHandle = connectionHandleIn;

View file

@ -20,17 +20,17 @@
#include "ble/DiscoveredCharacteristic.h"
#include "ble_gatt.h"
class nRF51GattClient; /* forward declaration */
class nRF5xGattClient; /* forward declaration */
class nRF51DiscoveredCharacteristic : public DiscoveredCharacteristic {
class nRF5xDiscoveredCharacteristic : public DiscoveredCharacteristic {
public:
void setup(nRF51GattClient *gattcIn,
void setup(nRF5xGattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn);
void setup(nRF51GattClient *gattcIn,
void setup(nRF5xGattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
UUID::ShortUUIDBytes_t uuidIn,
ble_gatt_char_props_t propsIn,

View file

@ -14,18 +14,22 @@
* limitations under the License.
*/
#include "nRF51Gap.h"
#include "nRF5xGap.h"
#include "mbed.h"
#include "common/common.h"
#include "ble_advdata.h"
#include "ble_hci.h"
nRF51Gap &nRF51Gap::getInstance() {
static nRF51Gap m_instance;
nRF5xGap &nRF5xGap::getInstance() {
static nRF5xGap m_instance;
return m_instance;
}
void radioNotificationStaticCallback(bool param) {
nRF5xGap::getInstance().processRadioNotificationEvent(param);
}
/**************************************************************************/
/*!
@brief Sets the advertising parameters and payload for the device
@ -63,7 +67,7 @@ nRF51Gap &nRF51Gap::getInstance() {
@endcode
*/
/**************************************************************************/
ble_error_t nRF51Gap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
ble_error_t nRF5xGap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
{
/* Make sure we don't exceed the advertising payload length */
if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
@ -128,7 +132,7 @@ ble_error_t nRF51Gap::setAdvertisingData(const GapAdvertisingData &advData, cons
@endcode
*/
/**************************************************************************/
ble_error_t nRF51Gap::startAdvertising(const GapAdvertisingParams &params)
ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
{
/* Make sure we support the advertising type */
if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
@ -196,7 +200,7 @@ ble_error_t nRF51Gap::startAdvertising(const GapAdvertisingParams &params)
@endcode
*/
/**************************************************************************/
ble_error_t nRF51Gap::stopAdvertising(void)
ble_error_t nRF5xGap::stopAdvertising(void)
{
/* Stop Advertising */
ASSERT(ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
@ -206,7 +210,7 @@ ble_error_t nRF51Gap::stopAdvertising(void)
return BLE_ERROR_NONE;
}
ble_error_t nRF51Gap::connect(const Address_t peerAddr,
ble_error_t nRF5xGap::connect(const Address_t peerAddr,
Gap::AddressType_t peerAddrType,
const ConnectionParams_t *connectionParams,
const GapScanningParams *scanParamsIn)
@ -265,7 +269,7 @@ ble_error_t nRF51Gap::connect(const Address_t peerAddr,
}
}
ble_error_t nRF51Gap::disconnect(Handle_t connectionHandle, DisconnectionReason_t reason)
ble_error_t nRF5xGap::disconnect(Handle_t connectionHandle, DisconnectionReason_t reason)
{
state.advertising = 0;
state.connected = 0;
@ -296,12 +300,12 @@ ble_error_t nRF51Gap::disconnect(Handle_t connectionHandle, DisconnectionReason_
@retval BLE_ERROR_NONE
Everything executed properly
*/
ble_error_t nRF51Gap::disconnect(DisconnectionReason_t reason)
ble_error_t nRF5xGap::disconnect(DisconnectionReason_t reason)
{
return disconnect(m_connectionHandle, reason);
}
ble_error_t nRF51Gap::getPreferredConnectionParams(ConnectionParams_t *params)
ble_error_t nRF5xGap::getPreferredConnectionParams(ConnectionParams_t *params)
{
ASSERT_INT(NRF_SUCCESS,
sd_ble_gap_ppcp_get(reinterpret_cast<ble_gap_conn_params_t *>(params)),
@ -310,7 +314,7 @@ ble_error_t nRF51Gap::getPreferredConnectionParams(ConnectionParams_t *params)
return BLE_ERROR_NONE;
}
ble_error_t nRF51Gap::setPreferredConnectionParams(const ConnectionParams_t *params)
ble_error_t nRF5xGap::setPreferredConnectionParams(const ConnectionParams_t *params)
{
ASSERT_INT(NRF_SUCCESS,
sd_ble_gap_ppcp_set(reinterpret_cast<const ble_gap_conn_params_t *>(params)),
@ -319,7 +323,7 @@ ble_error_t nRF51Gap::setPreferredConnectionParams(const ConnectionParams_t *par
return BLE_ERROR_NONE;
}
ble_error_t nRF51Gap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *newParams)
ble_error_t nRF5xGap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *newParams)
{
uint32_t rc;
@ -336,7 +340,7 @@ ble_error_t nRF51Gap::updateConnectionParams(Handle_t handle, const ConnectionPa
@brief Sets the 16-bit connection handle
*/
/**************************************************************************/
void nRF51Gap::setConnectionHandle(uint16_t con_handle)
void nRF5xGap::setConnectionHandle(uint16_t con_handle)
{
m_connectionHandle = con_handle;
}
@ -346,7 +350,7 @@ void nRF51Gap::setConnectionHandle(uint16_t con_handle)
@brief Gets the 16-bit connection handle
*/
/**************************************************************************/
uint16_t nRF51Gap::getConnectionHandle(void)
uint16_t nRF5xGap::getConnectionHandle(void)
{
return m_connectionHandle;
}
@ -367,7 +371,7 @@ uint16_t nRF51Gap::getConnectionHandle(void)
@endcode
*/
/**************************************************************************/
ble_error_t nRF51Gap::setAddress(AddressType_t type, const Address_t address)
ble_error_t nRF5xGap::setAddress(AddressType_t type, const Address_t address)
{
if (type > ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) {
return BLE_ERROR_PARAM_OUT_OF_RANGE;
@ -382,7 +386,7 @@ ble_error_t nRF51Gap::setAddress(AddressType_t type, const Address_t address)
return BLE_ERROR_NONE;
}
ble_error_t nRF51Gap::getAddress(AddressType_t *typeP, Address_t address)
ble_error_t nRF5xGap::getAddress(AddressType_t *typeP, Address_t address)
{
ble_gap_addr_t dev_addr;
if (sd_ble_gap_address_get(&dev_addr) != NRF_SUCCESS) {
@ -398,7 +402,7 @@ ble_error_t nRF51Gap::getAddress(AddressType_t *typeP, Address_t address)
return BLE_ERROR_NONE;
}
ble_error_t nRF51Gap::setDeviceName(const uint8_t *deviceName)
ble_error_t nRF5xGap::setDeviceName(const uint8_t *deviceName)
{
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed
@ -410,7 +414,7 @@ ble_error_t nRF51Gap::setDeviceName(const uint8_t *deviceName)
}
}
ble_error_t nRF51Gap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
ble_error_t nRF5xGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
{
if (sd_ble_gap_device_name_get(deviceName, (uint16_t *)lengthP) == NRF_SUCCESS) {
return BLE_ERROR_NONE;
@ -419,7 +423,7 @@ ble_error_t nRF51Gap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
}
}
ble_error_t nRF51Gap::setAppearance(GapAdvertisingData::Appearance appearance)
ble_error_t nRF5xGap::setAppearance(GapAdvertisingData::Appearance appearance)
{
if (sd_ble_gap_appearance_set(appearance) == NRF_SUCCESS) {
return BLE_ERROR_NONE;
@ -428,7 +432,7 @@ ble_error_t nRF51Gap::setAppearance(GapAdvertisingData::Appearance appearance)
}
}
ble_error_t nRF51Gap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
ble_error_t nRF5xGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
{
if (sd_ble_gap_appearance_get(reinterpret_cast<uint16_t *>(appearanceP))) {
return BLE_ERROR_NONE;
@ -438,7 +442,7 @@ ble_error_t nRF51Gap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
}
/* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */
ble_error_t nRF51Gap::setTxPower(int8_t txPower)
ble_error_t nRF5xGap::setTxPower(int8_t txPower)
{
unsigned rc;
if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) {
@ -454,7 +458,7 @@ ble_error_t nRF51Gap::setTxPower(int8_t txPower)
return BLE_ERROR_NONE;
}
void nRF51Gap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
void nRF5xGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
{
static const int8_t permittedTxValues[] = {
-40, -30, -20, -16, -12, -8, -4, 0, 4

View file

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef __NRF51822_GAP_H__
#define __NRF51822_GAP_H__
#ifndef __NRF5x_GAP_H__
#define __NRF5x_GAP_H__
#include "mbed.h"
#include "ble/blecommon.h"
@ -29,16 +29,18 @@
#include "ble_radio_notification.h"
#include "btle_security.h"
void radioNotificationStaticCallback(bool param);
/**************************************************************************/
/*!
\brief
*/
/**************************************************************************/
class nRF51Gap : public Gap
class nRF5xGap : public Gap
{
public:
static nRF51Gap &getInstance();
static nRF5xGap &getInstance();
/* Functions that must be implemented from Gap */
virtual ble_error_t setAddress(AddressType_t type, const Address_t address);
@ -70,9 +72,12 @@ public:
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
virtual void onRadioNotification(RadioNotificationEventCallback_t callback) {
Gap::onRadioNotification(callback);
ble_radio_notification_init(NRF_APP_PRIORITY_HIGH, NRF_RADIO_NOTIFICATION_DISTANCE_800US, radioNotificationCallback);
virtual ble_error_t initRadioNotification(void) {
if (ble_radio_notification_init(NRF_APP_PRIORITY_HIGH, NRF_RADIO_NOTIFICATION_DISTANCE_800US, radioNotificationStaticCallback) == NRF_SUCCESS) {
return BLE_ERROR_NONE;
}
return BLE_ERROR_UNSPECIFIED;
}
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) {
@ -100,14 +105,24 @@ public:
return BLE_STACK_BUSY;
}
private:
/**
* A helper function to process radio-notification events; to be called internally.
* @param param [description]
*/
void processRadioNotificationEvent(bool param) {
radioNotificationCallback.call(param);
}
friend void radioNotificationStaticCallback(bool param); /* allow invocations of processRadioNotificationEvent() */
private:
uint16_t m_connectionHandle;
nRF51Gap() {
nRF5xGap() {
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
}
nRF51Gap(nRF51Gap const &);
void operator=(nRF51Gap const &);
nRF5xGap(nRF5xGap const &);
void operator=(nRF5xGap const &);
};
#endif // ifndef __NRF51822_GAP_H__
#endif // ifndef __NRF5x_GAP_H__

View file

@ -14,17 +14,17 @@
* limitations under the License.
*/
#include "nRF51GattClient.h"
#include "nRF5xGattClient.h"
nRF51GattClient nRFGattClientSingleton;
nRF5xGattClient nRFGattClientSingleton;
nRF51GattClient &
nRF51GattClient::getInstance(void) {
nRF5xGattClient &
nRF5xGattClient::getInstance(void) {
return nRFGattClientSingleton;
}
ble_error_t
nRF51GattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc,
ServiceDiscovery::CharacteristicCallback_t cc,
const UUID &matchingServiceUUIDIn,

View file

@ -18,12 +18,12 @@
#define __NRF51822_GATT_CLIENT_H__
#include "ble/GattClient.h"
#include "nRF51ServiceDiscovery.h"
#include "nRF5xServiceDiscovery.h"
class nRF51GattClient : public GattClient
class nRF5xGattClient : public GattClient
{
public:
static nRF51GattClient &getInstance();
static nRF5xGattClient &getInstance();
/**
* Launch service discovery. Once launched, service discovery will remain
@ -140,18 +140,18 @@ public:
}
public:
nRF51GattClient() : discovery(this) {
nRF5xGattClient() : discovery(this) {
/* empty */
}
friend void bleGattcEventHandler(const ble_evt_t *p_ble_evt);
private:
nRF51GattClient(const nRF51GattClient &);
const nRF51GattClient& operator=(const nRF51GattClient &);
nRF5xGattClient(const nRF5xGattClient &);
const nRF5xGattClient& operator=(const nRF5xGattClient &);
private:
nRF51ServiceDiscovery discovery;
nRF5xServiceDiscovery discovery;
};
#endif // ifndef __NRF51822_GATT_CLIENT_H__

View file

@ -14,16 +14,16 @@
* limitations under the License.
*/
#include "nRF51GattServer.h"
#include "nRF5xGattServer.h"
#include "mbed.h"
#include "common/common.h"
#include "btle/custom/custom_helper.h"
#include "nRF51Gap.h"
#include "nRF5xGap.h"
nRF51GattServer &nRF51GattServer::getInstance(void) {
static nRF51GattServer m_instance;
nRF5xGattServer &nRF5xGattServer::getInstance(void) {
static nRF5xGattServer m_instance;
return m_instance;
}
@ -43,7 +43,7 @@ nRF51GattServer &nRF51GattServer::getInstance(void) {
@endcode
*/
/**************************************************************************/
ble_error_t nRF51GattServer::addService(GattService &service)
ble_error_t nRF5xGattServer::addService(GattService &service)
{
/* ToDo: Make sure we don't overflow the array, etc. */
/* ToDo: Make sure this service UUID doesn't already exist (?) */
@ -157,12 +157,12 @@ ble_error_t nRF51GattServer::addService(GattService &service)
Everything executed properly
*/
/**************************************************************************/
ble_error_t nRF51GattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
ble_error_t nRF5xGattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
{
return read(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, lengthP);
}
ble_error_t nRF51GattServer::read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
ble_error_t nRF5xGattServer::read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
{
ble_gatts_value_t value = {
.len = *lengthP,
@ -197,14 +197,14 @@ ble_error_t nRF51GattServer::read(Gap::Handle_t connectionHandle, GattAttribute:
Everything executed properly
*/
/**************************************************************************/
ble_error_t nRF51GattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
ble_error_t nRF5xGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
return write(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, len, localOnly);
}
ble_error_t nRF51GattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
uint16_t gapConnectionHandle = nRF51Gap::getInstance().getConnectionHandle();
uint16_t gapConnectionHandle = nRF5xGap::getInstance().getConnectionHandle();
ble_error_t returnValue = BLE_ERROR_NONE;
ble_gatts_value_t value = {
@ -259,13 +259,13 @@ ble_error_t nRF51GattServer::write(Gap::Handle_t connectionHandle, GattAttribute
return returnValue;
}
ble_error_t nRF51GattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
ble_error_t nRF5xGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
{
/* Forward the call with the default connection handle. */
return areUpdatesEnabled(nRF51Gap::getInstance().getConnectionHandle(), characteristic, enabledP);
return areUpdatesEnabled(nRF5xGap::getInstance().getConnectionHandle(), characteristic, enabledP);
}
ble_error_t nRF51GattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
{
int characteristicIndex = resolveValueHandleToCharIndex(characteristic.getValueHandle());
if (characteristicIndex == -1) {
@ -297,7 +297,7 @@ ble_error_t nRF51GattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, c
@brief Callback handler for events getting pushed up from the SD
*/
/**************************************************************************/
void nRF51GattServer::hwCallback(ble_evt_t *p_ble_evt)
void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
{
GattAttribute::Handle_t handle_value;
GattServerEvents::gattEvent_t eventType;

View file

@ -24,10 +24,10 @@
#include "ble/Gap.h"
#include "ble/GattServer.h"
class nRF51GattServer : public GattServer
class nRF5xGattServer : public GattServer
{
public:
static nRF51GattServer &getInstance();
static nRF5xGattServer &getInstance();
/* Functions that must be implemented from GattServer */
virtual ble_error_t addService(GattService &);
@ -86,13 +86,13 @@ private:
uint8_t descriptorCount;
uint16_t nrfDescriptorHandles[BLE_TOTAL_DESCRIPTORS];
nRF51GattServer() : GattServer(), p_characteristics(), nrfCharacteristicHandles(), p_descriptors(), descriptorCount(0), nrfDescriptorHandles() {
nRF5xGattServer() : GattServer(), p_characteristics(), nrfCharacteristicHandles(), p_descriptors(), descriptorCount(0), nrfDescriptorHandles() {
/* empty */
}
private:
nRF51GattServer(const nRF51GattServer &);
const nRF51GattServer& operator=(const nRF51GattServer &);
nRF5xGattServer(const nRF5xGattServer &);
const nRF5xGattServer& operator=(const nRF5xGattServer &);
};
#endif // ifndef __NRF51822_GATT_SERVER_H__

View file

@ -14,9 +14,9 @@
* limitations under the License.
*/
#include "nRF51SecurityManager.h"
#include "nRF5xSecurityManager.h"
nRF51SecurityManager &nRF51SecurityManager::getInstance(void) {
static nRF51SecurityManager m_instance;
nRF5xSecurityManager &nRF5xSecurityManager::getInstance(void) {
static nRF5xSecurityManager m_instance;
return m_instance;
}

View file

@ -22,10 +22,10 @@
#include "ble/SecurityManager.h"
#include "btle_security.h"
class nRF51SecurityManager : public SecurityManager
class nRF5xSecurityManager : public SecurityManager
{
public:
static nRF51SecurityManager &getInstance();
static nRF5xSecurityManager &getInstance();
/* Functions that must be implemented from SecurityManager */
virtual ble_error_t init(bool enableBonding,
@ -44,13 +44,13 @@ public:
}
public:
nRF51SecurityManager() {
nRF5xSecurityManager() {
/* empty */
}
private:
nRF51SecurityManager(const nRF51SecurityManager &);
const nRF51SecurityManager& operator=(const nRF51SecurityManager &);
nRF5xSecurityManager(const nRF5xSecurityManager &);
const nRF5xSecurityManager& operator=(const nRF5xSecurityManager &);
};
#endif // ifndef __NRF51822_SECURITY_MANAGER_H__

View file

@ -14,12 +14,12 @@
* limitations under the License.
*/
#include "nRF51ServiceDiscovery.h"
#include "nRF5xServiceDiscovery.h"
ble_error_t
nRF51ServiceDiscovery::launchCharacteristicDiscovery(Gap::Handle_t connectionHandle,
Gap::Handle_t startHandle,
Gap::Handle_t endHandle)
nRF5xServiceDiscovery::launchCharacteristicDiscovery(Gap::Handle_t connectionHandle,
Gap::Handle_t startHandle,
Gap::Handle_t endHandle)
{
characteristicDiscoveryStarted(connectionHandle);
@ -46,7 +46,7 @@ nRF51ServiceDiscovery::launchCharacteristicDiscovery(Gap::Handle_t connectionHan
}
void
nRF51ServiceDiscovery::setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response)
nRF5xServiceDiscovery::setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response)
{
serviceIndex = 0;
numServices = response->count;
@ -76,7 +76,7 @@ nRF51ServiceDiscovery::setupDiscoveredServices(const ble_gattc_evt_prim_srvc_dis
}
void
nRF51ServiceDiscovery::setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response)
nRF5xServiceDiscovery::setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response)
{
characteristicIndex = 0;
numCharacteristics = response->count;
@ -112,12 +112,12 @@ nRF51ServiceDiscovery::setupDiscoveredCharacteristics(const ble_gattc_evt_char_d
}
void
nRF51ServiceDiscovery::progressCharacteristicDiscovery(void)
nRF5xServiceDiscovery::progressCharacteristicDiscovery(void)
{
/* Iterate through the previously discovered characteristics cached in characteristics[]. */
while ((state == CHARACTERISTIC_DISCOVERY_ACTIVE) && (characteristicIndex < numCharacteristics)) {
if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
((matchingCharacteristicUUID == characteristics[characteristicIndex].getShortUUID()) &&
((matchingCharacteristicUUID == characteristics[characteristicIndex].getUUID()) &&
(matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
if (characteristicCallback) {
characteristicCallback(&characteristics[characteristicIndex]);
@ -149,12 +149,12 @@ nRF51ServiceDiscovery::progressCharacteristicDiscovery(void)
}
void
nRF51ServiceDiscovery::progressServiceDiscovery(void)
nRF5xServiceDiscovery::progressServiceDiscovery(void)
{
/* Iterate through the previously discovered services cached in services[]. */
while ((state == SERVICE_DISCOVERY_ACTIVE) && (serviceIndex < numServices)) {
if ((matchingServiceUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
(matchingServiceUUID == services[serviceIndex].getUUID().getShortUUID())) {
(matchingServiceUUID == services[serviceIndex].getUUID())) {
if (serviceCallback && (matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN))) {
serviceCallback(&services[serviceIndex]);
@ -187,7 +187,7 @@ nRF51ServiceDiscovery::progressServiceDiscovery(void)
}
void
nRF51ServiceDiscovery::ServiceUUIDDiscoveryQueue::triggerFirst(void)
nRF5xServiceDiscovery::ServiceUUIDDiscoveryQueue::triggerFirst(void)
{
while (numIndices) { /* loop until a call to char_value_by_uuid_read() succeeds or we run out of pending indices. */
parentDiscoveryObject->state = DISCOVER_SERVICE_UUIDS;
@ -217,7 +217,7 @@ nRF51ServiceDiscovery::ServiceUUIDDiscoveryQueue::triggerFirst(void)
}
void
nRF51ServiceDiscovery::CharUUIDDiscoveryQueue::triggerFirst(void)
nRF5xServiceDiscovery::CharUUIDDiscoveryQueue::triggerFirst(void)
{
while (numIndices) { /* loop until a call to char_value_by_uuid_read() succeeds or we run out of pending indices. */
parentDiscoveryObject->state = DISCOVER_CHARACTERISTIC_UUIDS;
@ -246,7 +246,7 @@ nRF51ServiceDiscovery::CharUUIDDiscoveryQueue::triggerFirst(void)
}
void
nRF51ServiceDiscovery::processDiscoverUUIDResponse(const ble_gattc_evt_char_val_by_uuid_read_rsp_t *response)
nRF5xServiceDiscovery::processDiscoverUUIDResponse(const ble_gattc_evt_char_val_by_uuid_read_rsp_t *response)
{
if (state == DISCOVER_SERVICE_UUIDS) {
if ((response->count == 1) && (response->value_len == UUID::LENGTH_OF_LONG_UUID)) {

View file

@ -19,14 +19,14 @@
#include "ble/ServiceDiscovery.h"
#include "ble/DiscoveredService.h"
#include "nRF51DiscoveredCharacteristic.h"
#include "nRF5xDiscoveredCharacteristic.h"
#include "ble.h"
#include "ble_gattc.h"
class nRF51GattClient; /* forward declaration */
class nRF5xGattClient; /* forward declaration */
class nRF51ServiceDiscovery : public ServiceDiscovery
class nRF5xServiceDiscovery : public ServiceDiscovery
{
public:
static const uint16_t SRV_DISC_START_HANDLE = 0x0001; /**< The start handle value used during service discovery. */
@ -37,7 +37,7 @@ public:
static const unsigned BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV = 4; /**< Maximum number of characteristics per service we can retain information for. */
public:
nRF51ServiceDiscovery(nRF51GattClient *gattcIn) :
nRF5xServiceDiscovery(nRF5xGattClient *gattcIn) :
gattc(gattcIn),
serviceIndex(0),
numServices(0),
@ -158,7 +158,7 @@ private:
*/
class ServiceUUIDDiscoveryQueue {
public:
ServiceUUIDDiscoveryQueue(nRF51ServiceDiscovery *parent) :
ServiceUUIDDiscoveryQueue(nRF5xServiceDiscovery *parent) :
numIndices(0),
serviceIndices(),
parentDiscoveryObject(parent) {
@ -207,7 +207,7 @@ private:
size_t numIndices;
int serviceIndices[BLE_DB_DISCOVERY_MAX_SRV];
nRF51ServiceDiscovery *parentDiscoveryObject;
nRF5xServiceDiscovery *parentDiscoveryObject;
};
friend class ServiceUUIDDiscoveryQueue;
@ -217,7 +217,7 @@ private:
*/
class CharUUIDDiscoveryQueue {
public:
CharUUIDDiscoveryQueue(nRF51ServiceDiscovery *parent) :
CharUUIDDiscoveryQueue(nRF5xServiceDiscovery *parent) :
numIndices(0),
charIndices(),
parentDiscoveryObject(parent) {
@ -266,7 +266,7 @@ private:
size_t numIndices;
int charIndices[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV];
nRF51ServiceDiscovery *parentDiscoveryObject;
nRF5xServiceDiscovery *parentDiscoveryObject;
};
friend class CharUUIDDiscoveryQueue;
@ -276,7 +276,7 @@ private:
void progressServiceDiscovery(void);
private:
nRF51GattClient *gattc;
nRF5xGattClient *gattc;
private:
uint8_t serviceIndex; /**< Index of the current service being discovered. This is intended for internal use during service discovery.*/
@ -294,7 +294,7 @@ private:
DiscoveredService services[BLE_DB_DISCOVERY_MAX_SRV]; /**< Information related to the current service being discovered.
* This is intended for internal use during service discovery. */
nRF51DiscoveredCharacteristic characteristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV];
nRF5xDiscoveredCharacteristic characteristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV];
ServiceUUIDDiscoveryQueue serviceUUIDDiscoveryQueue;
CharUUIDDiscoveryQueue charUUIDDiscoveryQueue;

View file

@ -15,7 +15,7 @@
*/
#include "mbed.h"
#include "nRF51822n.h"
#include "nRF5xn.h"
#include "nrf_soc.h"
#include "btle/btle.h"
@ -26,7 +26,7 @@
/**
* The singleton which represents the nRF51822 transport for the BLE.
*/
static nRF51822n deviceInstance;
static nRF5xn deviceInstance;
/**
* BLE-API requires an implementation of the following function in order to
@ -38,15 +38,15 @@ createBLEInstance(void)
return (&deviceInstance);
}
nRF51822n::nRF51822n(void)
nRF5xn::nRF5xn(void)
{
}
nRF51822n::~nRF51822n(void)
nRF5xn::~nRF5xn(void)
{
}
const char *nRF51822n::getVersion(void)
const char *nRF5xn::getVersion(void)
{
static char versionString[32];
static bool versionFetched = false;
@ -71,7 +71,7 @@ const char *nRF51822n::getVersion(void)
return versionString;
}
ble_error_t nRF51822n::init(void)
ble_error_t nRF5xn::init(void)
{
/* ToDo: Clear memory contents, reset the SD, etc. */
btle_init();
@ -79,13 +79,13 @@ ble_error_t nRF51822n::init(void)
return BLE_ERROR_NONE;
}
ble_error_t nRF51822n::shutdown(void)
ble_error_t nRF5xn::shutdown(void)
{
return (softdevice_handler_sd_disable() == NRF_SUCCESS) ? BLE_ERROR_NONE : BLE_STACK_BUSY;
}
void
nRF51822n::waitForEvent(void)
nRF5xn::waitForEvent(void)
{
sd_app_evt_wait();
}

View file

@ -20,44 +20,44 @@
#include "mbed.h"
#include "ble/blecommon.h"
#include "ble/BLE.h"
#include "nRF51Gap.h"
#include "nRF51GattServer.h"
#include "nRF51GattClient.h"
#include "nRF51SecurityManager.h"
#include "nRF5xGap.h"
#include "nRF5xGattServer.h"
#include "nRF5xGattClient.h"
#include "nRF5xSecurityManager.h"
#include "btle.h"
class nRF51822n : public BLEInstanceBase
class nRF5xn : public BLEInstanceBase
{
public:
nRF51822n(void);
virtual ~nRF51822n(void);
nRF5xn(void);
virtual ~nRF5xn(void);
virtual ble_error_t init(void);
virtual ble_error_t shutdown(void);
virtual const char *getVersion(void);
virtual Gap &getGap() {
return nRF51Gap::getInstance();
return nRF5xGap::getInstance();
};
virtual const Gap &getGap() const {
return nRF51Gap::getInstance();
return nRF5xGap::getInstance();
};
virtual GattServer &getGattServer() {
return nRF51GattServer::getInstance();
return nRF5xGattServer::getInstance();
};
virtual const GattServer &getGattServer() const {
return nRF51GattServer::getInstance();
return nRF5xGattServer::getInstance();
};
virtual GattClient &getGattClient() {
return nRF51GattClient::getInstance();
return nRF5xGattClient::getInstance();
}
virtual const SecurityManager &getSecurityManager() const {
return nRF51SecurityManager::getInstance();
return nRF5xSecurityManager::getInstance();
}
virtual SecurityManager &getSecurityManager() {
return nRF51SecurityManager::getInstance();
return nRF5xSecurityManager::getInstance();
}
virtual void waitForEvent(void);
virtual void waitForEvent(void);
};
#endif

View file

@ -31,7 +31,7 @@
*/
#include <stdio.h>
#include "compiler_abstraction.h"
#include "nrf.h"
#include "nrf_delay.h"