2021-09-14 03:22:00 +02:00
|
|
|
#include "BleFingerprintCollection.h"
|
|
|
|
|
|
|
|
void BleFingerprintCollection::cleanupOldFingerprints()
|
|
|
|
{
|
2021-10-05 13:54:41 +02:00
|
|
|
auto now = millis();
|
|
|
|
if (now - lastCleanup < 5000) return;
|
|
|
|
lastCleanup = now;
|
2021-09-30 18:48:50 +02:00
|
|
|
auto it = fingerprints.begin();
|
|
|
|
while (it != fingerprints.end())
|
2021-09-14 03:22:00 +02:00
|
|
|
{
|
2022-03-14 02:54:50 +01:00
|
|
|
auto age = (*it)->getMsSinceLastSeen();
|
2022-03-06 17:48:04 +01:00
|
|
|
if (age > forgetMs)
|
2021-09-30 18:48:50 +02:00
|
|
|
{
|
2022-03-06 17:48:04 +01:00
|
|
|
GUI::removed((*it));
|
|
|
|
delete *it;
|
2021-09-30 18:48:50 +02:00
|
|
|
it = fingerprints.erase(it);
|
|
|
|
}
|
|
|
|
else
|
2021-09-14 03:22:00 +02:00
|
|
|
{
|
2021-09-30 18:48:50 +02:00
|
|
|
++it;
|
2021-09-14 03:22:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BleFingerprint *BleFingerprintCollection::getFingerprintInternal(BLEAdvertisedDevice *advertisedDevice)
|
|
|
|
{
|
|
|
|
auto mac = advertisedDevice->getAddress();
|
|
|
|
|
|
|
|
auto it = std::find_if(fingerprints.begin(), fingerprints.end(), [mac](BleFingerprint *f)
|
|
|
|
{ return f->getAddress() == mac; });
|
|
|
|
if (it != fingerprints.end())
|
|
|
|
return *it;
|
|
|
|
|
2021-09-30 18:48:50 +02:00
|
|
|
auto created = new BleFingerprint(this, advertisedDevice, ONE_EURO_FCMIN, ONE_EURO_BETA, ONE_EURO_DCUTOFF);
|
2021-09-14 03:22:00 +02:00
|
|
|
auto it2 = std::find_if(fingerprints.begin(), fingerprints.end(), [created](BleFingerprint *f)
|
|
|
|
{ return f->getId() == created->getId(); });
|
|
|
|
if (it2 != fingerprints.end())
|
|
|
|
{
|
|
|
|
auto found = *it2;
|
2021-09-30 18:48:50 +02:00
|
|
|
created->setInitial(found->getRssi(), found->getDistance());
|
2021-09-14 03:22:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fingerprints.push_front(created);
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
|
|
|
|
BleFingerprint *BleFingerprintCollection::getFingerprint(BLEAdvertisedDevice *advertisedDevice)
|
|
|
|
{
|
|
|
|
if (xSemaphoreTake(fingerprintSemaphore, 1000) != pdTRUE)
|
|
|
|
log_e("Couldn't take semaphore!");
|
|
|
|
auto f = getFingerprintInternal(advertisedDevice);
|
|
|
|
if (xSemaphoreGive(fingerprintSemaphore) != pdTRUE)
|
|
|
|
log_e("Couldn't give semaphore!");
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2022-03-14 02:54:50 +01:00
|
|
|
const std::list<BleFingerprint *> BleFingerprintCollection::getCopy()
|
2021-09-14 03:22:00 +02:00
|
|
|
{
|
|
|
|
if (xSemaphoreTake(fingerprintSemaphore, 1000) != pdTRUE)
|
|
|
|
log_e("Couldn't take semaphore!");
|
|
|
|
cleanupOldFingerprints();
|
2021-10-05 13:54:41 +02:00
|
|
|
std::list<BleFingerprint *> copy(fingerprints);
|
2021-09-14 03:22:00 +02:00
|
|
|
if (xSemaphoreGive(fingerprintSemaphore) != pdTRUE)
|
|
|
|
log_e("Couldn't give semaphore!");
|
2022-03-14 02:54:50 +01:00
|
|
|
return std::move(copy);
|
|
|
|
}
|
|
|
|
String BleFingerprintCollection::include{}, BleFingerprintCollection::exclude{}, BleFingerprintCollection::query{}, BleFingerprintCollection::knownMacs{}, BleFingerprintCollection::countIds{};
|
|
|
|
float BleFingerprintCollection::skipDistance = 0.0f, BleFingerprintCollection::maxDistance = 0.0f, BleFingerprintCollection::absorption = 3.5f, BleFingerprintCollection::countEnter = 2, BleFingerprintCollection::countExit = 4;
|
|
|
|
int BleFingerprintCollection::refRssi = 0, BleFingerprintCollection::forgetMs = 0, BleFingerprintCollection::skipMs = 0, BleFingerprintCollection::countMs = 10000;
|
|
|
|
|
|
|
|
const std::list<BleFingerprint *>* const BleFingerprintCollection::getNative()
|
|
|
|
{
|
|
|
|
return &fingerprints;
|
2021-09-14 03:22:00 +02:00
|
|
|
}
|