Minor temporary patch to allow DFU packet callback

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Mon Sep 22 10:59:09 2014 +0100
Revision:
118:620d28e7a1ba
Child:
237:6050833395f1
Release 0.2.0
=============

Highlights:
Introducing standard services to simplify applications.
Add support for over-the-air firmware updates.

Features
~~~~~~~~

- This release introduces 'templates' for common services such as heart-rate,
battery-level, device-info, UART, device-firmware-update etc. These services
take the shape of class declarations within header files aggregated under a
new folder called 'services/'. These service-classes provide a high-level
API hopefully easing the burden of developing BLE applications. The
underlying APIs to work with characteristics and services are still
available to allow greater control if needed. We expect to grow the
supported services to include all SIG defined BLE profiles.

- WriteCallbackParams now includes the characteristic's value-attribute
handle; this changes the signature of onDataWritten().

- BLEDevice::onDataWritten() now allows chaining of callbacks--this means that
it is possible to chain together multiple onDataWritten callbacks
(potentially from different modules of an application) to receive updates to
characteristics. Many services, such as DFU and UART add their own
onDataWritten callbacks behind the scenes to trap interesting events. It is
also possible to chain callbacks to functions within objects.

- Added the following expectation for GattCharacteristic: If valuePtr ==
NULL, initialLength == 0, and properties == READ for the value attribute of
a characteristic, then that particular characteristic may be considered
optional and dropped while instantiating the service with the underlying BLE
stack.

- Introducing the typedef GattAttribute::Handle_t to capture Attribute handles.

Bugfixes
~~~~~~~~

None.

Compatibility
~~~~~~~~~~~~~

The signature of onDataWritten() has seen a change; so application programs
using this new version of the BLE API will need minor modifications. Please
refer to sample programs under BLE team page.

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__*/