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@30:9614522cf932, 2014-01-17 (annotated)
- Committer:
- ktownsend
- Date:
- Fri Jan 17 14:25:29 2014 +0000
- Revision:
- 30:9614522cf932
- Parent:
- 29:011e95ce78b8
- Child:
- 31:2c94f0501807
Added Gap and GattServer event definitions
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. |
| ktownsend | 29:011e95ce78b8 | 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 | |
| ktownsend | 29:011e95ce78b8 | 20 | #include "blecommon.h" |
| ktownsend | 29:011e95ce78b8 | 21 | #include "UUID.h" |
| ktownsend | 29:011e95ce78b8 | 22 | #include "GattService.h" |
| ktownsend | 29:011e95ce78b8 | 23 | #include "mbed.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 | { |
| ktownsend | 29:011e95ce78b8 | 34 | protected: |
| ktownsend | 29:011e95ce78b8 | 35 | FunctionPointer m_callback_event; |
| ktownsend | 29:011e95ce78b8 | 36 | |
| ktownsend | 29:011e95ce78b8 | 37 | public: |
| ktownsend | 29:011e95ce78b8 | 38 | /******************************************************************/ |
| ktownsend | 29:011e95ce78b8 | 39 | /*! |
| ktownsend | 29:011e95ce78b8 | 40 | \brief |
| ktownsend | 29:011e95ce78b8 | 41 | Identifies GATT events generated by the radio HW when an event |
| ktownsend | 29:011e95ce78b8 | 42 | callback occurs |
| ktownsend | 29:011e95ce78b8 | 43 | */ |
| ktownsend | 29:011e95ce78b8 | 44 | /******************************************************************/ |
| ktownsend | 29:011e95ce78b8 | 45 | typedef enum gatt_event_e |
| ktownsend | 29:011e95ce78b8 | 46 | { |
| ktownsend | 30:9614522cf932 | 47 | GATT_EVENT_DATA_SENT = 1, /* Fired when a msg was successfully sent out */ |
| ktownsend | 30:9614522cf932 | 48 | GATT_EVENT_DATA_WRITTEN = 2, /* Client wrote data to Server (separate into char and descriptor writes?) */ |
| ktownsend | 30:9614522cf932 | 49 | GATT_EVENT_UPDATES_ENABLED = 3, /* Notify/Indicate Enabled in CCCD */ |
| ktownsend | 30:9614522cf932 | 50 | GATT_EVENT_UPDATES_DISABLED = 4, /* Notify/Indicate Disnabled in CCCD */ |
| ktownsend | 30:9614522cf932 | 51 | GATT_EVENT_CONFIRMATION_RECEIVED = 5 /* Response received from Indicate message */ |
| ktownsend | 29:011e95ce78b8 | 52 | } gattEvent_t; |
| ktownsend | 29:011e95ce78b8 | 53 | |
| ktownsend | 29:011e95ce78b8 | 54 | /* These functions must be defined in the sub-class */ |
| ktownsend | 29:011e95ce78b8 | 55 | virtual ble_error_t addService(GattService &) = 0; |
| ktownsend | 29:011e95ce78b8 | 56 | virtual ble_error_t readValue(uint8_t, uint8_t[], uint16_t) = 0; |
| ktownsend | 29:011e95ce78b8 | 57 | virtual ble_error_t updateValue(uint8_t, uint8_t[], uint16_t) = 0; |
| ktownsend | 30:9614522cf932 | 58 | |
| ktownsend | 30:9614522cf932 | 59 | // ToDo: For updateValue, check the CCCD to see if the value we are |
| ktownsend | 30:9614522cf932 | 60 | // updating has the notify or indicate bits sent, and if BOTH are set |
| ktownsend | 30:9614522cf932 | 61 | // be sure to call sd_ble_gatts_hvx() twice with notify then indicate! |
| ktownsend | 30:9614522cf932 | 62 | // Strange use case, but valid and must be covered! |
| ktownsend | 29:011e95ce78b8 | 63 | |
| ktownsend | 29:011e95ce78b8 | 64 | uint8_t serviceCount; |
| ktownsend | 29:011e95ce78b8 | 65 | uint8_t characteristicCount; |
| ktownsend | 29:011e95ce78b8 | 66 | |
| ktownsend | 29:011e95ce78b8 | 67 | /* Event callback */ |
| ktownsend | 29:011e95ce78b8 | 68 | void attach(void (*function)(void)) { |
| ktownsend | 29:011e95ce78b8 | 69 | m_callback_event.attach( function ); |
| ktownsend | 29:011e95ce78b8 | 70 | } |
| ktownsend | 29:011e95ce78b8 | 71 | |
| ktownsend | 29:011e95ce78b8 | 72 | template<typename T> |
| ktownsend | 29:011e95ce78b8 | 73 | void attach(T *object, void (T::*member)(void)) { |
| ktownsend | 29:011e95ce78b8 | 74 | m_callback_event.attach( object, member ); |
| ktownsend | 29:011e95ce78b8 | 75 | } |
| ktownsend | 29:011e95ce78b8 | 76 | }; |
| ktownsend | 29:011e95ce78b8 | 77 | |
| ktownsend | 29:011e95ce78b8 | 78 | #endif |
