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