had to change the parameter boundaries of the wifi optimizer to be able to use it for bluetooth... this should be refactored to something more generic.. some minor changes in ble
103 lines
2.8 KiB
C++
103 lines
2.8 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 BEACONMODELLOGDIST_H
|
||
#define BEACONMODELLOGDIST_H
|
||
|
||
#include "BeaconModel.h"
|
||
#include "../../radio/model/LogDistanceModel.h"
|
||
|
||
#include <unordered_map>
|
||
|
||
/**
|
||
* signal-strength estimation using log-distance model
|
||
*/
|
||
class BeaconModelLogDist : public BeaconModel {
|
||
|
||
public:
|
||
|
||
/** parameters describing one beacons 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 beacons (and their parameters) known to the model */
|
||
std::unordered_map<MACAddress, APEntry> beacons;
|
||
|
||
public:
|
||
|
||
/** ctor */
|
||
BeaconModelLogDist() {
|
||
;
|
||
}
|
||
|
||
/** get a list of all beacons known to the model */
|
||
std::vector<Beacon> getAllBeacons() const {
|
||
std::vector<Beacon> aps;
|
||
for (const auto it : beacons) {aps.push_back(Beacon(it.first));}
|
||
return aps;
|
||
}
|
||
|
||
/** make the given beacon (and its parameters) known to the model */
|
||
void addAP(const MACAddress& beacon, const APEntry& params) {
|
||
|
||
// sanity check
|
||
Assert::isBetween(params.txp, -65.0f, -30.0f, "TXP out of bounds [-65:-30]");
|
||
Assert::isBetween(params.exp, 1.0f, 5.0f, "EXP out of bounds [1:5]");
|
||
|
||
// add
|
||
beacons.insert( std::pair<MACAddress, APEntry>(beacon, params) );
|
||
|
||
}
|
||
|
||
void updateBeacon(const BeaconMeasurement beacon) override{
|
||
// try to get the corresponding parameters
|
||
const auto it = beacons.find(MACAddress(beacon.getBeacon().getMAC()));
|
||
|
||
// beacon unknown? -> NAN
|
||
if (it == beacons.end()) {return;}
|
||
|
||
it->second.txp = beacon.getBeacon().getTXP();
|
||
}
|
||
|
||
virtual float getRSSI(const MACAddress& beacon, const Point3 position_m) const override {
|
||
|
||
// try to get the corresponding parameters
|
||
const auto it = beacons.find(beacon);
|
||
|
||
// AP unknown? -> NAN
|
||
if (it == beacons.end()) {return NAN;}
|
||
|
||
// the beacons' 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;
|
||
|
||
}
|
||
|
||
};
|
||
|
||
#endif // BEACONMODELLOGDIST_H
|