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