fixed some issues
some new helper methods added listener-support to offline-reader
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "Splitter.h"
|
||||
#include "Sensors.h"
|
||||
#include "Listener.h"
|
||||
|
||||
#warning "adjust to to use the new splitter for all parsers [gps, compass, etc. already do!]"
|
||||
|
||||
@@ -49,6 +50,8 @@ namespace Offline {
|
||||
|
||||
static constexpr char sep = ';';
|
||||
|
||||
Listener* listener = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
/** empty ctor. call open() */
|
||||
@@ -62,7 +65,8 @@ namespace Offline {
|
||||
}
|
||||
|
||||
/** open the given file */
|
||||
void open(const std::string& file) {
|
||||
void open(const std::string& file, Listener* listener = nullptr) {
|
||||
this->listener = listener;
|
||||
parse(file);
|
||||
}
|
||||
|
||||
@@ -142,20 +146,27 @@ namespace Offline {
|
||||
TS<LinearAccelerationData> elem(ts, LinearAccelerationData(std::stof(x), std::stof(y), std::stof(z)));
|
||||
lin_acc.push_back(elem);
|
||||
entries.push_back(Entry(Sensor::LIN_ACC, ts, lin_acc.size()-1));
|
||||
|
||||
}
|
||||
|
||||
void parseGravity(const uint64_t ts, const std::string& data){
|
||||
|
||||
GravityData gravData;
|
||||
|
||||
const auto pos1 = data.find(';');
|
||||
const auto pos2 = data.find(';', pos1+1);
|
||||
|
||||
const std::string x = data.substr(0, pos1);
|
||||
const std::string y = data.substr(pos1+1, pos2-pos1-1);
|
||||
const std::string z = data.substr(pos2+1);
|
||||
gravData.x = std::stof(data.substr(0, pos1));
|
||||
gravData.y = std::stof(data.substr(pos1+1, pos2-pos1-1));
|
||||
gravData.z = std::stof(data.substr(pos2+1));
|
||||
|
||||
TS<GravityData> elem(ts, GravityData(std::stof(x), std::stof(y), std::stof(z)));
|
||||
TS<GravityData> elem(ts, gravData);
|
||||
gravity.push_back(elem);
|
||||
entries.push_back(Entry(Sensor::GRAVITY, ts, gravity.size()-1));
|
||||
|
||||
// inform listener
|
||||
if (listener) {listener->onGravity(Timestamp::fromMS(ts), gravData);}
|
||||
|
||||
}
|
||||
|
||||
void parseAccelerometer(const uint64_t ts, const std::string& data) {
|
||||
@@ -167,10 +178,14 @@ namespace Offline {
|
||||
const std::string y = data.substr(pos1+1, pos2-pos1-1);
|
||||
const std::string z = data.substr(pos2+1);
|
||||
|
||||
TS<AccelerometerData> elem(ts, AccelerometerData(std::stof(x), std::stof(y), std::stof(z)));
|
||||
const AccelerometerData accData(std::stof(x), std::stof(y), std::stof(z));
|
||||
TS<AccelerometerData> elem(ts, accData);
|
||||
acc.push_back(elem);
|
||||
entries.push_back(Entry(Sensor::ACC, ts, acc.size()-1));
|
||||
|
||||
// inform listener
|
||||
if (listener) {listener->onAccelerometer(Timestamp::fromMS(ts), accData);}
|
||||
|
||||
}
|
||||
|
||||
void parseGyroscope(const uint64_t ts, const std::string& data) {
|
||||
@@ -182,10 +197,14 @@ namespace Offline {
|
||||
const std::string y = data.substr(pos1+1, pos2-pos1-1);
|
||||
const std::string z = data.substr(pos2+1);
|
||||
|
||||
TS<GyroscopeData> elem(ts, GyroscopeData(std::stof(x), std::stof(y), std::stof(z)));
|
||||
const GyroscopeData gyroData(std::stof(x), std::stof(y), std::stof(z));
|
||||
TS<GyroscopeData> elem(ts, gyroData);
|
||||
gyro.push_back(elem);
|
||||
entries.push_back(Entry(Sensor::GYRO, ts, gyro.size()-1));
|
||||
|
||||
// inform listener
|
||||
if (listener) {listener->onGyroscope(Timestamp::fromMS(ts), gyroData);}
|
||||
|
||||
}
|
||||
|
||||
void parseWiFi(const uint64_t ts, const std::string& data) {
|
||||
@@ -210,6 +229,9 @@ namespace Offline {
|
||||
this->wifi.push_back(TS<WiFiMeasurements>(ts, wifi));
|
||||
entries.push_back(Entry(Sensor::WIFI, ts, this->wifi.size()-1));
|
||||
|
||||
// inform listener
|
||||
if (listener) {listener->onWiFi(Timestamp::fromMS(ts), wifi);}
|
||||
|
||||
}
|
||||
|
||||
void parseBeacons(const uint64_t ts, const std::string& data) {
|
||||
@@ -250,6 +272,9 @@ namespace Offline {
|
||||
barometer.push_back(elem);
|
||||
entries.push_back(Entry(Sensor::BARO, ts, barometer.size()-1));
|
||||
|
||||
// inform listener
|
||||
if (listener) {listener->onBarometer(Timestamp::fromMS(ts), baro);}
|
||||
|
||||
}
|
||||
|
||||
void parseCompass(const uint64_t ts, const std::string& data) {
|
||||
@@ -264,6 +289,9 @@ namespace Offline {
|
||||
this->compass.push_back(elem);
|
||||
entries.push_back(Entry(Sensor::COMPASS, ts, this->compass.size()-1));
|
||||
|
||||
// inform listener
|
||||
if (listener) {listener->onCompass(Timestamp::fromMS(ts), compass);}
|
||||
|
||||
}
|
||||
|
||||
/** parse the given GPS entry */
|
||||
@@ -282,6 +310,8 @@ namespace Offline {
|
||||
this->gps.push_back(elem);
|
||||
entries.push_back(Entry(Sensor::GPS, ts, this->gps.size()-1));
|
||||
|
||||
// inform listener
|
||||
if (listener) {listener->onGPS(Timestamp::fromMS(ts), gps);}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Offline {
|
||||
|
||||
virtual void onGyroscope(const Timestamp ts, const GyroscopeData data) = 0;
|
||||
virtual void onAccelerometer(const Timestamp ts, const AccelerometerData data) = 0;
|
||||
virtual void onGravity(const Timestamp ts, const AccelerometerData data) = 0;
|
||||
virtual void onGravity(const Timestamp ts, const GravityData data) = 0;
|
||||
virtual void onWiFi(const Timestamp ts, const WiFiMeasurements data) = 0;
|
||||
virtual void onBarometer(const Timestamp ts, const BarometerData data) = 0;
|
||||
virtual void onGPS(const Timestamp ts, const GPSData data) = 0;
|
||||
|
||||
Reference in New Issue
Block a user