Lightly modified version of the BLE stack, that doesn't bring up a DFUService by default... as we have our own.

Fork of BLE_API by Bluetooth Low Energy

Revision:
140:407d134c179d
Parent:
139:baaf1c5f0db2
Child:
145:a7ded9ad83c8
diff -r baaf1c5f0db2 -r 407d134c179d public/BLEDevice.h
--- a/public/BLEDevice.h	Fri Nov 21 09:23:24 2014 +0000
+++ b/public/BLEDevice.h	Fri Nov 21 09:23:24 2014 +0000
@@ -17,6 +17,7 @@
 #ifndef __BLE_DEVICE__
 #define __BLE_DEVICE__
 
+#include "mbed.h"
 #include "blecommon.h"
 #include "Gap.h"
 #include "GattServer.h"
@@ -42,13 +43,13 @@
      * Set the BTLE MAC address and type.
      * @return BLE_ERROR_NONE on success.
      */
-    ble_error_t setAddress(Gap::addr_type_t type, const uint8_t address[Gap::ADDR_LEN]);
+    ble_error_t setAddress(Gap::addr_type_t type, const Gap::address_t address);
 
     /**
      * Fetch the BTLE MAC address and type.
      * @return BLE_ERROR_NONE on success.
      */
-    ble_error_t getAddress(Gap::addr_type_t *typeP, uint8_t address[Gap::ADDR_LEN]);
+    ble_error_t getAddress(Gap::addr_type_t *typeP, Gap::address_t address);
 
     /**
      * @param[in] advType
@@ -228,7 +229,7 @@
      * some object.
      */
     void onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP));
-    template <typename T> void onDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context));
+    template <typename T> void onDataWritten(T * objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context));
 
     void onUpdatesEnabled(GattServer::EventCallback_t callback);
     void onUpdatesDisabled(GattServer::EventCallback_t callback);
@@ -253,7 +254,7 @@
      * @param  localOnly
      *         Only update the characteristic locally regardless of notify/indicate flags in the CCCD.
      */
-    ble_error_t updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly = false);
+    ble_error_t updateCharacteristicValue(uint16_t handle, const uint8_t *value, uint16_t size, bool localOnly = false);
 
     /**
      * Yield control to the BLE stack or to other tasks waiting for events. This
@@ -276,56 +277,56 @@
      */
     const char *getVersion(void);
 
-     /**
-      * Set the device name characteristic in the GAP service.
-      * @param  deviceName The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string.
-      */
-     ble_error_t setDeviceName(const uint8_t *deviceName);
+    /**
+     * Set the device name characteristic in the GAP service.
+     * @param  deviceName The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string.
+     */
+    ble_error_t setDeviceName(const uint8_t *deviceName);
 
-     /**
-      * Get the value of the device name characteristic in the GAP service.
-      * @param[out]    deviceName Pointer to an empty buffer where the UTF-8 *non NULL-
-      *                           terminated* string will be placed. Set this
-      *                           value to NULL in order to obtain the deviceName-length
-      *                           from the 'length' parameter.
-      *
-      * @param[in/out] lengthP    (on input) Length of the buffer pointed to by deviceName;
-      *                           (on output) the complete device name length (without the
-      *                           null terminator).
-      *
-      * @note          If the device name is longer than the size of the supplied buffer,
-      *                length will return the complete device name length,
-      *                and not the number of bytes actually returned in deviceName.
-      *                The application may use this information to retry with a suitable buffer size.
-      *
-      * Sample use:
-      *     uint8_t deviceName[20];
-      *     unsigned length = sizeof(deviceName);
-      *     ble.getDeviceName(deviceName, &length);
-      *     if (length < sizeof(deviceName)) {
-      *         deviceName[length] = 0;
-      *     }
-      *     DEBUG("length: %u, deviceName: %s\r\n", length, deviceName);
-      */
-     ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
+    /**
+     * Get the value of the device name characteristic in the GAP service.
+     * @param[out]    deviceName Pointer to an empty buffer where the UTF-8 *non NULL-
+     *                           terminated* string will be placed. Set this
+     *                           value to NULL in order to obtain the deviceName-length
+     *                           from the 'length' parameter.
+     *
+     * @param[in/out] lengthP    (on input) Length of the buffer pointed to by deviceName;
+     *                           (on output) the complete device name length (without the
+     *                           null terminator).
+     *
+     * @note          If the device name is longer than the size of the supplied buffer,
+     *                length will return the complete device name length,
+     *                and not the number of bytes actually returned in deviceName.
+     *                The application may use this information to retry with a suitable buffer size.
+     *
+     * Sample use:
+     *     uint8_t deviceName[20];
+     *     unsigned length = sizeof(deviceName);
+     *     ble.getDeviceName(deviceName, &length);
+     *     if (length < sizeof(deviceName)) {
+     *         deviceName[length] = 0;
+     *     }
+     *     DEBUG("length: %u, deviceName: %s\r\n", length, deviceName);
+     */
+    ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
 
-     /**
-      * Set the appearance characteristic in the GAP service.
-      * @param[in]  appearance The new value for the device-appearance.
-      */
-     ble_error_t setAppearance(uint16_t appearance);
+    /**
+     * Set the appearance characteristic in the GAP service.
+     * @param[in]  appearance The new value for the device-appearance.
+     */
+    ble_error_t setAppearance(uint16_t appearance);
 
-     /**
-      * Set the appearance characteristic in the GAP service.
-      * @param[out]  appearance The new value for the device-appearance.
-      */
-     ble_error_t getAppearance(uint16_t *appearanceP);
+    /**
+     * Set the appearance characteristic in the GAP service.
+     * @param[out]  appearance The new value for the device-appearance.
+     */
+    ble_error_t getAppearance(uint16_t *appearanceP);
 
-     /**
-      * Set the radio's transmit power.
-      * @param[in] txPower Radio transmit power in dBm.
-      */
-     ble_error_t setTxPower(int8_t txPower);
+    /**
+     * Set the radio's transmit power.
+     * @param[in] txPower Radio transmit power in dBm.
+     */
+    ble_error_t setTxPower(int8_t txPower);
 
 public:
     BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true) {
@@ -365,13 +366,13 @@
 }
 
 inline ble_error_t
-BLEDevice::setAddress(Gap::addr_type_t type, const uint8_t address[Gap::ADDR_LEN])
+BLEDevice::setAddress(Gap::addr_type_t type, const Gap::address_t address)
 {
     return transport->getGap().setAddress(type, address);
 }
 
 inline ble_error_t
-BLEDevice::getAddress(Gap::addr_type_t *typeP, uint8_t address[Gap::ADDR_LEN])
+BLEDevice::getAddress(Gap::addr_type_t *typeP, Gap::address_t address)
 {
     return transport->getGap().getAddress(typeP, address);
 }
@@ -418,6 +419,7 @@
 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app)
 {
     needToSetAdvPayload = true;
+    transport->getGap().setAppearance(app);
     return advPayload.addAppearance(app);
 }
 
@@ -432,6 +434,9 @@
 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
 {
     needToSetAdvPayload = true;
+    if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) {
+        transport->getGap().setDeviceName(data);
+    }
     return advPayload.addData(type, data, len);
 }
 
@@ -451,8 +456,11 @@
 inline ble_error_t
 BLEDevice::startAdvertising(void)
 {
+    ble_error_t rc;
+    if ((rc = transport->getGattServer().initializeGATTDatabase()) != BLE_ERROR_NONE) {
+        return rc;
+    }
     if (needToSetAdvPayload) {
-        ble_error_t rc;
         if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) {
             return rc;
         }
@@ -507,7 +515,6 @@
     transport->getGattServer().setOnDataWritten(objPtr, memberPtr);
 }
 
-
 inline void
 BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback)
 {
@@ -544,7 +551,7 @@
 }
 
 inline ble_error_t
-BLEDevice::updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly)
+BLEDevice::updateCharacteristicValue(uint16_t handle, const uint8_t *value, uint16_t size, bool localOnly)
 {
     return transport->getGattServer().updateValue(handle, const_cast<uint8_t *>(value), size, localOnly);
 }