bluetooth control motor

Dependents:   BLE_LED_IDB0XA1_demo MOTOR_BLE_V2 Motor_Ble_v1 Motor_Ble_v10223 ... more

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Vincent Coubard
Date:
Thu Sep 15 10:51:21 2016 +0100
Branch:
70f819844d61400a7b6772dcc911a63fc73af09e
Revision:
259:323f588e5f57
Parent:
253:9665a6f8bbdb
Child:
262:a3460768f3b7
Sync with 70f819844d61400a7b6772dcc911a63fc73af09e

2016-07-08 12:18:26+01:00: Vincent Coubard
Fix ServiceInstantiation_test_xx

Fix the last handle set for characteristics
Fix discovery order.
From a user perspective, the service tree is traversed in deep.

The previous behavior was:

for service in services:
service_callback(callback)

for characteristic in characteristics:
characteristic_callback(characteristic)

The new behavior is:

for service in services:
service_callback(callback)
for characteristic in service.characteristics:
characteristic_callback(characteristic)

Reserve the valid count of attribute records when declaring a service.
Report error when it is not possible to add a service.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Andrea Palmieri 229:9981f62cdb1a 1 /* mbed Microcontroller Library
Andrea Palmieri 229:9981f62cdb1a 2 * Copyright (c) 2006-2013 ARM Limited
Andrea Palmieri 229:9981f62cdb1a 3 *
Andrea Palmieri 229:9981f62cdb1a 4 * Licensed under the Apache License, Version 2.0 (the "License");
Andrea Palmieri 229:9981f62cdb1a 5 * you may not use this file except in compliance with the License.
Andrea Palmieri 229:9981f62cdb1a 6 * You may obtain a copy of the License at
Andrea Palmieri 229:9981f62cdb1a 7 *
Andrea Palmieri 229:9981f62cdb1a 8 * http://www.apache.org/licenses/LICENSE-2.0
Andrea Palmieri 229:9981f62cdb1a 9 *
Andrea Palmieri 229:9981f62cdb1a 10 * Unless required by applicable law or agreed to in writing, software
Andrea Palmieri 229:9981f62cdb1a 11 * distributed under the License is distributed on an "AS IS" BASIS,
Andrea Palmieri 229:9981f62cdb1a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Andrea Palmieri 229:9981f62cdb1a 13 * See the License for the specific language governing permissions and
Andrea Palmieri 229:9981f62cdb1a 14 * limitations under the License.
Andrea Palmieri 229:9981f62cdb1a 15 */
Andrea Palmieri 229:9981f62cdb1a 16 /**
Andrea Palmieri 229:9981f62cdb1a 17 ******************************************************************************
Vincent Coubard 259:323f588e5f57 18 * @file BlueNRGGattServer.cpp
Andrea Palmieri 229:9981f62cdb1a 19 * @author STMicroelectronics
Andrea Palmieri 229:9981f62cdb1a 20 * @brief Implementation of BlueNRG BLE_API GattServer Class
Andrea Palmieri 229:9981f62cdb1a 21 ******************************************************************************
Andrea Palmieri 229:9981f62cdb1a 22 * @copy
Andrea Palmieri 229:9981f62cdb1a 23 *
Andrea Palmieri 229:9981f62cdb1a 24 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Andrea Palmieri 229:9981f62cdb1a 25 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
Andrea Palmieri 229:9981f62cdb1a 26 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
Andrea Palmieri 229:9981f62cdb1a 27 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
Andrea Palmieri 229:9981f62cdb1a 28 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
Andrea Palmieri 229:9981f62cdb1a 29 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Andrea Palmieri 229:9981f62cdb1a 30 *
Andrea Palmieri 229:9981f62cdb1a 31 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
Vincent Coubard 259:323f588e5f57 32 */
Vincent Coubard 259:323f588e5f57 33
Andrea Palmieri 229:9981f62cdb1a 34 /** @defgroup BlueNRGGATTClient
Andrea Palmieri 229:9981f62cdb1a 35 * @brief BlueNRG BLE_API GattClient Adaptation
Andrea Palmieri 229:9981f62cdb1a 36 * @{
Andrea Palmieri 229:9981f62cdb1a 37 */
Vincent Coubard 259:323f588e5f57 38
Andrea Palmieri 229:9981f62cdb1a 39 #include "BlueNRGGattClient.h"
Vincent Coubard 253:9665a6f8bbdb 40 #include "mbed-drivers/mbed.h"
Andrea Palmieri 229:9981f62cdb1a 41 #include "BlueNRGGap.h"
Andrea Palmieri 229:9981f62cdb1a 42 #include "Utils.h"
Andrea Palmieri 229:9981f62cdb1a 43 #include "debug.h"
Andrea Palmieri 229:9981f62cdb1a 44
Andrea Palmieri 229:9981f62cdb1a 45 static uint8_t props_mask[] = {
Andrea Palmieri 229:9981f62cdb1a 46 0x01,
Andrea Palmieri 229:9981f62cdb1a 47 0x02,
Andrea Palmieri 229:9981f62cdb1a 48 0x04,
Andrea Palmieri 229:9981f62cdb1a 49 0x08,
Andrea Palmieri 229:9981f62cdb1a 50 0x10,
Andrea Palmieri 229:9981f62cdb1a 51 0x20,
Andrea Palmieri 229:9981f62cdb1a 52 0x40,
Andrea Palmieri 229:9981f62cdb1a 53 0x80
Andrea Palmieri 229:9981f62cdb1a 54 };
Andrea Palmieri 229:9981f62cdb1a 55
Andrea Palmieri 229:9981f62cdb1a 56 void BlueNRGGattClient::gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code)
Andrea Palmieri 229:9981f62cdb1a 57 {
Andrea Palmieri 229:9981f62cdb1a 58 if(error_code != BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 59 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 60 return;
Andrea Palmieri 229:9981f62cdb1a 61 }
Vincent Coubard 259:323f588e5f57 62
Andrea Palmieri 229:9981f62cdb1a 63 // Service Discovery complete
Andrea Palmieri 229:9981f62cdb1a 64 /*
Vincent Coubard 259:323f588e5f57 65 if(_currentState != GATT_IDLE &&
Andrea Palmieri 229:9981f62cdb1a 66 _currentState != GATT_DISCOVERY_TERMINATED &&
Andrea Palmieri 229:9981f62cdb1a 67 _currentState != GATT_WRITE_CHAR &&
Andrea Palmieri 229:9981f62cdb1a 68 _currentState != GATT_READ_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 69 */
Andrea Palmieri 229:9981f62cdb1a 70 if(_currentState == GATT_SERVICE_DISCOVERY) {
Andrea Palmieri 229:9981f62cdb1a 71 findServiceChars(connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 72 }
Andrea Palmieri 229:9981f62cdb1a 73
Andrea Palmieri 229:9981f62cdb1a 74 if(_currentState == GATT_CHAR_DESC_DISCOVERY) {
Andrea Palmieri 229:9981f62cdb1a 75 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 76 }
Andrea Palmieri 229:9981f62cdb1a 77
Andrea Palmieri 229:9981f62cdb1a 78 // Read complete
Andrea Palmieri 229:9981f62cdb1a 79 if(_currentState == GATT_READ_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 80 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 81 }
Andrea Palmieri 229:9981f62cdb1a 82
Andrea Palmieri 229:9981f62cdb1a 83 // Write complete
Andrea Palmieri 229:9981f62cdb1a 84 if(_currentState == GATT_WRITE_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 85 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 86 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 87 }
Andrea Palmieri 229:9981f62cdb1a 88 }
Vincent Coubard 259:323f588e5f57 89
Andrea Palmieri 229:9981f62cdb1a 90 void BlueNRGGattClient::primaryServicesCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 91 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 92 uint8_t attribute_data_length,
Andrea Palmieri 229:9981f62cdb1a 93 uint8_t *attribute_data_list)
Andrea Palmieri 229:9981f62cdb1a 94 {
Andrea Palmieri 229:9981f62cdb1a 95 GattAttribute::Handle_t startHandle, endHandle;
Andrea Palmieri 229:9981f62cdb1a 96 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 97 uint8_t i, offset, numAttr;
Andrea Palmieri 229:9981f62cdb1a 98 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 99 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 100
Andrea Palmieri 229:9981f62cdb1a 101 numAttr = (event_data_length - 1) / attribute_data_length;
Andrea Palmieri 229:9981f62cdb1a 102
Andrea Palmieri 229:9981f62cdb1a 103 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 104 for (i=0; i<numAttr; i++) {
Andrea Palmieri 229:9981f62cdb1a 105 startHandle = attribute_data_list[offset];
Andrea Palmieri 229:9981f62cdb1a 106 endHandle = attribute_data_list[offset+2];
Andrea Palmieri 229:9981f62cdb1a 107
Andrea Palmieri 229:9981f62cdb1a 108 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 109 if (attribute_data_length == 6) {
Vincent Coubard 259:323f588e5f57 110
Andrea Palmieri 229:9981f62cdb1a 111 PRINTF("UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 112 uuid = attribute_data_list[offset+5]<<8|attribute_data_list[offset+4];
Andrea Palmieri 229:9981f62cdb1a 113 PRINTF("S UUID-%X attrs[%u %u]\r\n", uuid.getShortUUID(), startHandle, endHandle);
Vincent Coubard 259:323f588e5f57 114
Andrea Palmieri 229:9981f62cdb1a 115 } else {
Vincent Coubard 259:323f588e5f57 116
Andrea Palmieri 229:9981f62cdb1a 117 PRINTF("UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 118 uuid.setupLong(attribute_data_list+offset+4, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 119
Andrea Palmieri 229:9981f62cdb1a 120 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 121 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 122 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 123 for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) {
Andrea Palmieri 229:9981f62cdb1a 124 PRINTF("%02x", longUUIDBytes[j]);
Andrea Palmieri 229:9981f62cdb1a 125 }
Andrea Palmieri 229:9981f62cdb1a 126 #endif
Andrea Palmieri 229:9981f62cdb1a 127 PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle);
Vincent Coubard 259:323f588e5f57 128
Andrea Palmieri 229:9981f62cdb1a 129 }
Vincent Coubard 259:323f588e5f57 130
Andrea Palmieri 229:9981f62cdb1a 131 PRINTF("Setup serviceIndex = %d\n\r", _numServices);
Andrea Palmieri 229:9981f62cdb1a 132 discoveredService[_numServices].setup(uuid, startHandle, endHandle);
Vincent Coubard 259:323f588e5f57 133
Andrea Palmieri 229:9981f62cdb1a 134 _numServices++;
Andrea Palmieri 229:9981f62cdb1a 135
Andrea Palmieri 229:9981f62cdb1a 136 offset += attribute_data_length;
Andrea Palmieri 229:9981f62cdb1a 137 }
Andrea Palmieri 229:9981f62cdb1a 138
Andrea Palmieri 229:9981f62cdb1a 139 PRINTF("!!!Service Discovery complete (numAttr=%u)!!!\n\r", numAttr);
Andrea Palmieri 229:9981f62cdb1a 140
Andrea Palmieri 229:9981f62cdb1a 141 }
Andrea Palmieri 229:9981f62cdb1a 142
Andrea Palmieri 229:9981f62cdb1a 143 void BlueNRGGattClient::primaryServiceCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 144 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 145 uint8_t *handles_info_list)
Andrea Palmieri 229:9981f62cdb1a 146 {
Andrea Palmieri 229:9981f62cdb1a 147 GattAttribute::Handle_t startHandle, endHandle;
Andrea Palmieri 229:9981f62cdb1a 148 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 149 uint8_t i, offset, numHandlePairs;
Andrea Palmieri 229:9981f62cdb1a 150 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 151 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 152
Andrea Palmieri 229:9981f62cdb1a 153 numHandlePairs = (event_data_length - 1) / 2;
Andrea Palmieri 229:9981f62cdb1a 154
Andrea Palmieri 229:9981f62cdb1a 155 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 156 for (i=0; i<numHandlePairs; i++) {
Andrea Palmieri 229:9981f62cdb1a 157 startHandle = handles_info_list[offset];
Andrea Palmieri 229:9981f62cdb1a 158 endHandle = handles_info_list[offset+2];
Andrea Palmieri 229:9981f62cdb1a 159
Andrea Palmieri 229:9981f62cdb1a 160 PRINTF("primaryServiceCB attrs[%u %u]\r\n", startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 161
Andrea Palmieri 229:9981f62cdb1a 162
Andrea Palmieri 229:9981f62cdb1a 163 if (_matchingServiceUUID.shortOrLong() == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 164 PRINTF("S UUID-%x attrs[%u %u]\r\n", _matchingServiceUUID.getShortUUID(), startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 165 uuid = _matchingServiceUUID.getShortUUID();
Andrea Palmieri 229:9981f62cdb1a 166 } else {
Andrea Palmieri 229:9981f62cdb1a 167 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 168 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 169 const uint8_t *longUUIDBytes = _matchingServiceUUID.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 170 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 171 PRINTF("%02x", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 172 }
Andrea Palmieri 229:9981f62cdb1a 173 #endif
Andrea Palmieri 229:9981f62cdb1a 174 PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 175 uuid.setupLong(_matchingServiceUUID.getBaseUUID(), UUID::MSB);
Andrea Palmieri 229:9981f62cdb1a 176 }
Andrea Palmieri 229:9981f62cdb1a 177
Andrea Palmieri 229:9981f62cdb1a 178 discoveredService[i].setup(uuid, startHandle, endHandle);
Vincent Coubard 259:323f588e5f57 179
Andrea Palmieri 229:9981f62cdb1a 180 _numServices++;
Vincent Coubard 259:323f588e5f57 181
Andrea Palmieri 229:9981f62cdb1a 182 offset += 4;
Andrea Palmieri 229:9981f62cdb1a 183 }
Andrea Palmieri 229:9981f62cdb1a 184 }
Andrea Palmieri 229:9981f62cdb1a 185
Andrea Palmieri 229:9981f62cdb1a 186 void BlueNRGGattClient::serviceCharsCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 187 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 188 uint8_t handle_value_pair_length,
Andrea Palmieri 229:9981f62cdb1a 189 uint8_t *handle_value_pair)
Andrea Palmieri 229:9981f62cdb1a 190 {
Andrea Palmieri 229:9981f62cdb1a 191 // Charac Handle (2), Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16)
Andrea Palmieri 229:9981f62cdb1a 192
Andrea Palmieri 229:9981f62cdb1a 193 GattAttribute::Handle_t declHandle, valueHandle, lastHandle;
Andrea Palmieri 229:9981f62cdb1a 194 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 195 uint8_t i, numChar, offset;
Andrea Palmieri 229:9981f62cdb1a 196
Andrea Palmieri 229:9981f62cdb1a 197 numChar = (event_data_length - 1) / handle_value_pair_length;
Andrea Palmieri 229:9981f62cdb1a 198
Andrea Palmieri 229:9981f62cdb1a 199 PRINTF("event_data_length=%d handle_value_pair_length=%d numChar=%d\n\r", event_data_length, handle_value_pair_length, numChar);
Andrea Palmieri 229:9981f62cdb1a 200
Andrea Palmieri 229:9981f62cdb1a 201 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 202 for (i=0; i<numChar; i++) {
Andrea Palmieri 229:9981f62cdb1a 203 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 204 if (handle_value_pair_length == 7) {
Andrea Palmieri 229:9981f62cdb1a 205 PRINTF("Char UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 206 uuid = handle_value_pair[offset+6]<<8|handle_value_pair[offset+5];
Andrea Palmieri 229:9981f62cdb1a 207 PRINTF("C UUID-%X\r\n", uuid.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 208 } else {
Andrea Palmieri 229:9981f62cdb1a 209 PRINTF("Char UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 210 uuid.setupLong(handle_value_pair+offset+5, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 211 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 212 PRINTF("C UUID-");
Andrea Palmieri 229:9981f62cdb1a 213 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 214 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 215 PRINTF("%02X", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 216 }
Andrea Palmieri 229:9981f62cdb1a 217 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 218 #endif
Andrea Palmieri 229:9981f62cdb1a 219 }
Vincent Coubard 259:323f588e5f57 220
Andrea Palmieri 229:9981f62cdb1a 221 // Properties
Andrea Palmieri 229:9981f62cdb1a 222 DiscoveredCharacteristic::Properties_t p;
Vincent Coubard 259:323f588e5f57 223
Andrea Palmieri 229:9981f62cdb1a 224 p._broadcast = (props_mask[0] & handle_value_pair[offset+2]);
Andrea Palmieri 229:9981f62cdb1a 225 p._read = (props_mask[1] & handle_value_pair[offset+2])>>1;
Andrea Palmieri 229:9981f62cdb1a 226 p._writeWoResp = (props_mask[2] & handle_value_pair[offset+2])>>2;
Andrea Palmieri 229:9981f62cdb1a 227 p._write = (props_mask[3] & handle_value_pair[offset+2])>>3;
Andrea Palmieri 229:9981f62cdb1a 228 p._notify = (props_mask[4] & handle_value_pair[offset+2])>>4;
Andrea Palmieri 229:9981f62cdb1a 229 p._indicate = (props_mask[5] & handle_value_pair[offset+2])>>5;
Andrea Palmieri 229:9981f62cdb1a 230 p._authSignedWrite = (props_mask[6] & handle_value_pair[offset+2])>>6;
Andrea Palmieri 229:9981f62cdb1a 231 PRINTF("p._broadcast=%d\n\r", p._broadcast);
Andrea Palmieri 229:9981f62cdb1a 232 PRINTF("p._read=%d\n\r", p._read);
Andrea Palmieri 229:9981f62cdb1a 233 PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp);
Andrea Palmieri 229:9981f62cdb1a 234 PRINTF("p._write=%d\n\r", p._write);
Andrea Palmieri 229:9981f62cdb1a 235 PRINTF("p._notify=%d\n\r", p._notify);
Andrea Palmieri 229:9981f62cdb1a 236 PRINTF("p._indicate=%d\n\r", p._indicate);
Andrea Palmieri 229:9981f62cdb1a 237 PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite);
Andrea Palmieri 229:9981f62cdb1a 238
Andrea Palmieri 229:9981f62cdb1a 239 /*
Andrea Palmieri 229:9981f62cdb1a 240 uint8_t props = handle_value_pair[offset+2];
Andrea Palmieri 229:9981f62cdb1a 241 PRINTF("CHAR PROPS: %d\n\r", props);
Andrea Palmieri 229:9981f62cdb1a 242 */
Andrea Palmieri 229:9981f62cdb1a 243
Andrea Palmieri 229:9981f62cdb1a 244 // Handles
Andrea Palmieri 229:9981f62cdb1a 245 declHandle = handle_value_pair[offset];
Andrea Palmieri 229:9981f62cdb1a 246 valueHandle = handle_value_pair[offset+3];
Andrea Palmieri 229:9981f62cdb1a 247 lastHandle = valueHandle+1;
Andrea Palmieri 229:9981f62cdb1a 248 PRINTF("declHandle: %u valueHandle=%u lastHandle=%u\n\r", declHandle, valueHandle, lastHandle);
Andrea Palmieri 229:9981f62cdb1a 249
Andrea Palmieri 229:9981f62cdb1a 250 discoveredChar[_numChars].setup(this,
Andrea Palmieri 229:9981f62cdb1a 251 connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 252 uuid,
Andrea Palmieri 229:9981f62cdb1a 253 p,
Andrea Palmieri 229:9981f62cdb1a 254 declHandle,
Andrea Palmieri 229:9981f62cdb1a 255 valueHandle,
Andrea Palmieri 229:9981f62cdb1a 256 lastHandle);
Andrea Palmieri 229:9981f62cdb1a 257
Vincent Coubard 259:323f588e5f57 258 if (_numChars != 0) {
Vincent Coubard 259:323f588e5f57 259 discoveredChar[_numChars - 1].setLastHandle(declHandle - 1);
Vincent Coubard 259:323f588e5f57 260
Vincent Coubard 259:323f588e5f57 261 if(characteristicDiscoveryCallback) {
Vincent Coubard 259:323f588e5f57 262 characteristicDiscoveryCallback(&discoveredChar[_numChars - 1]);
Vincent Coubard 259:323f588e5f57 263 }
Andrea Palmieri 229:9981f62cdb1a 264 }
Vincent Coubard 259:323f588e5f57 265
Andrea Palmieri 229:9981f62cdb1a 266 _numChars++;
Andrea Palmieri 229:9981f62cdb1a 267
Andrea Palmieri 229:9981f62cdb1a 268 offset += handle_value_pair_length;
Andrea Palmieri 229:9981f62cdb1a 269 }
Andrea Palmieri 229:9981f62cdb1a 270 }
Andrea Palmieri 229:9981f62cdb1a 271
Andrea Palmieri 229:9981f62cdb1a 272 void BlueNRGGattClient::serviceCharByUUIDCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 273 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 274 uint16_t attr_handle,
Andrea Palmieri 229:9981f62cdb1a 275 uint8_t *attr_value)
Andrea Palmieri 229:9981f62cdb1a 276 {
Andrea Palmieri 229:9981f62cdb1a 277 // Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16)
Andrea Palmieri 229:9981f62cdb1a 278 GattAttribute::Handle_t declHandle, valueHandle, lastHandle;
Andrea Palmieri 229:9981f62cdb1a 279 UUID uuid;
Vincent Coubard 259:323f588e5f57 280
Andrea Palmieri 229:9981f62cdb1a 281 PRINTF("serviceCharByUUIDCB\n\r");
Vincent Coubard 259:323f588e5f57 282
Andrea Palmieri 229:9981f62cdb1a 283 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 284 if (event_data_length == 7) {
Andrea Palmieri 229:9981f62cdb1a 285 PRINTF("Char UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 286 uuid = attr_value[4]<<8|attr_value[3];
Andrea Palmieri 229:9981f62cdb1a 287 PRINTF("C UUID-%X\r\n", uuid.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 288 } else {
Andrea Palmieri 229:9981f62cdb1a 289 PRINTF("Char UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 290 uuid.setupLong(attr_value+3, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 291 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 292 PRINTF("C UUID-");
Andrea Palmieri 229:9981f62cdb1a 293 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 294 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 295 PRINTF("%02X", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 296 }
Andrea Palmieri 229:9981f62cdb1a 297 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 298 #endif
Andrea Palmieri 229:9981f62cdb1a 299 }
Andrea Palmieri 229:9981f62cdb1a 300
Andrea Palmieri 229:9981f62cdb1a 301 // Properties
Andrea Palmieri 229:9981f62cdb1a 302 DiscoveredCharacteristic::Properties_t p;
Vincent Coubard 259:323f588e5f57 303
Andrea Palmieri 229:9981f62cdb1a 304 p._broadcast = (props_mask[0] & attr_value[0]);
Andrea Palmieri 229:9981f62cdb1a 305 p._read = (props_mask[1] & attr_value[0])>>1;
Andrea Palmieri 229:9981f62cdb1a 306 p._writeWoResp = (props_mask[2] & attr_value[0])>>2;
Andrea Palmieri 229:9981f62cdb1a 307 p._write = (props_mask[3] & attr_value[0])>>3;
Andrea Palmieri 229:9981f62cdb1a 308 p._notify = (props_mask[4] & attr_value[0])>>4;
Andrea Palmieri 229:9981f62cdb1a 309 p._indicate = (props_mask[5] & attr_value[0])>>5;
Andrea Palmieri 229:9981f62cdb1a 310 p._authSignedWrite = (props_mask[6] & attr_value[0])>>6;
Andrea Palmieri 229:9981f62cdb1a 311 PRINTF("p._broadcast=%d\n\r", p._broadcast);
Andrea Palmieri 229:9981f62cdb1a 312 PRINTF("p._read=%d\n\r", p._read);
Andrea Palmieri 229:9981f62cdb1a 313 PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp);
Andrea Palmieri 229:9981f62cdb1a 314 PRINTF("p._write=%d\n\r", p._write);
Andrea Palmieri 229:9981f62cdb1a 315 PRINTF("p._notify=%d\n\r", p._notify);
Andrea Palmieri 229:9981f62cdb1a 316 PRINTF("p._indicate=%d\n\r", p._indicate);
Andrea Palmieri 229:9981f62cdb1a 317 PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite);
Andrea Palmieri 229:9981f62cdb1a 318
Andrea Palmieri 229:9981f62cdb1a 319 /*
Andrea Palmieri 229:9981f62cdb1a 320 uint8_t props = attr_value[0];
Andrea Palmieri 229:9981f62cdb1a 321 PRINTF("CHAR PROPS: %d\n\r", props);
Andrea Palmieri 229:9981f62cdb1a 322 */
Andrea Palmieri 229:9981f62cdb1a 323
Andrea Palmieri 229:9981f62cdb1a 324 // Handles
Andrea Palmieri 229:9981f62cdb1a 325 declHandle = attr_handle;
Andrea Palmieri 229:9981f62cdb1a 326 valueHandle = attr_value[1];
Andrea Palmieri 229:9981f62cdb1a 327 lastHandle = valueHandle+1;
Andrea Palmieri 229:9981f62cdb1a 328
Andrea Palmieri 229:9981f62cdb1a 329 discoveredChar[_numChars].setup(this,
Andrea Palmieri 229:9981f62cdb1a 330 connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 331 uuid,
Andrea Palmieri 229:9981f62cdb1a 332 p,
Andrea Palmieri 229:9981f62cdb1a 333 declHandle,
Andrea Palmieri 229:9981f62cdb1a 334 valueHandle,
Andrea Palmieri 229:9981f62cdb1a 335 lastHandle);
Vincent Coubard 259:323f588e5f57 336
Andrea Palmieri 229:9981f62cdb1a 337 if(characteristicDiscoveryCallback) {
Andrea Palmieri 229:9981f62cdb1a 338 characteristicDiscoveryCallback(&discoveredChar[_numChars]);
Andrea Palmieri 229:9981f62cdb1a 339 }
Andrea Palmieri 229:9981f62cdb1a 340 _numChars++;
Andrea Palmieri 229:9981f62cdb1a 341 }
Andrea Palmieri 229:9981f62cdb1a 342
Andrea Palmieri 229:9981f62cdb1a 343 ble_error_t BlueNRGGattClient::findServiceChars(Gap::Handle_t connectionHandle)
Andrea Palmieri 229:9981f62cdb1a 344 {
Andrea Palmieri 229:9981f62cdb1a 345 PRINTF("findServiceChars\n\r");
Vincent Coubard 259:323f588e5f57 346
Andrea Palmieri 229:9981f62cdb1a 347 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 348 uint8_t uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 349 uint8_t short_uuid[2];
Andrea Palmieri 229:9981f62cdb1a 350 uint8_t *uuid = NULL;
Vincent Coubard 259:323f588e5f57 351
Andrea Palmieri 229:9981f62cdb1a 352 DiscoveredService *service;
Vincent Coubard 259:323f588e5f57 353
Vincent Coubard 259:323f588e5f57 354 // complete the discovery of the last characteristic of the previous service.
Vincent Coubard 259:323f588e5f57 355 // Its last handle wasn't known before this point
Vincent Coubard 259:323f588e5f57 356 // update the handle and call the characteristic discovery callback.
Vincent Coubard 259:323f588e5f57 357 if (_servIndex != 0 && _numChars != 0) {
Vincent Coubard 259:323f588e5f57 358 discoveredChar[_numChars - 1].setLastHandle(discoveredService[_servIndex - 1].getEndHandle());
Vincent Coubard 259:323f588e5f57 359
Vincent Coubard 259:323f588e5f57 360 if(characteristicDiscoveryCallback) {
Vincent Coubard 259:323f588e5f57 361 characteristicDiscoveryCallback(&discoveredChar[_numChars - 1]);
Vincent Coubard 259:323f588e5f57 362 }
Vincent Coubard 259:323f588e5f57 363 }
Vincent Coubard 259:323f588e5f57 364
Vincent Coubard 259:323f588e5f57 365 _numChars = 0;
Vincent Coubard 259:323f588e5f57 366
Andrea Palmieri 229:9981f62cdb1a 367 // We finished chars discovery for all services
Andrea Palmieri 229:9981f62cdb1a 368 if(_servIndex >= _numServices) {
Andrea Palmieri 229:9981f62cdb1a 369 PRINTF("!!!We finished chars discovery for all services!!!\n\r");
Andrea Palmieri 229:9981f62cdb1a 370 //_currentState = GATT_CHARS_DISCOVERY_COMPLETE;
Vincent Coubard 259:323f588e5f57 371
Andrea Palmieri 229:9981f62cdb1a 372 terminateServiceDiscovery();
Vincent Coubard 259:323f588e5f57 373
Andrea Palmieri 229:9981f62cdb1a 374 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 375 }
Vincent Coubard 259:323f588e5f57 376
Andrea Palmieri 229:9981f62cdb1a 377 service = &discoveredService[_servIndex];
Andrea Palmieri 229:9981f62cdb1a 378 /*
Andrea Palmieri 229:9981f62cdb1a 379 if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 380 PRINTF("S UUID-%X\r\n", service->getUUID().getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 381 } else {
Andrea Palmieri 229:9981f62cdb1a 382 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 383 const uint8_t *longUUIDBytes = service->getUUID().getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 384 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 385 PRINTF("%02X", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 386 }
Andrea Palmieri 229:9981f62cdb1a 387 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 388 }
Andrea Palmieri 229:9981f62cdb1a 389 */
Vincent Coubard 259:323f588e5f57 390
Vincent Coubard 259:323f588e5f57 391 if(serviceDiscoveryCallback) {
Vincent Coubard 259:323f588e5f57 392 serviceDiscoveryCallback(service);
Vincent Coubard 259:323f588e5f57 393 }
Vincent Coubard 259:323f588e5f57 394
Andrea Palmieri 229:9981f62cdb1a 395 PRINTF("findServiceChars (_servIndex=%d)\n\r", _servIndex);
Andrea Palmieri 229:9981f62cdb1a 396 //ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle());
Andrea Palmieri 229:9981f62cdb1a 397
Vincent Coubard 259:323f588e5f57 398 if(_matchingCharacteristicUUIDIn == BLE_UUID_UNKNOWN) {
Vincent Coubard 259:323f588e5f57 399 PRINTF("findServiceChars (BLE_UUID_UNKNOWN)\n\r");
Vincent Coubard 259:323f588e5f57 400 ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle());
Vincent Coubard 259:323f588e5f57 401 } else {
Vincent Coubard 259:323f588e5f57 402
Vincent Coubard 259:323f588e5f57 403 uint8_t type = _matchingCharacteristicUUIDIn.shortOrLong();
Vincent Coubard 259:323f588e5f57 404
Vincent Coubard 259:323f588e5f57 405 if(type == UUID::UUID_TYPE_SHORT) {
Vincent Coubard 259:323f588e5f57 406 STORE_LE_16(short_uuid, _matchingCharacteristicUUIDIn.getShortUUID());
Vincent Coubard 259:323f588e5f57 407
Vincent Coubard 259:323f588e5f57 408 uuid_type = UUID_TYPE_16;
Vincent Coubard 259:323f588e5f57 409 uuid = short_uuid;
Andrea Palmieri 229:9981f62cdb1a 410 #ifdef DEBUG
Vincent Coubard 259:323f588e5f57 411 PRINTF("findServiceChars C UUID-");
Vincent Coubard 259:323f588e5f57 412 for(unsigned i = 0; i < 2; i++) {
Vincent Coubard 259:323f588e5f57 413 PRINTF("%02X", short_uuid[i]);
Vincent Coubard 259:323f588e5f57 414 }
Vincent Coubard 259:323f588e5f57 415 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 416 #endif
Vincent Coubard 259:323f588e5f57 417 } else if(type==UUID::UUID_TYPE_LONG) {
Vincent Coubard 259:323f588e5f57 418
Vincent Coubard 259:323f588e5f57 419 uuid_type = UUID_TYPE_128;
Vincent Coubard 259:323f588e5f57 420 uuid = (unsigned char*)_matchingCharacteristicUUIDIn.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 421 #ifdef DEBUG
Vincent Coubard 259:323f588e5f57 422 PRINTF("(findServiceChars) C UUID-");
Vincent Coubard 259:323f588e5f57 423 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Vincent Coubard 259:323f588e5f57 424 PRINTF("%02X", uuid[i]);
Vincent Coubard 259:323f588e5f57 425 }
Vincent Coubard 259:323f588e5f57 426 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 427 #endif
Vincent Coubard 259:323f588e5f57 428 }
Vincent Coubard 259:323f588e5f57 429
Vincent Coubard 259:323f588e5f57 430 ret = aci_gatt_disc_charac_by_uuid(connectionHandle,
Vincent Coubard 259:323f588e5f57 431 service->getStartHandle(),
Vincent Coubard 259:323f588e5f57 432 service->getEndHandle(),
Vincent Coubard 259:323f588e5f57 433 uuid_type,
Vincent Coubard 259:323f588e5f57 434 uuid);
Andrea Palmieri 229:9981f62cdb1a 435 }
Andrea Palmieri 229:9981f62cdb1a 436
Andrea Palmieri 229:9981f62cdb1a 437 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 438 _servIndex++;
Andrea Palmieri 229:9981f62cdb1a 439 }
Vincent Coubard 259:323f588e5f57 440
Andrea Palmieri 229:9981f62cdb1a 441 PRINTF("findServiceChars ret=%d\n\r", ret);
Vincent Coubard 259:323f588e5f57 442
Andrea Palmieri 229:9981f62cdb1a 443 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 444 }
Andrea Palmieri 229:9981f62cdb1a 445
Andrea Palmieri 229:9981f62cdb1a 446 ble_error_t BlueNRGGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 447 ServiceDiscovery::ServiceCallback_t sc,
Andrea Palmieri 229:9981f62cdb1a 448 ServiceDiscovery::CharacteristicCallback_t cc,
Andrea Palmieri 229:9981f62cdb1a 449 const UUID &matchingServiceUUID,
Andrea Palmieri 229:9981f62cdb1a 450 const UUID &matchingCharacteristicUUIDIn)
Andrea Palmieri 229:9981f62cdb1a 451 {
Andrea Palmieri 229:9981f62cdb1a 452 PRINTF("launchServiceDiscovery\n\r");
Vincent Coubard 259:323f588e5f57 453
Andrea Palmieri 229:9981f62cdb1a 454 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 455 uint8_t uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 456 uint8_t short_uuid[2];
Andrea Palmieri 229:9981f62cdb1a 457 uint8_t *uuid = NULL;
Andrea Palmieri 229:9981f62cdb1a 458 unsigned j;
Andrea Palmieri 229:9981f62cdb1a 459
Andrea Palmieri 229:9981f62cdb1a 460 if(isServiceDiscoveryActive()) {
Andrea Palmieri 229:9981f62cdb1a 461 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 462 }
Andrea Palmieri 229:9981f62cdb1a 463
Andrea Palmieri 229:9981f62cdb1a 464 if(!sc && !cc) {
Andrea Palmieri 229:9981f62cdb1a 465 // nothing to do
Andrea Palmieri 229:9981f62cdb1a 466 PRINTF("launchServiceDiscovery: nothing to do\n\r");
Andrea Palmieri 229:9981f62cdb1a 467 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 468 }
Andrea Palmieri 229:9981f62cdb1a 469
Andrea Palmieri 229:9981f62cdb1a 470 _connectionHandle = connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 471 serviceDiscoveryCallback = sc;
Andrea Palmieri 229:9981f62cdb1a 472 characteristicDiscoveryCallback = cc;
Andrea Palmieri 229:9981f62cdb1a 473 _matchingServiceUUID = matchingServiceUUID;
Andrea Palmieri 229:9981f62cdb1a 474 _matchingCharacteristicUUIDIn = matchingCharacteristicUUIDIn;
Andrea Palmieri 229:9981f62cdb1a 475
Andrea Palmieri 229:9981f62cdb1a 476 //reset services
Andrea Palmieri 229:9981f62cdb1a 477 _numServices = 0;
Andrea Palmieri 229:9981f62cdb1a 478 _numChars = 0;
Andrea Palmieri 229:9981f62cdb1a 479 _servIndex = 0;
Andrea Palmieri 229:9981f62cdb1a 480 for(j = 0; j < BLE_TOTAL_DISCOVERED_SERVICES; j++) {
Andrea Palmieri 229:9981f62cdb1a 481 discoveredService[j].setup(BLE_UUID_UNKNOWN, GattAttribute::INVALID_HANDLE, GattAttribute::INVALID_HANDLE);
Andrea Palmieri 229:9981f62cdb1a 482 }
Vincent Coubard 259:323f588e5f57 483
Andrea Palmieri 229:9981f62cdb1a 484 if(matchingServiceUUID == BLE_UUID_UNKNOWN) {
Vincent Coubard 259:323f588e5f57 485
Andrea Palmieri 229:9981f62cdb1a 486 // Wildcard: search for all services
Andrea Palmieri 229:9981f62cdb1a 487 ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle);
Vincent Coubard 259:323f588e5f57 488
Andrea Palmieri 229:9981f62cdb1a 489 } else {
Vincent Coubard 259:323f588e5f57 490
Andrea Palmieri 229:9981f62cdb1a 491 uint8_t type = matchingServiceUUID.shortOrLong();
Andrea Palmieri 229:9981f62cdb1a 492 //PRINTF("AddService(): Type:%d\n\r", type);
Vincent Coubard 259:323f588e5f57 493
Andrea Palmieri 229:9981f62cdb1a 494 if(type == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 495 STORE_LE_16(short_uuid, matchingServiceUUID.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 496 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 497 PRINTF("launchServiceDiscovery short_uuid=0x");
Andrea Palmieri 229:9981f62cdb1a 498 for(j = 0; j < 2; j++) {
Andrea Palmieri 229:9981f62cdb1a 499 PRINTF("%02X", short_uuid[j]);
Andrea Palmieri 229:9981f62cdb1a 500 }
Andrea Palmieri 229:9981f62cdb1a 501 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 502 #endif
Vincent Coubard 259:323f588e5f57 503
Andrea Palmieri 229:9981f62cdb1a 504 uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 505 uuid = short_uuid;
Vincent Coubard 259:323f588e5f57 506
Andrea Palmieri 229:9981f62cdb1a 507 } else if(type==UUID::UUID_TYPE_LONG) {
Andrea Palmieri 229:9981f62cdb1a 508
Andrea Palmieri 229:9981f62cdb1a 509 uuid_type = UUID_TYPE_128;
Andrea Palmieri 229:9981f62cdb1a 510 uuid = (unsigned char*)matchingServiceUUID.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 511
Andrea Palmieri 229:9981f62cdb1a 512 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 513 PRINTF("launchServiceDiscovery base_uuid=0x");
Andrea Palmieri 229:9981f62cdb1a 514 for(j = 0; j < 16; j++) {
Andrea Palmieri 229:9981f62cdb1a 515 PRINTF("%02X", uuid[j]);
Andrea Palmieri 229:9981f62cdb1a 516 }
Andrea Palmieri 229:9981f62cdb1a 517 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 518 #endif
Andrea Palmieri 229:9981f62cdb1a 519 }
Vincent Coubard 259:323f588e5f57 520
Andrea Palmieri 229:9981f62cdb1a 521 // search for specific service by UUID
Andrea Palmieri 229:9981f62cdb1a 522 ret = aci_gatt_disc_prim_service_by_uuid((uint16_t)connectionHandle, uuid_type, uuid);
Andrea Palmieri 229:9981f62cdb1a 523 //ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 524 }
Vincent Coubard 259:323f588e5f57 525
Andrea Palmieri 229:9981f62cdb1a 526 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 527 _currentState = GATT_SERVICE_DISCOVERY;
Andrea Palmieri 229:9981f62cdb1a 528 }
Vincent Coubard 259:323f588e5f57 529
Andrea Palmieri 229:9981f62cdb1a 530 PRINTF("launchServiceDiscovery ret=%d\n\r", ret);
Vincent Coubard 259:323f588e5f57 531
Andrea Palmieri 229:9981f62cdb1a 532 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 533 }
Andrea Palmieri 229:9981f62cdb1a 534
Andrea Palmieri 229:9981f62cdb1a 535 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 536 ServiceDiscovery::ServiceCallback_t callback,
Andrea Palmieri 229:9981f62cdb1a 537 const UUID &matchingServiceUUID)
Andrea Palmieri 229:9981f62cdb1a 538 {
Andrea Palmieri 229:9981f62cdb1a 539 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 540 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 541 (void)callback;
Andrea Palmieri 229:9981f62cdb1a 542 (void)matchingServiceUUID;
Andrea Palmieri 229:9981f62cdb1a 543
Andrea Palmieri 229:9981f62cdb1a 544 return BLE_ERROR_NOT_IMPLEMENTED;
Andrea Palmieri 229:9981f62cdb1a 545 }
Andrea Palmieri 229:9981f62cdb1a 546
Andrea Palmieri 229:9981f62cdb1a 547 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 548 ServiceDiscovery::ServiceCallback_t callback,
Andrea Palmieri 229:9981f62cdb1a 549 GattAttribute::Handle_t startHandle,
Andrea Palmieri 229:9981f62cdb1a 550 GattAttribute::Handle_t endHandle)
Andrea Palmieri 229:9981f62cdb1a 551 {
Andrea Palmieri 229:9981f62cdb1a 552 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 553 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 554 (void)callback;
Andrea Palmieri 229:9981f62cdb1a 555 (void)startHandle;
Andrea Palmieri 229:9981f62cdb1a 556 (void)endHandle;
Andrea Palmieri 229:9981f62cdb1a 557
Andrea Palmieri 229:9981f62cdb1a 558 return BLE_ERROR_NOT_IMPLEMENTED;
Andrea Palmieri 229:9981f62cdb1a 559 }
Andrea Palmieri 229:9981f62cdb1a 560
Andrea Palmieri 229:9981f62cdb1a 561 bool BlueNRGGattClient::isServiceDiscoveryActive(void) const
Andrea Palmieri 229:9981f62cdb1a 562 {
Andrea Palmieri 229:9981f62cdb1a 563 if(_currentState == GATT_SERVICE_DISCOVERY) {
Andrea Palmieri 229:9981f62cdb1a 564 return true;
Andrea Palmieri 229:9981f62cdb1a 565 }
Andrea Palmieri 229:9981f62cdb1a 566
Andrea Palmieri 229:9981f62cdb1a 567 return false;
Andrea Palmieri 229:9981f62cdb1a 568 /*
Andrea Palmieri 229:9981f62cdb1a 569 if(_currentState == GATT_IDLE ||
Andrea Palmieri 229:9981f62cdb1a 570 _currentState == GATT_DISCOVERY_TERMINATED ||
Andrea Palmieri 229:9981f62cdb1a 571 _currentState == GATT_READ_CHAR ||
Andrea Palmieri 229:9981f62cdb1a 572 _currentState == GATT_WRITE_CHAR ) {
Andrea Palmieri 229:9981f62cdb1a 573 return false;
Andrea Palmieri 229:9981f62cdb1a 574 }
Vincent Coubard 259:323f588e5f57 575
Andrea Palmieri 229:9981f62cdb1a 576 return true;
Andrea Palmieri 229:9981f62cdb1a 577 */
Andrea Palmieri 229:9981f62cdb1a 578 }
Andrea Palmieri 229:9981f62cdb1a 579
Andrea Palmieri 229:9981f62cdb1a 580 void BlueNRGGattClient::terminateServiceDiscovery(void)
Andrea Palmieri 229:9981f62cdb1a 581 {
Andrea Palmieri 229:9981f62cdb1a 582 _currentState = GATT_IDLE;//GATT_DISCOVERY_TERMINATED;
Vincent Coubard 259:323f588e5f57 583
Andrea Palmieri 229:9981f62cdb1a 584 if (terminationCallback) {
Andrea Palmieri 229:9981f62cdb1a 585 terminationCallback(_connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 586 }
Andrea Palmieri 229:9981f62cdb1a 587 }
Andrea Palmieri 229:9981f62cdb1a 588
Andrea Palmieri 229:9981f62cdb1a 589 void BlueNRGGattClient::charReadCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 590 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 591 uint8_t* attribute_value)
Andrea Palmieri 229:9981f62cdb1a 592 {
Andrea Palmieri 229:9981f62cdb1a 593 readCBParams.connHandle = connHandle;
Andrea Palmieri 229:9981f62cdb1a 594 readCBParams.offset = 0;
Andrea Palmieri 229:9981f62cdb1a 595 readCBParams.len = event_data_length;
Andrea Palmieri 229:9981f62cdb1a 596 readCBParams.data = attribute_value;
Andrea Palmieri 229:9981f62cdb1a 597
Andrea Palmieri 229:9981f62cdb1a 598 BlueNRGGattClient::getInstance().processReadResponse(&readCBParams);
Andrea Palmieri 229:9981f62cdb1a 599 }
Andrea Palmieri 229:9981f62cdb1a 600
Andrea Palmieri 229:9981f62cdb1a 601 ble_error_t BlueNRGGattClient::read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const
Andrea Palmieri 229:9981f62cdb1a 602 {
Andrea Palmieri 229:9981f62cdb1a 603 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 604 (void)offset;
Andrea Palmieri 229:9981f62cdb1a 605
Andrea Palmieri 229:9981f62cdb1a 606 tBleStatus ret;
Vincent Coubard 259:323f588e5f57 607
Andrea Palmieri 229:9981f62cdb1a 608 BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this);
Vincent Coubard 259:323f588e5f57 609
Vincent Coubard 259:323f588e5f57 610 // Save the attribute_handle not provided by evt_att_read_resp
Andrea Palmieri 229:9981f62cdb1a 611 gattc->readCBParams.handle = attributeHandle;
Vincent Coubard 259:323f588e5f57 612
Andrea Palmieri 229:9981f62cdb1a 613 // FIXME: We need to wait for a while before starting a read
Andrea Palmieri 229:9981f62cdb1a 614 // due to BlueNRG process queue handling
Andrea Palmieri 229:9981f62cdb1a 615 Clock_Wait(100);
Andrea Palmieri 229:9981f62cdb1a 616
Andrea Palmieri 229:9981f62cdb1a 617 ret = aci_gatt_read_charac_val(connHandle, attributeHandle);
Vincent Coubard 259:323f588e5f57 618
Andrea Palmieri 229:9981f62cdb1a 619 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 620 gattc->_currentState = GATT_READ_CHAR;
Andrea Palmieri 229:9981f62cdb1a 621 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 622 }
Andrea Palmieri 229:9981f62cdb1a 623 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 624 case BLE_STATUS_BUSY:
Andrea Palmieri 229:9981f62cdb1a 625 return BLE_STACK_BUSY;
Andrea Palmieri 229:9981f62cdb1a 626 default:
Andrea Palmieri 229:9981f62cdb1a 627 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 628 }
Andrea Palmieri 229:9981f62cdb1a 629 }
Andrea Palmieri 229:9981f62cdb1a 630
Andrea Palmieri 229:9981f62cdb1a 631 void BlueNRGGattClient::charWritePrepareCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 632 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 633 uint16_t attribute_handle,
Andrea Palmieri 229:9981f62cdb1a 634 uint16_t offset,
Andrea Palmieri 229:9981f62cdb1a 635 uint8_t *part_attr_value)
Andrea Palmieri 229:9981f62cdb1a 636 {
Andrea Palmieri 229:9981f62cdb1a 637 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 638 (void)connHandle;
Andrea Palmieri 229:9981f62cdb1a 639
Andrea Palmieri 229:9981f62cdb1a 640 // Update the write response params
Andrea Palmieri 229:9981f62cdb1a 641 writeCBParams.handle = attribute_handle;
Andrea Palmieri 229:9981f62cdb1a 642 writeCBParams.offset = offset;
Andrea Palmieri 229:9981f62cdb1a 643 writeCBParams.len = event_data_length-4; //(?)
Andrea Palmieri 229:9981f62cdb1a 644 writeCBParams.data = part_attr_value;
Andrea Palmieri 229:9981f62cdb1a 645
Andrea Palmieri 229:9981f62cdb1a 646 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 647 }
Andrea Palmieri 229:9981f62cdb1a 648
Andrea Palmieri 229:9981f62cdb1a 649 void BlueNRGGattClient::charWriteExecCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 650 uint8_t event_data_length)
Andrea Palmieri 229:9981f62cdb1a 651 {
Andrea Palmieri 229:9981f62cdb1a 652 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 653 (void)event_data_length;
Andrea Palmieri 229:9981f62cdb1a 654
Andrea Palmieri 229:9981f62cdb1a 655 writeCBParams.connHandle = connHandle;
Vincent Coubard 259:323f588e5f57 656
Andrea Palmieri 229:9981f62cdb1a 657 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 658 }
Andrea Palmieri 229:9981f62cdb1a 659
Andrea Palmieri 229:9981f62cdb1a 660 ble_error_t BlueNRGGattClient::write(GattClient::WriteOp_t cmd,
Andrea Palmieri 229:9981f62cdb1a 661 Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 662 GattAttribute::Handle_t attributeHandle,
Andrea Palmieri 229:9981f62cdb1a 663 size_t length,
Andrea Palmieri 229:9981f62cdb1a 664 const uint8_t *value) const
Andrea Palmieri 229:9981f62cdb1a 665 {
Andrea Palmieri 229:9981f62cdb1a 666 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 667 (void)cmd;
Andrea Palmieri 229:9981f62cdb1a 668
Andrea Palmieri 229:9981f62cdb1a 669 tBleStatus ret;
Vincent Coubard 259:323f588e5f57 670
Andrea Palmieri 229:9981f62cdb1a 671 BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this);
Vincent Coubard 259:323f588e5f57 672
Andrea Palmieri 229:9981f62cdb1a 673 // We save the write response params (used by the callback) because
Andrea Palmieri 229:9981f62cdb1a 674 // when the aci_gatt_write_charac_value() is used the only event received is the EVT_BLUE_GATT_PROCEDURE_COMPLETE
Andrea Palmieri 229:9981f62cdb1a 675 gattc->writeCBParams.connHandle = connHandle;
Andrea Palmieri 229:9981f62cdb1a 676 gattc->writeCBParams.writeOp = GattWriteCallbackParams::OP_WRITE_CMD;
Andrea Palmieri 229:9981f62cdb1a 677 gattc->writeCBParams.handle = attributeHandle;
Andrea Palmieri 229:9981f62cdb1a 678 gattc->writeCBParams.offset = 0;
Andrea Palmieri 229:9981f62cdb1a 679 gattc->writeCBParams.len = length;
Andrea Palmieri 229:9981f62cdb1a 680 gattc->writeCBParams.data = value;
Vincent Coubard 259:323f588e5f57 681
Andrea Palmieri 229:9981f62cdb1a 682 ret = aci_gatt_write_charac_value(connHandle, attributeHandle, length, const_cast<uint8_t *>(value));
Andrea Palmieri 229:9981f62cdb1a 683 //ret = aci_gatt_write_charac_reliable(connHandle, attributeHandle, 0, length, const_cast<uint8_t *>(value));
Vincent Coubard 259:323f588e5f57 684
Andrea Palmieri 229:9981f62cdb1a 685 if (ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 686 gattc->_currentState = GATT_WRITE_CHAR;
Andrea Palmieri 229:9981f62cdb1a 687 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 688 }
Andrea Palmieri 229:9981f62cdb1a 689 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 690 case BLE_STATUS_BUSY:
Andrea Palmieri 229:9981f62cdb1a 691 return BLE_STACK_BUSY;
Andrea Palmieri 229:9981f62cdb1a 692 default:
Andrea Palmieri 229:9981f62cdb1a 693 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 694 }
Andrea Palmieri 229:9981f62cdb1a 695
Andrea Palmieri 229:9981f62cdb1a 696 }
Andrea Palmieri 229:9981f62cdb1a 697
Andrea Palmieri 229:9981f62cdb1a 698 void BlueNRGGattClient::discAllCharacDescCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 699 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 700 uint8_t format,
Andrea Palmieri 229:9981f62cdb1a 701 uint8_t *handle_uuid_pair) {
Andrea Palmieri 229:9981f62cdb1a 702 GattAttribute::Handle_t attHandle;
Andrea Palmieri 229:9981f62cdb1a 703 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 704 uint8_t i, numCharacDesc, offset, handle_uuid_length;
Andrea Palmieri 229:9981f62cdb1a 705
Andrea Palmieri 229:9981f62cdb1a 706 handle_uuid_length = 4; //Handle + UUID_16
Andrea Palmieri 229:9981f62cdb1a 707 if (format == 2)
Andrea Palmieri 229:9981f62cdb1a 708 handle_uuid_length = 18; //Handle + UUID_128
Andrea Palmieri 229:9981f62cdb1a 709
Andrea Palmieri 229:9981f62cdb1a 710 numCharacDesc = (event_data_length - 1) / handle_uuid_length;
Vincent Coubard 259:323f588e5f57 711
Andrea Palmieri 229:9981f62cdb1a 712 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 713
Andrea Palmieri 229:9981f62cdb1a 714 for (i=0; i<numCharacDesc; i++) {
Andrea Palmieri 229:9981f62cdb1a 715 attHandle = handle_uuid_pair[offset];
Andrea Palmieri 229:9981f62cdb1a 716
Andrea Palmieri 229:9981f62cdb1a 717 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 718 if (handle_uuid_length == 4) {
Vincent Coubard 259:323f588e5f57 719
Andrea Palmieri 229:9981f62cdb1a 720 PRINTF("UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 721 uuid = handle_uuid_pair[offset+3]<<8|handle_uuid_pair[offset+2];
Andrea Palmieri 229:9981f62cdb1a 722 PRINTF("D UUID-%X attHandle=%u\r\n", uuid.getShortUUID(), attHandle);
Vincent Coubard 259:323f588e5f57 723
Andrea Palmieri 229:9981f62cdb1a 724 } else {
Vincent Coubard 259:323f588e5f57 725
Andrea Palmieri 229:9981f62cdb1a 726 PRINTF("UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 727 uuid.setupLong(handle_uuid_pair+offset+2, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 728 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 729 PRINTF("D UUID-");
Andrea Palmieri 229:9981f62cdb1a 730 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 731 for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) {
Andrea Palmieri 229:9981f62cdb1a 732 PRINTF("%02x", longUUIDBytes[j]);
Andrea Palmieri 229:9981f62cdb1a 733 }
Andrea Palmieri 229:9981f62cdb1a 734 #endif
Andrea Palmieri 229:9981f62cdb1a 735 }
Andrea Palmieri 229:9981f62cdb1a 736
Andrea Palmieri 229:9981f62cdb1a 737 if(charDescDiscoveryCallback != NULL) {
Andrea Palmieri 229:9981f62cdb1a 738 CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
Andrea Palmieri 229:9981f62cdb1a 739 _characteristic,
Andrea Palmieri 229:9981f62cdb1a 740 DiscoveredCharacteristicDescriptor(
Andrea Palmieri 229:9981f62cdb1a 741 _characteristic.getGattClient(),
Andrea Palmieri 229:9981f62cdb1a 742 connHandle,
Andrea Palmieri 229:9981f62cdb1a 743 attHandle,
Andrea Palmieri 229:9981f62cdb1a 744 uuid
Andrea Palmieri 229:9981f62cdb1a 745 )
Andrea Palmieri 229:9981f62cdb1a 746 };
Andrea Palmieri 229:9981f62cdb1a 747 charDescDiscoveryCallback(&params);
Andrea Palmieri 229:9981f62cdb1a 748 }
Andrea Palmieri 229:9981f62cdb1a 749
Andrea Palmieri 229:9981f62cdb1a 750 _numCharDesc++;
Andrea Palmieri 229:9981f62cdb1a 751
Andrea Palmieri 229:9981f62cdb1a 752 offset += handle_uuid_length;
Andrea Palmieri 229:9981f62cdb1a 753 }
Andrea Palmieri 229:9981f62cdb1a 754
Andrea Palmieri 229:9981f62cdb1a 755 if(charDescTerminationCallback != NULL) {
Andrea Palmieri 229:9981f62cdb1a 756 CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
Andrea Palmieri 229:9981f62cdb1a 757 _characteristic,
Andrea Palmieri 229:9981f62cdb1a 758 BLE_ERROR_NONE
Andrea Palmieri 229:9981f62cdb1a 759 };
Andrea Palmieri 229:9981f62cdb1a 760 charDescTerminationCallback(&params);
Andrea Palmieri 229:9981f62cdb1a 761 }
Andrea Palmieri 229:9981f62cdb1a 762
Andrea Palmieri 229:9981f62cdb1a 763 }
Andrea Palmieri 229:9981f62cdb1a 764
Andrea Palmieri 229:9981f62cdb1a 765 ble_error_t BlueNRGGattClient::discoverCharacteristicDescriptors(
Andrea Palmieri 229:9981f62cdb1a 766 const DiscoveredCharacteristic& characteristic,
Andrea Palmieri 229:9981f62cdb1a 767 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
Andrea Palmieri 229:9981f62cdb1a 768 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback) {
Andrea Palmieri 229:9981f62cdb1a 769
Andrea Palmieri 229:9981f62cdb1a 770 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 771
Andrea Palmieri 229:9981f62cdb1a 772 if(_currentState != GATT_IDLE) {
Andrea Palmieri 229:9981f62cdb1a 773 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 774 }
Andrea Palmieri 229:9981f62cdb1a 775
Andrea Palmieri 229:9981f62cdb1a 776 charDescDiscoveryCallback = discoveryCallback;
Andrea Palmieri 229:9981f62cdb1a 777 charDescTerminationCallback = terminationCallback;
Andrea Palmieri 229:9981f62cdb1a 778
Andrea Palmieri 229:9981f62cdb1a 779 Gap::Handle_t connHandle = characteristic.getConnectionHandle();
Andrea Palmieri 229:9981f62cdb1a 780 GattAttribute::Handle_t valueHandle = characteristic.getValueHandle();
Andrea Palmieri 229:9981f62cdb1a 781 GattAttribute::Handle_t lastHandle = characteristic.getLastHandle();
Andrea Palmieri 229:9981f62cdb1a 782
Andrea Palmieri 231:a0d2544b38cd 783 PRINTF("Starting aci_gatt_disc_all_charac_descriptors...\n\r");
Andrea Palmieri 229:9981f62cdb1a 784 ret = aci_gatt_disc_all_charac_descriptors(connHandle, valueHandle, lastHandle);
Andrea Palmieri 229:9981f62cdb1a 785
Andrea Palmieri 229:9981f62cdb1a 786 if (ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 787 _currentState = GATT_CHAR_DESC_DISCOVERY;
Andrea Palmieri 229:9981f62cdb1a 788 _characteristic = characteristic;
Andrea Palmieri 229:9981f62cdb1a 789 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 790 }
Andrea Palmieri 229:9981f62cdb1a 791 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 792 case BLE_STATUS_INVALID_PARAMS:
Andrea Palmieri 229:9981f62cdb1a 793 return BLE_ERROR_INVALID_PARAM;
Andrea Palmieri 229:9981f62cdb1a 794 default:
Andrea Palmieri 229:9981f62cdb1a 795 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 796 }
Andrea Palmieri 229:9981f62cdb1a 797 }
Andrea Palmieri 229:9981f62cdb1a 798
Andrea Palmieri 229:9981f62cdb1a 799 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 800 /*!
Andrea Palmieri 229:9981f62cdb1a 801 @brief Clear BlueNRGGattServer's state.
Andrea Palmieri 229:9981f62cdb1a 802
Andrea Palmieri 229:9981f62cdb1a 803 @returns ble_error_t
Andrea Palmieri 229:9981f62cdb1a 804
Andrea Palmieri 229:9981f62cdb1a 805 @retval BLE_ERROR_NONE
Andrea Palmieri 229:9981f62cdb1a 806 Everything executed properly
Andrea Palmieri 229:9981f62cdb1a 807 */
Andrea Palmieri 229:9981f62cdb1a 808 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 809 ble_error_t BlueNRGGattClient::reset(void) {
Andrea Palmieri 229:9981f62cdb1a 810 /* Clear all state that is from the parent, including private members */
Andrea Palmieri 229:9981f62cdb1a 811 if (GattClient::reset() != BLE_ERROR_NONE) {
Andrea Palmieri 229:9981f62cdb1a 812 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 813 }
Andrea Palmieri 229:9981f62cdb1a 814
Andrea Palmieri 229:9981f62cdb1a 815 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 816 _matchingServiceUUID = BLE_UUID_UNKNOWN;
Andrea Palmieri 229:9981f62cdb1a 817 _matchingCharacteristicUUIDIn = BLE_UUID_UNKNOWN;
Andrea Palmieri 229:9981f62cdb1a 818
Andrea Palmieri 229:9981f62cdb1a 819 _numServices = 0;
Andrea Palmieri 229:9981f62cdb1a 820 _servIndex = 0;
Andrea Palmieri 229:9981f62cdb1a 821 _numChars = 0;
Andrea Palmieri 229:9981f62cdb1a 822 _numCharDesc = 0;
Andrea Palmieri 229:9981f62cdb1a 823
Andrea Palmieri 229:9981f62cdb1a 824 /* Clear class members */
Andrea Palmieri 229:9981f62cdb1a 825 memset(discoveredService, 0, sizeof(discoveredService));
Andrea Palmieri 229:9981f62cdb1a 826 memset(discoveredChar, 0, sizeof(discoveredChar));
Andrea Palmieri 229:9981f62cdb1a 827
Andrea Palmieri 229:9981f62cdb1a 828 return BLE_ERROR_NONE;
Vincent Coubard 259:323f588e5f57 829 }