diff --git a/public/BLE.h b/ble/BLE.h similarity index 100% rename from public/BLE.h rename to ble/BLE.h diff --git a/common/BLEInstanceBase.h b/ble/BLEInstanceBase.h similarity index 100% rename from common/BLEInstanceBase.h rename to ble/BLEInstanceBase.h diff --git a/public/CallChainOfFunctionPointersWithContext.h b/ble/CallChainOfFunctionPointersWithContext.h similarity index 100% rename from public/CallChainOfFunctionPointersWithContext.h rename to ble/CallChainOfFunctionPointersWithContext.h diff --git a/public/DiscoveredCharacteristic.h b/ble/DiscoveredCharacteristic.h similarity index 100% rename from public/DiscoveredCharacteristic.h rename to ble/DiscoveredCharacteristic.h diff --git a/public/DiscoveredService.h b/ble/DiscoveredService.h similarity index 100% rename from public/DiscoveredService.h rename to ble/DiscoveredService.h diff --git a/public/FunctionPointerWithContext.h b/ble/FunctionPointerWithContext.h similarity index 100% rename from public/FunctionPointerWithContext.h rename to ble/FunctionPointerWithContext.h diff --git a/public/Gap.h b/ble/Gap.h similarity index 100% rename from public/Gap.h rename to ble/Gap.h diff --git a/public/GapAdvertisingData.h b/ble/GapAdvertisingData.h similarity index 100% rename from public/GapAdvertisingData.h rename to ble/GapAdvertisingData.h diff --git a/public/GapAdvertisingParams.h b/ble/GapAdvertisingParams.h similarity index 100% rename from public/GapAdvertisingParams.h rename to ble/GapAdvertisingParams.h diff --git a/public/GapEvents.h b/ble/GapEvents.h similarity index 100% rename from public/GapEvents.h rename to ble/GapEvents.h diff --git a/public/GapScanningParams.h b/ble/GapScanningParams.h similarity index 100% rename from public/GapScanningParams.h rename to ble/GapScanningParams.h diff --git a/public/GattAttribute.h b/ble/GattAttribute.h similarity index 100% rename from public/GattAttribute.h rename to ble/GattAttribute.h diff --git a/public/GattCallbackParamTypes.h b/ble/GattCallbackParamTypes.h similarity index 100% rename from public/GattCallbackParamTypes.h rename to ble/GattCallbackParamTypes.h diff --git a/public/GattCharacteristic.h b/ble/GattCharacteristic.h similarity index 100% rename from public/GattCharacteristic.h rename to ble/GattCharacteristic.h diff --git a/public/GattClient.h b/ble/GattClient.h similarity index 100% rename from public/GattClient.h rename to ble/GattClient.h diff --git a/public/GattServer.h b/ble/GattServer.h similarity index 100% rename from public/GattServer.h rename to ble/GattServer.h diff --git a/public/GattServerEvents.h b/ble/GattServerEvents.h similarity index 100% rename from public/GattServerEvents.h rename to ble/GattServerEvents.h diff --git a/public/GattService.h b/ble/GattService.h similarity index 100% rename from public/GattService.h rename to ble/GattService.h diff --git a/public/SecurityManager.h b/ble/SecurityManager.h similarity index 100% rename from public/SecurityManager.h rename to ble/SecurityManager.h diff --git a/public/ServiceDiscovery.h b/ble/ServiceDiscovery.h similarity index 100% rename from public/ServiceDiscovery.h rename to ble/ServiceDiscovery.h diff --git a/public/UUID.h b/ble/UUID.h similarity index 100% rename from public/UUID.h rename to ble/UUID.h diff --git a/common/blecommon.h b/ble/blecommon.h similarity index 100% rename from common/blecommon.h rename to ble/blecommon.h diff --git a/services/BatteryService.h b/ble/services/BatteryService.h similarity index 99% rename from services/BatteryService.h rename to ble/services/BatteryService.h index de736c7..6bc0723 100644 --- a/services/BatteryService.h +++ b/ble/services/BatteryService.h @@ -17,7 +17,7 @@ #ifndef __BLE_BATTERY_SERVICE_H__ #define __BLE_BATTERY_SERVICE_H__ -#include "BLE.h" +#include "ble/BLE.h" /** * @class BatteryService diff --git a/services/DFUService.h b/ble/services/DFUService.h similarity index 99% rename from services/DFUService.h rename to ble/services/DFUService.h index b5f9a93..253890e 100644 --- a/services/DFUService.h +++ b/ble/services/DFUService.h @@ -17,8 +17,8 @@ #ifndef __BLE_DFU_SERVICE_H__ #define __BLE_DFU_SERVICE_H__ -#include "BLE.h" -#include "UUID.h" +#include "ble/BLE.h" +#include "ble/UUID.h" extern "C" void bootloader_start(void); diff --git a/services/DeviceInformationService.h b/ble/services/DeviceInformationService.h similarity index 99% rename from services/DeviceInformationService.h rename to ble/services/DeviceInformationService.h index 7220b63..9e72233 100644 --- a/services/DeviceInformationService.h +++ b/ble/services/DeviceInformationService.h @@ -17,7 +17,7 @@ #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__ #define __BLE_DEVICE_INFORMATION_SERVICE_H__ -#include "BLE.h" +#include "ble/BLE.h" /** * @class DeviceInformationService diff --git a/services/HealthThermometerService.h b/ble/services/HealthThermometerService.h similarity index 100% rename from services/HealthThermometerService.h rename to ble/services/HealthThermometerService.h diff --git a/services/HeartRateService.h b/ble/services/HeartRateService.h similarity index 99% rename from services/HeartRateService.h rename to ble/services/HeartRateService.h index 1832712..606dc9f 100644 --- a/services/HeartRateService.h +++ b/ble/services/HeartRateService.h @@ -17,7 +17,7 @@ #ifndef __BLE_HEART_RATE_SERVICE_H__ #define __BLE_HEART_RATE_SERVICE_H__ -#include "BLE.h" +#include "ble/BLE.h" /** * @class HeartRateService diff --git a/services/LinkLossService.h b/ble/services/LinkLossService.h similarity index 100% rename from services/LinkLossService.h rename to ble/services/LinkLossService.h diff --git a/services/UARTService.h b/ble/services/UARTService.h similarity index 99% rename from services/UARTService.h rename to ble/services/UARTService.h index 3959898..64676fe 100644 --- a/services/UARTService.h +++ b/ble/services/UARTService.h @@ -20,8 +20,8 @@ #include "mbed.h" #include "Stream.h" -#include "UUID.h" -#include "BLE.h" +#include "ble/UUID.h" +#include "ble/BLE.h" extern const uint8_t UARTServiceBaseUUID[UUID::LENGTH_OF_LONG_UUID]; extern const uint16_t UARTServiceShortUUID; diff --git a/services/URIBeaconConfigService.h b/ble/services/URIBeaconConfigService.h similarity index 89% rename from services/URIBeaconConfigService.h rename to ble/services/URIBeaconConfigService.h index 6001e6d..4ceaa05 100644 --- a/services/URIBeaconConfigService.h +++ b/ble/services/URIBeaconConfigService.h @@ -17,7 +17,7 @@ #ifndef SERVICES_URIBEACONCONFIGSERVICE_H_ #define SERVICES_URIBEACONCONFIGSERVICE_H_ -#include "BLE.h" +#include "ble/BLE.h" #include "mbed.h" extern const uint8_t UUID_URI_BEACON_SERVICE[UUID::LENGTH_OF_LONG_UUID]; @@ -159,26 +159,26 @@ class URIBeaconConfigService { { const char DEVICE_NAME[] = "mUriBeacon Config"; - ble.clearAdvertisingPayload(); + ble.gap().clearAdvertisingPayload(); - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); // UUID is in different order in the ADV frame (!) uint8_t reversedServiceUUID[sizeof(UUID_URI_BEACON_SERVICE)]; for (unsigned int i = 0; i < sizeof(UUID_URI_BEACON_SERVICE); i++) { reversedServiceUUID[i] = UUID_URI_BEACON_SERVICE[sizeof(UUID_URI_BEACON_SERVICE) - i - 1]; } - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, reversedServiceUUID, sizeof(reversedServiceUUID)); - ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_TAG); - ble.accumulateScanResponse(GapAdvertisingData::COMPLETE_LOCAL_NAME, reinterpret_cast(&DEVICE_NAME), sizeof(DEVICE_NAME)); - ble.accumulateScanResponse(GapAdvertisingData::TX_POWER_LEVEL, - reinterpret_cast(&defaultAdvPowerLevels[URIBeaconConfigService::TX_POWER_MODE_LOW]), - sizeof(uint8_t)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, reversedServiceUUID, sizeof(reversedServiceUUID)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_TAG); + ble.gap().accumulateScanResponse(GapAdvertisingData::COMPLETE_LOCAL_NAME, reinterpret_cast(&DEVICE_NAME), sizeof(DEVICE_NAME)); + ble.gap().accumulateScanResponse(GapAdvertisingData::TX_POWER_LEVEL, + reinterpret_cast(&defaultAdvPowerLevels[URIBeaconConfigService::TX_POWER_MODE_LOW]), + sizeof(uint8_t)); - ble.setTxPower(params.advPowerLevels[params.txPowerMode]); - ble.setDeviceName(reinterpret_cast(&DEVICE_NAME)); - ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(ADVERTISING_INTERVAL_MSEC)); + ble.gap().setTxPower(params.advPowerLevels[params.txPowerMode]); + ble.gap().setDeviceName(reinterpret_cast(&DEVICE_NAME)); + ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble.gap().setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(ADVERTISING_INTERVAL_MSEC)); } /* Helper function to switch to the non-connectible normal mode for URIBeacon. This gets called after a timeout. */ @@ -202,12 +202,12 @@ class URIBeaconConfigService { extern void saveURIBeaconConfigParams(const Params_t *paramsP); /* forward declaration; necessary to avoid a circular dependency. */ saveURIBeaconConfigParams(¶ms); - ble.clearAdvertisingPayload(); - ble.setTxPower(params.advPowerLevels[params.txPowerMode]); - ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); - ble.setAdvertisingInterval(beaconPeriod); - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_UUID, sizeof(BEACON_UUID)); + ble.gap().clearAdvertisingPayload(); + ble.gap().setTxPower(params.advPowerLevels[params.txPowerMode]); + ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); + ble.gap().setAdvertisingInterval(beaconPeriod); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_UUID, sizeof(BEACON_UUID)); serviceData[serviceDataLen++] = BEACON_UUID[0]; serviceData[serviceDataLen++] = BEACON_UUID[1]; @@ -216,7 +216,7 @@ class URIBeaconConfigService { for (unsigned j = 0; j < uriDataLength; j++) { serviceData[serviceDataLen++] = uriData[j]; } - ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceData, serviceDataLen); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceData, serviceDataLen); } private: @@ -259,11 +259,11 @@ class URIBeaconConfigService { /* Re-map beaconPeriod to within permissible bounds if necessary. */ if (params.beaconPeriod != 0) { bool paramsUpdated = false; - if (params.beaconPeriod < ble.getMinAdvertisingInterval()) { - params.beaconPeriod = ble.getMinAdvertisingInterval(); + if (params.beaconPeriod < ble.gap().getMinAdvertisingInterval()) { + params.beaconPeriod = ble.gap().getMinAdvertisingInterval(); paramsUpdated = true; - } else if (params.beaconPeriod > ble.getMaxAdvertisingInterval()) { - params.beaconPeriod = ble.getMaxAdvertisingInterval(); + } else if (params.beaconPeriod > ble.gap().getMaxAdvertisingInterval()) { + params.beaconPeriod = ble.gap().getMaxAdvertisingInterval(); paramsUpdated = true; } if (paramsUpdated) { diff --git a/services/iBeaconService.h b/ble/services/iBeaconService.h similarity index 100% rename from services/iBeaconService.h rename to ble/services/iBeaconService.h diff --git a/common/readme.txt b/common/readme.txt deleted file mode 100644 index df4d6e4..0000000 --- a/common/readme.txt +++ /dev/null @@ -1 +0,0 @@ -These files are common to all implementations of the BLE_API. \ No newline at end of file diff --git a/module.json b/module.json new file mode 100644 index 0000000..d3fa167 --- /dev/null +++ b/module.json @@ -0,0 +1,29 @@ +{ + "name": "ble", + "version": "0.0.0", + "description": "The BLE module offers a high level abstraction for using Bluetooth Low Energy on multiple platforms.", + "keywords": [ + "Bluetooth", + "BLE" + ], + "author": "Rohit Grover", + "repository": { + "url": "git@github.com:mbedmicro/BLE_API.git", + "type": "git" + }, + "homepage": "http://mbed.org/ble", + "licenses": [ + { + "url": "https://spdx.org/licenses/Apache-2.0", + "type": "Apache-2.0" + } + ], + "dependencies": { + "mbed": "^3.0.2" + }, + "targetDependencies": { + "nrf51822": { + "ble-nrf51822":"~0.0.1" + } + } +} diff --git a/public/readme.txt b/public/readme.txt deleted file mode 100644 index 1b278e8..0000000 --- a/public/readme.txt +++ /dev/null @@ -1 +0,0 @@ -The public API exposed through header files. \ No newline at end of file diff --git a/common/BLEDevice.cpp b/source/BLE.cpp similarity index 98% rename from common/BLEDevice.cpp rename to source/BLE.cpp index 5df661a..181e001 100644 --- a/common/BLEDevice.cpp +++ b/source/BLE.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "BLE.h" +#include "ble/BLE.h" #if defined(TARGET_OTA_ENABLED) #include "DFUService.h" diff --git a/common/DiscoveredCharacteristic.cpp b/source/DiscoveredCharacteristic.cpp similarity index 96% rename from common/DiscoveredCharacteristic.cpp rename to source/DiscoveredCharacteristic.cpp index 081b61d..3991421 100644 --- a/common/DiscoveredCharacteristic.cpp +++ b/source/DiscoveredCharacteristic.cpp @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "DiscoveredCharacteristic.h" -#include "GattClient.h" +#include "ble/DiscoveredCharacteristic.h" +#include "ble/GattClient.h" GattClient::ReadCallback_t DiscoveredCharacteristic::onDataReadCallback; GattClient::WriteCallback_t DiscoveredCharacteristic::onDataWriteCallback; diff --git a/common/GapScanningParams.cpp b/source/GapScanningParams.cpp similarity index 97% rename from common/GapScanningParams.cpp rename to source/GapScanningParams.cpp index 3120502..e409745 100644 --- a/common/GapScanningParams.cpp +++ b/source/GapScanningParams.cpp @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "Gap.h" -#include "GapScanningParams.h" +#include "ble/Gap.h" +#include "ble/GapScanningParams.h" GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) : _interval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)), diff --git a/services/DFUService.cpp b/source/services/DFUService.cpp similarity index 98% rename from services/DFUService.cpp rename to source/services/DFUService.cpp index ccecad6..a72e559 100644 --- a/services/DFUService.cpp +++ b/source/services/DFUService.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "DFUService.h" +#include "ble/services/DFUService.h" const uint8_t DFUServiceBaseUUID[] = { 0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0xEF, 0xDE, diff --git a/services/UARTService.cpp b/source/services/UARTService.cpp similarity index 98% rename from services/UARTService.cpp rename to source/services/UARTService.cpp index 592aac1..6d1edea 100644 --- a/services/UARTService.cpp +++ b/source/services/UARTService.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "UARTService.h" +#include "ble/services/UARTService.h" const uint8_t UARTServiceBaseUUID[UUID::LENGTH_OF_LONG_UUID] = { 0x6E, 0x40, 0x00, 0x00, 0xB5, 0xA3, 0xF3, 0x93, diff --git a/services/URIBeaconConfigService.cpp b/source/services/URIBeaconConfigService.cpp similarity index 97% rename from services/URIBeaconConfigService.cpp rename to source/services/URIBeaconConfigService.cpp index 26cf535..bcdcbb0 100644 --- a/services/URIBeaconConfigService.cpp +++ b/source/services/URIBeaconConfigService.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "URIBeaconConfigService.h" +#include "ble/services/URIBeaconConfigService.h" #define UUID_URI_BEACON(FIRST, SECOND) { \ 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \