back up of work during May 2019
Dependencies: microbit
HIDDeviceInformationService.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_HID_DEVICE_INFORMATION_SERVICE_H__ 00018 #define __BLE_HID_DEVICE_INFORMATION_SERVICE_H__ 00019 00020 #include "ble/BLE.h" 00021 00022 #include "HID_types.h" 00023 00024 /** 00025 * @class HIDDeviceInformationService 00026 * @brief BLE Device Information Service <br> 00027 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml <br> 00028 * Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml 00029 */ 00030 class HIDDeviceInformationService { 00031 public: 00032 /** 00033 * @brief Device Information Service Constructor. 00034 * 00035 * @param[ref] _ble 00036 * BLE object for the underlying controller. 00037 * @param[in] manufacturersName 00038 * This characteristic represents the name of the 00039 * manufacturer of the device. The name is copied into the 00040 * BLE stack during this constructor. 00041 * @param[in] modelNumber 00042 * This characteristic represents the model number that is 00043 * assigned by the device vendor. The value is copied into 00044 * the BLE stack during this constructor. 00045 * @param[in] serialNumber 00046 * This characteristic represents the serial number for a 00047 * particular instance of the device. The value is copied 00048 * into the BLE stack during this constructor. 00049 * @param[in] hardwareRevision 00050 * This characteristic represents the hardware revision for 00051 * the hardware within the device. The value is copied 00052 * into the BLE stack during this constructor. 00053 * @param[in] firmwareRevision 00054 * This characteristic represents the firmware revision for 00055 * the firmware within the device. The value is copied 00056 * into the BLE stack during this constructor. 00057 * @param[in] softwareRevision 00058 * This characteristic represents the software revision for 00059 * the software within the device. The value is copied 00060 * into the BLE stack during this constructor. 00061 * @param[in] pnpID 00062 * This characteristic represents HID-specific information, 00063 * such as vendor id, product id and version. 00064 */ 00065 HIDDeviceInformationService(BLE &_ble, 00066 const char *manufacturersName = NULL, 00067 const char *modelNumber = NULL, 00068 const char *serialNumber = NULL, 00069 const char *hardwareRevision = NULL, 00070 const char *firmwareRevision = NULL, 00071 const char *softwareRevision = NULL, 00072 PnPID_t *PnPID = NULL) : 00073 ble(_ble), 00074 manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR, 00075 (uint8_t *)manufacturersName, 00076 (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */ 00077 (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */ 00078 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00079 modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR, 00080 (uint8_t *)modelNumber, 00081 (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */ 00082 (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */ 00083 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00084 serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR, 00085 (uint8_t *)serialNumber, 00086 (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */ 00087 (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */ 00088 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00089 hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR, 00090 (uint8_t *)hardwareRevision, 00091 (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */ 00092 (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */ 00093 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00094 firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, 00095 (uint8_t *)firmwareRevision, 00096 (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */ 00097 (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */ 00098 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00099 softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR, 00100 (uint8_t *)softwareRevision, 00101 (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */ 00102 (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */ 00103 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), 00104 pnpIDCharacteristic(GattCharacteristic::UUID_PNP_ID_CHAR, 00105 PnPID) 00106 { 00107 static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */ 00108 if (serviceAdded) { 00109 return; 00110 } 00111 00112 GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic, 00113 &modelNumberStringCharacteristic, 00114 &serialNumberStringCharacteristic, 00115 &hardwareRevisionStringCharacteristic, 00116 &firmwareRevisionStringCharacteristic, 00117 &softwareRevisionStringCharacteristic, 00118 &pnpIDCharacteristic}; 00119 GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable, 00120 sizeof(charTable) / sizeof(GattCharacteristic *)); 00121 00122 /* 00123 * This is a hack to make things work on MacOSX 10.10. I don't have the details, but MacOSX 00124 * 10.10 gets confused when only characteristics from HID Service require security... 00125 */ 00126 pnpIDCharacteristic.requireSecurity(SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM); 00127 ble.addService(deviceInformationService); 00128 serviceAdded = true; 00129 } 00130 00131 protected: 00132 BLE &ble; 00133 GattCharacteristic manufacturersNameStringCharacteristic; 00134 GattCharacteristic modelNumberStringCharacteristic; 00135 GattCharacteristic serialNumberStringCharacteristic; 00136 GattCharacteristic hardwareRevisionStringCharacteristic; 00137 GattCharacteristic firmwareRevisionStringCharacteristic; 00138 GattCharacteristic softwareRevisionStringCharacteristic; 00139 ReadOnlyGattCharacteristic<PnPID_t> pnpIDCharacteristic; 00140 }; 00141 00142 #endif /* #ifndef __BLE_HID_DEVICE_INFORMATION_SERVICE_H__*/ 00143 00144
Generated on Mon Jul 18 2022 14:25:12 by 1.7.2