Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
services/DeviceInformationService.h@710:b2e1a2660ec2, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:53:28 2015 +0100
- Revision:
- 710:b2e1a2660ec2
- Parent:
- 671:33ec93d25695
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 |
---|---|---|---|
Rohit Grover |
118:620d28e7a1ba | 1 | /* mbed Microcontroller Library |
Rohit Grover |
118:620d28e7a1ba | 2 | * Copyright (c) 2006-2013 ARM Limited |
Rohit Grover |
118:620d28e7a1ba | 3 | * |
Rohit Grover |
118:620d28e7a1ba | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Rohit Grover |
118:620d28e7a1ba | 5 | * you may not use this file except in compliance with the License. |
Rohit Grover |
118:620d28e7a1ba | 6 | * You may obtain a copy of the License at |
Rohit Grover |
118:620d28e7a1ba | 7 | * |
Rohit Grover |
118:620d28e7a1ba | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Rohit Grover |
118:620d28e7a1ba | 9 | * |
Rohit Grover |
118:620d28e7a1ba | 10 | * Unless required by applicable law or agreed to in writing, software |
Rohit Grover |
118:620d28e7a1ba | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Rohit Grover |
118:620d28e7a1ba | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Rohit Grover |
118:620d28e7a1ba | 13 | * See the License for the specific language governing permissions and |
Rohit Grover |
118:620d28e7a1ba | 14 | * limitations under the License. |
Rohit Grover |
118:620d28e7a1ba | 15 | */ |
Rohit Grover |
118:620d28e7a1ba | 16 | |
Rohit Grover |
118:620d28e7a1ba | 17 | #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__ |
Rohit Grover |
118:620d28e7a1ba | 18 | #define __BLE_DEVICE_INFORMATION_SERVICE_H__ |
Rohit Grover |
118:620d28e7a1ba | 19 | |
rgrover1 | 710:b2e1a2660ec2 | 20 | #include "BLEDevice.h" |
Rohit Grover |
118:620d28e7a1ba | 21 | |
mbedAustin | 237:6050833395f1 | 22 | /** |
mbedAustin | 237:6050833395f1 | 23 | * @class DeviceInformationService |
rgrover1 | 242:0e9201b67e2f | 24 | * @brief BLE Device Information Service <br> |
mbedAustin | 237:6050833395f1 | 25 | * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml <br> |
rgrover1 | 242:0e9201b67e2f | 26 | * Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml |
mbedAustin | 237:6050833395f1 | 27 | */ |
Rohit Grover |
118:620d28e7a1ba | 28 | class DeviceInformationService { |
Rohit Grover |
118:620d28e7a1ba | 29 | public: |
Rohit Grover |
118:620d28e7a1ba | 30 | /** |
rgrover1 | 242:0e9201b67e2f | 31 | * @brief Device Information Service Constructor. |
Rohit Grover |
118:620d28e7a1ba | 32 | * |
mbedAustin | 237:6050833395f1 | 33 | * @param[ref] _ble |
rgrover1 | 710:b2e1a2660ec2 | 34 | * BLEDevice object for the underlying controller. |
Rohit Grover |
118:620d28e7a1ba | 35 | * @param[in] manufacturersName |
Rohit Grover |
118:620d28e7a1ba | 36 | * This characteristic represents the name of the |
Rohit Grover |
118:620d28e7a1ba | 37 | * manufacturer of the device. The name is copied into the |
Rohit Grover |
118:620d28e7a1ba | 38 | * BLE stack during this constructor. |
Rohit Grover |
118:620d28e7a1ba | 39 | * @param[in] modelNumber |
Rohit Grover |
118:620d28e7a1ba | 40 | * This characteristic represents the model number that is |
Rohit Grover |
118:620d28e7a1ba | 41 | * assigned by the device vendor. The value is copied into |
Rohit Grover |
118:620d28e7a1ba | 42 | * the BLE stack during this constructor. |
Rohit Grover |
118:620d28e7a1ba | 43 | * @param[in] serialNumber |
Rohit Grover |
118:620d28e7a1ba | 44 | * This characteristic represents the serial number for a |
Rohit Grover |
118:620d28e7a1ba | 45 | * particular instance of the device. The value is copied |
Rohit Grover |
118:620d28e7a1ba | 46 | * into the BLE stack during this constructor. |
Rohit Grover |
118:620d28e7a1ba | 47 | * @param[in] hardwareRevision |
Rohit Grover |
118:620d28e7a1ba | 48 | * This characteristic represents the hardware revision for |
Rohit Grover |
118:620d28e7a1ba | 49 | * the hardware within the device. The value is copied |
Rohit Grover |
118:620d28e7a1ba | 50 | * into the BLE stack during this constructor. |
Rohit Grover |
118:620d28e7a1ba | 51 | * @param[in] firmwareRevision |
Rohit Grover |
118:620d28e7a1ba | 52 | * This characteristic represents the firmware revision for |
Rohit Grover |
118:620d28e7a1ba | 53 | * the firmware within the device. The value is copied |
Rohit Grover |
118:620d28e7a1ba | 54 | * into the BLE stack during this constructor. |
Rohit Grover |
118:620d28e7a1ba | 55 | * @param[in] softwareRevision |
Rohit Grover |
118:620d28e7a1ba | 56 | * This characteristic represents the software revision for |
Rohit Grover |
118:620d28e7a1ba | 57 | * the software within the device. The value is copied |
Rohit Grover |
118:620d28e7a1ba | 58 | * into the BLE stack during this constructor. |
Rohit Grover |
118:620d28e7a1ba | 59 | */ |
rgrover1 | 710:b2e1a2660ec2 | 60 | DeviceInformationService(BLEDevice &_ble, |
Rohit Grover |
118:620d28e7a1ba | 61 | const char *manufacturersName = NULL, |
Rohit Grover |
118:620d28e7a1ba | 62 | const char *modelNumber = NULL, |
Rohit Grover |
118:620d28e7a1ba | 63 | const char *serialNumber = NULL, |
Rohit Grover |
118:620d28e7a1ba | 64 | const char *hardwareRevision = NULL, |
Rohit Grover |
118:620d28e7a1ba | 65 | const char *firmwareRevision = NULL, |
Rohit Grover |
118:620d28e7a1ba | 66 | const char *softwareRevision = NULL) : |
Rohit Grover |
118:620d28e7a1ba | 67 | ble(_ble), |
Rohit Grover |
118:620d28e7a1ba | 68 | manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR, |
Rohit Grover |
118:620d28e7a1ba | 69 | (uint8_t *)manufacturersName, |
Rohit Grover |
118:620d28e7a1ba | 70 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */ |
Rohit Grover |
118:620d28e7a1ba | 71 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */ |
Rohit Grover |
118:620d28e7a1ba | 72 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
Rohit Grover |
118:620d28e7a1ba | 73 | modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR, |
Rohit Grover |
118:620d28e7a1ba | 74 | (uint8_t *)modelNumber, |
Rohit Grover |
118:620d28e7a1ba | 75 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */ |
Rohit Grover |
118:620d28e7a1ba | 76 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */ |
Rohit Grover |
118:620d28e7a1ba | 77 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
Rohit Grover |
118:620d28e7a1ba | 78 | serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR, |
Rohit Grover |
118:620d28e7a1ba | 79 | (uint8_t *)serialNumber, |
Rohit Grover |
118:620d28e7a1ba | 80 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */ |
Rohit Grover |
118:620d28e7a1ba | 81 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */ |
Rohit Grover |
118:620d28e7a1ba | 82 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
Rohit Grover |
118:620d28e7a1ba | 83 | hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR, |
Rohit Grover |
118:620d28e7a1ba | 84 | (uint8_t *)hardwareRevision, |
Rohit Grover |
118:620d28e7a1ba | 85 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */ |
Rohit Grover |
118:620d28e7a1ba | 86 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */ |
Rohit Grover |
118:620d28e7a1ba | 87 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
Rohit Grover |
118:620d28e7a1ba | 88 | firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, |
Rohit Grover |
118:620d28e7a1ba | 89 | (uint8_t *)firmwareRevision, |
Rohit Grover |
118:620d28e7a1ba | 90 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */ |
Rohit Grover |
118:620d28e7a1ba | 91 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */ |
Rohit Grover |
118:620d28e7a1ba | 92 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
Rohit Grover |
118:620d28e7a1ba | 93 | softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR, |
Rohit Grover |
118:620d28e7a1ba | 94 | (uint8_t *)softwareRevision, |
Rohit Grover |
118:620d28e7a1ba | 95 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */ |
Rohit Grover |
118:620d28e7a1ba | 96 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */ |
Rohit Grover |
118:620d28e7a1ba | 97 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) |
rgrover1 | 242:0e9201b67e2f | 98 | { |
Rohit Grover |
118:620d28e7a1ba | 99 | static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */ |
Rohit Grover |
118:620d28e7a1ba | 100 | if (serviceAdded) { |
Rohit Grover |
118:620d28e7a1ba | 101 | return; |
Rohit Grover |
118:620d28e7a1ba | 102 | } |
Rohit Grover |
118:620d28e7a1ba | 103 | |
Rohit Grover |
118:620d28e7a1ba | 104 | GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic, |
Rohit Grover |
118:620d28e7a1ba | 105 | &modelNumberStringCharacteristic, |
Rohit Grover |
118:620d28e7a1ba | 106 | &serialNumberStringCharacteristic, |
Rohit Grover |
118:620d28e7a1ba | 107 | &hardwareRevisionStringCharacteristic, |
Rohit Grover |
118:620d28e7a1ba | 108 | &firmwareRevisionStringCharacteristic, |
Rohit Grover |
118:620d28e7a1ba | 109 | &softwareRevisionStringCharacteristic}; |
Rohit Grover |
118:620d28e7a1ba | 110 | GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable, |
Rohit Grover |
118:620d28e7a1ba | 111 | sizeof(charTable) / sizeof(GattCharacteristic *)); |
Rohit Grover |
118:620d28e7a1ba | 112 | |
Rohit Grover |
118:620d28e7a1ba | 113 | ble.addService(deviceInformationService); |
Rohit Grover |
118:620d28e7a1ba | 114 | serviceAdded = true; |
Rohit Grover |
118:620d28e7a1ba | 115 | } |
Rohit Grover |
118:620d28e7a1ba | 116 | |
rgrover1 | 710:b2e1a2660ec2 | 117 | private: |
rgrover1 | 710:b2e1a2660ec2 | 118 | BLEDevice &ble; |
Rohit Grover |
118:620d28e7a1ba | 119 | GattCharacteristic manufacturersNameStringCharacteristic; |
Rohit Grover |
118:620d28e7a1ba | 120 | GattCharacteristic modelNumberStringCharacteristic; |
Rohit Grover |
118:620d28e7a1ba | 121 | GattCharacteristic serialNumberStringCharacteristic; |
Rohit Grover |
118:620d28e7a1ba | 122 | GattCharacteristic hardwareRevisionStringCharacteristic; |
Rohit Grover |
118:620d28e7a1ba | 123 | GattCharacteristic firmwareRevisionStringCharacteristic; |
Rohit Grover |
118:620d28e7a1ba | 124 | GattCharacteristic softwareRevisionStringCharacteristic; |
Rohit Grover |
118:620d28e7a1ba | 125 | }; |
Rohit Grover |
118:620d28e7a1ba | 126 | |
rgrover1 | 242:0e9201b67e2f | 127 | #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/ |