I don't know why this is happening.
Fork of BLE_API by
services/DeviceInformationService.h@714:a6130aaa0fd9, 2015-07-02 (annotated)
- Committer:
- rgrover1
- Date:
- Thu Jul 02 09:06:11 2015 +0100
- Revision:
- 714:a6130aaa0fd9
Synchronized with git rev 7e8977d8
Author: Rohit Grover
Release 0.3.8
=============
This is a minor set of enhancements before we yotta-ize BLE_API.
Enhancements
~~~~~~~~~~~~
* Minor rework for class UUID; added a default and copy constructor; and a != operator.
* Added copy constructor and accessors for GapAdvertisingParams.
* GapScanningParams:: remove unnecessary checks for SCAN_TIMEOUT_MAX.
* Add a comment header block to explain why BLEDevice::init() may not be safe
to call from global static context.
* Introduce GattAttribute::INVALID_HANDLE.
* Replace some deprecated uses of Gap::address_t with Gap::Address_t.
Bugfixes
~~~~~~~~
* None.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 714:a6130aaa0fd9 | 1 | /* mbed Microcontroller Library |
rgrover1 | 714:a6130aaa0fd9 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 714:a6130aaa0fd9 | 3 | * |
rgrover1 | 714:a6130aaa0fd9 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 714:a6130aaa0fd9 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 714:a6130aaa0fd9 | 6 | * You may obtain a copy of the License at |
rgrover1 | 714:a6130aaa0fd9 | 7 | * |
rgrover1 | 714:a6130aaa0fd9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 714:a6130aaa0fd9 | 9 | * |
rgrover1 | 714:a6130aaa0fd9 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 714:a6130aaa0fd9 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 714:a6130aaa0fd9 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 714:a6130aaa0fd9 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 714:a6130aaa0fd9 | 14 | * limitations under the License. |
rgrover1 | 714:a6130aaa0fd9 | 15 | */ |
rgrover1 | 714:a6130aaa0fd9 | 16 | |
rgrover1 | 714:a6130aaa0fd9 | 17 | #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__ |
rgrover1 | 714:a6130aaa0fd9 | 18 | #define __BLE_DEVICE_INFORMATION_SERVICE_H__ |
rgrover1 | 714:a6130aaa0fd9 | 19 | |
rgrover1 | 714:a6130aaa0fd9 | 20 | #include "BLEDevice.h" |
rgrover1 | 714:a6130aaa0fd9 | 21 | |
rgrover1 | 714:a6130aaa0fd9 | 22 | /** |
rgrover1 | 714:a6130aaa0fd9 | 23 | * @class DeviceInformationService |
rgrover1 | 714:a6130aaa0fd9 | 24 | * @brief BLE Device Information Service <br> |
rgrover1 | 714:a6130aaa0fd9 | 25 | * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml <br> |
rgrover1 | 714:a6130aaa0fd9 | 26 | * Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml |
rgrover1 | 714:a6130aaa0fd9 | 27 | */ |
rgrover1 | 714:a6130aaa0fd9 | 28 | class DeviceInformationService { |
rgrover1 | 714:a6130aaa0fd9 | 29 | public: |
rgrover1 | 714:a6130aaa0fd9 | 30 | /** |
rgrover1 | 714:a6130aaa0fd9 | 31 | * @brief Device Information Service Constructor. |
rgrover1 | 714:a6130aaa0fd9 | 32 | * |
rgrover1 | 714:a6130aaa0fd9 | 33 | * @param[ref] _ble |
rgrover1 | 714:a6130aaa0fd9 | 34 | * BLEDevice object for the underlying controller. |
rgrover1 | 714:a6130aaa0fd9 | 35 | * @param[in] manufacturersName |
rgrover1 | 714:a6130aaa0fd9 | 36 | * This characteristic represents the name of the |
rgrover1 | 714:a6130aaa0fd9 | 37 | * manufacturer of the device. The name is copied into the |
rgrover1 | 714:a6130aaa0fd9 | 38 | * BLE stack during this constructor. |
rgrover1 | 714:a6130aaa0fd9 | 39 | * @param[in] modelNumber |
rgrover1 | 714:a6130aaa0fd9 | 40 | * This characteristic represents the model number that is |
rgrover1 | 714:a6130aaa0fd9 | 41 | * assigned by the device vendor. The value is copied into |
rgrover1 | 714:a6130aaa0fd9 | 42 | * the BLE stack during this constructor. |
rgrover1 | 714:a6130aaa0fd9 | 43 | * @param[in] serialNumber |
rgrover1 | 714:a6130aaa0fd9 | 44 | * This characteristic represents the serial number for a |
rgrover1 | 714:a6130aaa0fd9 | 45 | * particular instance of the device. The value is copied |
rgrover1 | 714:a6130aaa0fd9 | 46 | * into the BLE stack during this constructor. |
rgrover1 | 714:a6130aaa0fd9 | 47 | * @param[in] hardwareRevision |
rgrover1 | 714:a6130aaa0fd9 | 48 | * This characteristic represents the hardware revision for |
rgrover1 | 714:a6130aaa0fd9 | 49 | * the hardware within the device. The value is copied |
rgrover1 | 714:a6130aaa0fd9 | 50 | * into the BLE stack during this constructor. |
rgrover1 | 714:a6130aaa0fd9 | 51 | * @param[in] firmwareRevision |
rgrover1 | 714:a6130aaa0fd9 | 52 | * This characteristic represents the firmware revision for |
rgrover1 | 714:a6130aaa0fd9 | 53 | * the firmware within the device. The value is copied |
rgrover1 | 714:a6130aaa0fd9 | 54 | * into the BLE stack during this constructor. |
rgrover1 | 714:a6130aaa0fd9 | 55 | * @param[in] softwareRevision |
rgrover1 | 714:a6130aaa0fd9 | 56 | * This characteristic represents the software revision for |
rgrover1 | 714:a6130aaa0fd9 | 57 | * the software within the device. The value is copied |
rgrover1 | 714:a6130aaa0fd9 | 58 | * into the BLE stack during this constructor. |
rgrover1 | 714:a6130aaa0fd9 | 59 | */ |
rgrover1 | 714:a6130aaa0fd9 | 60 | DeviceInformationService(BLEDevice &_ble, |
rgrover1 | 714:a6130aaa0fd9 | 61 | const char *manufacturersName = NULL, |
rgrover1 | 714:a6130aaa0fd9 | 62 | const char *modelNumber = NULL, |
rgrover1 | 714:a6130aaa0fd9 | 63 | const char *serialNumber = NULL, |
rgrover1 | 714:a6130aaa0fd9 | 64 | const char *hardwareRevision = NULL, |
rgrover1 | 714:a6130aaa0fd9 | 65 | const char *firmwareRevision = NULL, |
rgrover1 | 714:a6130aaa0fd9 | 66 | const char *softwareRevision = NULL) : |
rgrover1 | 714:a6130aaa0fd9 | 67 | ble(_ble), |
rgrover1 | 714:a6130aaa0fd9 | 68 | manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR, |
rgrover1 | 714:a6130aaa0fd9 | 69 | (uint8_t *)manufacturersName, |
rgrover1 | 714:a6130aaa0fd9 | 70 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */ |
rgrover1 | 714:a6130aaa0fd9 | 71 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */ |
rgrover1 | 714:a6130aaa0fd9 | 72 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
rgrover1 | 714:a6130aaa0fd9 | 73 | modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR, |
rgrover1 | 714:a6130aaa0fd9 | 74 | (uint8_t *)modelNumber, |
rgrover1 | 714:a6130aaa0fd9 | 75 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */ |
rgrover1 | 714:a6130aaa0fd9 | 76 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */ |
rgrover1 | 714:a6130aaa0fd9 | 77 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
rgrover1 | 714:a6130aaa0fd9 | 78 | serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR, |
rgrover1 | 714:a6130aaa0fd9 | 79 | (uint8_t *)serialNumber, |
rgrover1 | 714:a6130aaa0fd9 | 80 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */ |
rgrover1 | 714:a6130aaa0fd9 | 81 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */ |
rgrover1 | 714:a6130aaa0fd9 | 82 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
rgrover1 | 714:a6130aaa0fd9 | 83 | hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR, |
rgrover1 | 714:a6130aaa0fd9 | 84 | (uint8_t *)hardwareRevision, |
rgrover1 | 714:a6130aaa0fd9 | 85 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */ |
rgrover1 | 714:a6130aaa0fd9 | 86 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */ |
rgrover1 | 714:a6130aaa0fd9 | 87 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
rgrover1 | 714:a6130aaa0fd9 | 88 | firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, |
rgrover1 | 714:a6130aaa0fd9 | 89 | (uint8_t *)firmwareRevision, |
rgrover1 | 714:a6130aaa0fd9 | 90 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */ |
rgrover1 | 714:a6130aaa0fd9 | 91 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */ |
rgrover1 | 714:a6130aaa0fd9 | 92 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
rgrover1 | 714:a6130aaa0fd9 | 93 | softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR, |
rgrover1 | 714:a6130aaa0fd9 | 94 | (uint8_t *)softwareRevision, |
rgrover1 | 714:a6130aaa0fd9 | 95 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */ |
rgrover1 | 714:a6130aaa0fd9 | 96 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */ |
rgrover1 | 714:a6130aaa0fd9 | 97 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) |
rgrover1 | 714:a6130aaa0fd9 | 98 | { |
rgrover1 | 714:a6130aaa0fd9 | 99 | static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */ |
rgrover1 | 714:a6130aaa0fd9 | 100 | if (serviceAdded) { |
rgrover1 | 714:a6130aaa0fd9 | 101 | return; |
rgrover1 | 714:a6130aaa0fd9 | 102 | } |
rgrover1 | 714:a6130aaa0fd9 | 103 | |
rgrover1 | 714:a6130aaa0fd9 | 104 | GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic, |
rgrover1 | 714:a6130aaa0fd9 | 105 | &modelNumberStringCharacteristic, |
rgrover1 | 714:a6130aaa0fd9 | 106 | &serialNumberStringCharacteristic, |
rgrover1 | 714:a6130aaa0fd9 | 107 | &hardwareRevisionStringCharacteristic, |
rgrover1 | 714:a6130aaa0fd9 | 108 | &firmwareRevisionStringCharacteristic, |
rgrover1 | 714:a6130aaa0fd9 | 109 | &softwareRevisionStringCharacteristic}; |
rgrover1 | 714:a6130aaa0fd9 | 110 | GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable, |
rgrover1 | 714:a6130aaa0fd9 | 111 | sizeof(charTable) / sizeof(GattCharacteristic *)); |
rgrover1 | 714:a6130aaa0fd9 | 112 | |
rgrover1 | 714:a6130aaa0fd9 | 113 | ble.addService(deviceInformationService); |
rgrover1 | 714:a6130aaa0fd9 | 114 | serviceAdded = true; |
rgrover1 | 714:a6130aaa0fd9 | 115 | } |
rgrover1 | 714:a6130aaa0fd9 | 116 | |
rgrover1 | 714:a6130aaa0fd9 | 117 | private: |
rgrover1 | 714:a6130aaa0fd9 | 118 | BLEDevice &ble; |
rgrover1 | 714:a6130aaa0fd9 | 119 | GattCharacteristic manufacturersNameStringCharacteristic; |
rgrover1 | 714:a6130aaa0fd9 | 120 | GattCharacteristic modelNumberStringCharacteristic; |
rgrover1 | 714:a6130aaa0fd9 | 121 | GattCharacteristic serialNumberStringCharacteristic; |
rgrover1 | 714:a6130aaa0fd9 | 122 | GattCharacteristic hardwareRevisionStringCharacteristic; |
rgrover1 | 714:a6130aaa0fd9 | 123 | GattCharacteristic firmwareRevisionStringCharacteristic; |
rgrover1 | 714:a6130aaa0fd9 | 124 | GattCharacteristic softwareRevisionStringCharacteristic; |
rgrover1 | 714:a6130aaa0fd9 | 125 | }; |
rgrover1 | 714:a6130aaa0fd9 | 126 | |
rgrover1 | 714:a6130aaa0fd9 | 127 | #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/ |