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