Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
hw/GattServer.h@75:d08bdef22500, 2014-06-06 (annotated)
- Committer:
- Rohit Grover
- Date:
- Fri Jun 06 14:14:46 2014 +0100
- Revision:
- 75:d08bdef22500
- Parent:
- 64:95529f47b782
- Child:
- 77:1436ecf09583
white space changes to move away from 80-column rule
Who changed what in which revision?
| User | Revision | Line number | New 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 |
75:d08bdef22500 | 37 | virtual ble_error_t readValue(uint16_t, uint8_t[], uint16_t) = 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 |
34:da2ea8cd6216 | 65 | case GattServerEvents::GATT_EVENT_DATA_SENT: |
| Rohit Grover |
64:95529f47b782 | 66 | if (onDataSent) { |
| Rohit Grover |
64:95529f47b782 | 67 | onDataSent(charHandle); |
| Rohit Grover |
64:95529f47b782 | 68 | } |
| Rohit Grover |
34:da2ea8cd6216 | 69 | break; |
| Rohit Grover |
34:da2ea8cd6216 | 70 | case GattServerEvents::GATT_EVENT_DATA_WRITTEN: |
| Rohit Grover |
64:95529f47b782 | 71 | if (onDataWritten) { |
| Rohit Grover |
64:95529f47b782 | 72 | onDataWritten(charHandle); |
| Rohit Grover |
64:95529f47b782 | 73 | } |
| Rohit Grover |
34:da2ea8cd6216 | 74 | break; |
| Rohit Grover |
34:da2ea8cd6216 | 75 | case GattServerEvents::GATT_EVENT_UPDATES_ENABLED: |
| Rohit Grover |
64:95529f47b782 | 76 | if (onUpdatesEnabled) { |
| Rohit Grover |
64:95529f47b782 | 77 | onUpdatesEnabled(charHandle); |
| Rohit Grover |
64:95529f47b782 | 78 | } |
| Rohit Grover |
34:da2ea8cd6216 | 79 | break; |
| Rohit Grover |
34:da2ea8cd6216 | 80 | case GattServerEvents::GATT_EVENT_UPDATES_DISABLED: |
| Rohit Grover |
64:95529f47b782 | 81 | if (onUpdatesDisabled) { |
| Rohit Grover |
64:95529f47b782 | 82 | onUpdatesDisabled(charHandle); |
| Rohit Grover |
64:95529f47b782 | 83 | } |
| Rohit Grover |
34:da2ea8cd6216 | 84 | break; |
| Rohit Grover |
34:da2ea8cd6216 | 85 | case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED: |
| Rohit Grover |
64:95529f47b782 | 86 | if (onConfirmationReceived) { |
| Rohit Grover |
64:95529f47b782 | 87 | onConfirmationReceived(charHandle); |
| Rohit Grover |
64:95529f47b782 | 88 | } |
| Rohit Grover |
34:da2ea8cd6216 | 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__ |
