Skip to content

Commit 1d416fa

Browse files
removed redundant payload analysis code
since we connect based on address
1 parent 0252bb4 commit 1d416fa

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

BLE_SM/source/main.cpp

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -372,39 +372,27 @@ class SMDeviceCentral : public SMDevice {
372372
return;
373373
}
374374

375-
/* parse the advertising payload, looking for a discoverable device */
376-
for (uint8_t i = 0; i < params->advertisingDataLen; ++i) {
377-
/* The advertising payload is a collection of key/value records where
378-
* byte 0: length of the record excluding this byte
379-
* byte 1: The key, it is the type of the data
380-
* byte [2..N] The value. N is equal to byte0 - 1 */
381-
const uint8_t record_length = params->advertisingData[i];
382-
if (record_length == 0) {
383-
continue;
384-
}
385-
386-
/* connect to the same device that connected to us */
387-
if (memcmp(params->peerAddr, _peer_address, sizeof(_peer_address)) == 0) {
388-
389-
ble_error_t error = _ble.gap().connect(
390-
params->peerAddr, params->addressType,
391-
NULL, NULL
392-
);
393-
394-
if (error) {
395-
printf("Error during Gap::connect %d\r\n", error);
396-
return;
397-
}
375+
/* connect to the same device that connected to us */
376+
if (memcmp(params->peerAddr, _peer_address, sizeof(_peer_address)) == 0) {
398377

399-
/* we may have already scan events waiting
400-
* to be processed so we need to remember
401-
* that we are already connecting and ignore them */
402-
_is_connecting = true;
378+
ble_error_t error = _ble.gap().connect(
379+
params->peerAddr, params->addressType,
380+
NULL, NULL
381+
);
403382

383+
if (error) {
384+
printf("Error during Gap::connect %d\r\n", error);
404385
return;
405386
}
406387

407-
i += record_length;
388+
printf("Connecting... ");
389+
390+
/* we may have already scan events waiting
391+
* to be processed so we need to remember
392+
* that we are already connecting and ignore them */
393+
_is_connecting = true;
394+
395+
return;
408396
}
409397
};
410398

0 commit comments

Comments
 (0)