Mistake on this page?
Report an issue in GitHub or email us
DeviceInformationService.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2020 ARM Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /* MBED_DEPRECATED */
20 #warning "These services are deprecated and will be removed. Please see services.md for details about replacement services."
21 
22 #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__
23 #define __BLE_DEVICE_INFORMATION_SERVICE_H__
24 
25 #include "ble/BLE.h"
26 #include "ble/Gap.h"
27 #include "ble/GattServer.h"
28 
29 #if BLE_FEATURE_GATT_SERVER
30 
31 /**
32 * @class DeviceInformationService
33 * @brief BLE Device Information Service
34 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml
35 * Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml
36 */
38 public:
39  /**
40  * @brief Device Information Service Constructor: copies device-specific information
41  * into the BLE stack.
42  *
43  * @param[in] _ble
44  * A reference to a BLE object for the underlying controller.
45  * @param[in] manufacturersName
46  * The name of the manufacturer of the device.
47  * @param[in] modelNumber
48  * The model number that is assigned by the device vendor.
49  * @param[in] serialNumber
50  * The serial number for a particular instance of the device.
51  * @param[in] hardwareRevision
52  * The hardware revision for the hardware within the device.
53  * @param[in] firmwareRevision
54  * The device's firmware version.
55  * @param[in] softwareRevision
56  * The device's software version.
57  */
59  const char *manufacturersName = nullptr,
60  const char *modelNumber = nullptr,
61  const char *serialNumber = nullptr,
62  const char *hardwareRevision = nullptr,
63  const char *firmwareRevision = nullptr,
64  const char *softwareRevision = nullptr) :
65  ble(_ble),
66  manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR,
67  (uint8_t *)manufacturersName,
68  (manufacturersName != nullptr) ? strlen(manufacturersName) : 0, /* Min length */
69  (manufacturersName != nullptr) ? strlen(manufacturersName) : 0, /* Max length */
70  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
71  modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR,
72  (uint8_t *)modelNumber,
73  (modelNumber != nullptr) ? strlen(modelNumber) : 0, /* Min length */
74  (modelNumber != nullptr) ? strlen(modelNumber) : 0, /* Max length */
75  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
76  serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR,
77  (uint8_t *)serialNumber,
78  (serialNumber != nullptr) ? strlen(serialNumber) : 0, /* Min length */
79  (serialNumber != nullptr) ? strlen(serialNumber) : 0, /* Max length */
80  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
81  hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR,
82  (uint8_t *)hardwareRevision,
83  (hardwareRevision != nullptr) ? strlen(hardwareRevision) : 0, /* Min length */
84  (hardwareRevision != nullptr) ? strlen(hardwareRevision) : 0, /* Max length */
85  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
86  firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR,
87  (uint8_t *)firmwareRevision,
88  (firmwareRevision != nullptr) ? strlen(firmwareRevision) : 0, /* Min length */
89  (firmwareRevision != nullptr) ? strlen(firmwareRevision) : 0, /* Max length */
90  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
91  softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR,
92  (uint8_t *)softwareRevision,
93  (softwareRevision != nullptr) ? strlen(softwareRevision) : 0, /* Min length */
94  (softwareRevision != nullptr) ? strlen(softwareRevision) : 0, /* Max length */
95  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
96  {
97  static bool serviceAdded = false; /* We only add the information service once. */
98  if (serviceAdded) {
99  return;
100  }
101 
108  GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable,
109  sizeof(charTable) / sizeof(charTable[0]));
110 
111  ble.gattServer().addService(deviceInformationService);
112  serviceAdded = true;
113  }
114 
115 protected:
116  /**
117  * A reference to the BLE instance object to which the services and
118  * characteristics will be added.
119  */
121  /**
122  * BLE characterising to allow BLE peers access to the manufacturer's name.
123  */
125  /**
126  * BLE characterising to allow BLE peers access to the model number.
127  */
129  /**
130  * BLE characterising to allow BLE peers access to the serial number.
131  */
133  /**
134  * BLE characterising to allow BLE peers access to the hardware revision string.
135  */
137  /**
138  * BLE characterising to allow BLE peers access to the firmware revision string.
139  */
141  /**
142  * BLE characterising to allow BLE peers access to the software revision string.
143  */
145 };
146 
147 #endif // BLE_FEATURE_GATT_SERVER
148 
149 #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/
GattCharacteristic softwareRevisionStringCharacteristic
BLE characterising to allow BLE peers access to the software revision string.
GattCharacteristic modelNumberStringCharacteristic
BLE characterising to allow BLE peers access to the model number.
GattCharacteristic serialNumberStringCharacteristic
BLE characterising to allow BLE peers access to the serial number.
UUID of the Device Information Service (DIS).
GattCharacteristic manufacturersNameStringCharacteristic
BLE characterising to allow BLE peers access to the manufacturer's name.
BLE Device Information Service Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceVi...
DeviceInformationService(BLE &_ble, const char *manufacturersName=nullptr, const char *modelNumber=nullptr, const char *serialNumber=nullptr, const char *hardwareRevision=nullptr, const char *firmwareRevision=nullptr, const char *softwareRevision=nullptr)
Device Information Service Constructor: copies device-specific information into the BLE stack...
Representation of a GattServer characteristic.
GattCharacteristic hardwareRevisionStringCharacteristic
BLE characterising to allow BLE peers access to the hardware revision string.
Representation of a GattServer service.
GattCharacteristic firmwareRevisionStringCharacteristic
BLE characterising to allow BLE peers access to the firmware revision string.
Entry namespace for all BLE API definitions.
Abstract away BLE-capable radio transceivers or SOCs.
Definition: BLE.h:137
BLE & ble
A reference to the BLE instance object to which the services and characteristics will be added...
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.