changes from the laptop

- some should be the same as previous commit (sorry!)
- some should be new: LINT checks, ...?
This commit is contained in:
2017-05-24 10:03:39 +02:00
parent f67f95d1ce
commit 04d8ae8c74
42 changed files with 1344 additions and 60 deletions

View File

@@ -0,0 +1,76 @@
#ifndef PLOTWIFIMEASUREMENTS_H
#define PLOTWIFIMEASUREMENTS_H
#include <KLib/misc/gnuplot/Gnuplot.h>
#include <KLib/misc/gnuplot/GnuplotPlot.h>
#include <KLib/misc/gnuplot/GnuplotPlotElementLines.h>
#include "../sensors/radio/WiFiMeasurements.h"
#include "../sensors/radio/WiFiQualityAnalyzer.h"
#include <unordered_map>
/**
* helper-class that plots incoming wifi measurements
* one line per AP
*/
class PlotWifiMeasurements {
K::Gnuplot gp;
K::GnuplotPlot gplot;
K::GnuplotPlotElementLines lineQuality;
std::unordered_map<MACAddress, K::GnuplotPlotElementLines*> lineForMac;
WiFiQualityAnalyzer quality;
public:
PlotWifiMeasurements(const std::string& labelX = "time (sec)", const std::string& labelY = "dBm") {
gplot.getAxisX().setLabel(labelX);
gplot.getAxisY().setLabel(labelY);
// quality indicator using the 2nd y axis
gplot.add(&lineQuality); lineQuality.getStroke().setWidth(2); lineQuality.setUseAxis(1, 2);
gplot.getAxisY2().setTicsVisible(true);
gplot.getAxisY2().setRange(K::GnuplotAxis::Range(0, 1));
}
K::Gnuplot& getGP() {
return gp;
}
K::GnuplotPlot& getPlot() {
return gplot;
}
void add(const WiFiMeasurements& mes) {
const Timestamp ts = mes.entries.front().getTimestamp();
for (const WiFiMeasurement& m : mes.entries) {
const auto& it = lineForMac.find(m.getAP().getMAC());
if (it == lineForMac.end()) {
K::GnuplotPlotElementLines* line = new K::GnuplotPlotElementLines();
line->setTitle(m.getAP().getMAC().asString());
line->getStroke().getColor().setAuto();
lineForMac[m.getAP().getMAC()] = line;
gplot.add(line);
}
const K::GnuplotPoint2 gp2(m.getTimestamp().sec(), m.getRSSI());
lineForMac[m.getAP().getMAC()]->add(gp2);
}
quality.add(mes);
lineQuality.add(K::GnuplotPoint2(ts.sec(), quality.getQuality()));
}
void plot() {
gp.draw(gplot);
gp.flush();
}
};
#endif // PLOTWIFIMEASUREMENTS_H