BLE API as used in the blog entry.
Dependents: BLE_iBeacon_Exercise
Fork of BLE_API_Native by
hw/GattServer.h@15:a854d49b3d25, 2014-02-20 (annotated)
- Committer:
- ktownsend
- Date:
- Thu Feb 20 17:23:17 2014 +0000
- Revision:
- 15:a854d49b3d25
- Parent:
- 0:4c3097c65247
Prototype functions for GattServerEvents
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ktownsend | 0:4c3097c65247 | 1 | /* mbed Microcontroller Library |
ktownsend | 0:4c3097c65247 | 2 | * Copyright (c) 2006-2013 ARM Limited |
ktownsend | 0:4c3097c65247 | 3 | * |
ktownsend | 0:4c3097c65247 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ktownsend | 0:4c3097c65247 | 5 | * you may not use this file except in compliance with the License. |
ktownsend | 0:4c3097c65247 | 6 | * You may obtain a copy of the License at |
ktownsend | 0:4c3097c65247 | 7 | * |
ktownsend | 0:4c3097c65247 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ktownsend | 0:4c3097c65247 | 9 | * |
ktownsend | 0:4c3097c65247 | 10 | * Unless required by applicable law or agreed to in writing, software |
ktownsend | 0:4c3097c65247 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
ktownsend | 0:4c3097c65247 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ktownsend | 0:4c3097c65247 | 13 | * See the License for the specific language governing permissions and |
ktownsend | 0:4c3097c65247 | 14 | * limitations under the License. |
ktownsend | 0:4c3097c65247 | 15 | */ |
ktownsend | 0:4c3097c65247 | 16 | |
ktownsend | 0:4c3097c65247 | 17 | #ifndef __GATT_SERVER_H__ |
ktownsend | 0:4c3097c65247 | 18 | #define __GATT_SERVER_H__ |
ktownsend | 0:4c3097c65247 | 19 | |
ktownsend | 0:4c3097c65247 | 20 | #include "mbed.h" |
ktownsend | 0:4c3097c65247 | 21 | #include "blecommon.h" |
ktownsend | 0:4c3097c65247 | 22 | #include "GattService.h" |
ktownsend | 0:4c3097c65247 | 23 | #include "GattServerEvents.h" |
ktownsend | 0:4c3097c65247 | 24 | |
ktownsend | 0:4c3097c65247 | 25 | /**************************************************************************/ |
ktownsend | 0:4c3097c65247 | 26 | /*! |
ktownsend | 0:4c3097c65247 | 27 | \brief |
ktownsend | 0:4c3097c65247 | 28 | The base class used to abstract GATT Server functionality to a specific |
ktownsend | 0:4c3097c65247 | 29 | radio transceiver, SOC or BLE Stack. |
ktownsend | 0:4c3097c65247 | 30 | */ |
ktownsend | 0:4c3097c65247 | 31 | /**************************************************************************/ |
ktownsend | 0:4c3097c65247 | 32 | class GattServer |
ktownsend | 0:4c3097c65247 | 33 | { |
ktownsend | 0:4c3097c65247 | 34 | private: |
ktownsend | 0:4c3097c65247 | 35 | GattServerEvents *m_pEventHandler; |
ktownsend | 0:4c3097c65247 | 36 | |
ktownsend | 0:4c3097c65247 | 37 | public: |
ktownsend | 0:4c3097c65247 | 38 | /* These functions must be defined in the sub-class */ |
ktownsend | 0:4c3097c65247 | 39 | virtual ble_error_t addService(GattService &) = 0; |
ktownsend | 0:4c3097c65247 | 40 | virtual ble_error_t readValue(uint16_t, uint8_t[], uint16_t) = 0; |
ktownsend | 0:4c3097c65247 | 41 | virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t) = 0; |
ktownsend | 0:4c3097c65247 | 42 | |
ktownsend | 0:4c3097c65247 | 43 | // ToDo: For updateValue, check the CCCD to see if the value we are |
ktownsend | 0:4c3097c65247 | 44 | // updating has the notify or indicate bits sent, and if BOTH are set |
ktownsend | 0:4c3097c65247 | 45 | // be sure to call sd_ble_gatts_hvx() twice with notify then indicate! |
ktownsend | 0:4c3097c65247 | 46 | // Strange use case, but valid and must be covered! |
ktownsend | 0:4c3097c65247 | 47 | |
ktownsend | 0:4c3097c65247 | 48 | /* Event callback handlers */ |
ktownsend | 0:4c3097c65247 | 49 | void setEventHandler(GattServerEvents *pEventHandler) {m_pEventHandler = pEventHandler;} |
ktownsend | 15:a854d49b3d25 | 50 | void handleEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle) { |
ktownsend | 0:4c3097c65247 | 51 | if (NULL == m_pEventHandler) |
ktownsend | 0:4c3097c65247 | 52 | return; |
ktownsend | 0:4c3097c65247 | 53 | switch(type) { |
ktownsend | 0:4c3097c65247 | 54 | case GattServerEvents::GATT_EVENT_DATA_SENT: |
ktownsend | 15:a854d49b3d25 | 55 | m_pEventHandler->onDataSent(charHandle); |
ktownsend | 0:4c3097c65247 | 56 | break; |
ktownsend | 0:4c3097c65247 | 57 | case GattServerEvents::GATT_EVENT_DATA_WRITTEN: |
ktownsend | 15:a854d49b3d25 | 58 | m_pEventHandler->onDataWritten(charHandle); |
ktownsend | 0:4c3097c65247 | 59 | break; |
ktownsend | 0:4c3097c65247 | 60 | case GattServerEvents::GATT_EVENT_UPDATES_ENABLED: |
ktownsend | 15:a854d49b3d25 | 61 | m_pEventHandler->onUpdatesEnabled(charHandle); |
ktownsend | 0:4c3097c65247 | 62 | break; |
ktownsend | 0:4c3097c65247 | 63 | case GattServerEvents::GATT_EVENT_UPDATES_DISABLED: |
ktownsend | 15:a854d49b3d25 | 64 | m_pEventHandler->onUpdatesDisabled(charHandle); |
ktownsend | 0:4c3097c65247 | 65 | break; |
ktownsend | 0:4c3097c65247 | 66 | case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED: |
ktownsend | 15:a854d49b3d25 | 67 | m_pEventHandler->onConfirmationReceived(charHandle); |
ktownsend | 0:4c3097c65247 | 68 | break; |
ktownsend | 0:4c3097c65247 | 69 | } |
ktownsend | 0:4c3097c65247 | 70 | } |
ktownsend | 0:4c3097c65247 | 71 | |
ktownsend | 0:4c3097c65247 | 72 | uint8_t serviceCount; |
ktownsend | 0:4c3097c65247 | 73 | uint8_t characteristicCount; |
ktownsend | 0:4c3097c65247 | 74 | }; |
ktownsend | 0:4c3097c65247 | 75 | |
ktownsend | 0:4c3097c65247 | 76 | #endif |