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 99ee95ce7b worked on signal-strength-estimation
add this information to grid nodes
evaluate this information
new test-cases
2016-07-15 15:29:07 +02:00

85 lines
2.2 KiB
C++

#ifndef WIFIGRIDESTIMATOR_H
#define WIFIGRIDESTIMATOR_H
#include "../../grid/Grid.h"
#include "model/WiFiModel.h"
#include "WiFiGridNode.h"
#include "../../Assertions.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:
/**
* 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