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