ESP32-PaxCounter/src/corona.cpp

55 lines
1.6 KiB
C++
Raw Normal View History

2020-09-02 11:21:56 +02:00
// routines for counting the number of devices which advertise Exposure
// Notification Service e.g. "Corona Warn App" in Germany
// copied from https://github.com/kmetz/BLEExposureNotificationBeeper
// (c) by Kaspar Metz
// modified for use in the Paxcounter by AQ
2021-01-03 21:52:55 +01:00
#if (COUNT_ENS) && !(BLECOUNTER)
#warning ENS-Counter needs Bluetooth, but Bluetooth compile option is disabled
#endif
2020-09-02 11:21:56 +02:00
#if (COUNT_ENS)
// Local logging tag
static const char TAG[] = __FILE__;
#define BT_BD_ADDR_HEX(addr) \
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
#include "corona.h"
2020-09-03 16:37:51 +02:00
// When to forget old senders ** currently not used **
2020-09-02 11:21:56 +02:00
#define FORGET_AFTER_MINUTES 2
2020-09-03 16:37:51 +02:00
// array of timestamps for seen notifiers: hash -> timestamp[ms]
2020-09-02 11:21:56 +02:00
static std::map<uint16_t, unsigned long> cwaSeenNotifiers;
// Remove notifiers last seen over FORGET_AFTER_MINUTES ago.
void cwa_clear() {
2020-11-07 22:32:36 +01:00
#ifdef VERBOSE
ESP_LOGV(TAG, "CWA: forget old notifier: %d", cwaSeenNotifiers.size());
for (auto const &notifier : cwaSeenNotifiers) {
ESP_LOGD(TAG, "CWA forget <%04X>", notifier.first);
// }
}
#endif
2020-09-02 11:21:56 +02:00
// clear everything, otherwise we would count the same device again, as in the
// next cycle it likely will advertise with a different hash-value
cwaSeenNotifiers.clear();
}
// return the total number of devices seen advertising ENS
uint16_t cwa_report(void) { return cwaSeenNotifiers.size(); }
bool cwa_init(void) {
ESP_LOGD(TAG, "init BLE-scanner for ENS");
return true;
}
2020-09-03 16:37:51 +02:00
void cwa_mac_add(uint16_t hashedmac) {
cwaSeenNotifiers[hashedmac] = millis(); // hash last seen at ....
2020-09-02 11:21:56 +02:00
}
#endif