added stuff for bluetooth

worked on resampling methods
This commit is contained in:
mail@toni-fetzer.de
2019-06-05 18:09:15 +02:00
parent cb61e0fe68
commit 8d37e94647
12 changed files with 472 additions and 320 deletions

View File

@@ -48,6 +48,9 @@ public:
/** get the rssi */
float getRSSI() const {return rssi;}
/** set another signal strength */
void setRssi(float value){rssi = value;}
};

View File

@@ -24,11 +24,20 @@ struct BeaconMeasurements {
/** remove entries older then 3000 ms*/
void removeOld(const Timestamp latestTS) {
auto lambda = [latestTS] (const BeaconMeasurement& e) {
Timestamp age = latestTS - e.getTimestamp();
return age > Timestamp::fromMS(1000*3);
};
entries.erase(std::remove_if(entries.begin(), entries.end(), lambda), entries.end());
std::vector<BeaconMeasurement>::iterator it;
for (it = entries.begin(); it != entries.end(); ++it){
if(latestTS - it->getTimestamp() > Timestamp::fromMS(1000*3)){
entries.erase(it);
}
}
}
void add(const BeaconMeasurement& entry){
entries.push_back(entry);
//remove entries that are to old (3000ms)
removeOld(entry.getTimestamp());
}
};

View File

@@ -0,0 +1,103 @@
#ifndef BEACONFINGERPRINT_H
#define BEACONFINGERPRINT_H
#include "../../../geo/Point3.h"
#include "../BeaconMeasurements.h"
#include <unordered_map>
/**
* denotes a wifi fingerprint:
* known position and 1-n measurements [wifi-scan on all channels] conducted at this position
*
* if more than one measurement is conducted, each AP is contained more than once!
*/
struct WiFiFingerprint {
/** real-world-position that was measured */
Point3 pos_m;
/** seen APs at the given location */
BeaconMeasurements measurements;
/** ctor */
WiFiFingerprint() {;}
/** ctor */
WiFiFingerprint(const Point3 pos_m) : pos_m(pos_m) {;}
/** ctor */
WiFiFingerprint(const Point3 pos_m, const BeaconMeasurements& measurements) : pos_m(pos_m), measurements(measurements) {;}
/** as each AP might be contained more than once (scanned more than once), group them by MAC and use the average RSSI */
BeaconMeasurements average() {
// group scans by MAC (all measurements for one AP)
std::unordered_map<MACAddress, BeaconMeasurements> group;
for (BeaconMeasurement& bm : measurements.entries) {
group[bm.getBeacon().getMAC()].entries.push_back(bm);
}
// create the output that contains the AP's average
BeaconMeasurements res;
for (auto& it : group) {
const BeaconMeasurements& apMeasurements = it.second;
BeaconMeasurement avg = apMeasurements.entries.front(); // average starts with a copy of the first entry (to get all data-fields beside the rssi)
for (int i = 1; i < (int)apMeasurements.entries.size(); ++i) { // sum up all other entries [1:end]
avg.setRssi(avg.getRSSI() + apMeasurements.entries[i].getRSSI());
}
avg.setRssi(avg.getRSSI() / apMeasurements.entries.size());
res.entries.push_back(avg); // add to output
}
// done
return res;
}
/** get all measurements for the given MAC */
std::vector<BeaconMeasurement> getAllForMAC(const MACAddress& mac) const {
std::vector<BeaconMeasurement> res;
for (const BeaconMeasurement& m : measurements.entries) {
if (m.getBeacon().getMAC() == mac) {res.push_back(m);}
}
return res;
}
/** serialize */
void write(std::ostream& out) const {
out << "pos: " << pos_m.x << " " << pos_m.y << " " << pos_m.z << "\n";
out << "num: " << measurements.entries.size() << "\n";
for (const BeaconMeasurement& bm : measurements.entries) {
out << bm.getTimestamp().ms() << " " << bm.getBeacon().getMAC().asString() << " " << bm.getRSSI() << "\n";
}
}
/** deserialize */
void read(std::istream& inp) {
std::string tmp;
// read the position
inp >> tmp; if ("pos:" != tmp) {throw "error";}
inp >> pos_m.x >> pos_m.y >> pos_m.z;
// number of entries
inp >> tmp; if ("num:" != tmp) {throw "error";}
int numEntries; inp >> numEntries;
// read the entries
for (int i = 0; i < numEntries; ++i) {
uint64_t ms; inp >> ms;
std::string mac; inp >> mac;
float rssi; inp >> rssi;
BeaconMeasurement bm(Timestamp::fromMS(ms), Beacon(MACAddress(mac)), rssi);
measurements.entries.push_back(bm);
}
}
};
#endif // BEACONFINGERPRINT_H