Clone of the nRF51822 repository from github The correct home is https://github.com/lancaster-university/nRF51822
Dependencies: nrf51-sdk
Dependents: microbit-dal microbit-ble-open microbit-dal-eddystone microbit-dal-ble-accelerometer-example ... more
nRF5xGattServer.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef __NRF51822_GATT_SERVER_H__ 00018 #define __NRF51822_GATT_SERVER_H__ 00019 00020 #include <stddef.h> 00021 00022 #include "ble/blecommon.h" 00023 #include "ble.h" /* nordic ble */ 00024 #include "ble/Gap.h" 00025 #include "ble/GattServer.h" 00026 00027 class nRF5xGattServer : public GattServer 00028 { 00029 public: 00030 /* Functions that must be implemented from GattServer */ 00031 virtual ble_error_t addService(GattService &); 00032 virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); 00033 virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); 00034 virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); 00035 virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); 00036 virtual ble_error_t notify(GattAttribute::Handle_t, const uint8_t[], uint16_t); 00037 virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP); 00038 virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP); 00039 virtual ble_error_t reset(void); 00040 00041 /* nRF51 Functions */ 00042 void eventCallback(void); 00043 void hwCallback(ble_evt_t *p_ble_evt); 00044 00045 00046 private: 00047 const static unsigned BLE_TOTAL_CHARACTERISTICS = 30; 00048 const static unsigned BLE_TOTAL_DESCRIPTORS = 20; 00049 00050 private: 00051 /** 00052 * resolve a value attribute to its owning characteristic. 00053 * @param valueHandle the value handle to be resolved. 00054 * @return characteristic index if a resolution is found, else -1. 00055 */ 00056 int resolveValueHandleToCharIndex(GattAttribute::Handle_t valueHandle) const { 00057 unsigned charIndex; 00058 for (charIndex = 0; charIndex < characteristicCount; charIndex++) { 00059 if (nrfCharacteristicHandles[charIndex].value_handle == valueHandle) { 00060 return charIndex; 00061 } 00062 } 00063 00064 return -1; 00065 } 00066 00067 /** 00068 * resolve a CCCD attribute handle to its owning characteristic. 00069 * @param cccdHandle the CCCD handle to be resolved. 00070 * @return characteristic index if a resolution is found, else -1. 00071 */ 00072 int resolveCCCDHandleToCharIndex(GattAttribute::Handle_t cccdHandle) const { 00073 unsigned charIndex; 00074 for (charIndex = 0; charIndex < characteristicCount; charIndex++) { 00075 if (nrfCharacteristicHandles[charIndex].cccd_handle == cccdHandle) { 00076 return charIndex; 00077 } 00078 } 00079 00080 return -1; 00081 } 00082 00083 private: 00084 GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS]; 00085 ble_gatts_char_handles_t nrfCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS]; 00086 GattAttribute *p_descriptors[BLE_TOTAL_DESCRIPTORS]; 00087 uint8_t descriptorCount; 00088 uint16_t nrfDescriptorHandles[BLE_TOTAL_DESCRIPTORS]; 00089 00090 /* 00091 * Allow instantiation from nRF5xn when required. 00092 */ 00093 friend class nRF5xn; 00094 00095 nRF5xGattServer() : GattServer(), p_characteristics(), nrfCharacteristicHandles(), p_descriptors(), descriptorCount(0), nrfDescriptorHandles() { 00096 /* empty */ 00097 } 00098 00099 private: 00100 nRF5xGattServer(const nRF5xGattServer &); 00101 const nRF5xGattServer& operator=(const nRF5xGattServer &); 00102 }; 00103 00104 #endif // ifndef __NRF51822_GATT_SERVER_H__
Generated on Tue Jul 12 2022 15:23:08 by 1.7.2