This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/sensors/radio/WiFiMeasurements.h
kazu d40032ca74 interface changes
added new data-strcutures for new sensors
new helper methods
fixed some issues
2017-05-24 09:23:27 +02:00

78 lines
1.7 KiB
C++

#ifndef WIFIMEASUREMENTS_H
#define WIFIMEASUREMENTS_H
#include <vector>
#include "WiFiMeasurement.h"
/**
* group of several wifi measurements
*/
struct WiFiMeasurements {
/** all contained measurements */
std::vector<WiFiMeasurement> entries;
/** convert to string */
std::string asString() const {
std::string res;
for (const WiFiMeasurement& m : entries) {
res += m.getAP().getMAC().asString() + ": " + std::to_string(m.getRSSI()) + "\n";
}
return res;
}
/** get the measurements for the given MAC [if available] otherwise null */
const WiFiMeasurement* getForMac(const MACAddress& mac) const {
for (const WiFiMeasurement& m : entries) {
if (m.getAP().getMAC() == mac) {
return &m;
}
}
return nullptr;
}
/** remove the entry for the given MAC (if any) */
void remove(const MACAddress& mac) {
for (size_t i = 0; i < entries.size(); ++i) {
if (entries[i].getAP().getMAC() == mac) {
entries.erase(entries.begin() + i);
break;
}
}
}
/** create a combination */
static WiFiMeasurements mix(const WiFiMeasurements& a, const WiFiMeasurements& b, float sec = 3) {
Timestamp max;
WiFiMeasurements res;
for (const WiFiMeasurement& m : a.entries) {
res.entries.push_back(m);
if (m.getTimestamp() > max) {max = m.getTimestamp();}
}
for (const WiFiMeasurement& m : b.entries) {
res.entries.push_back(m);
if (m.getTimestamp() > max) {max = m.getTimestamp();}
}
std::vector<WiFiMeasurement> tmp;
std::swap(res.entries, tmp);
for (const WiFiMeasurement& m : tmp) {
if ((max - m.getTimestamp()).sec() < sec) {
res.entries.push_back(m);
}
}
return res;
}
};
#endif // WIFIMEASUREMENTS_H