Holla back

Fork of BLE_API by Bluetooth Low Energy

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 "BLEDevice.h"
00021 
00022 /* Device Information Service */
00023 /* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml */
00024 /* Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml */
00025 class DeviceInformationService {
00026 public:
00027     /**
00028      * Constructor.
00029      *
00030      * @param[in] _ble
00031      *                Reference to the BLEDevice.
00032      * @param[in] manufacturersName
00033      *                This characteristic represents the name of the
00034      *                manufacturer of the device. The name is copied into the
00035      *                BLE stack during this constructor.
00036      * @param[in] modelNumber
00037      *                This characteristic represents the model number that is
00038      *                assigned by the device vendor. The value is copied into
00039      *                the BLE stack during this constructor.
00040      * @param[in] serialNumber
00041      *                This characteristic represents the serial number for a
00042      *                particular instance of the device.  The value is copied
00043      *                into the BLE stack during this constructor.
00044      * @param[in] hardwareRevision
00045      *                This characteristic represents the hardware revision for
00046      *                the hardware within the device. The value is copied
00047      *                into the BLE stack during this constructor.
00048      * @param[in] firmwareRevision
00049      *                This characteristic represents the firmware revision for
00050      *                the firmware within the device. The value is copied
00051      *                into the BLE stack during this constructor.
00052      * @param[in] softwareRevision
00053      *                This characteristic represents the software revision for
00054      *                the software within the device. The value is copied
00055      *                into the BLE stack during this constructor.
00056      */
00057     DeviceInformationService(BLEDevice &_ble,
00058                              const char *manufacturersName = NULL,
00059                              const char *modelNumber       = NULL,
00060                              const char *serialNumber      = NULL,
00061                              const char *hardwareRevision  = NULL,
00062                              const char *firmwareRevision  = NULL,
00063                              const char *softwareRevision  = NULL) :
00064         ble(_ble),
00065         manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR,
00066                                               (uint8_t *)manufacturersName,
00067                                               (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */
00068                                               (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */
00069                                               GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00070         modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR,
00071                                         (uint8_t *)modelNumber,
00072                                         (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */
00073                                         (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */
00074                                         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00075         serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR,
00076                                          (uint8_t *)serialNumber,
00077                                          (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */
00078                                          (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */
00079                                          GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00080         hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR,
00081                                              (uint8_t *)hardwareRevision,
00082                                              (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */
00083                                              (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */
00084                                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00085         firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR,
00086                                              (uint8_t *)firmwareRevision,
00087                                              (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */
00088                                              (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */
00089                                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
00090         softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR,
00091                                              (uint8_t *)softwareRevision,
00092                                              (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */
00093                                              (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */
00094                                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
00095                                                {
00096         static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */
00097         if (serviceAdded) {
00098             return;
00099         }
00100 
00101         GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic,
00102                                            &modelNumberStringCharacteristic,
00103                                            &serialNumberStringCharacteristic,
00104                                            &hardwareRevisionStringCharacteristic,
00105                                            &firmwareRevisionStringCharacteristic,
00106                                            &softwareRevisionStringCharacteristic};
00107         GattService         deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable,
00108                                                      sizeof(charTable) / sizeof(GattCharacteristic *));
00109 
00110         ble.addService(deviceInformationService);
00111         serviceAdded = true;
00112     }
00113 
00114 private:
00115     BLEDevice          &ble;
00116     GattCharacteristic  manufacturersNameStringCharacteristic;
00117     GattCharacteristic  modelNumberStringCharacteristic;
00118     GattCharacteristic  serialNumberStringCharacteristic;
00119     GattCharacteristic  hardwareRevisionStringCharacteristic;
00120     GattCharacteristic  firmwareRevisionStringCharacteristic;
00121     GattCharacteristic  softwareRevisionStringCharacteristic;
00122 };
00123 
00124 #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/