test

Fork of nRF51822 by Nordic Semiconductor

Committer:
rgrover1
Date:
Fri Jun 19 15:55:27 2015 +0100
Revision:
289:b33301b019e6
Parent:
288:1d85c4a4d397
Child:
290:83c994bf62d0
Synchronized with git rev 18a8f47f
Author: Rohit Grover
switch access level of some constant members of NordicServiceDiscovery to public.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 239:693a1f145b5a 1 /* mbed Microcontroller Library
rgrover1 239:693a1f145b5a 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 239:693a1f145b5a 3 *
rgrover1 239:693a1f145b5a 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 239:693a1f145b5a 5 * you may not use this file except in compliance with the License.
rgrover1 239:693a1f145b5a 6 * You may obtain a copy of the License at
rgrover1 239:693a1f145b5a 7 *
rgrover1 239:693a1f145b5a 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 239:693a1f145b5a 9 *
rgrover1 239:693a1f145b5a 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 239:693a1f145b5a 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 239:693a1f145b5a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 239:693a1f145b5a 13 * See the License for the specific language governing permissions and
rgrover1 239:693a1f145b5a 14 * limitations under the License.
rgrover1 239:693a1f145b5a 15 */
rgrover1 239:693a1f145b5a 16
rgrover1 239:693a1f145b5a 17 #ifndef _BTLE_DISCOVERY_H_
rgrover1 239:693a1f145b5a 18 #define _BTLE_DISCOVERY_H_
rgrover1 239:693a1f145b5a 19
rgrover1 247:df37e7bb3f71 20 #include "ble.h"
rgrover1 263:d5da37e9a93b 21 #include "ServiceDiscovery.h"
rgrover1 247:df37e7bb3f71 22
rgrover1 247:df37e7bb3f71 23 void bleGattcEventHandler(const ble_evt_t *p_ble_evt);
rgrover1 239:693a1f145b5a 24
rgrover1 250:db3c51656388 25 class NordicServiceDiscovery : public ServiceDiscovery
rgrover1 250:db3c51656388 26 {
rgrover1 248:71ef03789dd3 27 public:
rgrover1 260:ea2798f615e5 28 static const uint16_t SRV_DISC_START_HANDLE = 0x0001; /**< The start handle value used during service discovery. */
rgrover1 284:29fb6af6671d 29 static const uint16_t SRV_DISC_END_HANDLE = 0xFFFF; /**< The end handle value used during service discovery. */
rgrover1 260:ea2798f615e5 30
rgrover1 289:b33301b019e6 31 public:
rgrover1 248:71ef03789dd3 32 static const unsigned BLE_DB_DISCOVERY_MAX_SRV = 4; /**< Maximum number of services we can retain information for after a single discovery. */
rgrover1 248:71ef03789dd3 33 static const unsigned BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV = 4; /**< Maximum number of characteristics per service we can retain information for. */
rgrover1 260:ea2798f615e5 34
rgrover1 260:ea2798f615e5 35 public:
rgrover1 288:1d85c4a4d397 36 NordicServiceDiscovery() : serviceIndex(0),
rgrover1 288:1d85c4a4d397 37 numServices(0),
rgrover1 288:1d85c4a4d397 38 characteristicIndex(0),
rgrover1 288:1d85c4a4d397 39 numCharacteristics(0),
rgrover1 288:1d85c4a4d397 40 state(INACTIVE),
rgrover1 288:1d85c4a4d397 41 services(),
rgrover1 288:1d85c4a4d397 42 characteristics(),
rgrover1 288:1d85c4a4d397 43 onTerminationCallback(NULL) {
rgrover1 288:1d85c4a4d397 44 /* empty */
rgrover1 288:1d85c4a4d397 45 }
rgrover1 288:1d85c4a4d397 46
rgrover1 288:1d85c4a4d397 47 public:
rgrover1 260:ea2798f615e5 48 ble_error_t launchCharacteristicDiscovery(Gap::Handle_t connectionHandle, Gap::Handle_t startHandle, Gap::Handle_t endHandle);
rgrover1 239:693a1f145b5a 49
rgrover1 239:693a1f145b5a 50 public:
rgrover1 248:71ef03789dd3 51 void setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response);
rgrover1 248:71ef03789dd3 52 void setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response);
rgrover1 248:71ef03789dd3 53
rgrover1 248:71ef03789dd3 54 void terminateServiceDiscovery(void) {
rgrover1 280:cbaa4cb83548 55 bool wasActive = isActive();
rgrover1 286:042b01e59cf8 56 state = INACTIVE;
rgrover1 280:cbaa4cb83548 57
rgrover1 280:cbaa4cb83548 58 if (wasActive && onTerminationCallback) {
rgrover1 280:cbaa4cb83548 59 onTerminationCallback(connHandle);
rgrover1 280:cbaa4cb83548 60 }
rgrover1 239:693a1f145b5a 61 }
rgrover1 239:693a1f145b5a 62
rgrover1 245:3abc61d38db3 63 void terminateCharacteristicDiscovery(void) {
rgrover1 286:042b01e59cf8 64 if (state == CHARACTERISTIC_DISCOVERY_ACTIVE) {
rgrover1 286:042b01e59cf8 65 state = SERVICE_DISCOVERY_ACTIVE;
rgrover1 286:042b01e59cf8 66 }
rgrover1 245:3abc61d38db3 67 serviceIndex++; /* Progress service index to keep discovery alive. */
rgrover1 245:3abc61d38db3 68 }
rgrover1 245:3abc61d38db3 69
rgrover1 279:6e5e79f1fb61 70 bool isActive(void) const {
rgrover1 286:042b01e59cf8 71 return state != INACTIVE;
rgrover1 279:6e5e79f1fb61 72 }
rgrover1 279:6e5e79f1fb61 73
rgrover1 280:cbaa4cb83548 74 void setOnTermination(TerminationCallback_t callback) {
rgrover1 280:cbaa4cb83548 75 onTerminationCallback = callback;
rgrover1 280:cbaa4cb83548 76 }
rgrover1 280:cbaa4cb83548 77
rgrover1 260:ea2798f615e5 78 private:
rgrover1 239:693a1f145b5a 79 void resetDiscoveredServices(void) {
rgrover1 242:73fc02cc20b1 80 numServices = 0;
rgrover1 242:73fc02cc20b1 81 serviceIndex = 0;
rgrover1 239:693a1f145b5a 82 memset(services, 0, sizeof(DiscoveredService) * BLE_DB_DISCOVERY_MAX_SRV);
rgrover1 239:693a1f145b5a 83 }
rgrover1 239:693a1f145b5a 84
rgrover1 245:3abc61d38db3 85 void resetDiscoveredCharacteristics(void) {
rgrover1 245:3abc61d38db3 86 numCharacteristics = 0;
rgrover1 245:3abc61d38db3 87 characteristicIndex = 0;
rgrover1 245:3abc61d38db3 88 memset(characteristics, 0, sizeof(DiscoveredCharacteristic) * BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV);
rgrover1 245:3abc61d38db3 89 }
rgrover1 245:3abc61d38db3 90
rgrover1 245:3abc61d38db3 91 public:
rgrover1 243:a966506d1e5b 92 void serviceDiscoveryStarted(Gap::Handle_t connectionHandle) {
rgrover1 243:a966506d1e5b 93 connHandle = connectionHandle;
rgrover1 243:a966506d1e5b 94 resetDiscoveredServices();
rgrover1 286:042b01e59cf8 95 state = SERVICE_DISCOVERY_ACTIVE;
rgrover1 243:a966506d1e5b 96 }
rgrover1 243:a966506d1e5b 97
rgrover1 260:ea2798f615e5 98 private:
rgrover1 245:3abc61d38db3 99 void characteristicDiscoveryStarted(Gap::Handle_t connectionHandle) {
rgrover1 245:3abc61d38db3 100 connHandle = connectionHandle;
rgrover1 245:3abc61d38db3 101 resetDiscoveredCharacteristics();
rgrover1 286:042b01e59cf8 102 state = CHARACTERISTIC_DISCOVERY_ACTIVE;
rgrover1 245:3abc61d38db3 103 }
rgrover1 245:3abc61d38db3 104
rgrover1 251:d4e0cf5e8751 105 private:
rgrover1 251:d4e0cf5e8751 106 friend void bleGattcEventHandler(const ble_evt_t *p_ble_evt);
rgrover1 251:d4e0cf5e8751 107 void progressCharacteristicDiscovery(void);
rgrover1 251:d4e0cf5e8751 108 void progressServiceDiscovery(void);
rgrover1 239:693a1f145b5a 109
rgrover1 248:71ef03789dd3 110 private:
rgrover1 248:71ef03789dd3 111 uint8_t serviceIndex; /**< Index of the current service being discovered. This is intended for internal use during service discovery.*/
rgrover1 248:71ef03789dd3 112 uint8_t numServices; /**< Number of services at the peers GATT database.*/
rgrover1 248:71ef03789dd3 113 uint8_t characteristicIndex; /**< Index of the current characteristic being discovered. This is intended for internal use during service discovery.*/
rgrover1 248:71ef03789dd3 114 uint8_t numCharacteristics; /**< Number of characteristics within the service.*/
rgrover1 248:71ef03789dd3 115
rgrover1 286:042b01e59cf8 116 enum State_t {
rgrover1 286:042b01e59cf8 117 INACTIVE,
rgrover1 286:042b01e59cf8 118 SERVICE_DISCOVERY_ACTIVE,
rgrover1 286:042b01e59cf8 119 CHARACTERISTIC_DISCOVERY_ACTIVE,
rgrover1 286:042b01e59cf8 120 } state;
rgrover1 248:71ef03789dd3 121
rgrover1 248:71ef03789dd3 122 DiscoveredService services[BLE_DB_DISCOVERY_MAX_SRV]; /**< Information related to the current service being discovered.
rgrover1 248:71ef03789dd3 123 * This is intended for internal use during service discovery. */
rgrover1 248:71ef03789dd3 124 DiscoveredCharacteristic characteristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV];
rgrover1 280:cbaa4cb83548 125
rgrover1 280:cbaa4cb83548 126 TerminationCallback_t onTerminationCallback;
rgrover1 240:75b69581d1dd 127 };
rgrover1 240:75b69581d1dd 128
rgrover1 239:693a1f145b5a 129 #endif /*_BTLE_DISCOVERY_H_*/