From ef93f6f14cc978887a0166e8e853daf5cfbe37c6 Mon Sep 17 00:00:00 2001 From: menesesleonardo <33615982+menesesleonardo@users.noreply.github.com> Date: Wed, 16 Jan 2019 21:53:45 -0500 Subject: [PATCH] Update main.c current alreadyDiscovered function only looks for a one byte difference, this way checks for all possible combinations and does it faster with memcmp. --- 23_ble_scan/main/main.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/23_ble_scan/main/main.c b/23_ble_scan/main/main.c index c9ea65f..607fb02 100644 --- a/23_ble_scan/main/main.c +++ b/23_ble_scan/main/main.c @@ -25,18 +25,25 @@ static esp_ble_scan_params_t ble_scan_params = { }; // check if the device was already discovered -bool alreadyDiscovered(esp_bd_addr_t address) { +bool alreadyDiscovered(esp_bd_addr_t address){ bool found = false; - + for(int i = 0; i < discovered_devices_num; i++) { - - for(int j = 0; j < ESP_BD_ADDR_LEN; j++) - found = (discovered_devices[i][j] == address[j]); - + + uint8_t alreadyFound[6] = { + discovered_devices[i][0], + discovered_devices[i][1], + discovered_devices[i][2], + discovered_devices[i][3], + discovered_devices[i][4], + discovered_devices[i][5]}; +// this way checks for all possible combinations of MAC addresses, instead of only last byte. + if(memcmp(alreadyFound,address,6) == 0) found = true; + if(found) break; } - + return found; } @@ -139,4 +146,4 @@ void app_main() { // configure scan parameters esp_ble_gap_set_scan_params(&ble_scan_params); -} \ No newline at end of file +}