diff --git a/host/include/PowerSensor.hpp b/host/include/PowerSensor.hpp index a2bbabd..806b082 100644 --- a/host/include/PowerSensor.hpp +++ b/host/include/PowerSensor.hpp @@ -53,7 +53,7 @@ class PowerSensor { State read() const; - void dump(const std::string dumpFileName); // dumpFileName == 0 --> stop dumping + void dump(const std::string dumpFileName, bool useAbsoluteTimestamp=false); // dumpFileName == 0 --> stop dumping void mark(char name); void reset(bool dfuMode); @@ -92,6 +92,7 @@ class PowerSensor { bool readLevelFromDevice(unsigned int* sensorNumber, uint16_t* level, unsigned int* marker); std::unique_ptr dumpFile; + bool useAbsoluteTimestamp; void dumpCurrentWattToFile(const char markerChar); Semaphore threadStarted; diff --git a/host/src/PowerSensor.cc b/host/src/PowerSensor.cc index 2926729..c4b4c3b 100644 --- a/host/src/PowerSensor.cc +++ b/host/src/PowerSensor.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include "PowerSensor.hpp" @@ -440,8 +441,9 @@ void PowerSensor::stopIOThread() { * @brief Enable dumping of sensor values to the given output file. * * @param dumpFileName + * @param useAbsoluteTimestamp */ -void PowerSensor::dump(std::string dumpFileName) { +void PowerSensor::dump(std::string dumpFileName, bool useAbsoluteTimestamp) { // if dumping to a new file or dumping should be stopped, first wait until all markers are written if (dumpFile != nullptr || dumpFileName.empty()) { waitForMarkers(); @@ -450,6 +452,7 @@ void PowerSensor::dump(std::string dumpFileName) { std::unique_lock lock(dumpFileMutex); dumpFile = std::unique_ptr(dumpFileName.empty() ? nullptr: new std::ofstream(dumpFileName)); if (!dumpFileName.empty()) { + this->useAbsoluteTimestamp = useAbsoluteTimestamp; *dumpFile << "marker time dt_micro device_timestamp"; for (unsigned int pairID=0; pairID < MAX_PAIRS; pairID++) { if (sensorPairs[pairID].inUse) @@ -472,7 +475,12 @@ void PowerSensor::dumpCurrentWattToFile(const char markerChar) { auto time = std::chrono::high_resolution_clock::now(); static auto previousTime = startTime; - *dumpFile << markerChar << ' ' << elapsedSeconds(startTime, time); + *dumpFile << markerChar << ' '; + if (useAbsoluteTimestamp) { + *dumpFile << std::fixed << std::setprecision(6) << std::chrono::duration_cast(time.time_since_epoch()).count() / 1.0e6; + } else { + *dumpFile << elapsedSeconds(startTime, time); + } *dumpFile << ' ' << static_cast(1e6 * elapsedSeconds(previousTime, time)); *dumpFile << ' ' << timestamp; previousTime = time;