test firmware for BLE Micro V1.3 1. test io, vcc and ble 2. act as a UART to BLE bridge

Dependencies:   BLE_API Buffer mbed

Fork of BLE_LEDBlinker by Bluetooth Low Energy

Committer:
arch
Date:
Tue Dec 08 06:02:25 2015 +0000
Revision:
11:c8cbc4bc2c17
test firmware for BLE Micro V1.3

Who changed what in which revision?

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