Writes measurement data / current reception parameters to a file.
More...
#include <MeasurementFileWriter.h>
Writes measurement data / current reception parameters to a file.
Definition at line 35 of file MeasurementFileWriter.h.
◆ MeasurementFileWriter()
| MeasurementFileWriter::MeasurementFileWriter |
( |
const libconfig::Config & |
cfg | ) |
|
|
explicit |
Default constructor.
- Parameters
-
| cfg | Config singleton reference |
Definition at line 37 of file MeasurementFileWriter.cpp.
39 bool gps_enabled =
false;
40 _cfg.lookupValue(
"measurement_file.gpsd.enabled", gps_enabled);
43 std::string host =
"localhost";
44 _cfg.lookupValue(
"measurement_file.gpsd.host", host);
46 std::string port = DEFAULT_GPSD_PORT;
47 _cfg.lookupValue(
"measurement_file.gpsd.port", port);
49 _gps = std::make_unique<gpsmm>(host.c_str(), port.c_str());
51 if (_gps->stream(WATCH_ENABLE | WATCH_JSON) ==
nullptr) {
52 spdlog::error(
"No GPSD running, cannot start GPS stream.");
54 spdlog::info(
"GPS data stream started");
57 _gps_reader_thread = std::thread{&MeasurementFileWriter::ReadGps,
this};
◆ WriteLogValues()
| void MeasurementFileWriter::WriteLogValues |
( |
const std::vector< std::string > & |
values | ) |
|
Write a line containing the passed values.
This methods always writes the first four columns containing:
- the current timestamp
- the GPS latitude (if a GPS device was configured)
- the GPS longitude (if a GPS device was configured)
- the GPS time (if a GPS device was configured)
followed by the values in the values vector.
Definition at line 100 of file MeasurementFileWriter.cpp.
102 time_t now = time(
nullptr);
103 struct tm ts = *localtime(&now);
105 buf.resize(kMaxTimestringSize);
106 strftime(&buf[0], buf.size(),
"%FT%T", &ts);
108 std::vector<std::string> cols = {buf, _last_gps_lat,
109 _last_gps_lng, _last_gps_time};
112 for (
const auto& col : cols) {
117 for (
const auto& val : values) {
123 std::string file_loc =
"/tmp/rp_measurements.csv";
124 _cfg.lookupValue(
"measurement_file.file_path", file_loc);
126 file.open(file_loc, std::ios_base::app);
127 file << line << std::endl;
The documentation for this class was generated from the following files: