Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DeviceInformationService.h Source File

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 "ble/BLE.h"
00021 
00022 #if BLE_FEATURE_GATT_SERVER
00023 
00024 /**
00025 * @class DeviceInformationService
00026 * @brief BLE Device Information Service
00027 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml
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 DeviceInformationService {
00031 public:
00032     /**
00033      * @brief Device Information Service Constructor: copies device-specific information
00034      * into the BLE stack.
00035      *
00036      * @param[in] _ble
00037      *                A reference to a BLE object for the underlying controller.
00038      * @param[in] manufacturersName
00039      *                The name of the manufacturer of the device.
00040      * @param[in] modelNumber
00041      *                The model number that is assigned by the device vendor.
00042      * @param[in] serialNumber
00043      *                The serial number for a particular instance of the device.
00044      * @param[in] hardwareRevision
00045      *                The hardware revision for the hardware within the device.
00046      * @param[in] firmwareRevision
00047      *                The device's firmware version.
00048      * @param[in] softwareRevision
00049      *                The device's software version.
00050      */
00051     DeviceInformationService(BLE        &_ble,
00052                              const char *manufacturersName = NULL,
00053                              const char *modelNumber       = NULL,
00054                              const char *serialNumber      = NULL,
00055                              const char *hardwareRevision  = NULL,
00056                              const char *firmwareRevision  = NULL,
00057                              const char *softwareRevision  = NULL) :
00058         ble(_ble),
00059         manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR,
00060                                               (uint8_t *)manufacturersName,
00061                                               (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* Min length */
00062                                               (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* Max length */
00063                                               GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00064         modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR,
00065                                         (uint8_t *)modelNumber,
00066                                         (modelNumber != NULL) ? strlen(modelNumber) : 0, /* Min length */
00067                                         (modelNumber != NULL) ? strlen(modelNumber) : 0, /* Max length */
00068                                         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00069         serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR,
00070                                          (uint8_t *)serialNumber,
00071                                          (serialNumber != NULL) ? strlen(serialNumber) : 0, /* Min length */
00072                                          (serialNumber != NULL) ? strlen(serialNumber) : 0, /* Max length */
00073                                          GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00074         hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR,
00075                                              (uint8_t *)hardwareRevision,
00076                                              (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* Min length */
00077                                              (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* Max length */
00078                                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00079         firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR,
00080                                              (uint8_t *)firmwareRevision,
00081                                              (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* Min length */
00082                                              (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* Max length */
00083                                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00084         softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR,
00085                                              (uint8_t *)softwareRevision,
00086                                              (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* Min length */
00087                                              (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* Max length */
00088                                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
00089     {
00090         static bool serviceAdded = false; /* We only add the information service once. */
00091         if (serviceAdded) {
00092             return;
00093         }
00094 
00095         GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic,
00096                                            &modelNumberStringCharacteristic,
00097                                            &serialNumberStringCharacteristic,
00098                                            &hardwareRevisionStringCharacteristic,
00099                                            &firmwareRevisionStringCharacteristic,
00100                                            &softwareRevisionStringCharacteristic};
00101         GattService         deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable,
00102                                                      sizeof(charTable) / sizeof(GattCharacteristic *));
00103 
00104         ble.addService(deviceInformationService);
00105         serviceAdded = true;
00106     }
00107 
00108 protected:
00109     /**
00110      * A reference to the BLE instance object to which the services and
00111      * characteristics will be added.
00112      */
00113     BLE                &ble;
00114     /**
00115      * BLE characterising to allow BLE peers access to the manufacturer's name.
00116      */
00117     GattCharacteristic  manufacturersNameStringCharacteristic;
00118     /**
00119      * BLE characterising to allow BLE peers access to the model number.
00120      */
00121     GattCharacteristic  modelNumberStringCharacteristic;
00122     /**
00123      * BLE characterising to allow BLE peers access to the serial number.
00124      */
00125     GattCharacteristic  serialNumberStringCharacteristic;
00126     /**
00127      * BLE characterising to allow BLE peers access to the hardware revision string.
00128      */
00129     GattCharacteristic  hardwareRevisionStringCharacteristic;
00130     /**
00131      * BLE characterising to allow BLE peers access to the firmware revision string.
00132      */
00133     GattCharacteristic  firmwareRevisionStringCharacteristic;
00134     /**
00135      * BLE characterising to allow BLE peers access to the software revision string.
00136      */
00137     GattCharacteristic  softwareRevisionStringCharacteristic;
00138 };
00139 
00140 #endif // BLE_FEATURE_GATT_SERVER
00141 
00142 #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/