112 lines
2.7 KiB
C++
112 lines
2.7 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef WIFIMODELLOGDIST_H
|
||
#define WIFIMODELLOGDIST_H
|
||
|
||
#include "WiFiModel.h"
|
||
#include "LogDistanceModel.h"
|
||
|
||
#include <unordered_map>
|
||
|
||
/**
|
||
* signal-strength estimation using log-distance model
|
||
*/
|
||
class WiFiModelLogDist : public WiFiModel {
|
||
|
||
public:
|
||
|
||
/** parameters describing one AP to the model */
|
||
struct APEntry {
|
||
|
||
Point3 position_m; // the AP's position (in meter)
|
||
float txp; // sending power (-40)
|
||
float exp; // path-loss-exponent (~2.0 - 4.0)
|
||
|
||
/** ctor */
|
||
APEntry(const Point3 position_m, const float txp, const float exp) :
|
||
position_m(position_m), txp(txp), exp(exp) {;}
|
||
|
||
};
|
||
|
||
private:
|
||
|
||
/** map of all APs (and their parameters) known to the model */
|
||
std::unordered_map<MACAddress, APEntry> accessPoints;
|
||
|
||
public:
|
||
|
||
/** ctor */
|
||
WiFiModelLogDist() {
|
||
;
|
||
}
|
||
|
||
/** get a list of all APs known to the model */
|
||
std::vector<AccessPoint> getAllAPs() const {
|
||
std::vector<AccessPoint> aps;
|
||
for (const auto it : accessPoints) {aps.push_back(AccessPoint(it.first));}
|
||
return aps;
|
||
}
|
||
|
||
/** make the given AP (and its parameters) known to the model */
|
||
void addAP(const MACAddress& accessPoint, const APEntry& params) {
|
||
|
||
// sanity check
|
||
Assert::isBetween(params.txp, -50.0f, -30.0f, "TXP out of bounds [-90:-30]");
|
||
Assert::isBetween(params.exp, 1.0f, 4.0f, "EXP out of bounds [1:4]");
|
||
|
||
// add
|
||
accessPoints.insert( std::pair<MACAddress, APEntry>(accessPoint, params) );
|
||
|
||
}
|
||
|
||
/** does the model know the given AP? */
|
||
bool knowsAP(const MACAddress& accessPoint) {
|
||
|
||
// try to get the corresponding parameters
|
||
const auto it = accessPoints.find(accessPoint);
|
||
|
||
// AP known?
|
||
return (it != accessPoints.end());
|
||
|
||
}
|
||
|
||
virtual float getRSSI(const MACAddress& accessPoint, const Point3 position_m) const override {
|
||
|
||
// try to get the corresponding parameters
|
||
const auto it = accessPoints.find(accessPoint);
|
||
|
||
// AP unknown? -> NAN
|
||
if (it == accessPoints.end()) {return NAN;}
|
||
|
||
// the access-points' parameters
|
||
const APEntry& params = it->second;
|
||
|
||
// free-space (line-of-sight) RSSI
|
||
const float distance_m = position_m.getDistance(params.position_m);
|
||
const float rssiLOS = LogDistanceModel::distanceToRssi(params.txp, params.exp, distance_m);
|
||
|
||
// done
|
||
return rssiLOS;
|
||
|
||
}
|
||
|
||
void readFromXML(XMLDoc* doc, XMLElem* src) override {
|
||
throw Exception("not yet implemented");
|
||
}
|
||
|
||
void writeToXML(XMLDoc* doc, XMLElem* dst) override {
|
||
throw Exception("not yet implemented");
|
||
}
|
||
|
||
};
|
||
|
||
#endif // WIFIMODELLOGDIST_H
|