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