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:
Wolfgang Betz
Date:
Wed Oct 21 11:56:41 2015 +0200
Revision:
144:bdf5e8432131
Parent:
142:adf1567d3900
Child:
145:024a552e4715
Get rid of warnings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 132:51056160fa4a 1 /* mbed Microcontroller Library
Wolfgang Betz 132:51056160fa4a 2 * Copyright (c) 2006-2013 ARM Limited
Wolfgang Betz 132:51056160fa4a 3 *
Wolfgang Betz 132:51056160fa4a 4 * Licensed under the Apache License, Version 2.0 (the "License");
Wolfgang Betz 132:51056160fa4a 5 * you may not use this file except in compliance with the License.
Wolfgang Betz 132:51056160fa4a 6 * You may obtain a copy of the License at
Wolfgang Betz 132:51056160fa4a 7 *
Wolfgang Betz 132:51056160fa4a 8 * http://www.apache.org/licenses/LICENSE-2.0
Wolfgang Betz 132:51056160fa4a 9 *
Wolfgang Betz 132:51056160fa4a 10 * Unless required by applicable law or agreed to in writing, software
Wolfgang Betz 132:51056160fa4a 11 * distributed under the License is distributed on an "AS IS" BASIS,
Wolfgang Betz 132:51056160fa4a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Wolfgang Betz 132:51056160fa4a 13 * See the License for the specific language governing permissions and
Wolfgang Betz 132:51056160fa4a 14 * limitations under the License.
Wolfgang Betz 132:51056160fa4a 15 */
Wolfgang Betz 132:51056160fa4a 16 /**
Wolfgang Betz 132:51056160fa4a 17 ******************************************************************************
Wolfgang Betz 132:51056160fa4a 18 * @file BlueNRGGattServer.cpp
Wolfgang Betz 132:51056160fa4a 19 * @author STMicroelectronics
Wolfgang Betz 132:51056160fa4a 20 * @brief Implementation of BlueNRG BLE_API GattServer Class
Wolfgang Betz 132:51056160fa4a 21 ******************************************************************************
Wolfgang Betz 132:51056160fa4a 22 * @copy
Wolfgang Betz 132:51056160fa4a 23 *
Wolfgang Betz 132:51056160fa4a 24 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Wolfgang Betz 132:51056160fa4a 25 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
Wolfgang Betz 132:51056160fa4a 26 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
Wolfgang Betz 132:51056160fa4a 27 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
Wolfgang Betz 132:51056160fa4a 28 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
Wolfgang Betz 132:51056160fa4a 29 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Wolfgang Betz 132:51056160fa4a 30 *
Wolfgang Betz 132:51056160fa4a 31 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
Wolfgang Betz 132:51056160fa4a 32 */
Wolfgang Betz 132:51056160fa4a 33
Wolfgang Betz 132:51056160fa4a 34 /** @defgroup BlueNRGGATTClient
Wolfgang Betz 132:51056160fa4a 35 * @brief BlueNRG BLE_API GattClient Adaptation
Wolfgang Betz 132:51056160fa4a 36 * @{
Wolfgang Betz 132:51056160fa4a 37 */
Wolfgang Betz 132:51056160fa4a 38
Wolfgang Betz 132:51056160fa4a 39 #include "BlueNRGGattClient.h"
Wolfgang Betz 144:bdf5e8432131 40 #include "mbed-drivers/mbed.h"
Wolfgang Betz 132:51056160fa4a 41 #include "BlueNRGGap.h"
Wolfgang Betz 132:51056160fa4a 42 #include "Utils.h"
Wolfgang Betz 132:51056160fa4a 43 #include "debug.h"
Wolfgang Betz 132:51056160fa4a 44
Wolfgang Betz 132:51056160fa4a 45 static uint8_t props_mask[] = {
Wolfgang Betz 132:51056160fa4a 46 0x01,
Wolfgang Betz 132:51056160fa4a 47 0x02,
Wolfgang Betz 132:51056160fa4a 48 0x04,
Wolfgang Betz 132:51056160fa4a 49 0x08,
Wolfgang Betz 132:51056160fa4a 50 0x10,
Wolfgang Betz 132:51056160fa4a 51 0x20,
Wolfgang Betz 132:51056160fa4a 52 0x40,
Wolfgang Betz 132:51056160fa4a 53 0x80
Wolfgang Betz 132:51056160fa4a 54 };
Wolfgang Betz 132:51056160fa4a 55
Wolfgang Betz 132:51056160fa4a 56 void BlueNRGGattClient::gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code)
Wolfgang Betz 132:51056160fa4a 57 {
Wolfgang Betz 132:51056160fa4a 58 if(error_code != BLE_STATUS_SUCCESS) {
Wolfgang Betz 132:51056160fa4a 59 return;
Wolfgang Betz 132:51056160fa4a 60 }
Wolfgang Betz 132:51056160fa4a 61
Wolfgang Betz 132:51056160fa4a 62 // Service Discovery complete
Wolfgang Betz 132:51056160fa4a 63 if(_currentState != GATT_IDLE &&
Wolfgang Betz 132:51056160fa4a 64 _currentState != GATT_DISCOVERY_TERMINATED &&
Wolfgang Betz 132:51056160fa4a 65 _currentState != GATT_WRITE_CHAR &&
Wolfgang Betz 132:51056160fa4a 66 _currentState != GATT_READ_CHAR) {
Wolfgang Betz 132:51056160fa4a 67
Wolfgang Betz 132:51056160fa4a 68 findServiceChars(connectionHandle);
Wolfgang Betz 132:51056160fa4a 69 }
Wolfgang Betz 132:51056160fa4a 70
Wolfgang Betz 132:51056160fa4a 71 if(_currentState == GATT_WRITE_CHAR) {
Wolfgang Betz 132:51056160fa4a 72 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Wolfgang Betz 132:51056160fa4a 73 _currentState = GATT_IDLE;
Wolfgang Betz 132:51056160fa4a 74 }
Wolfgang Betz 132:51056160fa4a 75 }
Wolfgang Betz 132:51056160fa4a 76
Wolfgang Betz 132:51056160fa4a 77 void BlueNRGGattClient::primaryServicesCB(Gap::Handle_t connectionHandle,
Wolfgang Betz 132:51056160fa4a 78 uint8_t event_data_length,
Wolfgang Betz 132:51056160fa4a 79 uint8_t attribute_data_length,
Wolfgang Betz 132:51056160fa4a 80 uint8_t *attribute_data_list)
Wolfgang Betz 132:51056160fa4a 81 {
Wolfgang Betz 132:51056160fa4a 82 GattAttribute::Handle_t startHandle, endHandle;
Wolfgang Betz 132:51056160fa4a 83 UUID uuid;
Wolfgang Betz 132:51056160fa4a 84 uint8_t i, offset, numAttr;
Andrea Palmieri 142:adf1567d3900 85 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 86 (void)connectionHandle;
Wolfgang Betz 132:51056160fa4a 87
Wolfgang Betz 132:51056160fa4a 88 numAttr = (event_data_length - 1) / attribute_data_length;
Wolfgang Betz 132:51056160fa4a 89
Wolfgang Betz 132:51056160fa4a 90 offset = 0;
Wolfgang Betz 132:51056160fa4a 91 for (i=0; i<numAttr; i++) {
Wolfgang Betz 132:51056160fa4a 92 startHandle = attribute_data_list[offset];
Wolfgang Betz 132:51056160fa4a 93 endHandle = attribute_data_list[offset+2];
Wolfgang Betz 132:51056160fa4a 94
Wolfgang Betz 132:51056160fa4a 95 // UUID Type
Wolfgang Betz 132:51056160fa4a 96 if (attribute_data_length == 6) {
Wolfgang Betz 132:51056160fa4a 97
Wolfgang Betz 132:51056160fa4a 98 PRINTF("UUID_TYPE_16\n\r");
Wolfgang Betz 132:51056160fa4a 99 uuid = attribute_data_list[offset+5]<<8|attribute_data_list[offset+4];
Wolfgang Betz 132:51056160fa4a 100 PRINTF("S UUID-%X attrs[%u %u]\r\n", uuid.getShortUUID(), startHandle, endHandle);
Wolfgang Betz 132:51056160fa4a 101
Wolfgang Betz 132:51056160fa4a 102 } else {
Wolfgang Betz 132:51056160fa4a 103
Wolfgang Betz 132:51056160fa4a 104 PRINTF("UUID_TYPE_128\n\r");
Wolfgang Betz 132:51056160fa4a 105 uuid.setupLong(attribute_data_list+offset+4);
Wolfgang Betz 132:51056160fa4a 106
Wolfgang Betz 132:51056160fa4a 107 PRINTF("S UUID-");
Wolfgang Betz 132:51056160fa4a 108 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Wolfgang Betz 132:51056160fa4a 109 for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) {
Wolfgang Betz 132:51056160fa4a 110 PRINTF("%02x", longUUIDBytes[j]);
Wolfgang Betz 132:51056160fa4a 111 }
Wolfgang Betz 132:51056160fa4a 112 PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle);
Wolfgang Betz 132:51056160fa4a 113
Wolfgang Betz 132:51056160fa4a 114 }
Wolfgang Betz 132:51056160fa4a 115
Wolfgang Betz 132:51056160fa4a 116 PRINTF("Setup serviceIndex = %d\n\r", _numServices);
Wolfgang Betz 132:51056160fa4a 117 discoveredService[_numServices].setup(uuid, startHandle, endHandle);
Wolfgang Betz 132:51056160fa4a 118
Wolfgang Betz 132:51056160fa4a 119 if(serviceDiscoveryCallback) {
Wolfgang Betz 132:51056160fa4a 120 if(_matchingServiceUUID == BLE_UUID_UNKNOWN || _matchingServiceUUID == discoveredService[_numServices].getUUID()) {
Wolfgang Betz 132:51056160fa4a 121 serviceDiscoveryCallback(&discoveredService[_numServices]);
Wolfgang Betz 132:51056160fa4a 122 }
Wolfgang Betz 132:51056160fa4a 123 }
Wolfgang Betz 132:51056160fa4a 124 _numServices++;
Wolfgang Betz 132:51056160fa4a 125
Wolfgang Betz 132:51056160fa4a 126 offset += attribute_data_length;
Wolfgang Betz 132:51056160fa4a 127 }
Wolfgang Betz 132:51056160fa4a 128
Wolfgang Betz 132:51056160fa4a 129 PRINTF("!!!Service Discovery complete (numAttr=%u)!!!\n\r", numAttr);
Wolfgang Betz 132:51056160fa4a 130
Wolfgang Betz 132:51056160fa4a 131 }
Wolfgang Betz 132:51056160fa4a 132
Wolfgang Betz 132:51056160fa4a 133 void BlueNRGGattClient::primaryServiceCB(Gap::Handle_t connectionHandle,
Wolfgang Betz 132:51056160fa4a 134 uint8_t event_data_length,
Wolfgang Betz 132:51056160fa4a 135 uint8_t *handles_info_list)
Wolfgang Betz 132:51056160fa4a 136 {
Wolfgang Betz 132:51056160fa4a 137 GattAttribute::Handle_t startHandle, endHandle;
Wolfgang Betz 132:51056160fa4a 138 UUID uuid;
Wolfgang Betz 132:51056160fa4a 139 uint8_t i, offset, numHandlePairs;
Andrea Palmieri 142:adf1567d3900 140 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 141 (void)connectionHandle;
Wolfgang Betz 132:51056160fa4a 142
Wolfgang Betz 132:51056160fa4a 143 numHandlePairs = (event_data_length - 1) / 2;
Wolfgang Betz 132:51056160fa4a 144
Wolfgang Betz 132:51056160fa4a 145 offset = 0;
Wolfgang Betz 132:51056160fa4a 146 for (i=0; i<numHandlePairs; i++) {
Wolfgang Betz 132:51056160fa4a 147 startHandle = handles_info_list[offset];
Wolfgang Betz 132:51056160fa4a 148 endHandle = handles_info_list[offset+2];
Wolfgang Betz 132:51056160fa4a 149
Wolfgang Betz 132:51056160fa4a 150 PRINTF("primaryServiceCB attrs[%u %u]\r\n", startHandle, endHandle);
Wolfgang Betz 132:51056160fa4a 151
Wolfgang Betz 132:51056160fa4a 152 discoveredService[i].setup(_matchingServiceUUID, startHandle, endHandle);
Wolfgang Betz 132:51056160fa4a 153
Wolfgang Betz 132:51056160fa4a 154 if(serviceDiscoveryCallback) {
Wolfgang Betz 132:51056160fa4a 155 serviceDiscoveryCallback(&discoveredService[_numServices]);
Wolfgang Betz 132:51056160fa4a 156 }
Wolfgang Betz 132:51056160fa4a 157 _numServices++;
Wolfgang Betz 132:51056160fa4a 158
Wolfgang Betz 132:51056160fa4a 159 offset += 4;
Wolfgang Betz 132:51056160fa4a 160 }
Wolfgang Betz 132:51056160fa4a 161 }
Wolfgang Betz 132:51056160fa4a 162
Wolfgang Betz 132:51056160fa4a 163 void BlueNRGGattClient::serviceCharsCB(Gap::Handle_t connectionHandle,
Wolfgang Betz 132:51056160fa4a 164 uint8_t event_data_length,
Wolfgang Betz 132:51056160fa4a 165 uint8_t handle_value_pair_length,
Wolfgang Betz 132:51056160fa4a 166 uint8_t *handle_value_pair)
Wolfgang Betz 132:51056160fa4a 167 {
Wolfgang Betz 132:51056160fa4a 168 // Charac Handle (2), Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16)
Wolfgang Betz 132:51056160fa4a 169
Wolfgang Betz 132:51056160fa4a 170 GattAttribute::Handle_t declHandle, valueHandle;
Wolfgang Betz 132:51056160fa4a 171 UUID uuid;
Wolfgang Betz 132:51056160fa4a 172 uint8_t i, numChar, offset;
Wolfgang Betz 132:51056160fa4a 173
Wolfgang Betz 132:51056160fa4a 174 numChar = (event_data_length - 1) / handle_value_pair_length;
Wolfgang Betz 132:51056160fa4a 175
Wolfgang Betz 132:51056160fa4a 176 offset = 0;
Wolfgang Betz 132:51056160fa4a 177 for (i=0; i<numChar; i++) {
Wolfgang Betz 132:51056160fa4a 178 // UUID Type
Wolfgang Betz 132:51056160fa4a 179 if (handle_value_pair_length == 7) {
Wolfgang Betz 132:51056160fa4a 180 PRINTF("Char UUID_TYPE_16\n\r");
Wolfgang Betz 132:51056160fa4a 181 uuid = handle_value_pair[offset+6]<<8|handle_value_pair[offset+5];
Wolfgang Betz 132:51056160fa4a 182 PRINTF("C UUID-%X\r\n", uuid.getShortUUID());
Wolfgang Betz 132:51056160fa4a 183 } else {
Wolfgang Betz 132:51056160fa4a 184 PRINTF("Char UUID_TYPE_128\n\r");
Wolfgang Betz 132:51056160fa4a 185 uuid.setupLong(handle_value_pair+offset+5);
Wolfgang Betz 132:51056160fa4a 186 PRINTF("C UUID-");
Wolfgang Betz 132:51056160fa4a 187 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Wolfgang Betz 132:51056160fa4a 188 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Wolfgang Betz 132:51056160fa4a 189 PRINTF("%02X", longUUIDBytes[i]);
Wolfgang Betz 132:51056160fa4a 190 }
Wolfgang Betz 132:51056160fa4a 191 PRINTF("\r\n");
Wolfgang Betz 132:51056160fa4a 192 }
Wolfgang Betz 132:51056160fa4a 193
Wolfgang Betz 132:51056160fa4a 194 // Properties
Wolfgang Betz 132:51056160fa4a 195 DiscoveredCharacteristic::Properties_t p;
Wolfgang Betz 132:51056160fa4a 196
Wolfgang Betz 132:51056160fa4a 197 p._broadcast = (props_mask[0] & handle_value_pair[offset+2]);
Wolfgang Betz 132:51056160fa4a 198 p._read = (props_mask[1] & handle_value_pair[offset+2])>>1;
Wolfgang Betz 132:51056160fa4a 199 p._writeWoResp = (props_mask[2] & handle_value_pair[offset+2])>>2;
Wolfgang Betz 132:51056160fa4a 200 p._write = (props_mask[3] & handle_value_pair[offset+2])>>3;
Wolfgang Betz 132:51056160fa4a 201 p._notify = (props_mask[4] & handle_value_pair[offset+2])>>4;
Wolfgang Betz 132:51056160fa4a 202 p._indicate = (props_mask[5] & handle_value_pair[offset+2])>>5;
Wolfgang Betz 132:51056160fa4a 203 p._authSignedWrite = (props_mask[6] & handle_value_pair[offset+2])>>6;
Wolfgang Betz 132:51056160fa4a 204 PRINTF("p._broadcast=%d\n\r", p._broadcast);
Wolfgang Betz 132:51056160fa4a 205 PRINTF("p._read=%d\n\r", p._read);
Wolfgang Betz 132:51056160fa4a 206 PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp);
Wolfgang Betz 132:51056160fa4a 207 PRINTF("p._write=%d\n\r", p._write);
Wolfgang Betz 132:51056160fa4a 208 PRINTF("p._notify=%d\n\r", p._notify);
Wolfgang Betz 132:51056160fa4a 209 PRINTF("p._indicate=%d\n\r", p._indicate);
Wolfgang Betz 132:51056160fa4a 210 PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite);
Wolfgang Betz 132:51056160fa4a 211
Wolfgang Betz 132:51056160fa4a 212 /*
Wolfgang Betz 132:51056160fa4a 213 uint8_t props = handle_value_pair[offset+2];
Wolfgang Betz 132:51056160fa4a 214 PRINTF("CHAR PROPS: %d\n\r", props);
Wolfgang Betz 132:51056160fa4a 215 */
Wolfgang Betz 132:51056160fa4a 216
Wolfgang Betz 132:51056160fa4a 217 // Handles
Wolfgang Betz 132:51056160fa4a 218 declHandle = handle_value_pair[offset];
Wolfgang Betz 132:51056160fa4a 219 valueHandle = handle_value_pair[offset+3];
Wolfgang Betz 132:51056160fa4a 220
Wolfgang Betz 132:51056160fa4a 221 discoveredChar[_numChars].setup(this,
Wolfgang Betz 132:51056160fa4a 222 connectionHandle,
Wolfgang Betz 132:51056160fa4a 223 uuid,
Wolfgang Betz 132:51056160fa4a 224 p,
Wolfgang Betz 132:51056160fa4a 225 declHandle,
Wolfgang Betz 132:51056160fa4a 226 valueHandle);
Wolfgang Betz 132:51056160fa4a 227
Wolfgang Betz 132:51056160fa4a 228 if(characteristicDiscoveryCallback) {
Wolfgang Betz 132:51056160fa4a 229 characteristicDiscoveryCallback(&discoveredChar[_numChars]);
Wolfgang Betz 132:51056160fa4a 230 }
Wolfgang Betz 132:51056160fa4a 231 _numChars++;
Wolfgang Betz 132:51056160fa4a 232
Wolfgang Betz 132:51056160fa4a 233 offset += handle_value_pair_length;
Wolfgang Betz 132:51056160fa4a 234 }
Wolfgang Betz 132:51056160fa4a 235 }
Wolfgang Betz 132:51056160fa4a 236
Wolfgang Betz 132:51056160fa4a 237 void BlueNRGGattClient::serviceCharByUUIDCB(Gap::Handle_t connectionHandle,
Wolfgang Betz 132:51056160fa4a 238 uint8_t event_data_length,
Wolfgang Betz 132:51056160fa4a 239 uint16_t attr_handle,
Wolfgang Betz 132:51056160fa4a 240 uint8_t *attr_value)
Wolfgang Betz 132:51056160fa4a 241 {
Wolfgang Betz 132:51056160fa4a 242 // Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16)
Wolfgang Betz 132:51056160fa4a 243 GattAttribute::Handle_t declHandle, valueHandle;
Wolfgang Betz 132:51056160fa4a 244 UUID uuid;
Wolfgang Betz 132:51056160fa4a 245
Wolfgang Betz 132:51056160fa4a 246 PRINTF("serviceCharByUUIDCB\n\r");
Wolfgang Betz 132:51056160fa4a 247
Wolfgang Betz 132:51056160fa4a 248 // UUID Type
Wolfgang Betz 132:51056160fa4a 249 if (event_data_length == 7) {
Wolfgang Betz 132:51056160fa4a 250 PRINTF("Char UUID_TYPE_16\n\r");
Wolfgang Betz 132:51056160fa4a 251 uuid = attr_value[4]<<8|attr_value[3];
Wolfgang Betz 132:51056160fa4a 252 PRINTF("C UUID-%X\r\n", uuid.getShortUUID());
Wolfgang Betz 132:51056160fa4a 253 } else {
Wolfgang Betz 132:51056160fa4a 254 PRINTF("Char UUID_TYPE_128\n\r");
Wolfgang Betz 132:51056160fa4a 255 uuid.setupLong(attr_value+3);
Wolfgang Betz 132:51056160fa4a 256 PRINTF("C UUID-");
Wolfgang Betz 132:51056160fa4a 257 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Wolfgang Betz 132:51056160fa4a 258 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Wolfgang Betz 132:51056160fa4a 259 PRINTF("%02X", longUUIDBytes[i]);
Wolfgang Betz 132:51056160fa4a 260 }
Wolfgang Betz 132:51056160fa4a 261 PRINTF("\r\n");
Wolfgang Betz 132:51056160fa4a 262 }
Wolfgang Betz 132:51056160fa4a 263
Wolfgang Betz 132:51056160fa4a 264 // Properties
Wolfgang Betz 132:51056160fa4a 265 DiscoveredCharacteristic::Properties_t p;
Wolfgang Betz 132:51056160fa4a 266
Wolfgang Betz 132:51056160fa4a 267 p._broadcast = (props_mask[0] & attr_value[0]);
Wolfgang Betz 132:51056160fa4a 268 p._read = (props_mask[1] & attr_value[0])>>1;
Wolfgang Betz 132:51056160fa4a 269 p._writeWoResp = (props_mask[2] & attr_value[0])>>2;
Wolfgang Betz 132:51056160fa4a 270 p._write = (props_mask[3] & attr_value[0])>>3;
Wolfgang Betz 132:51056160fa4a 271 p._notify = (props_mask[4] & attr_value[0])>>4;
Wolfgang Betz 132:51056160fa4a 272 p._indicate = (props_mask[5] & attr_value[0])>>5;
Wolfgang Betz 132:51056160fa4a 273 p._authSignedWrite = (props_mask[6] & attr_value[0])>>6;
Wolfgang Betz 132:51056160fa4a 274 PRINTF("p._broadcast=%d\n\r", p._broadcast);
Wolfgang Betz 132:51056160fa4a 275 PRINTF("p._read=%d\n\r", p._read);
Wolfgang Betz 132:51056160fa4a 276 PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp);
Wolfgang Betz 132:51056160fa4a 277 PRINTF("p._write=%d\n\r", p._write);
Wolfgang Betz 132:51056160fa4a 278 PRINTF("p._notify=%d\n\r", p._notify);
Wolfgang Betz 132:51056160fa4a 279 PRINTF("p._indicate=%d\n\r", p._indicate);
Wolfgang Betz 132:51056160fa4a 280 PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite);
Wolfgang Betz 132:51056160fa4a 281
Wolfgang Betz 132:51056160fa4a 282 /*
Wolfgang Betz 132:51056160fa4a 283 uint8_t props = attr_value[0];
Wolfgang Betz 132:51056160fa4a 284 PRINTF("CHAR PROPS: %d\n\r", props);
Wolfgang Betz 132:51056160fa4a 285 */
Wolfgang Betz 132:51056160fa4a 286
Wolfgang Betz 132:51056160fa4a 287 // Handles
Wolfgang Betz 132:51056160fa4a 288 declHandle = attr_handle;
Wolfgang Betz 132:51056160fa4a 289 valueHandle = attr_value[1];
Wolfgang Betz 132:51056160fa4a 290
Wolfgang Betz 132:51056160fa4a 291 discoveredChar[_numChars].setup(this,
Wolfgang Betz 132:51056160fa4a 292 connectionHandle,
Wolfgang Betz 132:51056160fa4a 293 uuid,
Wolfgang Betz 132:51056160fa4a 294 p,
Wolfgang Betz 132:51056160fa4a 295 declHandle,
Wolfgang Betz 132:51056160fa4a 296 valueHandle);
Wolfgang Betz 132:51056160fa4a 297
Wolfgang Betz 132:51056160fa4a 298 if(characteristicDiscoveryCallback) {
Wolfgang Betz 132:51056160fa4a 299 characteristicDiscoveryCallback(&discoveredChar[_numChars]);
Wolfgang Betz 132:51056160fa4a 300 }
Wolfgang Betz 132:51056160fa4a 301 _numChars++;
Wolfgang Betz 132:51056160fa4a 302 }
Wolfgang Betz 132:51056160fa4a 303
Wolfgang Betz 132:51056160fa4a 304 ble_error_t BlueNRGGattClient::findServiceChars(Gap::Handle_t connectionHandle)
Wolfgang Betz 132:51056160fa4a 305 {
Wolfgang Betz 132:51056160fa4a 306 PRINTF("findServiceChars\n\r");
Wolfgang Betz 132:51056160fa4a 307
Wolfgang Betz 132:51056160fa4a 308 tBleStatus ret;
Andrea Palmieri 142:adf1567d3900 309 uint8_t uuid_type = UUID_TYPE_16;
Wolfgang Betz 132:51056160fa4a 310 uint8_t short_uuid[2];
Andrea Palmieri 142:adf1567d3900 311 uint8_t *uuid = NULL;
Wolfgang Betz 132:51056160fa4a 312
Wolfgang Betz 132:51056160fa4a 313 DiscoveredService *service;
Wolfgang Betz 132:51056160fa4a 314
Wolfgang Betz 132:51056160fa4a 315 // We finished chars discovery for all services
Wolfgang Betz 132:51056160fa4a 316 if(_servIndex >= _numServices) {
Wolfgang Betz 132:51056160fa4a 317 PRINTF("!!!We finished chars discovery for all services!!!\n\r");
Wolfgang Betz 132:51056160fa4a 318 _currentState = GATT_CHARS_DISCOVERY_COMPLETE;
Wolfgang Betz 132:51056160fa4a 319
Wolfgang Betz 132:51056160fa4a 320 terminateServiceDiscovery();
Wolfgang Betz 132:51056160fa4a 321
Wolfgang Betz 132:51056160fa4a 322 return BLE_ERROR_NONE;
Wolfgang Betz 132:51056160fa4a 323 }
Wolfgang Betz 132:51056160fa4a 324
Wolfgang Betz 132:51056160fa4a 325 service = &discoveredService[_servIndex];
Wolfgang Betz 132:51056160fa4a 326 /*
Wolfgang Betz 132:51056160fa4a 327 if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) {
Wolfgang Betz 132:51056160fa4a 328 PRINTF("S UUID-%X\r\n", service->getUUID().getShortUUID());
Wolfgang Betz 132:51056160fa4a 329 } else {
Wolfgang Betz 132:51056160fa4a 330 PRINTF("S UUID-");
Wolfgang Betz 132:51056160fa4a 331 const uint8_t *longUUIDBytes = service->getUUID().getBaseUUID();
Wolfgang Betz 132:51056160fa4a 332 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Wolfgang Betz 132:51056160fa4a 333 PRINTF("%02X", longUUIDBytes[i]);
Wolfgang Betz 132:51056160fa4a 334 }
Wolfgang Betz 132:51056160fa4a 335 PRINTF("\r\n");
Wolfgang Betz 132:51056160fa4a 336 }
Wolfgang Betz 132:51056160fa4a 337 */
Wolfgang Betz 132:51056160fa4a 338
Wolfgang Betz 132:51056160fa4a 339 PRINTF("findServiceChars (_servIndex=%d)\n\r", _servIndex);
Wolfgang Betz 132:51056160fa4a 340 //ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle());
Wolfgang Betz 132:51056160fa4a 341
Wolfgang Betz 132:51056160fa4a 342 if(_matchingCharacteristicUUIDIn == BLE_UUID_UNKNOWN) {
Wolfgang Betz 132:51056160fa4a 343 PRINTF("findServiceChars (BLE_UUID_UNKNOWN)\n\r");
Wolfgang Betz 132:51056160fa4a 344 ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle());
Wolfgang Betz 132:51056160fa4a 345 } else {
Wolfgang Betz 132:51056160fa4a 346
Wolfgang Betz 132:51056160fa4a 347 uint8_t type = _matchingCharacteristicUUIDIn.shortOrLong();
Wolfgang Betz 132:51056160fa4a 348
Wolfgang Betz 132:51056160fa4a 349 if(type == UUID::UUID_TYPE_SHORT) {
Wolfgang Betz 132:51056160fa4a 350 STORE_LE_16(short_uuid, _matchingCharacteristicUUIDIn.getShortUUID());
Wolfgang Betz 132:51056160fa4a 351
Wolfgang Betz 132:51056160fa4a 352 uuid_type = UUID_TYPE_16;
Wolfgang Betz 132:51056160fa4a 353 uuid = short_uuid;
Wolfgang Betz 132:51056160fa4a 354
Wolfgang Betz 132:51056160fa4a 355 PRINTF("findServiceChars C UUID-");
Wolfgang Betz 132:51056160fa4a 356 for(unsigned i = 0; i < 2; i++) {
Wolfgang Betz 132:51056160fa4a 357 PRINTF("%02X", short_uuid[i]);
Wolfgang Betz 132:51056160fa4a 358 }
Wolfgang Betz 132:51056160fa4a 359 PRINTF("\n\r");
Wolfgang Betz 132:51056160fa4a 360
Wolfgang Betz 132:51056160fa4a 361 } else if(type==UUID::UUID_TYPE_LONG) {
Wolfgang Betz 132:51056160fa4a 362
Wolfgang Betz 132:51056160fa4a 363 uuid_type = UUID_TYPE_128;
Wolfgang Betz 132:51056160fa4a 364 uuid = (unsigned char*)_matchingCharacteristicUUIDIn.getBaseUUID();
Wolfgang Betz 132:51056160fa4a 365
Wolfgang Betz 132:51056160fa4a 366 PRINTF("(findServiceChars) C UUID-");
Wolfgang Betz 132:51056160fa4a 367 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Wolfgang Betz 132:51056160fa4a 368 PRINTF("%02X", uuid[i]);
Wolfgang Betz 132:51056160fa4a 369 }
Wolfgang Betz 132:51056160fa4a 370 PRINTF("\r\n");
Wolfgang Betz 132:51056160fa4a 371 }
Wolfgang Betz 132:51056160fa4a 372
Wolfgang Betz 132:51056160fa4a 373 ret = aci_gatt_disc_charac_by_uuid(connectionHandle,
Wolfgang Betz 132:51056160fa4a 374 service->getStartHandle(),
Wolfgang Betz 132:51056160fa4a 375 service->getEndHandle(),
Wolfgang Betz 132:51056160fa4a 376 uuid_type,
Wolfgang Betz 132:51056160fa4a 377 uuid);
Wolfgang Betz 132:51056160fa4a 378 }
Wolfgang Betz 132:51056160fa4a 379
Wolfgang Betz 132:51056160fa4a 380 if(ret == BLE_STATUS_SUCCESS) {
Wolfgang Betz 132:51056160fa4a 381 _servIndex++;
Wolfgang Betz 132:51056160fa4a 382 }
Wolfgang Betz 132:51056160fa4a 383
Wolfgang Betz 132:51056160fa4a 384 PRINTF("findServiceChars ret=%d\n\r", ret);
Wolfgang Betz 132:51056160fa4a 385
Wolfgang Betz 132:51056160fa4a 386 return BLE_ERROR_NONE;
Wolfgang Betz 132:51056160fa4a 387 }
Wolfgang Betz 132:51056160fa4a 388
Wolfgang Betz 132:51056160fa4a 389 ble_error_t BlueNRGGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
Wolfgang Betz 132:51056160fa4a 390 ServiceDiscovery::ServiceCallback_t sc,
Wolfgang Betz 132:51056160fa4a 391 ServiceDiscovery::CharacteristicCallback_t cc,
Wolfgang Betz 132:51056160fa4a 392 const UUID &matchingServiceUUID,
Wolfgang Betz 132:51056160fa4a 393 const UUID &matchingCharacteristicUUIDIn)
Wolfgang Betz 132:51056160fa4a 394 {
Wolfgang Betz 132:51056160fa4a 395 PRINTF("launchServiceDiscovery\n\r");
Wolfgang Betz 132:51056160fa4a 396
Wolfgang Betz 132:51056160fa4a 397 tBleStatus ret;
Andrea Palmieri 142:adf1567d3900 398 uint8_t uuid_type = UUID_TYPE_16;
Wolfgang Betz 132:51056160fa4a 399 uint8_t short_uuid[2];
Andrea Palmieri 142:adf1567d3900 400 uint8_t *uuid = NULL;
Wolfgang Betz 132:51056160fa4a 401 unsigned j;
Wolfgang Betz 132:51056160fa4a 402
Wolfgang Betz 132:51056160fa4a 403 _connectionHandle = connectionHandle;
Wolfgang Betz 132:51056160fa4a 404 serviceDiscoveryCallback = sc;
Wolfgang Betz 132:51056160fa4a 405 characteristicDiscoveryCallback = cc;
Wolfgang Betz 132:51056160fa4a 406 _matchingServiceUUID = matchingServiceUUID;
Wolfgang Betz 132:51056160fa4a 407 _matchingCharacteristicUUIDIn = matchingCharacteristicUUIDIn;
Wolfgang Betz 132:51056160fa4a 408
Wolfgang Betz 132:51056160fa4a 409 //reset services
Wolfgang Betz 132:51056160fa4a 410 _numServices = 0;
Wolfgang Betz 132:51056160fa4a 411 _numChars = 0;
Wolfgang Betz 132:51056160fa4a 412 _servIndex = 0;
Wolfgang Betz 132:51056160fa4a 413 for(j = 0; j < BLE_TOTAL_DISCOVERED_SERVICES; j++) {
Wolfgang Betz 132:51056160fa4a 414 discoveredService[j].setup(BLE_UUID_UNKNOWN, GattAttribute::INVALID_HANDLE, GattAttribute::INVALID_HANDLE);
Wolfgang Betz 132:51056160fa4a 415 }
Wolfgang Betz 132:51056160fa4a 416
Wolfgang Betz 132:51056160fa4a 417 if(matchingServiceUUID == BLE_UUID_UNKNOWN) {
Wolfgang Betz 132:51056160fa4a 418
Wolfgang Betz 132:51056160fa4a 419 // Wildcard: search for all services
Wolfgang Betz 132:51056160fa4a 420 ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle);
Wolfgang Betz 132:51056160fa4a 421
Wolfgang Betz 132:51056160fa4a 422 } else {
Wolfgang Betz 132:51056160fa4a 423
Wolfgang Betz 132:51056160fa4a 424 uint8_t type = matchingServiceUUID.shortOrLong();
Wolfgang Betz 132:51056160fa4a 425 //PRINTF("AddService(): Type:%d\n\r", type);
Wolfgang Betz 132:51056160fa4a 426
Wolfgang Betz 132:51056160fa4a 427 if(type == UUID::UUID_TYPE_SHORT) {
Wolfgang Betz 132:51056160fa4a 428 STORE_LE_16(short_uuid, matchingServiceUUID.getShortUUID());
Wolfgang Betz 132:51056160fa4a 429
Wolfgang Betz 132:51056160fa4a 430 PRINTF("launchServiceDiscovery short_uuid=0x");
Wolfgang Betz 132:51056160fa4a 431 for(j = 0; j < 2; j++) {
Wolfgang Betz 132:51056160fa4a 432 PRINTF("%02X", short_uuid[j]);
Wolfgang Betz 132:51056160fa4a 433 }
Wolfgang Betz 132:51056160fa4a 434 PRINTF("\n\r");
Wolfgang Betz 132:51056160fa4a 435
Wolfgang Betz 132:51056160fa4a 436
Wolfgang Betz 132:51056160fa4a 437 uuid_type = UUID_TYPE_16;
Wolfgang Betz 132:51056160fa4a 438 uuid = short_uuid;
Wolfgang Betz 132:51056160fa4a 439
Wolfgang Betz 132:51056160fa4a 440 } else if(type==UUID::UUID_TYPE_LONG) {
Wolfgang Betz 132:51056160fa4a 441
Wolfgang Betz 132:51056160fa4a 442 uuid_type = UUID_TYPE_128;
Wolfgang Betz 132:51056160fa4a 443 uuid = (unsigned char*)matchingServiceUUID.getBaseUUID();
Wolfgang Betz 132:51056160fa4a 444
Wolfgang Betz 132:51056160fa4a 445 /*
Wolfgang Betz 132:51056160fa4a 446 PRINTF("launchServiceDiscovery base_uuid=0x");
Wolfgang Betz 132:51056160fa4a 447 for(j = 0; j < 16; j++) {
Wolfgang Betz 132:51056160fa4a 448 PRINTF("%02X", uuid[j]);
Wolfgang Betz 132:51056160fa4a 449 }
Wolfgang Betz 132:51056160fa4a 450 PRINTF("\n\r");
Wolfgang Betz 132:51056160fa4a 451 */
Wolfgang Betz 132:51056160fa4a 452 }
Wolfgang Betz 132:51056160fa4a 453
Wolfgang Betz 132:51056160fa4a 454 // search for specific service by UUID
Wolfgang Betz 132:51056160fa4a 455 ret = aci_gatt_disc_prim_service_by_uuid((uint16_t)connectionHandle, uuid_type, uuid);
Wolfgang Betz 132:51056160fa4a 456 //ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle);
Wolfgang Betz 132:51056160fa4a 457 }
Wolfgang Betz 132:51056160fa4a 458
Wolfgang Betz 132:51056160fa4a 459 if(ret == BLE_STATUS_SUCCESS) {
Wolfgang Betz 132:51056160fa4a 460 _currentState = GATT_SERVICE_DISCOVERY;
Wolfgang Betz 132:51056160fa4a 461 }
Wolfgang Betz 132:51056160fa4a 462
Wolfgang Betz 132:51056160fa4a 463 PRINTF("launchServiceDiscovery ret=%d\n\r", ret);
Wolfgang Betz 132:51056160fa4a 464
Wolfgang Betz 132:51056160fa4a 465 return BLE_ERROR_NONE;
Wolfgang Betz 132:51056160fa4a 466 }
Wolfgang Betz 132:51056160fa4a 467
Wolfgang Betz 132:51056160fa4a 468 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
Wolfgang Betz 132:51056160fa4a 469 ServiceDiscovery::ServiceCallback_t callback,
Wolfgang Betz 132:51056160fa4a 470 const UUID &matchingServiceUUID)
Wolfgang Betz 132:51056160fa4a 471 {
Andrea Palmieri 142:adf1567d3900 472 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 473 (void)connectionHandle;
Andrea Palmieri 142:adf1567d3900 474 (void)callback;
Andrea Palmieri 142:adf1567d3900 475 (void)matchingServiceUUID;
Andrea Palmieri 142:adf1567d3900 476
Wolfgang Betz 132:51056160fa4a 477 return BLE_ERROR_NOT_IMPLEMENTED;
Wolfgang Betz 132:51056160fa4a 478 }
Wolfgang Betz 132:51056160fa4a 479
Wolfgang Betz 132:51056160fa4a 480 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
Wolfgang Betz 132:51056160fa4a 481 ServiceDiscovery::ServiceCallback_t callback,
Wolfgang Betz 132:51056160fa4a 482 GattAttribute::Handle_t startHandle,
Wolfgang Betz 132:51056160fa4a 483 GattAttribute::Handle_t endHandle)
Wolfgang Betz 132:51056160fa4a 484 {
Andrea Palmieri 142:adf1567d3900 485 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 486 (void)connectionHandle;
Andrea Palmieri 142:adf1567d3900 487 (void)callback;
Andrea Palmieri 142:adf1567d3900 488 (void)startHandle;
Andrea Palmieri 142:adf1567d3900 489 (void)endHandle;
Andrea Palmieri 142:adf1567d3900 490
Wolfgang Betz 132:51056160fa4a 491 return BLE_ERROR_NOT_IMPLEMENTED;
Wolfgang Betz 132:51056160fa4a 492 }
Wolfgang Betz 132:51056160fa4a 493
Wolfgang Betz 132:51056160fa4a 494 bool BlueNRGGattClient::isServiceDiscoveryActive(void) const
Wolfgang Betz 132:51056160fa4a 495 {
Wolfgang Betz 132:51056160fa4a 496 if(_currentState == GATT_IDLE ||
Wolfgang Betz 132:51056160fa4a 497 _currentState == GATT_DISCOVERY_TERMINATED ||
Wolfgang Betz 132:51056160fa4a 498 _currentState == GATT_READ_CHAR ||
Wolfgang Betz 132:51056160fa4a 499 _currentState == GATT_WRITE_CHAR ) {
Wolfgang Betz 132:51056160fa4a 500 return false;
Wolfgang Betz 132:51056160fa4a 501 }
Wolfgang Betz 132:51056160fa4a 502
Wolfgang Betz 132:51056160fa4a 503 return true;
Wolfgang Betz 132:51056160fa4a 504 }
Wolfgang Betz 132:51056160fa4a 505
Wolfgang Betz 132:51056160fa4a 506 void BlueNRGGattClient::terminateServiceDiscovery(void)
Wolfgang Betz 132:51056160fa4a 507 {
Wolfgang Betz 132:51056160fa4a 508 _currentState = GATT_DISCOVERY_TERMINATED;
Wolfgang Betz 132:51056160fa4a 509
Wolfgang Betz 132:51056160fa4a 510 if (terminationCallback) {
Wolfgang Betz 132:51056160fa4a 511 terminationCallback(_connectionHandle);
Wolfgang Betz 132:51056160fa4a 512 }
Wolfgang Betz 132:51056160fa4a 513 }
Wolfgang Betz 132:51056160fa4a 514
Wolfgang Betz 132:51056160fa4a 515 void BlueNRGGattClient::charReadCB(Gap::Handle_t connHandle,
Wolfgang Betz 132:51056160fa4a 516 uint8_t event_data_length,
Wolfgang Betz 132:51056160fa4a 517 uint8_t* attribute_value)
Wolfgang Betz 132:51056160fa4a 518 {
Wolfgang Betz 132:51056160fa4a 519 readCBParams.connHandle = connHandle;
Wolfgang Betz 132:51056160fa4a 520 readCBParams.offset = 0;
Wolfgang Betz 132:51056160fa4a 521 readCBParams.len = event_data_length;
Wolfgang Betz 132:51056160fa4a 522 readCBParams.data = attribute_value;
Wolfgang Betz 132:51056160fa4a 523
Wolfgang Betz 132:51056160fa4a 524 BlueNRGGattClient::getInstance().processReadResponse(&readCBParams);
Wolfgang Betz 132:51056160fa4a 525 }
Wolfgang Betz 132:51056160fa4a 526
Wolfgang Betz 132:51056160fa4a 527 ble_error_t BlueNRGGattClient::read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const
Wolfgang Betz 132:51056160fa4a 528 {
Andrea Palmieri 142:adf1567d3900 529 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 530 (void)offset;
Andrea Palmieri 142:adf1567d3900 531
Wolfgang Betz 132:51056160fa4a 532 tBleStatus ret;
Wolfgang Betz 132:51056160fa4a 533
Wolfgang Betz 132:51056160fa4a 534 BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this);
Wolfgang Betz 132:51056160fa4a 535
Wolfgang Betz 132:51056160fa4a 536 gattc->_currentState = GATT_READ_CHAR;
Wolfgang Betz 132:51056160fa4a 537
Wolfgang Betz 132:51056160fa4a 538 // Save the attribute_handle not provided by evt_att_read_resp
Wolfgang Betz 132:51056160fa4a 539 gattc->readCBParams.handle = attributeHandle;
Wolfgang Betz 132:51056160fa4a 540
Wolfgang Betz 132:51056160fa4a 541 ret = aci_gatt_read_charac_val(connHandle, attributeHandle);
Wolfgang Betz 132:51056160fa4a 542
Wolfgang Betz 132:51056160fa4a 543 if(ret == BLE_STATUS_SUCCESS) {
Wolfgang Betz 132:51056160fa4a 544 return BLE_ERROR_NONE;
Wolfgang Betz 132:51056160fa4a 545 }
Wolfgang Betz 132:51056160fa4a 546 switch (ret) {
Wolfgang Betz 132:51056160fa4a 547 case BLE_STATUS_BUSY:
Wolfgang Betz 132:51056160fa4a 548 return BLE_STACK_BUSY;
Wolfgang Betz 132:51056160fa4a 549 default:
Wolfgang Betz 132:51056160fa4a 550 return BLE_ERROR_INVALID_STATE;
Wolfgang Betz 132:51056160fa4a 551 }
Wolfgang Betz 132:51056160fa4a 552 }
Wolfgang Betz 132:51056160fa4a 553
Wolfgang Betz 132:51056160fa4a 554 void BlueNRGGattClient::charWritePrepareCB(Gap::Handle_t connHandle,
Wolfgang Betz 132:51056160fa4a 555 uint8_t event_data_length,
Wolfgang Betz 132:51056160fa4a 556 uint16_t attribute_handle,
Wolfgang Betz 132:51056160fa4a 557 uint16_t offset,
Wolfgang Betz 132:51056160fa4a 558 uint8_t *part_attr_value)
Wolfgang Betz 132:51056160fa4a 559 {
Andrea Palmieri 142:adf1567d3900 560 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 561 (void)connHandle;
Andrea Palmieri 142:adf1567d3900 562
Wolfgang Betz 132:51056160fa4a 563 // Update the write response params
Wolfgang Betz 132:51056160fa4a 564 writeCBParams.handle = attribute_handle;
Wolfgang Betz 132:51056160fa4a 565 writeCBParams.offset = offset;
Wolfgang Betz 132:51056160fa4a 566 writeCBParams.len = event_data_length-4; //(?)
Wolfgang Betz 132:51056160fa4a 567 writeCBParams.data = part_attr_value;
Wolfgang Betz 132:51056160fa4a 568
Wolfgang Betz 132:51056160fa4a 569 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Wolfgang Betz 132:51056160fa4a 570 }
Wolfgang Betz 132:51056160fa4a 571
Wolfgang Betz 132:51056160fa4a 572 void BlueNRGGattClient::charWriteExecCB(Gap::Handle_t connHandle,
Wolfgang Betz 132:51056160fa4a 573 uint8_t event_data_length)
Wolfgang Betz 132:51056160fa4a 574 {
Andrea Palmieri 142:adf1567d3900 575 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 576 (void)event_data_length;
Andrea Palmieri 142:adf1567d3900 577
Wolfgang Betz 132:51056160fa4a 578 writeCBParams.connHandle = connHandle;
Wolfgang Betz 132:51056160fa4a 579
Wolfgang Betz 132:51056160fa4a 580 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Wolfgang Betz 132:51056160fa4a 581 }
Wolfgang Betz 132:51056160fa4a 582
Wolfgang Betz 132:51056160fa4a 583 ble_error_t BlueNRGGattClient::write(GattClient::WriteOp_t cmd,
Wolfgang Betz 132:51056160fa4a 584 Gap::Handle_t connHandle,
Wolfgang Betz 132:51056160fa4a 585 GattAttribute::Handle_t attributeHandle,
Wolfgang Betz 132:51056160fa4a 586 size_t length,
Wolfgang Betz 132:51056160fa4a 587 const uint8_t *value) const
Wolfgang Betz 132:51056160fa4a 588 {
Andrea Palmieri 142:adf1567d3900 589 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 590 (void)cmd;
Andrea Palmieri 142:adf1567d3900 591
Wolfgang Betz 132:51056160fa4a 592 tBleStatus ret;
Wolfgang Betz 132:51056160fa4a 593
Wolfgang Betz 132:51056160fa4a 594 BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this);
Wolfgang Betz 132:51056160fa4a 595
Wolfgang Betz 132:51056160fa4a 596 gattc->_currentState = GATT_WRITE_CHAR;
Wolfgang Betz 132:51056160fa4a 597
Wolfgang Betz 132:51056160fa4a 598 // We save the write response params (used by the callback) because
Wolfgang Betz 132:51056160fa4a 599 // when the aci_gatt_write_charac_value() is used the only event received is the EVT_BLUE_GATT_PROCEDURE_COMPLETE
Wolfgang Betz 132:51056160fa4a 600 gattc->writeCBParams.connHandle = connHandle;
Wolfgang Betz 132:51056160fa4a 601 gattc->writeCBParams.writeOp = GattWriteCallbackParams::OP_WRITE_CMD;
Wolfgang Betz 132:51056160fa4a 602 gattc->writeCBParams.handle = attributeHandle;
Wolfgang Betz 132:51056160fa4a 603 gattc->writeCBParams.offset = 0;
Wolfgang Betz 132:51056160fa4a 604 gattc->writeCBParams.len = length;
Wolfgang Betz 132:51056160fa4a 605 gattc->writeCBParams.data = value;
Wolfgang Betz 132:51056160fa4a 606
Wolfgang Betz 132:51056160fa4a 607 ret = aci_gatt_write_charac_value(connHandle, attributeHandle, length, const_cast<uint8_t *>(value));
Wolfgang Betz 132:51056160fa4a 608 //ret = aci_gatt_write_charac_reliable(connHandle, attributeHandle, 0, length, const_cast<uint8_t *>(value));
Wolfgang Betz 132:51056160fa4a 609
Wolfgang Betz 132:51056160fa4a 610 if (ret == BLE_STATUS_SUCCESS) {
Wolfgang Betz 132:51056160fa4a 611 return BLE_ERROR_NONE;
Wolfgang Betz 132:51056160fa4a 612 }
Wolfgang Betz 132:51056160fa4a 613 switch (ret) {
Wolfgang Betz 132:51056160fa4a 614 case BLE_STATUS_BUSY:
Wolfgang Betz 132:51056160fa4a 615 return BLE_STACK_BUSY;
Wolfgang Betz 132:51056160fa4a 616 default:
Wolfgang Betz 132:51056160fa4a 617 return BLE_ERROR_INVALID_STATE;
Wolfgang Betz 132:51056160fa4a 618 }
Wolfgang Betz 132:51056160fa4a 619
Wolfgang Betz 132:51056160fa4a 620 }