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
92 lines
2.3 KiB
C++
92 lines
2.3 KiB
C++
#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
|