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