Merge branch 'develop'

This commit is contained in:
Rohit Grover 2015-11-02 08:58:14 +00:00
commit 479bae5fcb
14 changed files with 72 additions and 29 deletions

View File

@ -1,6 +1,6 @@
{
"name": "ble-nrf51822",
"version": "1.0.0",
"version": "2.0.0",
"description": "Nordic stack and drivers for the mbed BLE API.",
"keywords": [
"Bluetooth",
@ -21,7 +21,7 @@
}
],
"dependencies": {
"ble": "^1.0.0"
"ble": "^2.0.0"
},
"extraIncludes": [
"source/btle",

View File

@ -133,7 +133,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
dm_ble_evt_handler(p_ble_evt);
#if !defined(MCU_NRF51_16K_S110) && !defined(MCU_NRF51_32K_S110)
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
bleGattcEventHandler(p_ble_evt);
#endif
@ -141,7 +141,7 @@ 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;
#if defined(MCU_NRF51_16K_S110) || defined(MCU_NRF51_32K_S110)
#if defined(TARGET_MCU_NRF51_16K_S110) || defined(TARGET_MCU_NRF51_32K_S110)
/* Only peripheral role is supported by S110 */
Gap::Role_t role = Gap::PERIPHERAL;
#else

View File

@ -17,7 +17,7 @@
#include "nRF5xServiceDiscovery.h"
#include "nRF5xGattClient.h"
#if !defined(MCU_NRF51_16K_S110) && !defined(MCU_NRF51_32K_S110)
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
{
nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery;

View File

@ -26,7 +26,7 @@ typedef struct {
UUID::LongUUIDBytes_t uuid;
uint8_t type;
} converted_uuid_table_entry_t;
static const unsigned UUID_TABLE_MAX_ENTRIES = 8; /* This is the maximum number of 128-bit UUIDs with distinct bases that
static const unsigned UUID_TABLE_MAX_ENTRIES = 4; /* This is the maximum number of 128-bit UUIDs with distinct bases that
* we expect to be in use; increase this limit if needed. */
static unsigned uuidTableEntries = 0; /* current usage of the table */
converted_uuid_table_entry_t convertedUUIDTable[UUID_TABLE_MAX_ENTRIES];

View File

@ -233,17 +233,18 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr,
}
ble_gap_scan_params_t scanParams;
scanParams.active = 0; /**< If 1, perform active scanning (scan requests). */
scanParams.selective = 0; /**< If 1, ignore unknown devices (non whitelisted). */
scanParams.p_whitelist = NULL; /**< Pointer to whitelist, NULL if none is given. */
if (scanParamsIn != NULL) {
scanParams.active = scanParamsIn->getActiveScanning(); /**< If 1, perform active scanning (scan requests). */
scanParams.interval = scanParamsIn->getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
scanParams.window = scanParamsIn->getWindow(); /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
scanParams.timeout = scanParamsIn->getTimeout(); /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
} else {
scanParams.interval = 500; /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
scanParams.window = 200; /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
scanParams.timeout = 0; /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
scanParams.active = _scanningParams.getActiveScanning(); /**< If 1, perform active scanning (scan requests). */
scanParams.interval = _scanningParams.getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
scanParams.window = _scanningParams.getWindow(); /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
scanParams.timeout = _scanningParams.getTimeout(); /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
}
uint32_t rc = sd_ble_gap_connect(&addr, &scanParams, &connParams);

View File

@ -81,7 +81,7 @@ public:
}
/* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
#if !defined(MCU_NRF51_16K_S110) && !defined(MCU_NRF51_32K_S110)
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_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). */

View File

@ -18,11 +18,14 @@
nRF5xGattClient &
nRF5xGattClient::getInstance(void) {
static nRF5xGattClient nRFGattClientSingleton;
return nRFGattClientSingleton;
static nRF5xGattClient* nRFGattClientSingleton = NULL;
if (nRFGattClientSingleton == NULL) {
nRFGattClientSingleton = new nRF5xGattClient();
}
return *nRFGattClientSingleton;
}
#if !defined(MCU_NRF51_16K_S110) && !defined(MCU_NRF51_32K_S110)
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
ble_error_t
nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc,

View File

@ -29,7 +29,7 @@ public:
* When using S110, all Gatt client features will return
* BLE_ERROR_NOT_IMPLEMENTED
*/
#if !defined(MCU_NRF51_16K_S110) && !defined(MCU_NRF51_32K_S110)
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
/**
* Launch service discovery. Once launched, service discovery will remain

View File

@ -45,7 +45,6 @@ nRF5xGattServer &nRF5xGattServer::getInstance(void) {
/**************************************************************************/
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 (?) */
/* ToDo: Basic validation */
@ -63,6 +62,9 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
/* Add characteristics to the service */
for (uint8_t i = 0; i < service.getCharacteristicCount(); i++) {
if (characteristicCount >= BLE_TOTAL_CHARACTERISTICS) {
return BLE_ERROR_NO_MEM;
}
GattCharacteristic *p_char = service.getCharacteristic(i);
/* Skip any incompletely defined, read-only characteristics. */
@ -108,8 +110,11 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
characteristicCount++;
/* Add optional descriptors if any */
/* ToDo: Make sure we don't overflow the array */
for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
if (descriptorCount >= BLE_TOTAL_DESCRIPTORS) {
return BLE_ERROR_NO_MEM;
}
GattAttribute *p_desc = p_char->getDescriptor(j);
/* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {

View File

@ -17,6 +17,9 @@
#include "nRF5xSecurityManager.h"
nRF5xSecurityManager &nRF5xSecurityManager::getInstance(void) {
static nRF5xSecurityManager m_instance;
return m_instance;
static nRF5xSecurityManager* m_instance = NULL;
if (m_instance == NULL) {
m_instance = new nRF5xSecurityManager();
}
return *m_instance;
}

View File

@ -16,6 +16,7 @@
#include "mbed.h"
#include "nRF5xn.h"
#include "ble/blecommon.h"
#include "nrf_soc.h"
#include "btle/btle.h"
@ -38,7 +39,7 @@ createBLEInstance(void)
return (&deviceInstance);
}
nRF5xn::nRF5xn(void)
nRF5xn::nRF5xn(void) : initialized(false), instanceID(BLE::DEFAULT_INSTANCE)
{
}
@ -48,6 +49,10 @@ nRF5xn::~nRF5xn(void)
const char *nRF5xn::getVersion(void)
{
if (!initialized) {
return "INITIALIZATION_INCOMPLETE";
}
static char versionString[32];
static bool versionFetched = false;
@ -72,16 +77,33 @@ const char *nRF5xn::getVersion(void)
return versionString;
}
ble_error_t nRF5xn::init(void)
ble_error_t nRF5xn::init(BLE::InstanceID_t instanceID, BLE::InitializationCompleteCallback_t callback)
{
if (initialized) {
if (callback) {
callback(BLE::Instance(instanceID), BLE_ERROR_ALREADY_INITIALIZED);
}
return BLE_ERROR_ALREADY_INITIALIZED;
}
instanceID = instanceID;
/* ToDo: Clear memory contents, reset the SD, etc. */
btle_init();
initialized = true;
if (callback) {
callback(BLE::Instance(instanceID), BLE_ERROR_NONE);
}
return BLE_ERROR_NONE;
}
ble_error_t nRF5xn::shutdown(void)
{
if (!initialized) {
return BLE_ERROR_INITIALIZATION_INCOMPLETE;
}
return (softdevice_handler_sd_disable() == NRF_SUCCESS) ? BLE_ERROR_NONE : BLE_STACK_BUSY;
}

View File

@ -17,13 +17,15 @@
#ifndef __NRF51822_H__
#define __NRF51822_H__
#include "mbed.h"
#include "ble/blecommon.h"
#include "ble/BLE.h"
#include "ble/blecommon.h"
#include "ble/BLEInstanceBase.h"
#include "nRF5xGap.h"
#include "nRF5xGattServer.h"
#include "nRF5xGattClient.h"
#include "nRF5xSecurityManager.h"
#include "btle.h"
class nRF5xn : public BLEInstanceBase
@ -32,7 +34,10 @@ public:
nRF5xn(void);
virtual ~nRF5xn(void);
virtual ble_error_t init(void);
virtual ble_error_t init(BLE::InstanceID_t instanceID, BLE::InitializationCompleteCallback_t);
virtual bool hasInitialized(void) const {
return initialized;
}
virtual ble_error_t shutdown(void);
virtual const char *getVersion(void);
@ -58,6 +63,10 @@ public:
return nRF5xSecurityManager::getInstance();
}
virtual void waitForEvent(void);
private:
bool initialized;
BLE::InstanceID_t instanceID;
};
#endif

View File

@ -85,7 +85,7 @@
* be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL
* as event result at the completion of the security procedure.
*/
#define DEVICE_MANAGER_MAX_BONDS 4
#define DEVICE_MANAGER_MAX_BONDS 2
/**

View File

@ -547,7 +547,7 @@ typedef struct
{
ble_gap_addr_t peer_addr; /**< Bluetooth address of the peer device. */
ble_gap_addr_t own_addr; /**< Bluetooth address of the local device used during connection setup. */
#if !defined(MCU_NRF51_16K_S110) && !defined(MCU_NRF51_32K_S110)
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
uint8_t role; /**< BLE role for this connection, see @ref BLE_GAP_ROLES */
#endif
uint8_t irk_match :1; /**< If 1, peer device's address resolved using an IRK. */