adaptation for bkap
Fork of X_NUCLEO_IDB0XA1 by
source/BlueNRGGattClient.cpp@132:51056160fa4a, 2015-10-07 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Oct 07 08:39:04 2015 +0200
- Revision:
- 132:51056160fa4a
- Child:
- 142:adf1567d3900
Andrea's version as of mail from 10/06/2015 05:56 PM
From: Andrea PALMIERI <andrea.palmieri@st.com>
To: Wolfgang BETZ <wolfgang.betz@st.com>, Rohit Grover <rohit.grover@arm.com>,
Antonio VILEI <antonio.vilei@st.com>, Mihail Stoyanov
<Mihail.Stoyanov@arm.com>
CC: Nicola CAPOVILLA <nicola.capovilla@st.com>, Silvio Lucio OLIVA
<silvio.oliva@st.com>, "jonathan.austin@arm.com" <jonathan.austin@arm.com>
Content-Class: urn:content-classes:message
Date: Tue, 6 Oct 2015 17:56:34 +0200
Subject: RE: Arduino Compatibility of X-NUCLEO-IDB04A1
Who changed what in which revision?
User | Revision | Line number | New 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>© 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 |
132:51056160fa4a | 40 | #include "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; |
Wolfgang Betz |
132:51056160fa4a | 85 | |
Wolfgang Betz |
132:51056160fa4a | 86 | numAttr = (event_data_length - 1) / attribute_data_length; |
Wolfgang Betz |
132:51056160fa4a | 87 | |
Wolfgang Betz |
132:51056160fa4a | 88 | offset = 0; |
Wolfgang Betz |
132:51056160fa4a | 89 | for (i=0; i<numAttr; i++) { |
Wolfgang Betz |
132:51056160fa4a | 90 | startHandle = attribute_data_list[offset]; |
Wolfgang Betz |
132:51056160fa4a | 91 | endHandle = attribute_data_list[offset+2]; |
Wolfgang Betz |
132:51056160fa4a | 92 | |
Wolfgang Betz |
132:51056160fa4a | 93 | // UUID Type |
Wolfgang Betz |
132:51056160fa4a | 94 | if (attribute_data_length == 6) { |
Wolfgang Betz |
132:51056160fa4a | 95 | |
Wolfgang Betz |
132:51056160fa4a | 96 | PRINTF("UUID_TYPE_16\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 97 | uuid = attribute_data_list[offset+5]<<8|attribute_data_list[offset+4]; |
Wolfgang Betz |
132:51056160fa4a | 98 | PRINTF("S UUID-%X attrs[%u %u]\r\n", uuid.getShortUUID(), startHandle, endHandle); |
Wolfgang Betz |
132:51056160fa4a | 99 | |
Wolfgang Betz |
132:51056160fa4a | 100 | } else { |
Wolfgang Betz |
132:51056160fa4a | 101 | |
Wolfgang Betz |
132:51056160fa4a | 102 | PRINTF("UUID_TYPE_128\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 103 | uuid.setupLong(attribute_data_list+offset+4); |
Wolfgang Betz |
132:51056160fa4a | 104 | |
Wolfgang Betz |
132:51056160fa4a | 105 | PRINTF("S UUID-"); |
Wolfgang Betz |
132:51056160fa4a | 106 | const uint8_t *longUUIDBytes = uuid.getBaseUUID(); |
Wolfgang Betz |
132:51056160fa4a | 107 | for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) { |
Wolfgang Betz |
132:51056160fa4a | 108 | PRINTF("%02x", longUUIDBytes[j]); |
Wolfgang Betz |
132:51056160fa4a | 109 | } |
Wolfgang Betz |
132:51056160fa4a | 110 | PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle); |
Wolfgang Betz |
132:51056160fa4a | 111 | |
Wolfgang Betz |
132:51056160fa4a | 112 | } |
Wolfgang Betz |
132:51056160fa4a | 113 | |
Wolfgang Betz |
132:51056160fa4a | 114 | PRINTF("Setup serviceIndex = %d\n\r", _numServices); |
Wolfgang Betz |
132:51056160fa4a | 115 | discoveredService[_numServices].setup(uuid, startHandle, endHandle); |
Wolfgang Betz |
132:51056160fa4a | 116 | |
Wolfgang Betz |
132:51056160fa4a | 117 | if(serviceDiscoveryCallback) { |
Wolfgang Betz |
132:51056160fa4a | 118 | if(_matchingServiceUUID == BLE_UUID_UNKNOWN || _matchingServiceUUID == discoveredService[_numServices].getUUID()) { |
Wolfgang Betz |
132:51056160fa4a | 119 | serviceDiscoveryCallback(&discoveredService[_numServices]); |
Wolfgang Betz |
132:51056160fa4a | 120 | } |
Wolfgang Betz |
132:51056160fa4a | 121 | } |
Wolfgang Betz |
132:51056160fa4a | 122 | _numServices++; |
Wolfgang Betz |
132:51056160fa4a | 123 | |
Wolfgang Betz |
132:51056160fa4a | 124 | offset += attribute_data_length; |
Wolfgang Betz |
132:51056160fa4a | 125 | } |
Wolfgang Betz |
132:51056160fa4a | 126 | |
Wolfgang Betz |
132:51056160fa4a | 127 | PRINTF("!!!Service Discovery complete (numAttr=%u)!!!\n\r", numAttr); |
Wolfgang Betz |
132:51056160fa4a | 128 | |
Wolfgang Betz |
132:51056160fa4a | 129 | } |
Wolfgang Betz |
132:51056160fa4a | 130 | |
Wolfgang Betz |
132:51056160fa4a | 131 | void BlueNRGGattClient::primaryServiceCB(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 132 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 133 | uint8_t *handles_info_list) |
Wolfgang Betz |
132:51056160fa4a | 134 | { |
Wolfgang Betz |
132:51056160fa4a | 135 | GattAttribute::Handle_t startHandle, endHandle; |
Wolfgang Betz |
132:51056160fa4a | 136 | UUID uuid; |
Wolfgang Betz |
132:51056160fa4a | 137 | uint8_t i, offset, numHandlePairs; |
Wolfgang Betz |
132:51056160fa4a | 138 | |
Wolfgang Betz |
132:51056160fa4a | 139 | numHandlePairs = (event_data_length - 1) / 2; |
Wolfgang Betz |
132:51056160fa4a | 140 | |
Wolfgang Betz |
132:51056160fa4a | 141 | offset = 0; |
Wolfgang Betz |
132:51056160fa4a | 142 | for (i=0; i<numHandlePairs; i++) { |
Wolfgang Betz |
132:51056160fa4a | 143 | startHandle = handles_info_list[offset]; |
Wolfgang Betz |
132:51056160fa4a | 144 | endHandle = handles_info_list[offset+2]; |
Wolfgang Betz |
132:51056160fa4a | 145 | |
Wolfgang Betz |
132:51056160fa4a | 146 | PRINTF("primaryServiceCB attrs[%u %u]\r\n", startHandle, endHandle); |
Wolfgang Betz |
132:51056160fa4a | 147 | |
Wolfgang Betz |
132:51056160fa4a | 148 | discoveredService[i].setup(_matchingServiceUUID, startHandle, endHandle); |
Wolfgang Betz |
132:51056160fa4a | 149 | |
Wolfgang Betz |
132:51056160fa4a | 150 | if(serviceDiscoveryCallback) { |
Wolfgang Betz |
132:51056160fa4a | 151 | serviceDiscoveryCallback(&discoveredService[_numServices]); |
Wolfgang Betz |
132:51056160fa4a | 152 | } |
Wolfgang Betz |
132:51056160fa4a | 153 | _numServices++; |
Wolfgang Betz |
132:51056160fa4a | 154 | |
Wolfgang Betz |
132:51056160fa4a | 155 | offset += 4; |
Wolfgang Betz |
132:51056160fa4a | 156 | } |
Wolfgang Betz |
132:51056160fa4a | 157 | } |
Wolfgang Betz |
132:51056160fa4a | 158 | |
Wolfgang Betz |
132:51056160fa4a | 159 | void BlueNRGGattClient::serviceCharsCB(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 160 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 161 | uint8_t handle_value_pair_length, |
Wolfgang Betz |
132:51056160fa4a | 162 | uint8_t *handle_value_pair) |
Wolfgang Betz |
132:51056160fa4a | 163 | { |
Wolfgang Betz |
132:51056160fa4a | 164 | // Charac Handle (2), Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16) |
Wolfgang Betz |
132:51056160fa4a | 165 | |
Wolfgang Betz |
132:51056160fa4a | 166 | GattAttribute::Handle_t declHandle, valueHandle; |
Wolfgang Betz |
132:51056160fa4a | 167 | UUID uuid; |
Wolfgang Betz |
132:51056160fa4a | 168 | uint8_t i, numChar, offset; |
Wolfgang Betz |
132:51056160fa4a | 169 | |
Wolfgang Betz |
132:51056160fa4a | 170 | numChar = (event_data_length - 1) / handle_value_pair_length; |
Wolfgang Betz |
132:51056160fa4a | 171 | |
Wolfgang Betz |
132:51056160fa4a | 172 | offset = 0; |
Wolfgang Betz |
132:51056160fa4a | 173 | for (i=0; i<numChar; i++) { |
Wolfgang Betz |
132:51056160fa4a | 174 | // UUID Type |
Wolfgang Betz |
132:51056160fa4a | 175 | if (handle_value_pair_length == 7) { |
Wolfgang Betz |
132:51056160fa4a | 176 | PRINTF("Char UUID_TYPE_16\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 177 | uuid = handle_value_pair[offset+6]<<8|handle_value_pair[offset+5]; |
Wolfgang Betz |
132:51056160fa4a | 178 | PRINTF("C UUID-%X\r\n", uuid.getShortUUID()); |
Wolfgang Betz |
132:51056160fa4a | 179 | } else { |
Wolfgang Betz |
132:51056160fa4a | 180 | PRINTF("Char UUID_TYPE_128\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 181 | uuid.setupLong(handle_value_pair+offset+5); |
Wolfgang Betz |
132:51056160fa4a | 182 | PRINTF("C UUID-"); |
Wolfgang Betz |
132:51056160fa4a | 183 | const uint8_t *longUUIDBytes = uuid.getBaseUUID(); |
Wolfgang Betz |
132:51056160fa4a | 184 | for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) { |
Wolfgang Betz |
132:51056160fa4a | 185 | PRINTF("%02X", longUUIDBytes[i]); |
Wolfgang Betz |
132:51056160fa4a | 186 | } |
Wolfgang Betz |
132:51056160fa4a | 187 | PRINTF("\r\n"); |
Wolfgang Betz |
132:51056160fa4a | 188 | } |
Wolfgang Betz |
132:51056160fa4a | 189 | |
Wolfgang Betz |
132:51056160fa4a | 190 | // Properties |
Wolfgang Betz |
132:51056160fa4a | 191 | DiscoveredCharacteristic::Properties_t p; |
Wolfgang Betz |
132:51056160fa4a | 192 | |
Wolfgang Betz |
132:51056160fa4a | 193 | p._broadcast = (props_mask[0] & handle_value_pair[offset+2]); |
Wolfgang Betz |
132:51056160fa4a | 194 | p._read = (props_mask[1] & handle_value_pair[offset+2])>>1; |
Wolfgang Betz |
132:51056160fa4a | 195 | p._writeWoResp = (props_mask[2] & handle_value_pair[offset+2])>>2; |
Wolfgang Betz |
132:51056160fa4a | 196 | p._write = (props_mask[3] & handle_value_pair[offset+2])>>3; |
Wolfgang Betz |
132:51056160fa4a | 197 | p._notify = (props_mask[4] & handle_value_pair[offset+2])>>4; |
Wolfgang Betz |
132:51056160fa4a | 198 | p._indicate = (props_mask[5] & handle_value_pair[offset+2])>>5; |
Wolfgang Betz |
132:51056160fa4a | 199 | p._authSignedWrite = (props_mask[6] & handle_value_pair[offset+2])>>6; |
Wolfgang Betz |
132:51056160fa4a | 200 | PRINTF("p._broadcast=%d\n\r", p._broadcast); |
Wolfgang Betz |
132:51056160fa4a | 201 | PRINTF("p._read=%d\n\r", p._read); |
Wolfgang Betz |
132:51056160fa4a | 202 | PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp); |
Wolfgang Betz |
132:51056160fa4a | 203 | PRINTF("p._write=%d\n\r", p._write); |
Wolfgang Betz |
132:51056160fa4a | 204 | PRINTF("p._notify=%d\n\r", p._notify); |
Wolfgang Betz |
132:51056160fa4a | 205 | PRINTF("p._indicate=%d\n\r", p._indicate); |
Wolfgang Betz |
132:51056160fa4a | 206 | PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite); |
Wolfgang Betz |
132:51056160fa4a | 207 | |
Wolfgang Betz |
132:51056160fa4a | 208 | /* |
Wolfgang Betz |
132:51056160fa4a | 209 | uint8_t props = handle_value_pair[offset+2]; |
Wolfgang Betz |
132:51056160fa4a | 210 | PRINTF("CHAR PROPS: %d\n\r", props); |
Wolfgang Betz |
132:51056160fa4a | 211 | */ |
Wolfgang Betz |
132:51056160fa4a | 212 | |
Wolfgang Betz |
132:51056160fa4a | 213 | // Handles |
Wolfgang Betz |
132:51056160fa4a | 214 | declHandle = handle_value_pair[offset]; |
Wolfgang Betz |
132:51056160fa4a | 215 | valueHandle = handle_value_pair[offset+3]; |
Wolfgang Betz |
132:51056160fa4a | 216 | |
Wolfgang Betz |
132:51056160fa4a | 217 | discoveredChar[_numChars].setup(this, |
Wolfgang Betz |
132:51056160fa4a | 218 | connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 219 | uuid, |
Wolfgang Betz |
132:51056160fa4a | 220 | p, |
Wolfgang Betz |
132:51056160fa4a | 221 | declHandle, |
Wolfgang Betz |
132:51056160fa4a | 222 | valueHandle); |
Wolfgang Betz |
132:51056160fa4a | 223 | |
Wolfgang Betz |
132:51056160fa4a | 224 | if(characteristicDiscoveryCallback) { |
Wolfgang Betz |
132:51056160fa4a | 225 | characteristicDiscoveryCallback(&discoveredChar[_numChars]); |
Wolfgang Betz |
132:51056160fa4a | 226 | } |
Wolfgang Betz |
132:51056160fa4a | 227 | _numChars++; |
Wolfgang Betz |
132:51056160fa4a | 228 | |
Wolfgang Betz |
132:51056160fa4a | 229 | offset += handle_value_pair_length; |
Wolfgang Betz |
132:51056160fa4a | 230 | } |
Wolfgang Betz |
132:51056160fa4a | 231 | } |
Wolfgang Betz |
132:51056160fa4a | 232 | |
Wolfgang Betz |
132:51056160fa4a | 233 | void BlueNRGGattClient::serviceCharByUUIDCB(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 234 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 235 | uint16_t attr_handle, |
Wolfgang Betz |
132:51056160fa4a | 236 | uint8_t *attr_value) |
Wolfgang Betz |
132:51056160fa4a | 237 | { |
Wolfgang Betz |
132:51056160fa4a | 238 | // Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16) |
Wolfgang Betz |
132:51056160fa4a | 239 | GattAttribute::Handle_t declHandle, valueHandle; |
Wolfgang Betz |
132:51056160fa4a | 240 | UUID uuid; |
Wolfgang Betz |
132:51056160fa4a | 241 | |
Wolfgang Betz |
132:51056160fa4a | 242 | PRINTF("serviceCharByUUIDCB\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 243 | |
Wolfgang Betz |
132:51056160fa4a | 244 | // UUID Type |
Wolfgang Betz |
132:51056160fa4a | 245 | if (event_data_length == 7) { |
Wolfgang Betz |
132:51056160fa4a | 246 | PRINTF("Char UUID_TYPE_16\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 247 | uuid = attr_value[4]<<8|attr_value[3]; |
Wolfgang Betz |
132:51056160fa4a | 248 | PRINTF("C UUID-%X\r\n", uuid.getShortUUID()); |
Wolfgang Betz |
132:51056160fa4a | 249 | } else { |
Wolfgang Betz |
132:51056160fa4a | 250 | PRINTF("Char UUID_TYPE_128\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 251 | uuid.setupLong(attr_value+3); |
Wolfgang Betz |
132:51056160fa4a | 252 | PRINTF("C UUID-"); |
Wolfgang Betz |
132:51056160fa4a | 253 | const uint8_t *longUUIDBytes = uuid.getBaseUUID(); |
Wolfgang Betz |
132:51056160fa4a | 254 | for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) { |
Wolfgang Betz |
132:51056160fa4a | 255 | PRINTF("%02X", longUUIDBytes[i]); |
Wolfgang Betz |
132:51056160fa4a | 256 | } |
Wolfgang Betz |
132:51056160fa4a | 257 | PRINTF("\r\n"); |
Wolfgang Betz |
132:51056160fa4a | 258 | } |
Wolfgang Betz |
132:51056160fa4a | 259 | |
Wolfgang Betz |
132:51056160fa4a | 260 | // Properties |
Wolfgang Betz |
132:51056160fa4a | 261 | DiscoveredCharacteristic::Properties_t p; |
Wolfgang Betz |
132:51056160fa4a | 262 | |
Wolfgang Betz |
132:51056160fa4a | 263 | p._broadcast = (props_mask[0] & attr_value[0]); |
Wolfgang Betz |
132:51056160fa4a | 264 | p._read = (props_mask[1] & attr_value[0])>>1; |
Wolfgang Betz |
132:51056160fa4a | 265 | p._writeWoResp = (props_mask[2] & attr_value[0])>>2; |
Wolfgang Betz |
132:51056160fa4a | 266 | p._write = (props_mask[3] & attr_value[0])>>3; |
Wolfgang Betz |
132:51056160fa4a | 267 | p._notify = (props_mask[4] & attr_value[0])>>4; |
Wolfgang Betz |
132:51056160fa4a | 268 | p._indicate = (props_mask[5] & attr_value[0])>>5; |
Wolfgang Betz |
132:51056160fa4a | 269 | p._authSignedWrite = (props_mask[6] & attr_value[0])>>6; |
Wolfgang Betz |
132:51056160fa4a | 270 | PRINTF("p._broadcast=%d\n\r", p._broadcast); |
Wolfgang Betz |
132:51056160fa4a | 271 | PRINTF("p._read=%d\n\r", p._read); |
Wolfgang Betz |
132:51056160fa4a | 272 | PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp); |
Wolfgang Betz |
132:51056160fa4a | 273 | PRINTF("p._write=%d\n\r", p._write); |
Wolfgang Betz |
132:51056160fa4a | 274 | PRINTF("p._notify=%d\n\r", p._notify); |
Wolfgang Betz |
132:51056160fa4a | 275 | PRINTF("p._indicate=%d\n\r", p._indicate); |
Wolfgang Betz |
132:51056160fa4a | 276 | PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite); |
Wolfgang Betz |
132:51056160fa4a | 277 | |
Wolfgang Betz |
132:51056160fa4a | 278 | /* |
Wolfgang Betz |
132:51056160fa4a | 279 | uint8_t props = attr_value[0]; |
Wolfgang Betz |
132:51056160fa4a | 280 | PRINTF("CHAR PROPS: %d\n\r", props); |
Wolfgang Betz |
132:51056160fa4a | 281 | */ |
Wolfgang Betz |
132:51056160fa4a | 282 | |
Wolfgang Betz |
132:51056160fa4a | 283 | // Handles |
Wolfgang Betz |
132:51056160fa4a | 284 | declHandle = attr_handle; |
Wolfgang Betz |
132:51056160fa4a | 285 | valueHandle = attr_value[1]; |
Wolfgang Betz |
132:51056160fa4a | 286 | |
Wolfgang Betz |
132:51056160fa4a | 287 | discoveredChar[_numChars].setup(this, |
Wolfgang Betz |
132:51056160fa4a | 288 | connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 289 | uuid, |
Wolfgang Betz |
132:51056160fa4a | 290 | p, |
Wolfgang Betz |
132:51056160fa4a | 291 | declHandle, |
Wolfgang Betz |
132:51056160fa4a | 292 | valueHandle); |
Wolfgang Betz |
132:51056160fa4a | 293 | |
Wolfgang Betz |
132:51056160fa4a | 294 | if(characteristicDiscoveryCallback) { |
Wolfgang Betz |
132:51056160fa4a | 295 | characteristicDiscoveryCallback(&discoveredChar[_numChars]); |
Wolfgang Betz |
132:51056160fa4a | 296 | } |
Wolfgang Betz |
132:51056160fa4a | 297 | _numChars++; |
Wolfgang Betz |
132:51056160fa4a | 298 | } |
Wolfgang Betz |
132:51056160fa4a | 299 | |
Wolfgang Betz |
132:51056160fa4a | 300 | ble_error_t BlueNRGGattClient::findServiceChars(Gap::Handle_t connectionHandle) |
Wolfgang Betz |
132:51056160fa4a | 301 | { |
Wolfgang Betz |
132:51056160fa4a | 302 | PRINTF("findServiceChars\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 303 | |
Wolfgang Betz |
132:51056160fa4a | 304 | tBleStatus ret; |
Wolfgang Betz |
132:51056160fa4a | 305 | uint8_t uuid_type; |
Wolfgang Betz |
132:51056160fa4a | 306 | uint8_t short_uuid[2]; |
Wolfgang Betz |
132:51056160fa4a | 307 | uint8_t *uuid; |
Wolfgang Betz |
132:51056160fa4a | 308 | |
Wolfgang Betz |
132:51056160fa4a | 309 | DiscoveredService *service; |
Wolfgang Betz |
132:51056160fa4a | 310 | |
Wolfgang Betz |
132:51056160fa4a | 311 | // We finished chars discovery for all services |
Wolfgang Betz |
132:51056160fa4a | 312 | if(_servIndex >= _numServices) { |
Wolfgang Betz |
132:51056160fa4a | 313 | PRINTF("!!!We finished chars discovery for all services!!!\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 314 | _currentState = GATT_CHARS_DISCOVERY_COMPLETE; |
Wolfgang Betz |
132:51056160fa4a | 315 | |
Wolfgang Betz |
132:51056160fa4a | 316 | terminateServiceDiscovery(); |
Wolfgang Betz |
132:51056160fa4a | 317 | |
Wolfgang Betz |
132:51056160fa4a | 318 | return BLE_ERROR_NONE; |
Wolfgang Betz |
132:51056160fa4a | 319 | } |
Wolfgang Betz |
132:51056160fa4a | 320 | |
Wolfgang Betz |
132:51056160fa4a | 321 | service = &discoveredService[_servIndex]; |
Wolfgang Betz |
132:51056160fa4a | 322 | /* |
Wolfgang Betz |
132:51056160fa4a | 323 | if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) { |
Wolfgang Betz |
132:51056160fa4a | 324 | PRINTF("S UUID-%X\r\n", service->getUUID().getShortUUID()); |
Wolfgang Betz |
132:51056160fa4a | 325 | } else { |
Wolfgang Betz |
132:51056160fa4a | 326 | PRINTF("S UUID-"); |
Wolfgang Betz |
132:51056160fa4a | 327 | const uint8_t *longUUIDBytes = service->getUUID().getBaseUUID(); |
Wolfgang Betz |
132:51056160fa4a | 328 | for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) { |
Wolfgang Betz |
132:51056160fa4a | 329 | PRINTF("%02X", longUUIDBytes[i]); |
Wolfgang Betz |
132:51056160fa4a | 330 | } |
Wolfgang Betz |
132:51056160fa4a | 331 | PRINTF("\r\n"); |
Wolfgang Betz |
132:51056160fa4a | 332 | } |
Wolfgang Betz |
132:51056160fa4a | 333 | */ |
Wolfgang Betz |
132:51056160fa4a | 334 | |
Wolfgang Betz |
132:51056160fa4a | 335 | PRINTF("findServiceChars (_servIndex=%d)\n\r", _servIndex); |
Wolfgang Betz |
132:51056160fa4a | 336 | //ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle()); |
Wolfgang Betz |
132:51056160fa4a | 337 | |
Wolfgang Betz |
132:51056160fa4a | 338 | if(_matchingCharacteristicUUIDIn == BLE_UUID_UNKNOWN) { |
Wolfgang Betz |
132:51056160fa4a | 339 | PRINTF("findServiceChars (BLE_UUID_UNKNOWN)\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 340 | ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle()); |
Wolfgang Betz |
132:51056160fa4a | 341 | } else { |
Wolfgang Betz |
132:51056160fa4a | 342 | |
Wolfgang Betz |
132:51056160fa4a | 343 | uint8_t type = _matchingCharacteristicUUIDIn.shortOrLong(); |
Wolfgang Betz |
132:51056160fa4a | 344 | |
Wolfgang Betz |
132:51056160fa4a | 345 | if(type == UUID::UUID_TYPE_SHORT) { |
Wolfgang Betz |
132:51056160fa4a | 346 | STORE_LE_16(short_uuid, _matchingCharacteristicUUIDIn.getShortUUID()); |
Wolfgang Betz |
132:51056160fa4a | 347 | |
Wolfgang Betz |
132:51056160fa4a | 348 | uuid_type = UUID_TYPE_16; |
Wolfgang Betz |
132:51056160fa4a | 349 | uuid = short_uuid; |
Wolfgang Betz |
132:51056160fa4a | 350 | |
Wolfgang Betz |
132:51056160fa4a | 351 | PRINTF("findServiceChars C UUID-"); |
Wolfgang Betz |
132:51056160fa4a | 352 | for(unsigned i = 0; i < 2; i++) { |
Wolfgang Betz |
132:51056160fa4a | 353 | PRINTF("%02X", short_uuid[i]); |
Wolfgang Betz |
132:51056160fa4a | 354 | } |
Wolfgang Betz |
132:51056160fa4a | 355 | PRINTF("\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 356 | |
Wolfgang Betz |
132:51056160fa4a | 357 | } else if(type==UUID::UUID_TYPE_LONG) { |
Wolfgang Betz |
132:51056160fa4a | 358 | |
Wolfgang Betz |
132:51056160fa4a | 359 | uuid_type = UUID_TYPE_128; |
Wolfgang Betz |
132:51056160fa4a | 360 | uuid = (unsigned char*)_matchingCharacteristicUUIDIn.getBaseUUID(); |
Wolfgang Betz |
132:51056160fa4a | 361 | |
Wolfgang Betz |
132:51056160fa4a | 362 | PRINTF("(findServiceChars) C UUID-"); |
Wolfgang Betz |
132:51056160fa4a | 363 | for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) { |
Wolfgang Betz |
132:51056160fa4a | 364 | PRINTF("%02X", uuid[i]); |
Wolfgang Betz |
132:51056160fa4a | 365 | } |
Wolfgang Betz |
132:51056160fa4a | 366 | PRINTF("\r\n"); |
Wolfgang Betz |
132:51056160fa4a | 367 | } |
Wolfgang Betz |
132:51056160fa4a | 368 | |
Wolfgang Betz |
132:51056160fa4a | 369 | ret = aci_gatt_disc_charac_by_uuid(connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 370 | service->getStartHandle(), |
Wolfgang Betz |
132:51056160fa4a | 371 | service->getEndHandle(), |
Wolfgang Betz |
132:51056160fa4a | 372 | uuid_type, |
Wolfgang Betz |
132:51056160fa4a | 373 | uuid); |
Wolfgang Betz |
132:51056160fa4a | 374 | } |
Wolfgang Betz |
132:51056160fa4a | 375 | |
Wolfgang Betz |
132:51056160fa4a | 376 | if(ret == BLE_STATUS_SUCCESS) { |
Wolfgang Betz |
132:51056160fa4a | 377 | _servIndex++; |
Wolfgang Betz |
132:51056160fa4a | 378 | } |
Wolfgang Betz |
132:51056160fa4a | 379 | |
Wolfgang Betz |
132:51056160fa4a | 380 | PRINTF("findServiceChars ret=%d\n\r", ret); |
Wolfgang Betz |
132:51056160fa4a | 381 | |
Wolfgang Betz |
132:51056160fa4a | 382 | return BLE_ERROR_NONE; |
Wolfgang Betz |
132:51056160fa4a | 383 | } |
Wolfgang Betz |
132:51056160fa4a | 384 | |
Wolfgang Betz |
132:51056160fa4a | 385 | ble_error_t BlueNRGGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 386 | ServiceDiscovery::ServiceCallback_t sc, |
Wolfgang Betz |
132:51056160fa4a | 387 | ServiceDiscovery::CharacteristicCallback_t cc, |
Wolfgang Betz |
132:51056160fa4a | 388 | const UUID &matchingServiceUUID, |
Wolfgang Betz |
132:51056160fa4a | 389 | const UUID &matchingCharacteristicUUIDIn) |
Wolfgang Betz |
132:51056160fa4a | 390 | { |
Wolfgang Betz |
132:51056160fa4a | 391 | PRINTF("launchServiceDiscovery\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 392 | |
Wolfgang Betz |
132:51056160fa4a | 393 | tBleStatus ret; |
Wolfgang Betz |
132:51056160fa4a | 394 | uint8_t uuid_type; |
Wolfgang Betz |
132:51056160fa4a | 395 | uint8_t short_uuid[2]; |
Wolfgang Betz |
132:51056160fa4a | 396 | uint8_t *uuid; |
Wolfgang Betz |
132:51056160fa4a | 397 | unsigned j; |
Wolfgang Betz |
132:51056160fa4a | 398 | |
Wolfgang Betz |
132:51056160fa4a | 399 | _connectionHandle = connectionHandle; |
Wolfgang Betz |
132:51056160fa4a | 400 | serviceDiscoveryCallback = sc; |
Wolfgang Betz |
132:51056160fa4a | 401 | characteristicDiscoveryCallback = cc; |
Wolfgang Betz |
132:51056160fa4a | 402 | _matchingServiceUUID = matchingServiceUUID; |
Wolfgang Betz |
132:51056160fa4a | 403 | _matchingCharacteristicUUIDIn = matchingCharacteristicUUIDIn; |
Wolfgang Betz |
132:51056160fa4a | 404 | |
Wolfgang Betz |
132:51056160fa4a | 405 | //reset services |
Wolfgang Betz |
132:51056160fa4a | 406 | _numServices = 0; |
Wolfgang Betz |
132:51056160fa4a | 407 | _numChars = 0; |
Wolfgang Betz |
132:51056160fa4a | 408 | _servIndex = 0; |
Wolfgang Betz |
132:51056160fa4a | 409 | for(j = 0; j < BLE_TOTAL_DISCOVERED_SERVICES; j++) { |
Wolfgang Betz |
132:51056160fa4a | 410 | discoveredService[j].setup(BLE_UUID_UNKNOWN, GattAttribute::INVALID_HANDLE, GattAttribute::INVALID_HANDLE); |
Wolfgang Betz |
132:51056160fa4a | 411 | } |
Wolfgang Betz |
132:51056160fa4a | 412 | |
Wolfgang Betz |
132:51056160fa4a | 413 | if(matchingServiceUUID == BLE_UUID_UNKNOWN) { |
Wolfgang Betz |
132:51056160fa4a | 414 | |
Wolfgang Betz |
132:51056160fa4a | 415 | // Wildcard: search for all services |
Wolfgang Betz |
132:51056160fa4a | 416 | ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle); |
Wolfgang Betz |
132:51056160fa4a | 417 | |
Wolfgang Betz |
132:51056160fa4a | 418 | } else { |
Wolfgang Betz |
132:51056160fa4a | 419 | |
Wolfgang Betz |
132:51056160fa4a | 420 | uint8_t type = matchingServiceUUID.shortOrLong(); |
Wolfgang Betz |
132:51056160fa4a | 421 | //PRINTF("AddService(): Type:%d\n\r", type); |
Wolfgang Betz |
132:51056160fa4a | 422 | |
Wolfgang Betz |
132:51056160fa4a | 423 | if(type == UUID::UUID_TYPE_SHORT) { |
Wolfgang Betz |
132:51056160fa4a | 424 | STORE_LE_16(short_uuid, matchingServiceUUID.getShortUUID()); |
Wolfgang Betz |
132:51056160fa4a | 425 | |
Wolfgang Betz |
132:51056160fa4a | 426 | PRINTF("launchServiceDiscovery short_uuid=0x"); |
Wolfgang Betz |
132:51056160fa4a | 427 | for(j = 0; j < 2; j++) { |
Wolfgang Betz |
132:51056160fa4a | 428 | PRINTF("%02X", short_uuid[j]); |
Wolfgang Betz |
132:51056160fa4a | 429 | } |
Wolfgang Betz |
132:51056160fa4a | 430 | PRINTF("\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 431 | |
Wolfgang Betz |
132:51056160fa4a | 432 | |
Wolfgang Betz |
132:51056160fa4a | 433 | uuid_type = UUID_TYPE_16; |
Wolfgang Betz |
132:51056160fa4a | 434 | uuid = short_uuid; |
Wolfgang Betz |
132:51056160fa4a | 435 | |
Wolfgang Betz |
132:51056160fa4a | 436 | } else if(type==UUID::UUID_TYPE_LONG) { |
Wolfgang Betz |
132:51056160fa4a | 437 | |
Wolfgang Betz |
132:51056160fa4a | 438 | uuid_type = UUID_TYPE_128; |
Wolfgang Betz |
132:51056160fa4a | 439 | uuid = (unsigned char*)matchingServiceUUID.getBaseUUID(); |
Wolfgang Betz |
132:51056160fa4a | 440 | |
Wolfgang Betz |
132:51056160fa4a | 441 | /* |
Wolfgang Betz |
132:51056160fa4a | 442 | PRINTF("launchServiceDiscovery base_uuid=0x"); |
Wolfgang Betz |
132:51056160fa4a | 443 | for(j = 0; j < 16; j++) { |
Wolfgang Betz |
132:51056160fa4a | 444 | PRINTF("%02X", uuid[j]); |
Wolfgang Betz |
132:51056160fa4a | 445 | } |
Wolfgang Betz |
132:51056160fa4a | 446 | PRINTF("\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 447 | */ |
Wolfgang Betz |
132:51056160fa4a | 448 | } |
Wolfgang Betz |
132:51056160fa4a | 449 | |
Wolfgang Betz |
132:51056160fa4a | 450 | // search for specific service by UUID |
Wolfgang Betz |
132:51056160fa4a | 451 | ret = aci_gatt_disc_prim_service_by_uuid((uint16_t)connectionHandle, uuid_type, uuid); |
Wolfgang Betz |
132:51056160fa4a | 452 | //ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle); |
Wolfgang Betz |
132:51056160fa4a | 453 | } |
Wolfgang Betz |
132:51056160fa4a | 454 | |
Wolfgang Betz |
132:51056160fa4a | 455 | if(ret == BLE_STATUS_SUCCESS) { |
Wolfgang Betz |
132:51056160fa4a | 456 | _currentState = GATT_SERVICE_DISCOVERY; |
Wolfgang Betz |
132:51056160fa4a | 457 | } |
Wolfgang Betz |
132:51056160fa4a | 458 | |
Wolfgang Betz |
132:51056160fa4a | 459 | PRINTF("launchServiceDiscovery ret=%d\n\r", ret); |
Wolfgang Betz |
132:51056160fa4a | 460 | |
Wolfgang Betz |
132:51056160fa4a | 461 | return BLE_ERROR_NONE; |
Wolfgang Betz |
132:51056160fa4a | 462 | } |
Wolfgang Betz |
132:51056160fa4a | 463 | |
Wolfgang Betz |
132:51056160fa4a | 464 | ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 465 | ServiceDiscovery::ServiceCallback_t callback, |
Wolfgang Betz |
132:51056160fa4a | 466 | const UUID &matchingServiceUUID) |
Wolfgang Betz |
132:51056160fa4a | 467 | { |
Wolfgang Betz |
132:51056160fa4a | 468 | return BLE_ERROR_NOT_IMPLEMENTED; |
Wolfgang Betz |
132:51056160fa4a | 469 | } |
Wolfgang Betz |
132:51056160fa4a | 470 | |
Wolfgang Betz |
132:51056160fa4a | 471 | ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 472 | ServiceDiscovery::ServiceCallback_t callback, |
Wolfgang Betz |
132:51056160fa4a | 473 | GattAttribute::Handle_t startHandle, |
Wolfgang Betz |
132:51056160fa4a | 474 | GattAttribute::Handle_t endHandle) |
Wolfgang Betz |
132:51056160fa4a | 475 | { |
Wolfgang Betz |
132:51056160fa4a | 476 | return BLE_ERROR_NOT_IMPLEMENTED; |
Wolfgang Betz |
132:51056160fa4a | 477 | } |
Wolfgang Betz |
132:51056160fa4a | 478 | |
Wolfgang Betz |
132:51056160fa4a | 479 | bool BlueNRGGattClient::isServiceDiscoveryActive(void) const |
Wolfgang Betz |
132:51056160fa4a | 480 | { |
Wolfgang Betz |
132:51056160fa4a | 481 | if(_currentState == GATT_IDLE || |
Wolfgang Betz |
132:51056160fa4a | 482 | _currentState == GATT_DISCOVERY_TERMINATED || |
Wolfgang Betz |
132:51056160fa4a | 483 | _currentState == GATT_READ_CHAR || |
Wolfgang Betz |
132:51056160fa4a | 484 | _currentState == GATT_WRITE_CHAR ) { |
Wolfgang Betz |
132:51056160fa4a | 485 | return false; |
Wolfgang Betz |
132:51056160fa4a | 486 | } |
Wolfgang Betz |
132:51056160fa4a | 487 | |
Wolfgang Betz |
132:51056160fa4a | 488 | return true; |
Wolfgang Betz |
132:51056160fa4a | 489 | } |
Wolfgang Betz |
132:51056160fa4a | 490 | |
Wolfgang Betz |
132:51056160fa4a | 491 | void BlueNRGGattClient::terminateServiceDiscovery(void) |
Wolfgang Betz |
132:51056160fa4a | 492 | { |
Wolfgang Betz |
132:51056160fa4a | 493 | _currentState = GATT_DISCOVERY_TERMINATED; |
Wolfgang Betz |
132:51056160fa4a | 494 | |
Wolfgang Betz |
132:51056160fa4a | 495 | if (terminationCallback) { |
Wolfgang Betz |
132:51056160fa4a | 496 | terminationCallback(_connectionHandle); |
Wolfgang Betz |
132:51056160fa4a | 497 | } |
Wolfgang Betz |
132:51056160fa4a | 498 | } |
Wolfgang Betz |
132:51056160fa4a | 499 | |
Wolfgang Betz |
132:51056160fa4a | 500 | void BlueNRGGattClient::charReadCB(Gap::Handle_t connHandle, |
Wolfgang Betz |
132:51056160fa4a | 501 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 502 | uint8_t* attribute_value) |
Wolfgang Betz |
132:51056160fa4a | 503 | { |
Wolfgang Betz |
132:51056160fa4a | 504 | readCBParams.connHandle = connHandle; |
Wolfgang Betz |
132:51056160fa4a | 505 | readCBParams.offset = 0; |
Wolfgang Betz |
132:51056160fa4a | 506 | readCBParams.len = event_data_length; |
Wolfgang Betz |
132:51056160fa4a | 507 | readCBParams.data = attribute_value; |
Wolfgang Betz |
132:51056160fa4a | 508 | |
Wolfgang Betz |
132:51056160fa4a | 509 | BlueNRGGattClient::getInstance().processReadResponse(&readCBParams); |
Wolfgang Betz |
132:51056160fa4a | 510 | } |
Wolfgang Betz |
132:51056160fa4a | 511 | |
Wolfgang Betz |
132:51056160fa4a | 512 | ble_error_t BlueNRGGattClient::read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const |
Wolfgang Betz |
132:51056160fa4a | 513 | { |
Wolfgang Betz |
132:51056160fa4a | 514 | tBleStatus ret; |
Wolfgang Betz |
132:51056160fa4a | 515 | |
Wolfgang Betz |
132:51056160fa4a | 516 | BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this); |
Wolfgang Betz |
132:51056160fa4a | 517 | |
Wolfgang Betz |
132:51056160fa4a | 518 | gattc->_currentState = GATT_READ_CHAR; |
Wolfgang Betz |
132:51056160fa4a | 519 | |
Wolfgang Betz |
132:51056160fa4a | 520 | // Save the attribute_handle not provided by evt_att_read_resp |
Wolfgang Betz |
132:51056160fa4a | 521 | gattc->readCBParams.handle = attributeHandle; |
Wolfgang Betz |
132:51056160fa4a | 522 | |
Wolfgang Betz |
132:51056160fa4a | 523 | ret = aci_gatt_read_charac_val(connHandle, attributeHandle); |
Wolfgang Betz |
132:51056160fa4a | 524 | |
Wolfgang Betz |
132:51056160fa4a | 525 | if(ret == BLE_STATUS_SUCCESS) { |
Wolfgang Betz |
132:51056160fa4a | 526 | return BLE_ERROR_NONE; |
Wolfgang Betz |
132:51056160fa4a | 527 | } |
Wolfgang Betz |
132:51056160fa4a | 528 | switch (ret) { |
Wolfgang Betz |
132:51056160fa4a | 529 | case BLE_STATUS_BUSY: |
Wolfgang Betz |
132:51056160fa4a | 530 | return BLE_STACK_BUSY; |
Wolfgang Betz |
132:51056160fa4a | 531 | default: |
Wolfgang Betz |
132:51056160fa4a | 532 | return BLE_ERROR_INVALID_STATE; |
Wolfgang Betz |
132:51056160fa4a | 533 | } |
Wolfgang Betz |
132:51056160fa4a | 534 | } |
Wolfgang Betz |
132:51056160fa4a | 535 | |
Wolfgang Betz |
132:51056160fa4a | 536 | void BlueNRGGattClient::charWritePrepareCB(Gap::Handle_t connHandle, |
Wolfgang Betz |
132:51056160fa4a | 537 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 538 | uint16_t attribute_handle, |
Wolfgang Betz |
132:51056160fa4a | 539 | uint16_t offset, |
Wolfgang Betz |
132:51056160fa4a | 540 | uint8_t *part_attr_value) |
Wolfgang Betz |
132:51056160fa4a | 541 | { |
Wolfgang Betz |
132:51056160fa4a | 542 | // Update the write response params |
Wolfgang Betz |
132:51056160fa4a | 543 | writeCBParams.handle = attribute_handle; |
Wolfgang Betz |
132:51056160fa4a | 544 | writeCBParams.offset = offset; |
Wolfgang Betz |
132:51056160fa4a | 545 | writeCBParams.len = event_data_length-4; //(?) |
Wolfgang Betz |
132:51056160fa4a | 546 | writeCBParams.data = part_attr_value; |
Wolfgang Betz |
132:51056160fa4a | 547 | |
Wolfgang Betz |
132:51056160fa4a | 548 | BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams); |
Wolfgang Betz |
132:51056160fa4a | 549 | } |
Wolfgang Betz |
132:51056160fa4a | 550 | |
Wolfgang Betz |
132:51056160fa4a | 551 | void BlueNRGGattClient::charWriteExecCB(Gap::Handle_t connHandle, |
Wolfgang Betz |
132:51056160fa4a | 552 | uint8_t event_data_length) |
Wolfgang Betz |
132:51056160fa4a | 553 | { |
Wolfgang Betz |
132:51056160fa4a | 554 | writeCBParams.connHandle = connHandle; |
Wolfgang Betz |
132:51056160fa4a | 555 | |
Wolfgang Betz |
132:51056160fa4a | 556 | BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams); |
Wolfgang Betz |
132:51056160fa4a | 557 | } |
Wolfgang Betz |
132:51056160fa4a | 558 | |
Wolfgang Betz |
132:51056160fa4a | 559 | ble_error_t BlueNRGGattClient::write(GattClient::WriteOp_t cmd, |
Wolfgang Betz |
132:51056160fa4a | 560 | Gap::Handle_t connHandle, |
Wolfgang Betz |
132:51056160fa4a | 561 | GattAttribute::Handle_t attributeHandle, |
Wolfgang Betz |
132:51056160fa4a | 562 | size_t length, |
Wolfgang Betz |
132:51056160fa4a | 563 | const uint8_t *value) const |
Wolfgang Betz |
132:51056160fa4a | 564 | { |
Wolfgang Betz |
132:51056160fa4a | 565 | tBleStatus ret; |
Wolfgang Betz |
132:51056160fa4a | 566 | |
Wolfgang Betz |
132:51056160fa4a | 567 | |
Wolfgang Betz |
132:51056160fa4a | 568 | BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this); |
Wolfgang Betz |
132:51056160fa4a | 569 | |
Wolfgang Betz |
132:51056160fa4a | 570 | gattc->_currentState = GATT_WRITE_CHAR; |
Wolfgang Betz |
132:51056160fa4a | 571 | |
Wolfgang Betz |
132:51056160fa4a | 572 | // We save the write response params (used by the callback) because |
Wolfgang Betz |
132:51056160fa4a | 573 | // when the aci_gatt_write_charac_value() is used the only event received is the EVT_BLUE_GATT_PROCEDURE_COMPLETE |
Wolfgang Betz |
132:51056160fa4a | 574 | gattc->writeCBParams.connHandle = connHandle; |
Wolfgang Betz |
132:51056160fa4a | 575 | gattc->writeCBParams.writeOp = GattWriteCallbackParams::OP_WRITE_CMD; |
Wolfgang Betz |
132:51056160fa4a | 576 | gattc->writeCBParams.handle = attributeHandle; |
Wolfgang Betz |
132:51056160fa4a | 577 | gattc->writeCBParams.offset = 0; |
Wolfgang Betz |
132:51056160fa4a | 578 | gattc->writeCBParams.len = length; |
Wolfgang Betz |
132:51056160fa4a | 579 | gattc->writeCBParams.data = value; |
Wolfgang Betz |
132:51056160fa4a | 580 | |
Wolfgang Betz |
132:51056160fa4a | 581 | ret = aci_gatt_write_charac_value(connHandle, attributeHandle, length, const_cast<uint8_t *>(value)); |
Wolfgang Betz |
132:51056160fa4a | 582 | //ret = aci_gatt_write_charac_reliable(connHandle, attributeHandle, 0, length, const_cast<uint8_t *>(value)); |
Wolfgang Betz |
132:51056160fa4a | 583 | |
Wolfgang Betz |
132:51056160fa4a | 584 | if (ret == BLE_STATUS_SUCCESS) { |
Wolfgang Betz |
132:51056160fa4a | 585 | return BLE_ERROR_NONE; |
Wolfgang Betz |
132:51056160fa4a | 586 | } |
Wolfgang Betz |
132:51056160fa4a | 587 | switch (ret) { |
Wolfgang Betz |
132:51056160fa4a | 588 | case BLE_STATUS_BUSY: |
Wolfgang Betz |
132:51056160fa4a | 589 | return BLE_STACK_BUSY; |
Wolfgang Betz |
132:51056160fa4a | 590 | default: |
Wolfgang Betz |
132:51056160fa4a | 591 | return BLE_ERROR_INVALID_STATE; |
Wolfgang Betz |
132:51056160fa4a | 592 | } |
Wolfgang Betz |
132:51056160fa4a | 593 | |
Wolfgang Betz |
132:51056160fa4a | 594 | } |