None
Fork of nRF51822 by
source/nRF5xGattServer.h@388:db85a09c27ef, 2015-07-21 (annotated)
- Committer:
- rgrover1
- Date:
- Tue Jul 21 13:23:44 2015 +0100
- Revision:
- 388:db85a09c27ef
- Child:
- 561:613dbbdeed27
Synchronized with git rev 0eb58d86
Author: Rohit Grover
rename nRF51... to nRF5x...
This prepares us to support nRF52.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 388:db85a09c27ef | 1 | /* mbed Microcontroller Library |
rgrover1 | 388:db85a09c27ef | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 388:db85a09c27ef | 3 | * |
rgrover1 | 388:db85a09c27ef | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 388:db85a09c27ef | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 388:db85a09c27ef | 6 | * You may obtain a copy of the License at |
rgrover1 | 388:db85a09c27ef | 7 | * |
rgrover1 | 388:db85a09c27ef | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 388:db85a09c27ef | 9 | * |
rgrover1 | 388:db85a09c27ef | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 388:db85a09c27ef | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 388:db85a09c27ef | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 388:db85a09c27ef | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 388:db85a09c27ef | 14 | * limitations under the License. |
rgrover1 | 388:db85a09c27ef | 15 | */ |
rgrover1 | 388:db85a09c27ef | 16 | |
rgrover1 | 388:db85a09c27ef | 17 | #ifndef __NRF51822_GATT_SERVER_H__ |
rgrover1 | 388:db85a09c27ef | 18 | #define __NRF51822_GATT_SERVER_H__ |
rgrover1 | 388:db85a09c27ef | 19 | |
rgrover1 | 388:db85a09c27ef | 20 | #include <stddef.h> |
rgrover1 | 388:db85a09c27ef | 21 | |
rgrover1 | 388:db85a09c27ef | 22 | #include "ble/blecommon.h" |
rgrover1 | 388:db85a09c27ef | 23 | #include "ble.h" /* nordic ble */ |
rgrover1 | 388:db85a09c27ef | 24 | #include "ble/Gap.h" |
rgrover1 | 388:db85a09c27ef | 25 | #include "ble/GattServer.h" |
rgrover1 | 388:db85a09c27ef | 26 | |
rgrover1 | 388:db85a09c27ef | 27 | class nRF5xGattServer : public GattServer |
rgrover1 | 388:db85a09c27ef | 28 | { |
rgrover1 | 388:db85a09c27ef | 29 | public: |
rgrover1 | 388:db85a09c27ef | 30 | static nRF5xGattServer &getInstance(); |
rgrover1 | 388:db85a09c27ef | 31 | |
rgrover1 | 388:db85a09c27ef | 32 | /* Functions that must be implemented from GattServer */ |
rgrover1 | 388:db85a09c27ef | 33 | virtual ble_error_t addService(GattService &); |
rgrover1 | 388:db85a09c27ef | 34 | virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); |
rgrover1 | 388:db85a09c27ef | 35 | virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); |
rgrover1 | 388:db85a09c27ef | 36 | virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); |
rgrover1 | 388:db85a09c27ef | 37 | virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); |
rgrover1 | 388:db85a09c27ef | 38 | virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP); |
rgrover1 | 388:db85a09c27ef | 39 | virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP); |
rgrover1 | 388:db85a09c27ef | 40 | |
rgrover1 | 388:db85a09c27ef | 41 | /* nRF51 Functions */ |
rgrover1 | 388:db85a09c27ef | 42 | void eventCallback(void); |
rgrover1 | 388:db85a09c27ef | 43 | void hwCallback(ble_evt_t *p_ble_evt); |
rgrover1 | 388:db85a09c27ef | 44 | |
rgrover1 | 388:db85a09c27ef | 45 | private: |
rgrover1 | 388:db85a09c27ef | 46 | const static unsigned BLE_TOTAL_CHARACTERISTICS = 20; |
rgrover1 | 388:db85a09c27ef | 47 | const static unsigned BLE_TOTAL_DESCRIPTORS = 8; |
rgrover1 | 388:db85a09c27ef | 48 | |
rgrover1 | 388:db85a09c27ef | 49 | private: |
rgrover1 | 388:db85a09c27ef | 50 | /** |
rgrover1 | 388:db85a09c27ef | 51 | * resolve a value attribute to its owning characteristic. |
rgrover1 | 388:db85a09c27ef | 52 | * @param valueHandle the value handle to be resolved. |
rgrover1 | 388:db85a09c27ef | 53 | * @return characteristic index if a resolution is found, else -1. |
rgrover1 | 388:db85a09c27ef | 54 | */ |
rgrover1 | 388:db85a09c27ef | 55 | int resolveValueHandleToCharIndex(GattAttribute::Handle_t valueHandle) const { |
rgrover1 | 388:db85a09c27ef | 56 | unsigned charIndex; |
rgrover1 | 388:db85a09c27ef | 57 | for (charIndex = 0; charIndex < characteristicCount; charIndex++) { |
rgrover1 | 388:db85a09c27ef | 58 | if (nrfCharacteristicHandles[charIndex].value_handle == valueHandle) { |
rgrover1 | 388:db85a09c27ef | 59 | return charIndex; |
rgrover1 | 388:db85a09c27ef | 60 | } |
rgrover1 | 388:db85a09c27ef | 61 | } |
rgrover1 | 388:db85a09c27ef | 62 | |
rgrover1 | 388:db85a09c27ef | 63 | return -1; |
rgrover1 | 388:db85a09c27ef | 64 | } |
rgrover1 | 388:db85a09c27ef | 65 | |
rgrover1 | 388:db85a09c27ef | 66 | /** |
rgrover1 | 388:db85a09c27ef | 67 | * resolve a CCCD attribute handle to its owning characteristic. |
rgrover1 | 388:db85a09c27ef | 68 | * @param cccdHandle the CCCD handle to be resolved. |
rgrover1 | 388:db85a09c27ef | 69 | * @return characteristic index if a resolution is found, else -1. |
rgrover1 | 388:db85a09c27ef | 70 | */ |
rgrover1 | 388:db85a09c27ef | 71 | int resolveCCCDHandleToCharIndex(GattAttribute::Handle_t cccdHandle) const { |
rgrover1 | 388:db85a09c27ef | 72 | unsigned charIndex; |
rgrover1 | 388:db85a09c27ef | 73 | for (charIndex = 0; charIndex < characteristicCount; charIndex++) { |
rgrover1 | 388:db85a09c27ef | 74 | if (nrfCharacteristicHandles[charIndex].cccd_handle == cccdHandle) { |
rgrover1 | 388:db85a09c27ef | 75 | return charIndex; |
rgrover1 | 388:db85a09c27ef | 76 | } |
rgrover1 | 388:db85a09c27ef | 77 | } |
rgrover1 | 388:db85a09c27ef | 78 | |
rgrover1 | 388:db85a09c27ef | 79 | return -1; |
rgrover1 | 388:db85a09c27ef | 80 | } |
rgrover1 | 388:db85a09c27ef | 81 | |
rgrover1 | 388:db85a09c27ef | 82 | private: |
rgrover1 | 388:db85a09c27ef | 83 | GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS]; |
rgrover1 | 388:db85a09c27ef | 84 | ble_gatts_char_handles_t nrfCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS]; |
rgrover1 | 388:db85a09c27ef | 85 | GattAttribute *p_descriptors[BLE_TOTAL_DESCRIPTORS]; |
rgrover1 | 388:db85a09c27ef | 86 | uint8_t descriptorCount; |
rgrover1 | 388:db85a09c27ef | 87 | uint16_t nrfDescriptorHandles[BLE_TOTAL_DESCRIPTORS]; |
rgrover1 | 388:db85a09c27ef | 88 | |
rgrover1 | 388:db85a09c27ef | 89 | nRF5xGattServer() : GattServer(), p_characteristics(), nrfCharacteristicHandles(), p_descriptors(), descriptorCount(0), nrfDescriptorHandles() { |
rgrover1 | 388:db85a09c27ef | 90 | /* empty */ |
rgrover1 | 388:db85a09c27ef | 91 | } |
rgrover1 | 388:db85a09c27ef | 92 | |
rgrover1 | 388:db85a09c27ef | 93 | private: |
rgrover1 | 388:db85a09c27ef | 94 | nRF5xGattServer(const nRF5xGattServer &); |
rgrover1 | 388:db85a09c27ef | 95 | const nRF5xGattServer& operator=(const nRF5xGattServer &); |
rgrover1 | 388:db85a09c27ef | 96 | }; |
rgrover1 | 388:db85a09c27ef | 97 | |
rgrover1 | 388:db85a09c27ef | 98 | #endif // ifndef __NRF51822_GATT_SERVER_H__ |