merged
This commit is contained in:
@@ -38,7 +38,7 @@ TEST(MotionDetection, motionAxis) {
|
||||
//table_flat: phone was flat on the table and moved slowly forward/backward for 60 cm.
|
||||
//std::string filename = getDataFile("motion/table_flat.csv");
|
||||
|
||||
FileReader fr(filename);
|
||||
Offline::FileReader fr(filename);
|
||||
|
||||
K::Gnuplot gp;
|
||||
K::GnuplotPlot plot;
|
||||
@@ -52,14 +52,14 @@ TEST(MotionDetection, motionAxis) {
|
||||
Timestamp lastTs;
|
||||
|
||||
//calc motion axis
|
||||
for (const FileReader::Entry& e : fr.getEntries()) {
|
||||
for (const Offline::Entry& e : fr.getEntries()) {
|
||||
|
||||
ts = Timestamp::fromMS(e.ts);
|
||||
|
||||
if (e.type == FileReader::Sensor::LIN_ACC) {
|
||||
if (e.type == Offline::Sensor::LIN_ACC) {
|
||||
md.addLinearAcceleration(ts, fr.getLinearAcceleration()[e.idx].data);
|
||||
|
||||
} else if (e.type == FileReader::Sensor::GRAVITY) {
|
||||
} else if (e.type == Offline::Sensor::GRAVITY) {
|
||||
md.addGravity(ts, fr.getGravity()[e.idx].data);
|
||||
curVec = md.getCurrentMotionAxis();
|
||||
motionAxisAngleRad = md.getMotionChangeInRad();
|
||||
@@ -126,7 +126,7 @@ TEST(MotionDetection, motionAngle) {
|
||||
//table_flat: phone was flat on the table and moved slowly forward/backward for 60 cm.
|
||||
//std::string filename = getDataFile("motion/table_flat.csv");
|
||||
|
||||
FileReader fr(filename);
|
||||
Offline::FileReader fr(filename);
|
||||
Timestamp ts;
|
||||
|
||||
//save for later plotting
|
||||
@@ -134,23 +134,23 @@ TEST(MotionDetection, motionAngle) {
|
||||
std::vector<float> delta_turnAngles;
|
||||
|
||||
//calc motion axis
|
||||
for (const FileReader::Entry& e : fr.getEntries()) {
|
||||
for (const Offline::Entry& e : fr.getEntries()) {
|
||||
|
||||
ts = Timestamp::fromMS(e.ts);
|
||||
|
||||
if (e.type == FileReader::Sensor::LIN_ACC) {
|
||||
if (e.type == Offline::Sensor::LIN_ACC) {
|
||||
md.addLinearAcceleration(ts, fr.getLinearAcceleration()[e.idx].data);
|
||||
|
||||
} else if (e.type == FileReader::Sensor::GRAVITY) {
|
||||
} else if (e.type == Offline::Sensor::GRAVITY) {
|
||||
md.addGravity(ts, fr.getGravity()[e.idx].data);
|
||||
delta_motionAngles.push_back(md.getMotionChangeInRad());
|
||||
|
||||
} else if (e.type == FileReader::Sensor::ACC) {
|
||||
const FileReader::TS<AccelerometerData>& _acc = fr.getAccelerometer()[e.idx];
|
||||
} else if (e.type == Offline::Sensor::ACC) {
|
||||
const Offline::TS<AccelerometerData>& _acc = fr.getAccelerometer()[e.idx];
|
||||
td.addAccelerometer(ts, _acc.data);
|
||||
|
||||
} else if (e.type == FileReader::Sensor::GYRO) {
|
||||
const FileReader::TS<GyroscopeData>& _gyr = fr.getGyroscope()[e.idx];
|
||||
} else if (e.type == Offline::Sensor::GYRO) {
|
||||
const Offline::TS<GyroscopeData>& _gyr = fr.getGyroscope()[e.idx];
|
||||
delta_turnAngles.push_back(td.addGyroscope(ts, _gyr.data));
|
||||
}
|
||||
|
||||
|
||||
89
tests/sensors/offline/TestReadWrite.cpp
Normal file
89
tests/sensors/offline/TestReadWrite.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "../../Tests.h"
|
||||
|
||||
#include "../../../sensors/offline/FileReader.h"
|
||||
#include "../../../sensors/offline/FileWriter.h"
|
||||
|
||||
TEST(Offline, readWrite) {
|
||||
|
||||
std::string fileName = "/tmp/test.dat";
|
||||
|
||||
Offline::FileWriter out;
|
||||
out.open(fileName);
|
||||
|
||||
const GPSData gps(Timestamp::fromMS(1), 2, 3, 4);
|
||||
out.add(Timestamp::fromMS(11), gps);
|
||||
|
||||
const CompassData compass(4, 2);
|
||||
out.add(Timestamp::fromMS(13), compass);
|
||||
|
||||
const BarometerData baro(3);
|
||||
out.add(Timestamp::fromMS(15), baro);
|
||||
|
||||
const AccelerometerData acc(3,4,5);
|
||||
out.add(Timestamp::fromMS(17), acc);
|
||||
|
||||
const GravityData grav(5,9,7);
|
||||
out.add(Timestamp::fromMS(19), grav);
|
||||
|
||||
const GyroscopeData gyro(8, 5,11);
|
||||
out.add(Timestamp::fromMS(21), gyro);
|
||||
|
||||
const LinearAccelerationData lina(13, 12, 11);
|
||||
out.add(Timestamp::fromMS(23), lina);
|
||||
|
||||
WiFiMeasurements w1;
|
||||
w1.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:55:66")), -70));
|
||||
w1.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:55:67")), -72));
|
||||
w1.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:55:68")), -74));
|
||||
out.add(Timestamp::fromMS(25), w1);
|
||||
|
||||
WiFiMeasurements w2;
|
||||
w2.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:aa:66")), -60));
|
||||
w2.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:aa:67")), -62));
|
||||
w2.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:aa:68")), -64));
|
||||
out.add(Timestamp::fromMS(27), w2);
|
||||
|
||||
out.close();
|
||||
|
||||
Offline::FileReader reader;
|
||||
reader.open(fileName);
|
||||
|
||||
// check number of entries
|
||||
ASSERT_EQ(1, reader.getGPS().size());
|
||||
ASSERT_EQ(1, reader.getCompass().size());
|
||||
ASSERT_EQ(1, reader.getBarometer().size());
|
||||
ASSERT_EQ(1, reader.getAccelerometer().size());
|
||||
ASSERT_EQ(1, reader.getGravity().size());
|
||||
ASSERT_EQ(1, reader.getGyroscope().size());
|
||||
ASSERT_EQ(1, reader.getLinearAcceleration().size());
|
||||
ASSERT_EQ(2, reader.getWiFiGroupedByTime().size());
|
||||
|
||||
// check timestamps
|
||||
ASSERT_EQ(11, reader.getGPS().front().ts);
|
||||
ASSERT_EQ(13, reader.getCompass().front().ts);
|
||||
ASSERT_EQ(15, reader.getBarometer().front().ts);
|
||||
ASSERT_EQ(17, reader.getAccelerometer().front().ts);
|
||||
ASSERT_EQ(19, reader.getGravity().front().ts);
|
||||
ASSERT_EQ(21, reader.getGyroscope().front().ts);
|
||||
ASSERT_EQ(23, reader.getLinearAcceleration().front().ts);
|
||||
ASSERT_EQ(25, reader.getWiFiGroupedByTime().front().ts);
|
||||
ASSERT_EQ(27, reader.getWiFiGroupedByTime().back().ts);
|
||||
|
||||
// check content
|
||||
ASSERT_EQ(gps, reader.getGPS().front().data);
|
||||
ASSERT_EQ(compass, reader.getCompass().front().data);
|
||||
ASSERT_EQ(baro, reader.getBarometer().front().data);
|
||||
ASSERT_EQ(acc, reader.getAccelerometer().front().data);
|
||||
ASSERT_EQ(grav, reader.getGravity().front().data);
|
||||
ASSERT_EQ(gyro, reader.getGyroscope().front().data);
|
||||
ASSERT_EQ(lina, reader.getLinearAcceleration().front().data);
|
||||
|
||||
int i = 0; (void) i;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user