Lightly modified version of the BLE stack, that doesn't bring up a DFUService by default... as we have our own.

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Thu Dec 11 11:52:32 2014 +0000
Revision:
246:6c2402f286f6
Child:
277:1407d2f1ce3c
Synchronized with git rev 5ee435ea
Author: Rohit Grover
Release 0.2.8
=============

Minor API enhancements to support LinkLoss service.

Enhancements
~~~~~~~~~~~~

* Introduce LinkLoss Service.
https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.link_loss.xml

* Add BLEDevice::addToDisconnectionCallChain(). This is in some sense parallel
to the onDisconnection callback; but it allows for chaining and these
callbacks don't receive any context.

* Some improvements to documentation.

Bugfixes
~~~~~~~~

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

This release is backward compatible with 0.2.4.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 246:6c2402f286f6 1 /* mbed Microcontroller Library
rgrover1 246:6c2402f286f6 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 246:6c2402f286f6 3 *
rgrover1 246:6c2402f286f6 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 246:6c2402f286f6 5 * you may not use this file except in compliance with the License.
rgrover1 246:6c2402f286f6 6 * You may obtain a copy of the License at
rgrover1 246:6c2402f286f6 7 *
rgrover1 246:6c2402f286f6 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 246:6c2402f286f6 9 *
rgrover1 246:6c2402f286f6 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 246:6c2402f286f6 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 246:6c2402f286f6 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 246:6c2402f286f6 13 * See the License for the specific language governing permissions and
rgrover1 246:6c2402f286f6 14 * limitations under the License.
rgrover1 246:6c2402f286f6 15 */
rgrover1 246:6c2402f286f6 16
rgrover1 246:6c2402f286f6 17 #ifndef __BLE_LINK_LOSS_SERVICE_H__
rgrover1 246:6c2402f286f6 18 #define __BLE_LINK_LOSS_SERVICE_H__
rgrover1 246:6c2402f286f6 19
rgrover1 246:6c2402f286f6 20 #include "Gap.h"
rgrover1 246:6c2402f286f6 21
rgrover1 246:6c2402f286f6 22 /**
rgrover1 246:6c2402f286f6 23 * @class LinkLossService
rgrover1 246:6c2402f286f6 24 * @brief This service defines behavior when a link is lost between two devices. <br>
rgrover1 246:6c2402f286f6 25 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.link_loss.xml <br>
rgrover1 246:6c2402f286f6 26 * Alertness Level Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.alert_level.xml <br>
rgrover1 246:6c2402f286f6 27 */
rgrover1 246:6c2402f286f6 28 class LinkLossService {
rgrover1 246:6c2402f286f6 29 public:
rgrover1 246:6c2402f286f6 30 enum AlertLevel_t {
rgrover1 246:6c2402f286f6 31 NO_ALERT = 0,
rgrover1 246:6c2402f286f6 32 MILD_ALERT = 1,
rgrover1 246:6c2402f286f6 33 HIGH_ALERT = 2
rgrover1 246:6c2402f286f6 34 };
rgrover1 246:6c2402f286f6 35
rgrover1 246:6c2402f286f6 36 typedef void (* callback_t)(AlertLevel_t level);
rgrover1 246:6c2402f286f6 37
rgrover1 246:6c2402f286f6 38 /**
rgrover1 246:6c2402f286f6 39 * @param[ref] ble
rgrover1 246:6c2402f286f6 40 * BLEDevice object for the underlying controller.
rgrover1 246:6c2402f286f6 41 */
rgrover1 246:6c2402f286f6 42 LinkLossService(BLEDevice &bleIn, callback_t callbackIn, AlertLevel_t levelIn = NO_ALERT) :
rgrover1 246:6c2402f286f6 43 ble(bleIn),
rgrover1 246:6c2402f286f6 44 alertLevel(levelIn),
rgrover1 246:6c2402f286f6 45 callback(callbackIn),
rgrover1 246:6c2402f286f6 46 alertLevelChar(GattCharacteristic::UUID_ALERT_LEVEL_CHAR, reinterpret_cast<uint8_t *>(&alertLevel), sizeof(uint8_t), sizeof(uint8_t),
rgrover1 246:6c2402f286f6 47 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE) {
rgrover1 246:6c2402f286f6 48 static bool serviceAdded = false; /* We should only ever add one LinkLoss service. */
rgrover1 246:6c2402f286f6 49 if (serviceAdded) {
rgrover1 246:6c2402f286f6 50 return;
rgrover1 246:6c2402f286f6 51 }
rgrover1 246:6c2402f286f6 52
rgrover1 246:6c2402f286f6 53 GattCharacteristic *charTable[] = {&alertLevelChar};
rgrover1 246:6c2402f286f6 54 GattService linkLossService(GattService::UUID_LINK_LOSS_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
rgrover1 246:6c2402f286f6 55
rgrover1 246:6c2402f286f6 56 ble.addService(linkLossService);
rgrover1 246:6c2402f286f6 57 serviceAdded = true;
rgrover1 246:6c2402f286f6 58
rgrover1 246:6c2402f286f6 59 ble.addToDisconnectionCallChain(this, &LinkLossService::onDisconnectionFilter);
rgrover1 246:6c2402f286f6 60 ble.onDataWritten(this, &LinkLossService::onDataWritten);
rgrover1 246:6c2402f286f6 61 }
rgrover1 246:6c2402f286f6 62
rgrover1 246:6c2402f286f6 63 /**
rgrover1 246:6c2402f286f6 64 * Update the callback.
rgrover1 246:6c2402f286f6 65 */
rgrover1 246:6c2402f286f6 66 void setCallback(callback_t newCallback) {
rgrover1 246:6c2402f286f6 67 callback = newCallback;
rgrover1 246:6c2402f286f6 68 }
rgrover1 246:6c2402f286f6 69
rgrover1 246:6c2402f286f6 70 /**
rgrover1 246:6c2402f286f6 71 * Update Alertness Level.
rgrover1 246:6c2402f286f6 72 */
rgrover1 246:6c2402f286f6 73 void setAlertLevel(AlertLevel_t newLevel) {
rgrover1 246:6c2402f286f6 74 alertLevel = newLevel;
rgrover1 246:6c2402f286f6 75 }
rgrover1 246:6c2402f286f6 76
rgrover1 246:6c2402f286f6 77 private:
rgrover1 246:6c2402f286f6 78 /**
rgrover1 246:6c2402f286f6 79 * This callback allows receiving updates to the AlertLevel Characteristic.
rgrover1 246:6c2402f286f6 80 *
rgrover1 246:6c2402f286f6 81 * @param[in] params
rgrover1 246:6c2402f286f6 82 * Information about the characterisitc being updated.
rgrover1 246:6c2402f286f6 83 */
rgrover1 246:6c2402f286f6 84 virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) {
rgrover1 246:6c2402f286f6 85 if (params->charHandle == alertLevelChar.getValueHandle()) {
rgrover1 246:6c2402f286f6 86 alertLevel = *reinterpret_cast<const AlertLevel_t *>(params->data);
rgrover1 246:6c2402f286f6 87 }
rgrover1 246:6c2402f286f6 88 }
rgrover1 246:6c2402f286f6 89
rgrover1 246:6c2402f286f6 90 void onDisconnectionFilter(void) {
rgrover1 246:6c2402f286f6 91 if (alertLevel != NO_ALERT) {
rgrover1 246:6c2402f286f6 92 callback(alertLevel);
rgrover1 246:6c2402f286f6 93 }
rgrover1 246:6c2402f286f6 94 }
rgrover1 246:6c2402f286f6 95
rgrover1 246:6c2402f286f6 96 private:
rgrover1 246:6c2402f286f6 97 BLEDevice &ble;
rgrover1 246:6c2402f286f6 98 AlertLevel_t alertLevel;
rgrover1 246:6c2402f286f6 99 callback_t callback;
rgrover1 246:6c2402f286f6 100 GattCharacteristic alertLevelChar;
rgrover1 246:6c2402f286f6 101 };
rgrover1 246:6c2402f286f6 102
rgrover1 246:6c2402f286f6 103 #endif /* __BLE_LINK_LOSS_SERVICE_H__ */