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/WiFiGridEstimator.h
FrankE a2c9e575a2 huge commit
- worked on about everything
- grid walker using plugable modules
- wifi models
- new distributions
- worked on geometric data-structures
- added typesafe timestamps
- worked on grid-building
- added sensor-classes
- added sensor analysis (step-detection, turn-detection)
- offline data reader
- many test-cases
2016-08-29 08:18:44 +02:00

105 lines
2.7 KiB
C++

#ifndef WIFIGRIDESTIMATOR_H
#define WIFIGRIDESTIMATOR_H
#include "../../grid/Grid.h"
#include "model/WiFiModel.h"
#include "WiFiGridNode.h"
#include "../../Assertions.h"
#include "../../floorplan/v2/Floorplan.h"
#include <fstream>
/**
* estimates the signal-strength for all APs at a given GridNode
* and stores this precalculated value onto the node
*/
class WiFiGridEstimator {
public:
/**
* convenience method
*/
template <typename Node> static void estimate(Grid<Node>& grid, WiFiModel& mdl, const Floorplan::IndoorMap* im) {
// list of all APs
std::vector<LocatedAccessPoint> aps;
for (const Floorplan::Floor* f : im->floors) {
for (const Floorplan::AccessPoint* ap : f->accesspoints) {
aps.push_back(LocatedAccessPoint(*ap));
}
}
// perform estimation
estimate(grid, mdl, aps);
}
/**
* perform a signal-strength estimation for all of the given access points
* using the provided signal-strength prediction model.
* store the estimated strength onto each node.
* as nodes only provide a limited number of rssi-entries,
* store only the strongest ones.
*/
template <typename Node> static void estimate(Grid<Node>& grid, WiFiModel& mdl, const std::vector<LocatedAccessPoint> aps) {
// sanity checks
Assert::isTrue(Node::getMapAPs().empty(), "there are already some processed APs available!");
// attach the access-points to the shared node-vector
for (const LocatedAccessPoint& ap : aps) {
Node::getMapAPs().push_back(ap);
}
// process each node
for (Node& n : grid) {
// keep the strongest APs to attach to this node
std::vector<WiFiGridNodeAP> nodeAPs;
// process each AP
for (int apIdx = 0; apIdx < (int) aps.size(); ++apIdx) {
// estimate the signal-strength
const float rssi = mdl.getRSSI(aps[apIdx], n.inMeter());
// keep it
nodeAPs.push_back(WiFiGridNodeAP(apIdx, rssi));
}
// sort all APs by signal strength
auto comp = [] (const WiFiGridNodeAP& ap1, const WiFiGridNodeAP& ap2) {return ap1.getRSSI() > ap2.getRSSI();};
std::sort(nodeAPs.begin(), nodeAPs.end(), comp);
// attach the strongest X to the node
const int cnt = std::min( n.getMaxAPs(), (int) nodeAPs.size() );
for (int i = 0; i < cnt; ++i) {
n.strongestAPs[i] = nodeAPs[i];
}
}
}
/** gnuplot visualization dump for the given AP */
template <typename Node> static void dump(Grid<Node>& grid, const std::string& mac, const std::string& filename) {
std::ofstream out(filename);
out << "splot '-' with points palette \n";
for (Node& n : grid) {
out << n.x_cm << " " << n.y_cm << " " << n.z_cm << " " << n.getRSSI(mac) << "\n";
}
out << "e\n";
out.close();
}
};
#endif // WIFIGRIDESTIMATOR_H