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
DeviceInformationService.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__ 00018 #define __BLE_DEVICE_INFORMATION_SERVICE_H__ 00019 00020 #include "BLEDevice.h" 00021 00022 /** 00023 * @class DeviceInformationService 00024 * @brief BLE Device Information Service <br> 00025 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml <br> 00026 * Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml 00027 */ 00028 class DeviceInformationService { 00029 public: 00030 /** 00031 * @brief Device Information Service Constructor. 00032 * 00033 * @param[ref] _ble 00034 * BLEDevice object for the underlying controller. 00035 * @param[in] manufacturersName 00036 * This characteristic represents the name of the 00037 * manufacturer of the device. The name is copied into the 00038 * BLE stack during this constructor. 00039 * @param[in] modelNumber 00040 * This characteristic represents the model number that is 00041 * assigned by the device vendor. The value is copied into 00042 * the BLE stack during this constructor. 00043 * @param[in] serialNumber 00044 * This characteristic represents the serial number for a 00045 * particular instance of the device. The value is copied 00046 * into the BLE stack during this constructor. 00047 * @param[in] hardwareRevision 00048 * This characteristic represents the hardware revision for 00049 * the hardware within the device. The value is copied 00050 * into the BLE stack during this constructor. 00051 * @param[in] firmwareRevision 00052 * This characteristic represents the firmware revision for 00053 * the firmware within the device. The value is copied 00054 * into the BLE stack during this constructor. 00055 * @param[in] softwareRevision 00056 * This characteristic represents the software revision for 00057 * the software within the device. The value is copied 00058 * into the BLE stack during this constructor. 00059 */ 00060 DeviceInformationService(BLEDevice &_ble, 00061 const char *manufacturersName = NULL, 00062 const char *modelNumber = NULL, 00063 const char *serialNumber = NULL, 00064 const char *hardwareRevision = NULL, 00065 const char *firmwareRevision = NULL, 00066 const char *softwareRevision = NULL) : 00067 ble(_ble), 00068 manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR, 00069 (uint8_t *)manufacturersName, 00070 (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */ 00071 (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */ 00072 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00073 modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR, 00074 (uint8_t *)modelNumber, 00075 (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */ 00076 (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */ 00077 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00078 serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR, 00079 (uint8_t *)serialNumber, 00080 (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */ 00081 (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */ 00082 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00083 hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR, 00084 (uint8_t *)hardwareRevision, 00085 (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */ 00086 (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */ 00087 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00088 firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, 00089 (uint8_t *)firmwareRevision, 00090 (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */ 00091 (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */ 00092 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00093 softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR, 00094 (uint8_t *)softwareRevision, 00095 (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */ 00096 (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */ 00097 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) 00098 { 00099 static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */ 00100 if (serviceAdded) { 00101 return; 00102 } 00103 00104 GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic, 00105 &modelNumberStringCharacteristic, 00106 &serialNumberStringCharacteristic, 00107 &hardwareRevisionStringCharacteristic, 00108 &firmwareRevisionStringCharacteristic, 00109 &softwareRevisionStringCharacteristic}; 00110 GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable, 00111 sizeof(charTable) / sizeof(GattCharacteristic *)); 00112 00113 ble.addService(deviceInformationService); 00114 serviceAdded = true; 00115 } 00116 00117 private: 00118 BLEDevice &ble; 00119 GattCharacteristic manufacturersNameStringCharacteristic; 00120 GattCharacteristic modelNumberStringCharacteristic; 00121 GattCharacteristic serialNumberStringCharacteristic; 00122 GattCharacteristic hardwareRevisionStringCharacteristic; 00123 GattCharacteristic firmwareRevisionStringCharacteristic; 00124 GattCharacteristic softwareRevisionStringCharacteristic; 00125 }; 00126 00127 #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/
Generated on Tue Jul 12 2022 18:47:13 by
