#ifndef WIFIMODELLOGDISTCEILING_H #define WIFIMODELLOGDISTCEILING_H #include "../../../floorplan/v2/Floorplan.h" #include "../../../floorplan/v2/FloorplanCeilings.h" #include "../../../Assertions.h" #include "WiFiModel.h" #include "LogDistanceModel.h" #include "../VAPGrouper.h" #include "../../../misc/Debug.h" /** * signal-strength estimation using log-distance model * including ceilings between AP and position */ class WiFiModelLogDistCeiling : 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) float waf; // attenuation per ceiling/floor (~-8.0) /** ctor */ APEntry(const Point3 position_m, const float txp, const float exp, const float waf) : position_m(position_m), txp(txp), exp(exp), waf(waf) {;} }; private: /** map of all APs (and their parameters) known to the model */ std::unordered_map accessPoints; // /** position (height) of all ceilings (in meter) */ // std::vector ceilingsAtHeight_m; Floorplan::Ceilings ceilings; public: /** ctor with floorplan (needed for ceiling position) */ WiFiModelLogDistCeiling(const Floorplan::IndoorMap* map) : ceilings(map) { // sanity checks Assert::isTrue(map->floors.size() >= 1, "map has no floors?!"); } /** get a list of all APs known to the model */ std::vector getAllAPs() const { std::vector aps; for (const auto it : accessPoints) {aps.push_back(AccessPoint(it.first));} return aps; } /** load AP information from the floorplan. use the given fixed TXP/EXP/WAF for all APs */ void loadAPs(const Floorplan::IndoorMap* map, const float txp = -40.0f, const float exp = 2.5f, const float waf = -8.0f) { for (const Floorplan::Floor* floor : map->floors) { for (const Floorplan::AccessPoint* ap : floor->accesspoints) { const APEntry ape(ap->getPos(floor), txp, exp, waf); addAP(MACAddress(ap->mac), ape); } } } /** load AP information from the floorplan. use the given fixed TXP/EXP/WAF for all APs */ void loadAPs(const Floorplan::IndoorMap* map, const VAPGrouper& vg, const float txp = -40.0f, const float exp = 2.5f, const float waf = -8.0f) { for (const Floorplan::Floor* floor : map->floors) { for (const Floorplan::AccessPoint* ap : floor->accesspoints) { const APEntry ape(ap->getPos(floor), txp, exp, waf); const MACAddress mac = vg.getBaseMAC(MACAddress(ap->mac)); Log::add("WiModLDC", "AP: " + ap->mac + " -> " + mac.asString()); addAP(MACAddress(mac), ape); } } } /** make the given AP (and its parameters) known to the model */ void addAP(const MACAddress& accessPoint, const APEntry& params) { // sanity check Assert::isBetween(params.waf, -99.0f, 0.0f, "WAF out of bounds [-99:0]"); Assert::isBetween(params.txp, -50.0f, -30.0f, "TXP out of bounds [-50:-30]"); Assert::isBetween(params.exp, 1.0f, 4.0f, "EXP out of bounds [1:4]"); Assert::equal(accessPoints.find(accessPoint), accessPoints.end(), "AccessPoint already present! VAP-Grouping issue?"); // add accessPoints.insert( std::pair(accessPoint, params) ); } /** remove all added APs */ void clear() { accessPoints.clear(); } 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); // WAF loss (params.waf is a negative value!) -> WAF loss is also a negative value const float wafLoss = params.waf * ceilings.numCeilingsBetween(position_m, params.position_m); // combine return rssiLOS + wafLoss; } }; #endif // WIFIMODELLOGDISTCEILING_H