This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
YASMIN/tools/calibration/WiFiCalibrationScanDialog.h
mail@toni-fetzer.de ef6066ae14 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
2019-06-06 17:42:11 +02:00

123 lines
3.2 KiB
C++

#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"
#include "../tools/calibration/BLECalibrationDataModel.h"
/**
* show a dialog to perform a WiFiScan
*/
class WiFiCalibrationScanDialog : public QObject, public SensorListener<WiFiMeasurements>, public SensorListener<BeaconMeasurement> {
Q_OBJECT
private:
QDialog* dlg = new QDialog();
QLabel* lblStats;
QLabel* lblPoint;
QProgressBar* barProg;
struct Scan {
const int numRecords = 30;
int recordsDone = 0;
} scan;
/** the measurements model to fill with scan-entries */
WiFiFingerprint& wifiModel;
BeaconFingerprint& bleModel;
public:
static void get(WiFiFingerprint& wifiModel, BeaconFingerprint& bleModel) {
WiFiCalibrationScanDialog dlg(wifiModel, bleModel);
dlg.show();
}
private:
/** ctor */
WiFiCalibrationScanDialog(WiFiFingerprint& wifiModel, BeaconFingerprint& bleModel);
void show() {
refresh();
dlg->exec();
}
void close() {
stopRecord();
dlg->close();
}
void save() {
//mdl.save();;
}
Q_INVOKABLE void refresh() {
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() {
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 {
(void) sensor;
(void) ts;
++scan.recordsDone;
if (scan.recordsDone >= scan.numRecords) {stopRecord();}
wifiModel.measurements.entries.insert(wifiModel.measurements.entries.end(), data.entries.begin(), data.entries.end());
QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
}
//tmp stuff
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);
}
};
#endif // CALIBDIALOG_H