102 lines
2.1 KiB
C++
102 lines
2.1 KiB
C++
#ifndef WIFISENSORDUMMY_H
|
|
#define WIFISENSORDUMMY_H
|
|
|
|
#include "../WiFiSensor.h"
|
|
#include <thread>
|
|
|
|
#include <Indoor/geo/Point3.h>
|
|
#include <Indoor/sensors/radio/model/LogDistanceModel.h>
|
|
|
|
#include <Indoor/grid/Grid.h>
|
|
#include <Indoor/grid/factory/v2/GridFactory.h>
|
|
|
|
|
|
class WiFiSensorDummy : public WiFiSensor {
|
|
|
|
private:
|
|
|
|
bool enabled;
|
|
|
|
public:
|
|
|
|
|
|
/** singleton access */
|
|
static WiFiSensorDummy& get() {
|
|
static WiFiSensorDummy wifi;
|
|
return wifi;
|
|
}
|
|
|
|
bool isRunning() const override {
|
|
return enabled;
|
|
}
|
|
|
|
void start() override {
|
|
|
|
enabled = true;
|
|
std::thread t(&WiFiSensorDummy::simulate, this);
|
|
t.detach();
|
|
|
|
}
|
|
|
|
void stop() override {
|
|
enabled = false;
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
struct DummyAP {
|
|
std::string mac;
|
|
Point2 pos;
|
|
DummyAP(const std::string mac, const Point2 pos) : mac(mac), pos(pos) {;}
|
|
};
|
|
|
|
void simulate() {
|
|
|
|
std::vector<DummyAP> aps;
|
|
aps.push_back(DummyAP("00:00:00:00:00:01", Point2(0, 0)));
|
|
aps.push_back(DummyAP("00:00:00:00:00:02", Point2(20, 0)));
|
|
aps.push_back(DummyAP("00:00:00:00:00:03", Point2(10, 20)));
|
|
aps.push_back(DummyAP("00:00:00:00:00:04", Point2(10, 30)));
|
|
aps.push_back(DummyAP("00:00:00:00:00:05", Point2(10, 40)));
|
|
aps.push_back(DummyAP("00:00:00:00:00:06", Point2(10, 50)));
|
|
aps.push_back(DummyAP("00:00:00:00:00:07", Point2(10, 60)));
|
|
aps.push_back(DummyAP("00:00:00:00:00:08", Point2(10, 70)));
|
|
aps.push_back(DummyAP("00:00:00:00:00:09", Point2(10, 80)));
|
|
|
|
float deg = 0;
|
|
|
|
while(enabled) {
|
|
|
|
// wait
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
|
|
// circle-run around center
|
|
deg += M_PI * 0.4;
|
|
|
|
const float cx = 10;
|
|
const float cy = 10;
|
|
const float rad = 5;
|
|
|
|
const float x = cx + std::sin(deg) * rad;
|
|
const float y = cy + std::cos(deg) * rad;
|
|
|
|
// construct scan data
|
|
WiFiMeasurements scan;
|
|
for (DummyAP& ap : aps) {
|
|
const float dist = ap.pos.getDistance(Point2(x, y));
|
|
const float rssi = LogDistanceModel::distanceToRssi(-40, 1.5, dist);
|
|
scan.entries.push_back(WiFiMeasurement(AccessPoint(ap.mac), rssi));
|
|
}
|
|
|
|
// call
|
|
informListeners(scan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // WIFISENSORDUMMY_H
|