Optimize add function, fixed New/Already Seen bug

This commit is contained in:
Charles 2018-04-05 16:26:25 +02:00
parent 01d617f61e
commit 7fc0fc0a74

View File

@ -31,7 +31,6 @@ uint16_t salt_reset(void) {
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
char buff[16]; // temporary buffer for printf char buff[16]; // temporary buffer for printf
char typebuff[8];
bool added = false; bool added = false;
uint32_t addr2int; uint32_t addr2int;
uint32_t vendor2int; uint32_t vendor2int;
@ -56,22 +55,25 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
auto newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique auto newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique
added = newmac.second ? true:false; // true if hashed MAC is unique in container added = newmac.second ? true:false; // true if hashed MAC is unique in container
if (sniff_type == MAC_SNIFF_WIFI ) { // Insert only if it was not found on global count
rgb_set_color(COLOR_GREEN); if (added) {
wifis.insert(hashedmac); // add hashed MAC to wifi container if new unique if (sniff_type == MAC_SNIFF_WIFI ) {
strcpy(typebuff, "WiFi"); rgb_set_color(COLOR_GREEN);
rgb_set_color(COLOR_NONE); wifis.insert(hashedmac); // add hashed MAC to wifi container if new unique
} else if (sniff_type == MAC_SNIFF_BLE ) { } else if (sniff_type == MAC_SNIFF_BLE ) {
rgb_set_color(COLOR_MAGENTA); rgb_set_color(COLOR_MAGENTA);
bles.insert(hashedmac); // add hashed MAC to BLE container if new unique bles.insert(hashedmac); // add hashed MAC to BLE container if new unique
strcpy(typebuff, "BLE "); }
// Not sure user will have time to see the LED
// TBD do light off further in the code
rgb_set_color(COLOR_NONE); rgb_set_color(COLOR_NONE);
} }
ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLE:%d %s", ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLE:%d %s",
typebuff, rssi, buff, hashedmac, sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLE ",
rssi, buff, hashedmac,
(int) wifis.size(), (int) bles.size(), (int) wifis.size(), (int) bles.size(),
added ? "already seen" : "new"); added ? "New" : "Already seen");
#ifdef VENDORFILTER #ifdef VENDORFILTER
} else { } else {