we are now able to record bluetooth fingerprints
for this, we use the same ui interface and fingerprint positions as wifi. if wifi has done 30 scans, also the ble scans will be stopped. this is just a quick and dirte solution, as changing the gui completely for this two options was to time consuming
This commit is contained in:
@@ -1,4 +1,91 @@
|
||||
#ifndef BLECALIBRATIONDATAMODEL_H
|
||||
#define BLECALIBRATIONDATAMODEL_H
|
||||
|
||||
#include <fstream>
|
||||
#include <Indoor/sensors/beacon/setup/BeaconFingerprint.h>
|
||||
|
||||
class BLECalibrationDataModel {
|
||||
|
||||
private:
|
||||
|
||||
/** the file to save the calibration model to */
|
||||
std::string file;
|
||||
|
||||
/** all fingerprints (position -> measurements) within the model */
|
||||
std::vector<BeaconFingerprint> fingerprints;
|
||||
|
||||
public:
|
||||
|
||||
BLECalibrationDataModel(const std::string& file) : file(file) {
|
||||
load();
|
||||
}
|
||||
|
||||
const std::vector<BeaconFingerprint>& 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
|
||||
BeaconFingerprint bfp;
|
||||
bfp.read(inp);
|
||||
if (bfp.measurements.entries.empty()) {continue;}
|
||||
fingerprints.push_back(bfp);
|
||||
}
|
||||
|
||||
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 BeaconFingerprint& 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! */
|
||||
BeaconFingerprint& getFingerprint(const Point3 pos_m) {
|
||||
|
||||
// try to find an existing one
|
||||
for (BeaconFingerprint& bfp : fingerprints) {
|
||||
// get within range of floating-point rounding issues
|
||||
if (bfp.pos_m.getDistance(pos_m) < 0.01) {return bfp;}
|
||||
}
|
||||
|
||||
// create a new one and return its reference
|
||||
BeaconFingerprint bfp(pos_m);
|
||||
fingerprints.push_back(bfp);
|
||||
return fingerprints.back();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // BLECALIBRATIONDATAMODEL_H
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
#include "WiFiCalibrationScanDialog.h"
|
||||
|
||||
|
||||
WiFiCalibrationScanDialog::WiFiCalibrationScanDialog(WiFiFingerprint& model) : model(model) {
|
||||
WiFiCalibrationScanDialog::WiFiCalibrationScanDialog(WiFiFingerprint& wifiModel, BeaconFingerprint& bleModel) : wifiModel(wifiModel), bleModel(bleModel) {
|
||||
|
||||
dlg->resize(300, 300);
|
||||
dlg->resize(300, 300);
|
||||
|
||||
QGridLayout* lay = new QGridLayout(dlg);
|
||||
QGridLayout* lay = new QGridLayout(dlg);
|
||||
|
||||
int row = 0;
|
||||
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* 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);
|
||||
QPushButton* btnRecord = new QPushButton(dlg);
|
||||
btnRecord->setText("rec");
|
||||
btnRecord->connect(btnRecord, &QPushButton::clicked, [&] () {startRecord();});
|
||||
lay->addWidget(btnRecord, row, 2, 1, 1);
|
||||
|
||||
++row;
|
||||
++row;
|
||||
|
||||
lay->addWidget(new QLabel("point"), row, 0, 1, 1);
|
||||
lblPoint = new QLabel();
|
||||
lay->addWidget(lblPoint, row, 1, 1, 2);
|
||||
lay->addWidget(new QLabel("point"), row, 0, 1, 1);
|
||||
lblPoint = new QLabel();
|
||||
lay->addWidget(lblPoint, row, 1, 1, 2);
|
||||
|
||||
++row;
|
||||
++row;
|
||||
|
||||
lay->addWidget(new QLabel("stats"), row, 0, 1, 1);
|
||||
lblStats = new QLabel();
|
||||
lay->addWidget(lblStats, row, 1, 1, 2);
|
||||
lay->addWidget(new QLabel("stats"), row, 0, 1, 1);
|
||||
lblStats = new QLabel();
|
||||
lay->addWidget(lblStats, row, 1, 1, 2);
|
||||
|
||||
++row;
|
||||
++row;
|
||||
|
||||
barProg = new QProgressBar();
|
||||
lay->addWidget(barProg, row, 0, 1, 3);
|
||||
barProg = new QProgressBar();
|
||||
lay->addWidget(barProg, row, 0, 1, 3);
|
||||
|
||||
++row;
|
||||
++row;
|
||||
|
||||
QPushButton* btnCancel = new QPushButton(dlg);
|
||||
btnCancel->setText("cancel");
|
||||
btnCancel->connect(btnCancel, &QPushButton::clicked, [&] () {close();});
|
||||
lay->addWidget(btnCancel, row, 0, 1, 1);
|
||||
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);
|
||||
QPushButton* btnOK = new QPushButton(dlg);
|
||||
btnOK->setText("OK");
|
||||
btnOK->connect(btnOK, &QPushButton::clicked, [&] () {save(); close();});
|
||||
lay->addWidget(btnOK, row, 2, 1, 1);
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "../sensors/SensorFactory.h"
|
||||
#include "../tools/calibration/WiFiCalibrationDataModel.h"
|
||||
|
||||
#include "../tools/calibration/BLECalibrationDataModel.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,20 +33,20 @@ private:
|
||||
} scan;
|
||||
|
||||
/** the measurements model to fill with scan-entries */
|
||||
WiFiFingerprint& model;
|
||||
//BeaconFingerprint& blemodel;
|
||||
WiFiFingerprint& wifiModel;
|
||||
BeaconFingerprint& bleModel;
|
||||
|
||||
public:
|
||||
|
||||
static void get(WiFiFingerprint& model) {
|
||||
WiFiCalibrationScanDialog dlg(model);
|
||||
static void get(WiFiFingerprint& wifiModel, BeaconFingerprint& bleModel) {
|
||||
WiFiCalibrationScanDialog dlg(wifiModel, bleModel);
|
||||
dlg.show();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** ctor */
|
||||
WiFiCalibrationScanDialog(WiFiFingerprint& model);
|
||||
WiFiCalibrationScanDialog(WiFiFingerprint& wifiModel, BeaconFingerprint& bleModel);
|
||||
|
||||
void show() {
|
||||
refresh();
|
||||
@@ -63,28 +63,39 @@ private:
|
||||
}
|
||||
|
||||
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");
|
||||
lblPoint->setText(QString(wifiModel.pos_m.asString().c_str()));
|
||||
lblStats->setText( QString::number(wifiModel.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();
|
||||
wifiModel.measurements.entries.clear();
|
||||
bleModel.measurements.entries.clear();
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void startRecord() {
|
||||
scan.recordsDone = 0;
|
||||
|
||||
//add wifi
|
||||
SensorFactory::get().getWiFi().addListener(this);
|
||||
if (!SensorFactory::get().getWiFi().isRunning()) {
|
||||
SensorFactory::get().getWiFi().start();
|
||||
}
|
||||
|
||||
//add ble
|
||||
SensorFactory::get().getBLE().addListener(this);
|
||||
if (!SensorFactory::get().getBLE().isRunning()) {
|
||||
SensorFactory::get().getBLE().start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void stopRecord() {
|
||||
SensorFactory::get().getWiFi().removeListener(this);
|
||||
SensorFactory::get().getBLE().removeListener(this);
|
||||
}
|
||||
|
||||
virtual void onSensorData(Sensor<WiFiMeasurements>* sensor, const Timestamp ts, const WiFiMeasurements& data) override {
|
||||
@@ -92,7 +103,7 @@ private:
|
||||
(void) ts;
|
||||
++scan.recordsDone;
|
||||
if (scan.recordsDone >= scan.numRecords) {stopRecord();}
|
||||
model.measurements.entries.insert(model.measurements.entries.end(), data.entries.begin(), data.entries.end());
|
||||
wifiModel.measurements.entries.insert(wifiModel.measurements.entries.end(), data.entries.begin(), data.entries.end());
|
||||
QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
@@ -100,8 +111,7 @@ private:
|
||||
virtual void onSensorData(Sensor<BeaconMeasurement>* sensor, const Timestamp ts, const BeaconMeasurement& data) override {
|
||||
(void) sensor;
|
||||
(void) ts;
|
||||
|
||||
|
||||
bleModel.measurements.entries.push_back(data);
|
||||
QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user