current revision
This commit is contained in:
92
tools/calibration/WiFiCalibrationDataModel.h
Normal file
92
tools/calibration/WiFiCalibrationDataModel.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef WIFICALIBMODEL_H
|
||||
#define WIFICALIBMODEL_H
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <Indoor/sensors/radio/setup/WiFiFingerprint.h>
|
||||
|
||||
class WiFiCalibrationDataModel {
|
||||
|
||||
private:
|
||||
|
||||
/** the file to save the calibration model to */
|
||||
std::string file;
|
||||
|
||||
/** all fingerprints (position -> measurements) within the model */
|
||||
std::vector<WiFiFingerprint> fingerprints;
|
||||
|
||||
public:
|
||||
|
||||
WiFiCalibrationDataModel(const std::string& file) : file(file) {
|
||||
load();
|
||||
}
|
||||
|
||||
const std::vector<WiFiFingerprint>& getFingerprints() {
|
||||
return fingerprints;
|
||||
}
|
||||
|
||||
/** deserialize the model */
|
||||
void load() {
|
||||
|
||||
// open and check
|
||||
std::ifstream inp(file.c_str());
|
||||
if (inp.bad() || inp.eof() || ! inp.is_open()) { return; }
|
||||
|
||||
// read all entries
|
||||
while (!inp.eof()) {
|
||||
|
||||
// each section starts with [fingerprint]
|
||||
std::string section;
|
||||
inp >> section;
|
||||
if (inp.eof()) {break;}
|
||||
if (section != "[fingerprint]") {throw Exception("error!");}
|
||||
|
||||
// deserialize it
|
||||
WiFiFingerprint wfp;
|
||||
wfp.read(inp);
|
||||
fingerprints.push_back(wfp);
|
||||
|
||||
}
|
||||
|
||||
inp.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** serialize the model */
|
||||
void save() {
|
||||
|
||||
// open and check
|
||||
std::ofstream out(file.c_str());
|
||||
if (out.bad()) {throw Exception("error while opening " + file + " for write");}
|
||||
|
||||
// write all entries
|
||||
for (const WiFiFingerprint& wfp : fingerprints) {
|
||||
out << "[fingerprint]\n";
|
||||
wfp.write(out);
|
||||
}
|
||||
|
||||
// done
|
||||
out.close();
|
||||
|
||||
}
|
||||
|
||||
/** get the fingerprint for the given location. if no fingerprint exists, an empty one is created! */
|
||||
WiFiFingerprint& getFingerprint(const Point3 pos_m) {
|
||||
|
||||
// try to find an existing one
|
||||
for (WiFiFingerprint& wfp : fingerprints) {
|
||||
// get within range of floating-point rounding issues
|
||||
if (wfp.pos_m.getDistance(pos_m) < 0.001) {return wfp;}
|
||||
}
|
||||
|
||||
// create a new one and return its reference
|
||||
WiFiFingerprint wfp(pos_m);
|
||||
fingerprints.push_back(wfp);
|
||||
return fingerprints.back();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // WIFICALIBMODEL_H
|
||||
51
tools/calibration/WiFiCalibrationScanDialog.cpp
Normal file
51
tools/calibration/WiFiCalibrationScanDialog.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "WiFiCalibrationScanDialog.h"
|
||||
|
||||
|
||||
WiFiCalibrationScanDialog::WiFiCalibrationScanDialog(WiFiFingerprint& model) : model(model) {
|
||||
|
||||
dlg->resize(300, 300);
|
||||
|
||||
QGridLayout* lay = new QGridLayout(dlg);
|
||||
|
||||
int row = 0;
|
||||
|
||||
QPushButton* btnClear = new QPushButton(dlg);
|
||||
btnClear->setText("clear");
|
||||
btnClear->connect(btnClear, &QPushButton::clicked, [&] () {clear();});
|
||||
lay->addWidget(btnClear, row, 0, 1, 1);
|
||||
|
||||
QPushButton* btnRecord = new QPushButton(dlg);
|
||||
btnRecord->setText("rec");
|
||||
btnRecord->connect(btnRecord, &QPushButton::clicked, [&] () {startRecord();});
|
||||
lay->addWidget(btnRecord, row, 2, 1, 1);
|
||||
|
||||
++row;
|
||||
|
||||
lay->addWidget(new QLabel("point"), row, 0, 1, 1);
|
||||
lblPoint = new QLabel();
|
||||
lay->addWidget(lblPoint, row, 1, 1, 2);
|
||||
|
||||
++row;
|
||||
|
||||
lay->addWidget(new QLabel("stats"), row, 0, 1, 1);
|
||||
lblStats = new QLabel();
|
||||
lay->addWidget(lblStats, row, 1, 1, 2);
|
||||
|
||||
++row;
|
||||
|
||||
barProg = new QProgressBar();
|
||||
lay->addWidget(barProg, row, 0, 1, 3);
|
||||
|
||||
++row;
|
||||
|
||||
QPushButton* btnCancel = new QPushButton(dlg);
|
||||
btnCancel->setText("cancel");
|
||||
btnCancel->connect(btnCancel, &QPushButton::clicked, [&] () {close();});
|
||||
lay->addWidget(btnCancel, row, 0, 1, 1);
|
||||
|
||||
QPushButton* btnOK = new QPushButton(dlg);
|
||||
btnOK->setText("OK");
|
||||
btnOK->connect(btnOK, &QPushButton::clicked, [&] () {save(); close();});
|
||||
lay->addWidget(btnOK, row, 2, 1, 1);
|
||||
|
||||
}
|
||||
102
tools/calibration/WiFiCalibrationScanDialog.h
Normal file
102
tools/calibration/WiFiCalibrationScanDialog.h
Normal file
@@ -0,0 +1,102 @@
|
||||
#ifndef CALIBDIALOG_H
|
||||
#define CALIBDIALOG_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QProgressBar>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QDialog>
|
||||
|
||||
#include "../sensors/SensorFactory.h"
|
||||
#include "../tools/calibration/WiFiCalibrationDataModel.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* show a dialog to perform a WiFiScan
|
||||
*/
|
||||
class WiFiCalibrationScanDialog : public QObject, public SensorListener<WiFiMeasurements> {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
QDialog* dlg = new QDialog();
|
||||
QLabel* lblStats;
|
||||
QLabel* lblPoint;
|
||||
QProgressBar* barProg;
|
||||
|
||||
struct Scan {
|
||||
const int numRecords = 10;
|
||||
int recordsDone = 0;
|
||||
} scan;
|
||||
|
||||
/** the measurements model to fill with scan-entries */
|
||||
WiFiFingerprint& model;
|
||||
|
||||
public:
|
||||
|
||||
static void get(WiFiFingerprint& model) {
|
||||
WiFiCalibrationScanDialog dlg(model);
|
||||
dlg.show();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** ctor */
|
||||
WiFiCalibrationScanDialog(WiFiFingerprint& model);
|
||||
|
||||
void show() {
|
||||
refresh();
|
||||
dlg->exec();
|
||||
}
|
||||
|
||||
void close() {
|
||||
stopRecord();
|
||||
dlg->close();
|
||||
}
|
||||
|
||||
void save() {
|
||||
//mdl.save();;
|
||||
}
|
||||
|
||||
Q_INVOKABLE void refresh() {
|
||||
lblPoint->setText(QString(model.pos_m.asString().c_str()));
|
||||
lblStats->setText( QString::number(model.measurements.entries.size()) + " RSSI measurements\n" + QString::number(scan.recordsDone) + " scans");
|
||||
barProg->setValue(scan.recordsDone);
|
||||
barProg->setMaximum(scan.numRecords);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
model.measurements.entries.clear();
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void startRecord() {
|
||||
scan.recordsDone = 0;
|
||||
SensorFactory::get().getWiFi().addListener(this);
|
||||
if (!SensorFactory::get().getWiFi().isRunning()) {
|
||||
SensorFactory::get().getWiFi().start();
|
||||
}
|
||||
}
|
||||
|
||||
void stopRecord() {
|
||||
SensorFactory::get().getWiFi().removeListener(this);
|
||||
}
|
||||
|
||||
virtual void onSensorData(Sensor<WiFiMeasurements>* sensor, const Timestamp ts, const WiFiMeasurements& data) override {
|
||||
(void) sensor;
|
||||
(void) ts;
|
||||
++scan.recordsDone;
|
||||
if (scan.recordsDone >= scan.numRecords) {stopRecord();}
|
||||
model.measurements.entries.insert(model.measurements.entries.end(), data.entries.begin(), data.entries.end());
|
||||
QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // CALIBDIALOG_H
|
||||
Reference in New Issue
Block a user