add "LE Device Address" 0x1B to advertising data types

Fork of BLE_API by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Thu Dec 10 09:15:02 2015 +0000
Parent:
1022:306c409f6c09
Child:
1024:438b06bbca04
Commit message:
Synchronized with git rev b9af3222
Author: Irit Arkin
Edit

Changed in this revision

ble/UUID.h Show annotated file Show diff for this revision Revisions of this file
ble/services/EddystoneConfigService.h Show annotated file Show diff for this revision Revisions of this file
ble/services/HeartRateService.h Show annotated file Show diff for this revision Revisions of this file
ble/services/UARTService.h Show annotated file Show diff for this revision Revisions of this file
ble/services/URIBeaconConfigService.h Show annotated file Show diff for this revision Revisions of this file
source/services/DFUService.cpp Show annotated file Show diff for this revision Revisions of this file
source/services/UARTService.cpp Show annotated file Show diff for this revision Revisions of this file
source/services/URIBeaconConfigService.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ble/UUID.h	Thu Dec 10 09:15:02 2015 +0000
+++ b/ble/UUID.h	Thu Dec 10 09:15:02 2015 +0000
@@ -22,18 +22,6 @@
 
 #include "blecommon.h"
 
-static uint16_t char2int(char c) {
-    if ((c >= '0') && (c <= '9')) {
-        return c - '0';
-    } else if ((c >= 'a') && (c <= 'f')) {
-        return c - 'a' + 10;
-    } else if ((c >= 'A') && (c <= 'F')) {
-        return c - 'A' + 10;
-    } else {
-        return 0;
-    }
-}
-
 class UUID {
 public:
     enum UUID_Type_t {
@@ -47,49 +35,6 @@
     typedef uint8_t       LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
 
 public:
-
-    /**
-     * Creates a new 128-bit UUID.
-     *
-     * @note   The UUID is a unique 128-bit (16 byte) ID used to identify
-     *         different service or characteristics on the BLE device.
-     *
-     * @param  stringUUID
-     *          The 128-bit (16-byte) UUID as a human readable const-string.
-     *          Format: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
-     *          Upper and lower case supported. Hyphens are optional, but only
-     *          upto four of them. The UUID is stored internally as a 16 byte
-     *          array, LSB (little endian), which is opposite from the string.
-     */
-    UUID(const char* stringUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
-        bool nibble = false;
-        uint8_t byte = 0;
-        size_t baseIndex = 0;
-
-        // Iterate through string, abort if NULL is encountered prematurely.
-        // Ignore upto four hyphens. Reverse endian when storing internally.
-        for (size_t index = 0; (index < 36) && (baseIndex < LENGTH_OF_LONG_UUID); index++) {
-            if (stringUUID[index] == '\0') {
-                // error abort
-                break;
-            } else if (stringUUID[index] == '-') {
-                // ignore hyphen
-                continue;
-            } else if (nibble) {
-                // got second nibble
-                byte |= char2int(stringUUID[index]);
-                nibble = false;
-
-                // reverse endian
-                baseUUID[LENGTH_OF_LONG_UUID - 1 - baseIndex++] = byte;
-            } else {
-                // got first nibble
-                byte = char2int(stringUUID[index]) << 4;
-                nibble = true;
-            }
-        }
-    }
-
     /**
      * Creates a new 128-bit UUID.
      *
@@ -97,7 +42,7 @@
      *         different service or characteristics on the BLE device.
      *
      * @param longUUID
-     *          The 128-bit (16-byte) UUID value, LSB first (little-endian).
+     *          The 128-bit (16-byte) UUID value, MSB first (big-endian).
      */
     UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
         setupLong(longUUID);
@@ -149,7 +94,7 @@
     void setupLong(const LongUUIDBytes_t longUUID) {
         type      = UUID_TYPE_LONG;
         memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
-        shortUUID = (uint16_t)((longUUID[13] << 8) | (longUUID[12]));
+        shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3]));
     }
 
 public:
--- a/ble/services/EddystoneConfigService.h	Thu Dec 10 09:15:02 2015 +0000
+++ b/ble/services/EddystoneConfigService.h	Thu Dec 10 09:15:02 2015 +0000
@@ -23,9 +23,9 @@
 #include "ble/BLE.h"
 #include "ble/services/EddystoneService.h"
 
-#define UUID_URI_BEACON(FIRST, SECOND) {                        \
-        0xd8, 0x81, 0xc9, 0x1a,   0xb9,  0x99, 0x96, 0xab,      \
-        0xba, 0x40, 0x86, 0x87, SECOND, FIRST, 0x0c, 0xee       \
+#define UUID_URI_BEACON(FIRST, SECOND) {                         \
+        0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba,       \
+        0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8,          \
 }
 
 static const uint8_t UUID_URI_BEACON_SERVICE[]    = UUID_URI_BEACON(0x20, 0x80);
@@ -271,7 +271,12 @@
 
         ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
 
-        ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, UUID_URI_BEACON_SERVICE, sizeof(UUID_URI_BEACON_SERVICE));
+        // UUID is in a 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<const uint8_t *>(&DEVICE_NAME), sizeof(DEVICE_NAME));
         ble.accumulateScanResponse(
--- a/ble/services/HeartRateService.h	Thu Dec 10 09:15:02 2015 +0000
+++ b/ble/services/HeartRateService.h	Thu Dec 10 09:15:02 2015 +0000
@@ -21,35 +21,35 @@
 
 /**
 * @class HeartRateService
-* @brief BLE Service for HeartRate. This BLE Service contains the location of the sensor, the heartrate in beats per minute. <br>
-* Service:  https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.heart_rate.xml <br>
-* HRM Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml <br>
+* @brief BLE Service for HeartRate. This BLE Service contains the location of the sensor and the heart rate in beats per minute.
+* Service:  https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.heart_rate.xml
+* HRM Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
 * Location: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.body_sensor_location.xml
 */
 class HeartRateService {
 public:
     /**
     * @enum SensorLocation
-    * @brief Location of HeartRate sensor on body.
+    * @brief Location of the heart rate sensor on body.
     */
     enum {
-        LOCATION_OTHER = 0, /*!< Other Location */
-        LOCATION_CHEST,     /*!< Chest */
-        LOCATION_WRIST,     /*!< Wrist */
-        LOCATION_FINGER,    /*!< Finger */
-        LOCATION_HAND,      /*!< Hand */
-        LOCATION_EAR_LOBE,  /*!< Earlobe */
-        LOCATION_FOOT,      /*!< Foot */
+        LOCATION_OTHER = 0, /*!< Other location. */
+        LOCATION_CHEST,     /*!< Chest. */
+        LOCATION_WRIST,     /*!< Wrist. */
+        LOCATION_FINGER,    /*!< Finger. */
+        LOCATION_HAND,      /*!< Hand. */
+        LOCATION_EAR_LOBE,  /*!< Earlobe. */
+        LOCATION_FOOT,      /*!< Foot. */
     };
 
 public:
     /**
-     * @brief Constructor with 8bit HRM Counter value.
+     * @brief Constructor with 8-bit HRM Counter value.
      *
      * @param[ref] _ble
      *               Reference to the underlying BLE.
      * @param[in] hrmCounter (8-bit)
-     *               initial value for the hrm counter.
+     *               Initial value for the HRM counter.
      * @param[in] location
      *               Sensor's location.
      */
@@ -70,7 +70,7 @@
      * @param[in] _ble
      *               Reference to the underlying BLE.
      * @param[in] hrmCounter (8-bit)
-     *               initial value for the hrm counter.
+     *               Initial value for the HRM counter.
      * @param[in] location
      *               Sensor's location.
      */
@@ -86,10 +86,10 @@
     }
 
     /**
-     * @brief Set a new 8-bit value for heart rate.
+     * @brief Set a new 8-bit value for the heart rate.
      *
      * @param[in] hrmCounter
-     *                  HeartRate in bpm.
+     *                  Heart rate in BPM.
      */
     void updateHeartRate(uint8_t hrmCounter) {
         valueBytes.updateHeartRate(hrmCounter);
@@ -97,10 +97,10 @@
     }
 
     /**
-     * Set a new 16-bit value for heart rate.
+     * Set a new 16-bit value for the heart rate.
      *
      * @param[in] hrmCounter
-     *                  HeartRate in bpm.
+     *                  Heart rate in BPM.
      */
     void updateHeartRate(uint16_t hrmCounter) {
         valueBytes.updateHeartRate(hrmCounter);
@@ -108,8 +108,8 @@
     }
 
     /**
-     * This callback allows the HeartRateService to receive updates to the
-     * controlPoint Characteristic.
+     * This callback allows the heart rate service to receive updates to the
+     * controlPoint characteristic.
      *
      * @param[in] params
      *     Information about the characterisitc being updated.
@@ -118,7 +118,7 @@
         if (params->handle == controlPoint.getValueAttribute().getHandle()) {
             /* Do something here if the new value is 1; else you can override this method by
              * extending this class.
-             * @NOTE: if you are extending this class, be sure to also call
+             * @NOTE: If you are extending this class, be sure to also call
              * ble.onDataWritten(this, &ExtendedHRService::onDataWritten); in
              * your constructor.
              */
@@ -135,9 +135,9 @@
     }
 
 protected:
-    /* Private internal representation for the bytes used to work with the vaulue of the heart-rate characteristic. */
+    /* Private internal representation for the bytes used to work with the value of the heart rate characteristic. */
     struct HeartRateValueBytes {
-        static const unsigned MAX_VALUE_BYTES  = 3; /* FLAGS + up to two bytes for heart-rate */
+        static const unsigned MAX_VALUE_BYTES  = 3; /* Flags, and up to two bytes for heart rate. */
         static const unsigned FLAGS_BYTE_INDEX = 0;
 
         static const unsigned VALUE_FORMAT_BITNUM = 0;
@@ -175,8 +175,8 @@
         }
 
     private:
-        /* First byte = 8-bit values, no extra info, Second byte = uint8_t HRM value */
-        /* See --> https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml */
+        /* First byte: 8-bit values, no extra info. Second byte: uint8_t HRM value */
+        /* See https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml */
         uint8_t valueBytes[MAX_VALUE_BYTES];
     };
 
--- a/ble/services/UARTService.h	Thu Dec 10 09:15:02 2015 +0000
+++ b/ble/services/UARTService.h	Thu Dec 10 09:15:02 2015 +0000
@@ -34,6 +34,7 @@
 extern const uint16_t UARTServiceRXCharacteristicShortUUID;
 
 extern const uint8_t  UARTServiceUUID[UUID::LENGTH_OF_LONG_UUID];
+extern const uint8_t  UARTServiceUUID_reversed[UUID::LENGTH_OF_LONG_UUID];
 
 extern const uint8_t  UARTServiceTXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID];
 extern const uint8_t  UARTServiceRXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID];
--- a/ble/services/URIBeaconConfigService.h	Thu Dec 10 09:15:02 2015 +0000
+++ b/ble/services/URIBeaconConfigService.h	Thu Dec 10 09:15:02 2015 +0000
@@ -168,7 +168,12 @@
 
         ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
 
-        ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, UUID_URI_BEACON_SERVICE, sizeof(UUID_URI_BEACON_SERVICE));
+        // 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.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<const uint8_t *>(&DEVICE_NAME), sizeof(DEVICE_NAME));
         ble.gap().accumulateScanResponse(GapAdvertisingData::TX_POWER_LEVEL,
--- a/source/services/DFUService.cpp	Thu Dec 10 09:15:02 2015 +0000
+++ b/source/services/DFUService.cpp	Thu Dec 10 09:15:02 2015 +0000
@@ -19,24 +19,24 @@
 #include "ble/services/DFUService.h"
 
 const uint8_t              DFUServiceBaseUUID[] = {
-    0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
-    0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00
+    0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0xEF, 0xDE,
+    0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
 };
 const uint16_t             DFUServiceShortUUID                      = 0x1530;
 const uint16_t             DFUServiceControlCharacteristicShortUUID = 0x1531;
 const uint16_t             DFUServicePacketCharacteristicShortUUID  = 0x1532;
 
 const uint8_t              DFUServiceUUID[] = {
-    0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
-    0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServiceShortUUID & 0xFF), (uint8_t)(DFUServiceShortUUID >> 8), 0x00, 0x00
+    0x00, 0x00, (uint8_t)(DFUServiceShortUUID >> 8), (uint8_t)(DFUServiceShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
+    0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
 };
 const uint8_t              DFUServiceControlCharacteristicUUID[] = {
-    0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
-    0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), 0x00, 0x00
+    0x00, 0x00, (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
+    0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
 };
 const uint8_t              DFUServicePacketCharacteristicUUID[] = {
-    0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
-    0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), 0x00, 0x00
+    0x00, 0x00, (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
+    0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
 };
 
 DFUService::ResetPrepare_t DFUService::handoverCallback = NULL;
--- a/source/services/UARTService.cpp	Thu Dec 10 09:15:02 2015 +0000
+++ b/source/services/UARTService.cpp	Thu Dec 10 09:15:02 2015 +0000
@@ -17,21 +17,25 @@
 #include "ble/services/UARTService.h"
 
 const uint8_t  UARTServiceBaseUUID[UUID::LENGTH_OF_LONG_UUID] = {
-    0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
-    0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E
+    0x6E, 0x40, 0x00, 0x00, 0xB5, 0xA3, 0xF3, 0x93,
+    0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
 };
 const uint16_t UARTServiceShortUUID                 = 0x0001;
 const uint16_t UARTServiceTXCharacteristicShortUUID = 0x0002;
 const uint16_t UARTServiceRXCharacteristicShortUUID = 0x0003;
 const uint8_t  UARTServiceUUID[UUID::LENGTH_OF_LONG_UUID] = {
+    0x6E, 0x40, (uint8_t)(UARTServiceShortUUID >> 8), (uint8_t)(UARTServiceShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93,
+    0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
+};
+const uint8_t  UARTServiceUUID_reversed[UUID::LENGTH_OF_LONG_UUID] = {
     0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
     0x93, 0xF3, 0xA3, 0xB5, (uint8_t)(UARTServiceShortUUID & 0xFF), (uint8_t)(UARTServiceShortUUID >> 8), 0x40, 0x6E
 };
 const uint8_t  UARTServiceTXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID] = {
+    0x6E, 0x40, (uint8_t)(UARTServiceTXCharacteristicShortUUID >> 8), (uint8_t)(UARTServiceTXCharacteristicShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93,
     0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
-    0x93, 0xF3, 0xA3, 0xB5, (uint8_t)(UARTServiceTXCharacteristicShortUUID & 0xFF), (uint8_t)(UARTServiceTXCharacteristicShortUUID >> 8), 0x40, 0x6E
 };
 const uint8_t  UARTServiceRXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID] = {
+    0x6E, 0x40, (uint8_t)(UARTServiceRXCharacteristicShortUUID >> 8), (uint8_t)(UARTServiceRXCharacteristicShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93,
     0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
-    0x93, 0xF3, 0xA3, 0xB5, (uint8_t)(UARTServiceRXCharacteristicShortUUID & 0xFF), (uint8_t)(UARTServiceRXCharacteristicShortUUID >> 8), 0x40, 0x6E
 };
\ No newline at end of file
--- a/source/services/URIBeaconConfigService.cpp	Thu Dec 10 09:15:02 2015 +0000
+++ b/source/services/URIBeaconConfigService.cpp	Thu Dec 10 09:15:02 2015 +0000
@@ -17,8 +17,8 @@
 #include "ble/services/URIBeaconConfigService.h"
 
 #define UUID_URI_BEACON(FIRST, SECOND) {                         \
-        0xd8, 0x81, 0xc9, 0x1a,   0xb9,  0x99, 0x96, 0xab,      \
-        0xba, 0x40, 0x86, 0x87, SECOND, FIRST, 0x0c, 0xee       \
+        0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba,       \
+        0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8,          \
 }
 
 const uint8_t UUID_URI_BEACON_SERVICE[UUID::LENGTH_OF_LONG_UUID]    = UUID_URI_BEACON(0x20, 0x80);