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; return false;
} }
void BleFingerprint::setInitial(int initalRssi, float initalDistance) { void BleFingerprint::setInitial(const BleFingerprint &other) {
newest = recent = oldest = rssi = initalRssi; newest = other.newest;
raw = initalDistance; recent = other.recent;
hasValue = filter() || filter(); 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) { void BleFingerprint::fill(JsonObject *doc) {

View File

@ -80,7 +80,7 @@ class BleFingerprint {
bool setId(const String &newId, short int newIdType, const String &newName = ""); 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; const String getMac() const;

View File

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