Holla back

Fork of BLE_API by Bluetooth Low Energy

Committer:
jakerosenthal@gmail.com
Date:
Fri Oct 10 17:32:22 2014 -0700
Branch:
2chains
Revision:
123:d2cdf4ebe524
Parent:
118:620d28e7a1ba
first attempt at chaining onconnect and ondisconnect

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rohit Grover 118:620d28e7a1ba 1 /* mbed Microcontroller Library
Rohit Grover 118:620d28e7a1ba 2 * Copyright (c) 2006-2013 ARM Limited
Rohit Grover 118:620d28e7a1ba 3 *
Rohit Grover 118:620d28e7a1ba 4 * Licensed under the Apache License, Version 2.0 (the "License");
Rohit Grover 118:620d28e7a1ba 5 * you may not use this file except in compliance with the License.
Rohit Grover 118:620d28e7a1ba 6 * You may obtain a copy of the License at
Rohit Grover 118:620d28e7a1ba 7 *
Rohit Grover 118:620d28e7a1ba 8 * http://www.apache.org/licenses/LICENSE-2.0
Rohit Grover 118:620d28e7a1ba 9 *
Rohit Grover 118:620d28e7a1ba 10 * Unless required by applicable law or agreed to in writing, software
Rohit Grover 118:620d28e7a1ba 11 * distributed under the License is distributed on an "AS IS" BASIS,
Rohit Grover 118:620d28e7a1ba 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Rohit Grover 118:620d28e7a1ba 13 * See the License for the specific language governing permissions and
Rohit Grover 118:620d28e7a1ba 14 * limitations under the License.
Rohit Grover 118:620d28e7a1ba 15 */
Rohit Grover 118:620d28e7a1ba 16
Rohit Grover 118:620d28e7a1ba 17 #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__
Rohit Grover 118:620d28e7a1ba 18 #define __BLE_DEVICE_INFORMATION_SERVICE_H__
Rohit Grover 118:620d28e7a1ba 19
Rohit Grover 118:620d28e7a1ba 20 #include "BLEDevice.h"
Rohit Grover 118:620d28e7a1ba 21
Rohit Grover 118:620d28e7a1ba 22 /* Device Information Service */
Rohit Grover 118:620d28e7a1ba 23 /* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml */
Rohit Grover 118:620d28e7a1ba 24 /* Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml */
Rohit Grover 118:620d28e7a1ba 25 class DeviceInformationService {
Rohit Grover 118:620d28e7a1ba 26 public:
Rohit Grover 118:620d28e7a1ba 27 /**
Rohit Grover 118:620d28e7a1ba 28 * Constructor.
Rohit Grover 118:620d28e7a1ba 29 *
Rohit Grover 118:620d28e7a1ba 30 * @param[in] _ble
Rohit Grover 118:620d28e7a1ba 31 * Reference to the BLEDevice.
Rohit Grover 118:620d28e7a1ba 32 * @param[in] manufacturersName
Rohit Grover 118:620d28e7a1ba 33 * This characteristic represents the name of the
Rohit Grover 118:620d28e7a1ba 34 * manufacturer of the device. The name is copied into the
Rohit Grover 118:620d28e7a1ba 35 * BLE stack during this constructor.
Rohit Grover 118:620d28e7a1ba 36 * @param[in] modelNumber
Rohit Grover 118:620d28e7a1ba 37 * This characteristic represents the model number that is
Rohit Grover 118:620d28e7a1ba 38 * assigned by the device vendor. The value is copied into
Rohit Grover 118:620d28e7a1ba 39 * the BLE stack during this constructor.
Rohit Grover 118:620d28e7a1ba 40 * @param[in] serialNumber
Rohit Grover 118:620d28e7a1ba 41 * This characteristic represents the serial number for a
Rohit Grover 118:620d28e7a1ba 42 * particular instance of the device. The value is copied
Rohit Grover 118:620d28e7a1ba 43 * into the BLE stack during this constructor.
Rohit Grover 118:620d28e7a1ba 44 * @param[in] hardwareRevision
Rohit Grover 118:620d28e7a1ba 45 * This characteristic represents the hardware revision for
Rohit Grover 118:620d28e7a1ba 46 * the hardware within the device. The value is copied
Rohit Grover 118:620d28e7a1ba 47 * into the BLE stack during this constructor.
Rohit Grover 118:620d28e7a1ba 48 * @param[in] firmwareRevision
Rohit Grover 118:620d28e7a1ba 49 * This characteristic represents the firmware revision for
Rohit Grover 118:620d28e7a1ba 50 * the firmware within the device. The value is copied
Rohit Grover 118:620d28e7a1ba 51 * into the BLE stack during this constructor.
Rohit Grover 118:620d28e7a1ba 52 * @param[in] softwareRevision
Rohit Grover 118:620d28e7a1ba 53 * This characteristic represents the software revision for
Rohit Grover 118:620d28e7a1ba 54 * the software within the device. The value is copied
Rohit Grover 118:620d28e7a1ba 55 * into the BLE stack during this constructor.
Rohit Grover 118:620d28e7a1ba 56 */
Rohit Grover 118:620d28e7a1ba 57 DeviceInformationService(BLEDevice &_ble,
Rohit Grover 118:620d28e7a1ba 58 const char *manufacturersName = NULL,
Rohit Grover 118:620d28e7a1ba 59 const char *modelNumber = NULL,
Rohit Grover 118:620d28e7a1ba 60 const char *serialNumber = NULL,
Rohit Grover 118:620d28e7a1ba 61 const char *hardwareRevision = NULL,
Rohit Grover 118:620d28e7a1ba 62 const char *firmwareRevision = NULL,
Rohit Grover 118:620d28e7a1ba 63 const char *softwareRevision = NULL) :
Rohit Grover 118:620d28e7a1ba 64 ble(_ble),
Rohit Grover 118:620d28e7a1ba 65 manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR,
Rohit Grover 118:620d28e7a1ba 66 (uint8_t *)manufacturersName,
Rohit Grover 118:620d28e7a1ba 67 (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */
Rohit Grover 118:620d28e7a1ba 68 (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */
Rohit Grover 118:620d28e7a1ba 69 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
Rohit Grover 118:620d28e7a1ba 70 modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR,
Rohit Grover 118:620d28e7a1ba 71 (uint8_t *)modelNumber,
Rohit Grover 118:620d28e7a1ba 72 (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */
Rohit Grover 118:620d28e7a1ba 73 (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */
Rohit Grover 118:620d28e7a1ba 74 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
Rohit Grover 118:620d28e7a1ba 75 serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR,
Rohit Grover 118:620d28e7a1ba 76 (uint8_t *)serialNumber,
Rohit Grover 118:620d28e7a1ba 77 (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */
Rohit Grover 118:620d28e7a1ba 78 (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */
Rohit Grover 118:620d28e7a1ba 79 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
Rohit Grover 118:620d28e7a1ba 80 hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR,
Rohit Grover 118:620d28e7a1ba 81 (uint8_t *)hardwareRevision,
Rohit Grover 118:620d28e7a1ba 82 (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */
Rohit Grover 118:620d28e7a1ba 83 (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */
Rohit Grover 118:620d28e7a1ba 84 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
Rohit Grover 118:620d28e7a1ba 85 firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR,
Rohit Grover 118:620d28e7a1ba 86 (uint8_t *)firmwareRevision,
Rohit Grover 118:620d28e7a1ba 87 (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */
Rohit Grover 118:620d28e7a1ba 88 (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */
Rohit Grover 118:620d28e7a1ba 89 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
Rohit Grover 118:620d28e7a1ba 90 softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR,
Rohit Grover 118:620d28e7a1ba 91 (uint8_t *)softwareRevision,
Rohit Grover 118:620d28e7a1ba 92 (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */
Rohit Grover 118:620d28e7a1ba 93 (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */
Rohit Grover 118:620d28e7a1ba 94 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
Rohit Grover 118:620d28e7a1ba 95 {
Rohit Grover 118:620d28e7a1ba 96 static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */
Rohit Grover 118:620d28e7a1ba 97 if (serviceAdded) {
Rohit Grover 118:620d28e7a1ba 98 return;
Rohit Grover 118:620d28e7a1ba 99 }
Rohit Grover 118:620d28e7a1ba 100
Rohit Grover 118:620d28e7a1ba 101 GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic,
Rohit Grover 118:620d28e7a1ba 102 &modelNumberStringCharacteristic,
Rohit Grover 118:620d28e7a1ba 103 &serialNumberStringCharacteristic,
Rohit Grover 118:620d28e7a1ba 104 &hardwareRevisionStringCharacteristic,
Rohit Grover 118:620d28e7a1ba 105 &firmwareRevisionStringCharacteristic,
Rohit Grover 118:620d28e7a1ba 106 &softwareRevisionStringCharacteristic};
Rohit Grover 118:620d28e7a1ba 107 GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable,
Rohit Grover 118:620d28e7a1ba 108 sizeof(charTable) / sizeof(GattCharacteristic *));
Rohit Grover 118:620d28e7a1ba 109
Rohit Grover 118:620d28e7a1ba 110 ble.addService(deviceInformationService);
Rohit Grover 118:620d28e7a1ba 111 serviceAdded = true;
Rohit Grover 118:620d28e7a1ba 112 }
Rohit Grover 118:620d28e7a1ba 113
Rohit Grover 118:620d28e7a1ba 114 private:
Rohit Grover 118:620d28e7a1ba 115 BLEDevice &ble;
Rohit Grover 118:620d28e7a1ba 116 GattCharacteristic manufacturersNameStringCharacteristic;
Rohit Grover 118:620d28e7a1ba 117 GattCharacteristic modelNumberStringCharacteristic;
Rohit Grover 118:620d28e7a1ba 118 GattCharacteristic serialNumberStringCharacteristic;
Rohit Grover 118:620d28e7a1ba 119 GattCharacteristic hardwareRevisionStringCharacteristic;
Rohit Grover 118:620d28e7a1ba 120 GattCharacteristic firmwareRevisionStringCharacteristic;
Rohit Grover 118:620d28e7a1ba 121 GattCharacteristic softwareRevisionStringCharacteristic;
Rohit Grover 118:620d28e7a1ba 122 };
Rohit Grover 118:620d28e7a1ba 123
Rohit Grover 118:620d28e7a1ba 124 #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/