CWA code edits

This commit is contained in:
Klaus K Wilting 2020-09-03 16:37:51 +02:00
parent 2f0b3c8ef2
commit 0f6e08e7e1
3 changed files with 10 additions and 24 deletions

View File

@ -9,7 +9,7 @@
#include <map>
bool cwa_init(void);
bool cwa_mac_add(uint16_t hashedmac);
void cwa_mac_add(uint16_t hashedmac);
void cwa_clear(void);
uint16_t cwa_report(void);

View File

@ -160,14 +160,15 @@ IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event,
}
#endif
// hash and add this device and show new count total if it was not previously added
hashedmac = mac_add((uint8_t *)p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE);
// hash and add this device and show new count total if it was not
// previously added
hashedmac =
mac_add((uint8_t *)p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE);
#if (COUNT_ENS)
// check for ens signature
if (0 == strncmp((const char *)p->scan_rst.ble_adv, ensMagicBytes, 4)) {
if (0 == strncmp((const char *)p->scan_rst.ble_adv, ensMagicBytes, 4))
cwa_mac_add(hashedmac);
}
#endif
/* to be improved in vendorfilter if:

View File

@ -15,10 +15,10 @@ static const char TAG[] = __FILE__;
#include "corona.h"
// When to forget old senders.
// When to forget old senders ** currently not used **
#define FORGET_AFTER_MINUTES 2
// array of timestamps for seen notifiers
// array of timestamps for seen notifiers: hash -> timestamp[ms]
static std::map<uint16_t, unsigned long> cwaSeenNotifiers;
// Remove notifiers last seen over FORGET_AFTER_MINUTES ago.
@ -48,23 +48,8 @@ bool cwa_init(void) {
return true;
}
// similar to mac_add(), found in macsniff.cpp, for comments look into this function
bool cwa_mac_add(uint16_t hashedmac) {
bool added = false;
ESP_LOGD(TAG, "hashed ENS mac = %X, ENS count = %d (total=%d)", hashedmac,
cwaSeenNotifiers.count(hashedmac), cwaSeenNotifiers.size());
added = !(cwaSeenNotifiers.count(hashedmac) > 0);
// Count only if this ENS MAC was not yet seen
if (added) {
cwaSeenNotifiers[hashedmac] = millis(); // last seen at ....
ESP_LOGD(TAG, "added device with active ENS");
}
// True if ENS MAC was new
return added;
void cwa_mac_add(uint16_t hashedmac) {
cwaSeenNotifiers[hashedmac] = millis(); // hash last seen at ....
}
#endif