87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
#ifndef WIFIMEASUREMENTS_H
|
|
#define WIFIMEASUREMENTS_H
|
|
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
#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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/** get the oldest timestamp among all contained measurements */
|
|
Timestamp getOldestTS() const {
|
|
auto comp = [] (const WiFiMeasurement& m1, const WiFiMeasurement& m2) {return m1.getTimestamp() < m2.getTimestamp();};
|
|
auto it = std::max_element(entries.begin(), entries.end(), comp);
|
|
if (it == entries.end()) {throw Exception("no element found");}
|
|
return it->getTimestamp();
|
|
}
|
|
|
|
|
|
/** 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
|