Minor temporary patch to allow DFU packet callback

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Fri Jun 13 11:22:03 2014 +0100
Revision:
94:455363a6eb90
Parent:
77:1436ecf09583
Child:
99:58c47085e816
add BLEDevice::readCharacteristicValue()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 29:011e95ce78b8 1 /* mbed Microcontroller Library
ktownsend 29:011e95ce78b8 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 29:011e95ce78b8 3 *
ktownsend 29:011e95ce78b8 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 29:011e95ce78b8 5 * you may not use this file except in compliance with the License.
ktownsend 29:011e95ce78b8 6 * You may obtain a copy of the License at
ktownsend 29:011e95ce78b8 7 *
ktownsend 29:011e95ce78b8 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 29:011e95ce78b8 9 *
ktownsend 29:011e95ce78b8 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 29:011e95ce78b8 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 29:011e95ce78b8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 29:011e95ce78b8 13 * See the License for the specific language governing permissions and
ktownsend 29:011e95ce78b8 14 * limitations under the License.
Rohit Grover 34:da2ea8cd6216 15 */
ktownsend 29:011e95ce78b8 16
ktownsend 29:011e95ce78b8 17 #ifndef __GATT_SERVER_H__
ktownsend 29:011e95ce78b8 18 #define __GATT_SERVER_H__
ktownsend 29:011e95ce78b8 19
bogdanm 31:2c94f0501807 20 #include "mbed.h"
ktownsend 29:011e95ce78b8 21 #include "blecommon.h"
ktownsend 29:011e95ce78b8 22 #include "GattService.h"
bogdanm 31:2c94f0501807 23 #include "GattServerEvents.h"
ktownsend 29:011e95ce78b8 24
ktownsend 29:011e95ce78b8 25 /**************************************************************************/
ktownsend 29:011e95ce78b8 26 /*!
ktownsend 29:011e95ce78b8 27 \brief
ktownsend 29:011e95ce78b8 28 The base class used to abstract GATT Server functionality to a specific
ktownsend 29:011e95ce78b8 29 radio transceiver, SOC or BLE Stack.
ktownsend 29:011e95ce78b8 30 */
ktownsend 29:011e95ce78b8 31 /**************************************************************************/
ktownsend 29:011e95ce78b8 32 class GattServer
ktownsend 29:011e95ce78b8 33 {
Rohit Grover 34:da2ea8cd6216 34 public:
Rohit Grover 34:da2ea8cd6216 35 /* These functions must be defined in the sub-class */
Rohit Grover 34:da2ea8cd6216 36 virtual ble_error_t addService(GattService &) = 0;
Rohit Grover 94:455363a6eb90 37 virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP) = 0;
Rohit Grover 75:d08bdef22500 38 virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false) = 0;
bogdanm 31:2c94f0501807 39
Rohit Grover 34:da2ea8cd6216 40 // ToDo: For updateValue, check the CCCD to see if the value we are
Rohit Grover 34:da2ea8cd6216 41 // updating has the notify or indicate bits sent, and if BOTH are set
Rohit Grover 34:da2ea8cd6216 42 // be sure to call sd_ble_gatts_hvx() twice with notify then indicate!
Rohit Grover 34:da2ea8cd6216 43 // Strange use case, but valid and must be covered!
Rohit Grover 34:da2ea8cd6216 44
Rohit Grover 64:95529f47b782 45 /* Event callback handlers. */
Rohit Grover 64:95529f47b782 46 typedef void (*EventCallback_t)(uint16_t attributeHandle);
Rohit Grover 64:95529f47b782 47 void setOnDataSent(EventCallback_t callback) {
Rohit Grover 64:95529f47b782 48 onDataSent = callback;
Rohit Grover 64:95529f47b782 49 }
Rohit Grover 64:95529f47b782 50 void setOnDataWritten(EventCallback_t callback) {
Rohit Grover 64:95529f47b782 51 onDataWritten = callback;
Rohit Grover 64:95529f47b782 52 }
Rohit Grover 64:95529f47b782 53 void setOnUpdatesEnabled(EventCallback_t callback) {
Rohit Grover 64:95529f47b782 54 onUpdatesEnabled = callback;
Rohit Grover 64:95529f47b782 55 }
Rohit Grover 64:95529f47b782 56 void setOnUpdatesDisabled(EventCallback_t callback) {
Rohit Grover 64:95529f47b782 57 onUpdatesDisabled = callback;
Rohit Grover 64:95529f47b782 58 }
Rohit Grover 64:95529f47b782 59 void setOnConfirmationReceived(EventCallback_t callback) {
Rohit Grover 64:95529f47b782 60 onConfirmationReceived = callback;
Rohit Grover 34:da2ea8cd6216 61 }
ktownsend 29:011e95ce78b8 62
Rohit Grover 34:da2ea8cd6216 63 void handleEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle) {
Rohit Grover 34:da2ea8cd6216 64 switch (type) {
Rohit Grover 77:1436ecf09583 65 case GattServerEvents::GATT_EVENT_DATA_SENT:
Rohit Grover 77:1436ecf09583 66 if (onDataSent) {
Rohit Grover 77:1436ecf09583 67 onDataSent(charHandle);
Rohit Grover 77:1436ecf09583 68 }
Rohit Grover 77:1436ecf09583 69 break;
Rohit Grover 77:1436ecf09583 70 case GattServerEvents::GATT_EVENT_DATA_WRITTEN:
Rohit Grover 77:1436ecf09583 71 if (onDataWritten) {
Rohit Grover 77:1436ecf09583 72 onDataWritten(charHandle);
Rohit Grover 77:1436ecf09583 73 }
Rohit Grover 77:1436ecf09583 74 break;
Rohit Grover 77:1436ecf09583 75 case GattServerEvents::GATT_EVENT_UPDATES_ENABLED:
Rohit Grover 77:1436ecf09583 76 if (onUpdatesEnabled) {
Rohit Grover 77:1436ecf09583 77 onUpdatesEnabled(charHandle);
Rohit Grover 77:1436ecf09583 78 }
Rohit Grover 77:1436ecf09583 79 break;
Rohit Grover 77:1436ecf09583 80 case GattServerEvents::GATT_EVENT_UPDATES_DISABLED:
Rohit Grover 77:1436ecf09583 81 if (onUpdatesDisabled) {
Rohit Grover 77:1436ecf09583 82 onUpdatesDisabled(charHandle);
Rohit Grover 77:1436ecf09583 83 }
Rohit Grover 77:1436ecf09583 84 break;
Rohit Grover 77:1436ecf09583 85 case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED:
Rohit Grover 77:1436ecf09583 86 if (onConfirmationReceived) {
Rohit Grover 77:1436ecf09583 87 onConfirmationReceived(charHandle);
Rohit Grover 77:1436ecf09583 88 }
Rohit Grover 77:1436ecf09583 89 break;
Rohit Grover 34:da2ea8cd6216 90 }
Rohit Grover 34:da2ea8cd6216 91 }
bogdanm 31:2c94f0501807 92
Rohit Grover 64:95529f47b782 93 protected:
Rohit Grover 75:d08bdef22500 94 GattServer() : serviceCount(0), characteristicCount(0), onDataSent(NULL), onDataWritten(NULL), onUpdatesEnabled(NULL), onUpdatesDisabled(NULL), onConfirmationReceived(NULL) {
Rohit Grover 64:95529f47b782 95 /* empty */
Rohit Grover 64:95529f47b782 96 }
Rohit Grover 64:95529f47b782 97
Rohit Grover 64:95529f47b782 98 protected:
Rohit Grover 34:da2ea8cd6216 99 uint8_t serviceCount;
Rohit Grover 34:da2ea8cd6216 100 uint8_t characteristicCount;
Rohit Grover 64:95529f47b782 101
Rohit Grover 64:95529f47b782 102 private:
Rohit Grover 64:95529f47b782 103 EventCallback_t onDataSent;
Rohit Grover 64:95529f47b782 104 EventCallback_t onDataWritten;
Rohit Grover 64:95529f47b782 105 EventCallback_t onUpdatesEnabled;
Rohit Grover 64:95529f47b782 106 EventCallback_t onUpdatesDisabled;
Rohit Grover 64:95529f47b782 107 EventCallback_t onConfirmationReceived;
ktownsend 29:011e95ce78b8 108 };
ktownsend 29:011e95ce78b8 109
Rohit Grover 34:da2ea8cd6216 110 #endif // ifndef __GATT_SERVER_H__