project for nrf51822 qfab
Dependencies: eddystone_URL mbed
Fork of eddystone_URL by
BLE_API/services/DeviceInformationService.h@5:267bdacf5508, 2017-11-23 (annotated)
- Committer:
- tridung141196
- Date:
- Thu Nov 23 15:38:48 2017 +0000
- Revision:
- 5:267bdacf5508
- Parent:
- 0:76dfa9657d9d
ibeacon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:76dfa9657d9d | 1 | /* mbed Microcontroller Library |
jksoft | 0:76dfa9657d9d | 2 | * Copyright (c) 2006-2013 ARM Limited |
jksoft | 0:76dfa9657d9d | 3 | * |
jksoft | 0:76dfa9657d9d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jksoft | 0:76dfa9657d9d | 5 | * you may not use this file except in compliance with the License. |
jksoft | 0:76dfa9657d9d | 6 | * You may obtain a copy of the License at |
jksoft | 0:76dfa9657d9d | 7 | * |
jksoft | 0:76dfa9657d9d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jksoft | 0:76dfa9657d9d | 9 | * |
jksoft | 0:76dfa9657d9d | 10 | * Unless required by applicable law or agreed to in writing, software |
jksoft | 0:76dfa9657d9d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jksoft | 0:76dfa9657d9d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jksoft | 0:76dfa9657d9d | 13 | * See the License for the specific language governing permissions and |
jksoft | 0:76dfa9657d9d | 14 | * limitations under the License. |
jksoft | 0:76dfa9657d9d | 15 | */ |
jksoft | 0:76dfa9657d9d | 16 | |
jksoft | 0:76dfa9657d9d | 17 | #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__ |
jksoft | 0:76dfa9657d9d | 18 | #define __BLE_DEVICE_INFORMATION_SERVICE_H__ |
jksoft | 0:76dfa9657d9d | 19 | |
jksoft | 0:76dfa9657d9d | 20 | #include "BLEDevice.h" |
jksoft | 0:76dfa9657d9d | 21 | |
jksoft | 0:76dfa9657d9d | 22 | /* Device Information Service */ |
jksoft | 0:76dfa9657d9d | 23 | /* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml */ |
jksoft | 0:76dfa9657d9d | 24 | /* Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml */ |
jksoft | 0:76dfa9657d9d | 25 | class DeviceInformationService { |
jksoft | 0:76dfa9657d9d | 26 | public: |
jksoft | 0:76dfa9657d9d | 27 | /** |
jksoft | 0:76dfa9657d9d | 28 | * Constructor. |
jksoft | 0:76dfa9657d9d | 29 | * |
jksoft | 0:76dfa9657d9d | 30 | * @param[in] _ble |
jksoft | 0:76dfa9657d9d | 31 | * Reference to the BLEDevice. |
jksoft | 0:76dfa9657d9d | 32 | * @param[in] manufacturersName |
jksoft | 0:76dfa9657d9d | 33 | * This characteristic represents the name of the |
jksoft | 0:76dfa9657d9d | 34 | * manufacturer of the device. The name is copied into the |
jksoft | 0:76dfa9657d9d | 35 | * BLE stack during this constructor. |
jksoft | 0:76dfa9657d9d | 36 | * @param[in] modelNumber |
jksoft | 0:76dfa9657d9d | 37 | * This characteristic represents the model number that is |
jksoft | 0:76dfa9657d9d | 38 | * assigned by the device vendor. The value is copied into |
jksoft | 0:76dfa9657d9d | 39 | * the BLE stack during this constructor. |
jksoft | 0:76dfa9657d9d | 40 | * @param[in] serialNumber |
jksoft | 0:76dfa9657d9d | 41 | * This characteristic represents the serial number for a |
jksoft | 0:76dfa9657d9d | 42 | * particular instance of the device. The value is copied |
jksoft | 0:76dfa9657d9d | 43 | * into the BLE stack during this constructor. |
jksoft | 0:76dfa9657d9d | 44 | * @param[in] hardwareRevision |
jksoft | 0:76dfa9657d9d | 45 | * This characteristic represents the hardware revision for |
jksoft | 0:76dfa9657d9d | 46 | * the hardware within the device. The value is copied |
jksoft | 0:76dfa9657d9d | 47 | * into the BLE stack during this constructor. |
jksoft | 0:76dfa9657d9d | 48 | * @param[in] firmwareRevision |
jksoft | 0:76dfa9657d9d | 49 | * This characteristic represents the firmware revision for |
jksoft | 0:76dfa9657d9d | 50 | * the firmware within the device. The value is copied |
jksoft | 0:76dfa9657d9d | 51 | * into the BLE stack during this constructor. |
jksoft | 0:76dfa9657d9d | 52 | * @param[in] softwareRevision |
jksoft | 0:76dfa9657d9d | 53 | * This characteristic represents the software revision for |
jksoft | 0:76dfa9657d9d | 54 | * the software within the device. The value is copied |
jksoft | 0:76dfa9657d9d | 55 | * into the BLE stack during this constructor. |
jksoft | 0:76dfa9657d9d | 56 | */ |
jksoft | 0:76dfa9657d9d | 57 | DeviceInformationService(BLEDevice &_ble, |
jksoft | 0:76dfa9657d9d | 58 | const char *manufacturersName = NULL, |
jksoft | 0:76dfa9657d9d | 59 | const char *modelNumber = NULL, |
jksoft | 0:76dfa9657d9d | 60 | const char *serialNumber = NULL, |
jksoft | 0:76dfa9657d9d | 61 | const char *hardwareRevision = NULL, |
jksoft | 0:76dfa9657d9d | 62 | const char *firmwareRevision = NULL, |
jksoft | 0:76dfa9657d9d | 63 | const char *softwareRevision = NULL) : |
jksoft | 0:76dfa9657d9d | 64 | ble(_ble), |
jksoft | 0:76dfa9657d9d | 65 | manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR, |
jksoft | 0:76dfa9657d9d | 66 | (uint8_t *)manufacturersName, |
jksoft | 0:76dfa9657d9d | 67 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */ |
jksoft | 0:76dfa9657d9d | 68 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */ |
jksoft | 0:76dfa9657d9d | 69 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
jksoft | 0:76dfa9657d9d | 70 | modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR, |
jksoft | 0:76dfa9657d9d | 71 | (uint8_t *)modelNumber, |
jksoft | 0:76dfa9657d9d | 72 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */ |
jksoft | 0:76dfa9657d9d | 73 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */ |
jksoft | 0:76dfa9657d9d | 74 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
jksoft | 0:76dfa9657d9d | 75 | serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR, |
jksoft | 0:76dfa9657d9d | 76 | (uint8_t *)serialNumber, |
jksoft | 0:76dfa9657d9d | 77 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */ |
jksoft | 0:76dfa9657d9d | 78 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */ |
jksoft | 0:76dfa9657d9d | 79 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
jksoft | 0:76dfa9657d9d | 80 | hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR, |
jksoft | 0:76dfa9657d9d | 81 | (uint8_t *)hardwareRevision, |
jksoft | 0:76dfa9657d9d | 82 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */ |
jksoft | 0:76dfa9657d9d | 83 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */ |
jksoft | 0:76dfa9657d9d | 84 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
jksoft | 0:76dfa9657d9d | 85 | firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, |
jksoft | 0:76dfa9657d9d | 86 | (uint8_t *)firmwareRevision, |
jksoft | 0:76dfa9657d9d | 87 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */ |
jksoft | 0:76dfa9657d9d | 88 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */ |
jksoft | 0:76dfa9657d9d | 89 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
jksoft | 0:76dfa9657d9d | 90 | softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR, |
jksoft | 0:76dfa9657d9d | 91 | (uint8_t *)softwareRevision, |
jksoft | 0:76dfa9657d9d | 92 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */ |
jksoft | 0:76dfa9657d9d | 93 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */ |
jksoft | 0:76dfa9657d9d | 94 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) |
jksoft | 0:76dfa9657d9d | 95 | { |
jksoft | 0:76dfa9657d9d | 96 | static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */ |
jksoft | 0:76dfa9657d9d | 97 | if (serviceAdded) { |
jksoft | 0:76dfa9657d9d | 98 | return; |
jksoft | 0:76dfa9657d9d | 99 | } |
jksoft | 0:76dfa9657d9d | 100 | |
jksoft | 0:76dfa9657d9d | 101 | GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic, |
jksoft | 0:76dfa9657d9d | 102 | &modelNumberStringCharacteristic, |
jksoft | 0:76dfa9657d9d | 103 | &serialNumberStringCharacteristic, |
jksoft | 0:76dfa9657d9d | 104 | &hardwareRevisionStringCharacteristic, |
jksoft | 0:76dfa9657d9d | 105 | &firmwareRevisionStringCharacteristic, |
jksoft | 0:76dfa9657d9d | 106 | &softwareRevisionStringCharacteristic}; |
jksoft | 0:76dfa9657d9d | 107 | GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable, |
jksoft | 0:76dfa9657d9d | 108 | sizeof(charTable) / sizeof(GattCharacteristic *)); |
jksoft | 0:76dfa9657d9d | 109 | |
jksoft | 0:76dfa9657d9d | 110 | ble.addService(deviceInformationService); |
jksoft | 0:76dfa9657d9d | 111 | serviceAdded = true; |
jksoft | 0:76dfa9657d9d | 112 | } |
jksoft | 0:76dfa9657d9d | 113 | |
jksoft | 0:76dfa9657d9d | 114 | private: |
jksoft | 0:76dfa9657d9d | 115 | BLEDevice &ble; |
jksoft | 0:76dfa9657d9d | 116 | GattCharacteristic manufacturersNameStringCharacteristic; |
jksoft | 0:76dfa9657d9d | 117 | GattCharacteristic modelNumberStringCharacteristic; |
jksoft | 0:76dfa9657d9d | 118 | GattCharacteristic serialNumberStringCharacteristic; |
jksoft | 0:76dfa9657d9d | 119 | GattCharacteristic hardwareRevisionStringCharacteristic; |
jksoft | 0:76dfa9657d9d | 120 | GattCharacteristic firmwareRevisionStringCharacteristic; |
jksoft | 0:76dfa9657d9d | 121 | GattCharacteristic softwareRevisionStringCharacteristic; |
jksoft | 0:76dfa9657d9d | 122 | }; |
jksoft | 0:76dfa9657d9d | 123 | |
jksoft | 0:76dfa9657d9d | 124 | #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/ |