rename BLEDevice as BLE; BLEDeviceInstanceBase as BLEInstanceBase

master
Rohit Grover 2015-06-16 11:35:59 +01:00
parent 532535b1ec
commit c89eea7a32
12 changed files with 131 additions and 132 deletions

View File

@ -14,14 +14,14 @@
* limitations under the License.
*/
#include "BLEDevice.h"
#include "BLE.h"
#if defined(TARGET_OTA_ENABLED)
#include "DFUService.h"
#endif
ble_error_t
BLEDevice::init()
BLE::init()
{
ble_error_t err = transport->init();
if (err != BLE_ERROR_NONE) {

View File

@ -25,9 +25,9 @@ class GattClient;
/**
* The interface for the transport object to be created by the target library's
* createBLEDeviceInstance().
* createBLEInstance().
*/
class BLEDeviceInstanceBase
class BLEInstanceBase
{
public:
virtual ble_error_t init(void) = 0;
@ -45,13 +45,13 @@ public:
};
/**
* BLEDevice uses composition to hide an interface object encapsulating the
* BLE uses composition to hide an interface object encapsulating the
* backend transport.
*
* The following API is used to create the singleton interface object. An
* implementation for this function must be provided by the device-specific
* library, otherwise there will be a linker error.
*/
extern BLEDeviceInstanceBase *createBLEDeviceInstance(void);
extern BLEInstanceBase *createBLEInstance(void);
#endif // ifndef __BLE_DEVICE_INSTANCE_BASE__

View File

@ -14,14 +14,14 @@
* limitations under the License.
*/
#ifndef __BLE_DEVICE__
#define __BLE_DEVICE__
#ifndef __BLE_H__
#define __BLE_H__
#include "blecommon.h"
#include "Gap.h"
#include "GattServer.h"
#include "GattClient.h"
#include "BLEDeviceInstanceBase.h"
#include "BLEInstanceBase.h"
#include "GapAdvertisingData.h"
#include "GapAdvertisingParams.h"
@ -712,13 +712,13 @@ public:
void terminateServiceDiscovery(void);
public:
BLE() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true), scanningParams() {
BLE() : transport(createBLEInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true), scanningParams() {
advPayload.clear();
scanResponse.clear();
}
private:
BLEDeviceInstanceBase *const transport; /* the device specific backend */
BLEInstanceBase *const transport; /* the device specific backend */
GapAdvertisingParams advParams;
GapAdvertisingData advPayload;
@ -735,7 +735,7 @@ private:
typedef BLE BLEDevice; /* DEPRECATED. This type alias is retained for the sake of compatibilty with older
* code. Will be dropped at some point soon.*/
/* BLEDevice methods. Most of these simply forward the calls to the underlying
/* BLE methods. Most of these simply forward the calls to the underlying
* transport.*/
inline ble_error_t
@ -957,10 +957,10 @@ BLE::stopScan(void) {
}
inline ble_error_t
BLEDevice::connect(const Gap::Address_t peerAddr,
Gap::AddressType_t peerAddrType,
const Gap::ConnectionParams_t *connectionParams,
const GapScanningParams *scanParams) {
BLE::connect(const Gap::Address_t peerAddr,
Gap::AddressType_t peerAddrType,
const Gap::ConnectionParams_t *connectionParams,
const GapScanningParams *scanParams) {
return transport->getGap().connect(peerAddr, peerAddrType, connectionParams, scanParams);
}
@ -1208,17 +1208,17 @@ BLE::purgeAllBondingState(void)
}
inline ble_error_t
BLEDevice::launchServiceDiscovery(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc,
ServiceDiscovery::CharacteristicCallback_t cc,
const UUID &matchingServiceUUID,
const UUID &matchingCharacteristicUUID)
BLE::launchServiceDiscovery(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc,
ServiceDiscovery::CharacteristicCallback_t cc,
const UUID &matchingServiceUUID,
const UUID &matchingCharacteristicUUID)
{
return transport->getGattClient().launchServiceDiscovery(connectionHandle, sc, cc, matchingServiceUUID, matchingCharacteristicUUID);
}
inline void
BLEDevice::onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback)
BLE::onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback)
{
transport->getGattClient().onServiceDiscoveryTermination(callback);
}
@ -1227,7 +1227,7 @@ BLEDevice::onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t
* Is service-discovery currently active?
*/
inline bool
BLEDevice::isServiceDiscoveryActive(void)
BLE::isServiceDiscoveryActive(void)
{
return transport->getGattClient().isServiceDiscoveryActive();
}
@ -1237,10 +1237,9 @@ BLEDevice::isServiceDiscoveryActive(void)
* invocation of the TerminationCallback if service-discovery is active.
*/
inline void
BLEDevice::terminateServiceDiscovery(void)
BLE::terminateServiceDiscovery(void)
{
transport->getGattClient().terminateServiceDiscovery();
}
#endif // ifndef __BLE_DEVICE__
#endif // ifndef __BLE_H__

View File

@ -17,7 +17,7 @@
#ifndef __BLE_BATTERY_SERVICE_H__
#define __BLE_BATTERY_SERVICE_H__
#include "BLEDevice.h"
#include "BLE.h"
/**
* @class BatteryService
@ -29,11 +29,11 @@ class BatteryService {
public:
/**
* @param[ref] _ble
* BLEDevice object for the underlying controller.
* BLE object for the underlying controller.
* @param[in] level
* 8bit batterly level. Usually used to represent percentage of batterly charge remaining.
*/
BatteryService(BLEDevice &_ble, uint8_t level = 100) :
BatteryService(BLE &_ble, uint8_t level = 100) :
ble(_ble),
batteryLevel(level),
batteryLevelCharacteristic(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, &batteryLevel, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
@ -57,7 +57,7 @@ public:
}
protected:
BLEDevice &ble;
BLE &ble;
uint8_t batteryLevel;
ReadOnlyGattCharacteristic<uint8_t> batteryLevelCharacteristic;

View File

@ -17,7 +17,7 @@
#ifndef __BLE_DFU_SERVICE_H__
#define __BLE_DFU_SERVICE_H__
#include "BLEDevice.h"
#include "BLE.h"
#include "UUID.h"
extern "C" void bootloader_start(void);
@ -48,11 +48,11 @@ public:
* @brief Adds Device Firmware Update service to an existing ble object.
*
* @param[ref] _ble
* BLEDevice object for the underlying controller.
* BLE object for the underlying controller.
* @param[in] _handoverCallback
* Application specific handover callback.
*/
DFUService(BLEDevice &_ble, ResetPrepare_t _handoverCallback = NULL) :
DFUService(BLE &_ble, ResetPrepare_t _handoverCallback = NULL) :
ble(_ble),
controlPoint(DFUServiceControlCharacteristicUUID, controlBytes, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
packet(DFUServicePacketCharacteristicUUID, packetBytes, SIZEOF_PACKET_BYTES, SIZEOF_PACKET_BYTES,
@ -110,7 +110,7 @@ protected:
static const unsigned SIZEOF_PACKET_BYTES = 20;
protected:
BLEDevice &ble;
BLE &ble;
/**< Writing to the control characteristic triggers the handover to dfu-
* bootloader. At present, writing anything will do the trick--this needs

View File

@ -17,7 +17,7 @@
#ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__
#define __BLE_DEVICE_INFORMATION_SERVICE_H__
#include "BLEDevice.h"
#include "BLE.h"
/**
* @class DeviceInformationService
@ -31,7 +31,7 @@ public:
* @brief Device Information Service Constructor.
*
* @param[ref] _ble
* BLEDevice object for the underlying controller.
* BLE object for the underlying controller.
* @param[in] manufacturersName
* This characteristic represents the name of the
* manufacturer of the device. The name is copied into the
@ -57,7 +57,7 @@ public:
* the software within the device. The value is copied
* into the BLE stack during this constructor.
*/
DeviceInformationService(BLEDevice &_ble,
DeviceInformationService(BLE &_ble,
const char *manufacturersName = NULL,
const char *modelNumber = NULL,
const char *serialNumber = NULL,
@ -115,7 +115,7 @@ public:
}
protected:
BLEDevice &ble;
BLE &ble;
GattCharacteristic manufacturersNameStringCharacteristic;
GattCharacteristic modelNumberStringCharacteristic;
GattCharacteristic serialNumberStringCharacteristic;

View File

@ -17,7 +17,7 @@
#ifndef __BLE_HEALTH_THERMOMETER_SERVICE_H__
#define __BLE_HEALTH_THERMOMETER_SERVICE_H__
#include "BLEDevice.h"
#include "BLE.h"
/**
* @class HealthThermometerService
@ -51,7 +51,7 @@ public:
* @param[in] initialTemp initial value in celsius
* @param[in] _location
*/
HealthThermometerService(BLEDevice &_ble, float initialTemp, uint8_t _location) :
HealthThermometerService(BLE &_ble, float initialTemp, uint8_t _location) :
ble(_ble),
valueBytes(initialTemp),
tempMeasurement(GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, (TemperatureValueBytes *)valueBytes.getPointer(), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
@ -141,7 +141,7 @@ private:
};
private:
BLEDevice &ble;
BLE &ble;
TemperatureValueBytes valueBytes;
ReadOnlyGattCharacteristic<TemperatureValueBytes> tempMeasurement;
ReadOnlyGattCharacteristic<uint8_t> tempLocation;

View File

@ -17,7 +17,7 @@
#ifndef __BLE_HEART_RATE_SERVICE_H__
#define __BLE_HEART_RATE_SERVICE_H__
#include "BLEDevice.h"
#include "BLE.h"
/**
* @class HeartRateService
@ -47,13 +47,13 @@ public:
* @brief Constructor with 8bit HRM Counter value.
*
* @param[ref] _ble
* Reference to the underlying BLEDevice.
* Reference to the underlying BLE.
* @param[in] hrmCounter (8-bit)
* initial value for the hrm counter.
* @param[in] location
* Sensor's location.
*/
HeartRateService(BLEDevice &_ble, uint8_t hrmCounter, uint8_t location) :
HeartRateService(BLE &_ble, uint8_t hrmCounter, uint8_t location) :
ble(_ble),
valueBytes(hrmCounter),
hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, valueBytes.getPointer(),
@ -68,13 +68,13 @@ public:
* @brief Constructor with a 16-bit HRM Counter value.
*
* @param[in] _ble
* Reference to the underlying BLEDevice.
* Reference to the underlying BLE.
* @param[in] hrmCounter (8-bit)
* initial value for the hrm counter.
* @param[in] location
* Sensor's location.
*/
HeartRateService(BLEDevice &_ble, uint16_t hrmCounter, uint8_t location) :
HeartRateService(BLE &_ble, uint16_t hrmCounter, uint8_t location) :
ble(_ble),
valueBytes(hrmCounter),
hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, valueBytes.getPointer(),
@ -181,7 +181,7 @@ protected:
};
protected:
BLEDevice &ble;
BLE &ble;
HeartRateValueBytes valueBytes;
uint8_t controlPointValue;

View File

@ -37,9 +37,9 @@ public:
/**
* @param[ref] ble
* BLEDevice object for the underlying controller.
* BLE object for the underlying controller.
*/
LinkLossService(BLEDevice &bleIn, callback_t callbackIn, AlertLevel_t levelIn = NO_ALERT) :
LinkLossService(BLE &bleIn, callback_t callbackIn, AlertLevel_t levelIn = NO_ALERT) :
ble(bleIn),
alertLevel(levelIn),
callback(callbackIn),
@ -93,7 +93,7 @@ private:
}
protected:
BLEDevice &ble;
BLE &ble;
AlertLevel_t alertLevel;
callback_t callback;

View File

@ -21,7 +21,7 @@
#include "Stream.h"
#include "UUID.h"
#include "BLEDevice.h"
#include "BLE.h"
extern const uint8_t UARTServiceBaseUUID[UUID::LENGTH_OF_LONG_UUID];
extern const uint16_t UARTServiceShortUUID;
@ -48,9 +48,9 @@ public:
/**
* @param[ref] ble
* BLEDevice object for the underlying controller.
* BLE object for the underlying controller.
*/
UARTService(BLEDevice &_ble) :
UARTService(BLE &_ble) :
ble(_ble),
receiveBuffer(),
sendBuffer(),
@ -179,7 +179,7 @@ private:
}
private:
BLEDevice &ble;
BLE &ble;
uint8_t receiveBuffer[BLE_UART_SERVICE_MAX_DATA_LEN]; /**< The local buffer into which we receive
* inbound data before forwarding it to the

View File

@ -17,7 +17,7 @@
#ifndef SERVICES_URIBEACONCONFIGSERVICE_H_
#define SERVICES_URIBEACONCONFIGSERVICE_H_
#include "BLEDevice.h"
#include "BLE.h"
#include "mbed.h"
extern const uint8_t UUID_URI_BEACON_SERVICE[UUID::LENGTH_OF_LONG_UUID];
@ -71,7 +71,7 @@ class URIBeaconConfigService {
/**
* @param[ref] ble
* BLEDevice object for the underlying controller.
* BLE object for the underlying controller.
* @param[in/out] paramsIn
* Reference to application-visible beacon state, loaded
* from persistent storage at startup.
@ -85,7 +85,7 @@ class URIBeaconConfigService {
* @param[in] defaultAdvPowerLevelsIn
* Default power-levels array; applies only if the resetToDefaultsFlag is true.
*/
URIBeaconConfigService(BLEDevice &bleIn,
URIBeaconConfigService(BLE &bleIn,
Params_t &paramsIn,
bool resetToDefaultsFlag,
const char *defaultURIDataIn,
@ -371,7 +371,7 @@ private:
}
protected:
BLEDevice &ble;
BLE &ble;
Params_t &params;
size_t defaultUriDataLength; // Default value that is restored on reset

View File

@ -1,74 +1,74 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BLE_IBEACON_SERVICE_H__
#define __BLE_IBEACON_SERVICE_H__
#include "core_cmInstr.h"
#include "BLEDevice.h"
/**
* @class iBeaconService
* @brief iBeacon Service. This service sets up a device to broadcast advertising packets to mimic an iBeacon<br>
*/
class iBeaconService
{
public:
typedef const uint8_t LocationUUID_t[16];
union Payload {
uint8_t raw[25];
struct {
uint16_t companyID;
uint8_t ID;
uint8_t len;
uint8_t proximityUUID[16];
uint16_t majorNumber;
uint16_t minorNumber;
uint8_t txPower;
};
Payload(LocationUUID_t uuid, uint16_t majNum, uint16_t minNum, uint8_t transmitPower, uint16_t companyIDIn) :
companyID(companyIDIn), ID(0x02), len(0x15), majorNumber(__REV16(majNum)), minorNumber(__REV16(minNum)), txPower(transmitPower)
{
memcpy(proximityUUID, uuid, sizeof(LocationUUID_t));
}
};
public:
iBeaconService(BLEDevice &_ble,
LocationUUID_t uuid,
uint16_t majNum,
uint16_t minNum,
uint8_t txP = 0xC8,
uint16_t compID = 0x004C) :
ble(_ble), data(uuid, majNum, minNum, txP, compID)
{
// Generate the 0x020106 part of the iBeacon Prefix
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
// Generate the 0x1AFF part of the iBeacon Prefix
ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
// Set advertising type
ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
}
private:
BLEDevice &ble;
Payload data;
};
#endif //__BLE_IBEACON_SERVICE_H__
/* mbed Microcontroller Library
* Copyright (c) 2006-2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BLE_IBEACON_SERVICE_H__
#define __BLE_IBEACON_SERVICE_H__
#include "core_cmInstr.h"
#include "BLE.h"
/**
* @class iBeaconService
* @brief iBeacon Service. This service sets up a device to broadcast advertising packets to mimic an iBeacon<br>
*/
class iBeaconService
{
public:
typedef const uint8_t LocationUUID_t[16];
union Payload {
uint8_t raw[25];
struct {
uint16_t companyID;
uint8_t ID;
uint8_t len;
uint8_t proximityUUID[16];
uint16_t majorNumber;
uint16_t minorNumber;
uint8_t txPower;
};
Payload(LocationUUID_t uuid, uint16_t majNum, uint16_t minNum, uint8_t transmitPower, uint16_t companyIDIn) :
companyID(companyIDIn), ID(0x02), len(0x15), majorNumber(__REV16(majNum)), minorNumber(__REV16(minNum)), txPower(transmitPower)
{
memcpy(proximityUUID, uuid, sizeof(LocationUUID_t));
}
};
public:
iBeaconService(BLE &_ble,
LocationUUID_t uuid,
uint16_t majNum,
uint16_t minNum,
uint8_t txP = 0xC8,
uint16_t compID = 0x004C) :
ble(_ble), data(uuid, majNum, minNum, txP, compID)
{
// Generate the 0x020106 part of the iBeacon Prefix
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
// Generate the 0x1AFF part of the iBeacon Prefix
ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
// Set advertising type
ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
}
private:
BLE &ble;
Payload data;
};
#endif //__BLE_IBEACON_SERVICE_H__