I don't know why this is happening.

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Tue Sep 02 15:09:46 2014 +0100
Revision:
116:ca826083980e
Parent:
114:f1ede142a78f
Child:
118:620d28e7a1ba
Release 0.1.0
=============

Mostly API changes.

Features
~~~~~~~~

- onConnection() callback now receives connection-parameters applicable to the
new connection.

- onDataSent() callback now receives a count parameter containing the number of
times notifications were sent out since the last callback.

- A 'reason' parameter has been added to Gap::disconnect() to indicate the
reason for disconnection; and also to the onDisconnection callback to
receive a reason from the remote host.

Bugfixes
~~~~~~~~

- onDataWritten() callback now receives an additional parameter
(GattServer::WriteEventCallback_t) encapsulating the update. This avoids
having to re-fetch the updated characteristic's value attribute. It also
fixes a bug where multiple updates to the characteristic's value-attribute
could get clobbered if they occurred in quick succession before the
callbacks could be processed.

Who changed what in which revision?

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