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:
118:620d28e7a1ba
Child:
237:6050833395f1
diff -r 0fb20195102b -r 620d28e7a1ba services/DeviceInformationService.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/services/DeviceInformationService.h	Mon Sep 22 10:59:09 2014 +0100
@@ -0,0 +1,124 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 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_DEVICE_INFORMATION_SERVICE_H__
+#define __BLE_DEVICE_INFORMATION_SERVICE_H__
+
+#include "BLEDevice.h"
+
+/* Device Information Service */
+/* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml */
+/* Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml */
+class DeviceInformationService {
+public:
+    /**
+     * Constructor.
+     *
+     * @param[in] _ble
+     *                Reference to the BLEDevice.
+     * @param[in] manufacturersName
+     *                This characteristic represents the name of the
+     *                manufacturer of the device. The name is copied into the
+     *                BLE stack during this constructor.
+     * @param[in] modelNumber
+     *                This characteristic represents the model number that is
+     *                assigned by the device vendor. The value is copied into
+     *                the BLE stack during this constructor.
+     * @param[in] serialNumber
+     *                This characteristic represents the serial number for a
+     *                particular instance of the device.  The value is copied
+     *                into the BLE stack during this constructor.
+     * @param[in] hardwareRevision
+     *                This characteristic represents the hardware revision for
+     *                the hardware within the device. The value is copied
+     *                into the BLE stack during this constructor.
+     * @param[in] firmwareRevision
+     *                This characteristic represents the firmware revision for
+     *                the firmware within the device. The value is copied
+     *                into the BLE stack during this constructor.
+     * @param[in] softwareRevision
+     *                This characteristic represents the software revision for
+     *                the software within the device. The value is copied
+     *                into the BLE stack during this constructor.
+     */
+    DeviceInformationService(BLEDevice &_ble,
+                             const char *manufacturersName = NULL,
+                             const char *modelNumber       = NULL,
+                             const char *serialNumber      = NULL,
+                             const char *hardwareRevision  = NULL,
+                             const char *firmwareRevision  = NULL,
+                             const char *softwareRevision  = NULL) :
+        ble(_ble),
+        manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR,
+                                              (uint8_t *)manufacturersName,
+                                              (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */
+                                              (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */
+                                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
+        modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR,
+                                        (uint8_t *)modelNumber,
+                                        (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */
+                                        (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */
+                                        GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
+        serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR,
+                                         (uint8_t *)serialNumber,
+                                         (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */
+                                         (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */
+                                         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
+        hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR,
+                                             (uint8_t *)hardwareRevision,
+                                             (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */
+                                             (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */
+                                             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
+        firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR,
+                                             (uint8_t *)firmwareRevision,
+                                             (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */
+                                             (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */
+                                             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
+        softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR,
+                                             (uint8_t *)softwareRevision,
+                                             (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */
+                                             (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */
+                                             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
+                                               {
+        static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */
+        if (serviceAdded) {
+            return;
+        }
+
+        GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic,
+                                           &modelNumberStringCharacteristic,
+                                           &serialNumberStringCharacteristic,
+                                           &hardwareRevisionStringCharacteristic,
+                                           &firmwareRevisionStringCharacteristic,
+                                           &softwareRevisionStringCharacteristic};
+        GattService         deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable,
+                                                     sizeof(charTable) / sizeof(GattCharacteristic *));
+
+        ble.addService(deviceInformationService);
+        serviceAdded = true;
+    }
+
+private:
+    BLEDevice          &ble;
+    GattCharacteristic  manufacturersNameStringCharacteristic;
+    GattCharacteristic  modelNumberStringCharacteristic;
+    GattCharacteristic  serialNumberStringCharacteristic;
+    GattCharacteristic  hardwareRevisionStringCharacteristic;
+    GattCharacteristic  firmwareRevisionStringCharacteristic;
+    GattCharacteristic  softwareRevisionStringCharacteristic;
+};
+
+#endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/