Copy all statistics values when a device's MAC address changes (#1098)

When a device's MAC address changes we attempt to keep old distance
measurements. This can be improved by also copying the filter state
and a few more related values.
This commit is contained in:
Gunnar Beutner 2023-11-11 19:36:32 +01:00 committed by GitHub
parent 6eb2347e6e
commit a6e5a18dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View File

@ -449,10 +449,16 @@ bool BleFingerprint::seen(BLEAdvertisedDevice *advertisedDevice) {
return false;
}
void BleFingerprint::setInitial(int initalRssi, float initalDistance) {
newest = recent = oldest = rssi = initalRssi;
raw = initalDistance;
hasValue = filter() || filter();
void BleFingerprint::setInitial(const BleFingerprint &other) {
newest = other.newest;
recent = other.recent;
oldest = other.oldest;
rssi = other.rssi;
raw = other.rssi;
output = other.output;
oneEuro = other.oneEuro;
diffFilter = other.diffFilter;
hasValue = other.hasValue;
}
void BleFingerprint::fill(JsonObject *doc) {

View File

@ -80,7 +80,7 @@ class BleFingerprint {
bool setId(const String &newId, short int newIdType, const String &newName = "");
void setInitial(int rssi, float distance);
void setInitial(const BleFingerprint &other);
const String getMac() const;

View File

@ -201,7 +201,7 @@ BleFingerprint *getFingerprintInternal(BLEAdvertisedDevice *advertisedDevice) {
if (it2 != fingerprints.end()) {
auto found = *it2;
// Serial.printf("Detected mac switch for fingerprint id %s\r\n", found->getId().c_str());
created->setInitial(found->getRssi(), found->getDistance());
created->setInitial(*found);
if (found->getIdType() > ID_TYPE_UNIQUE)
found->expire();
}