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(
"modem.measurement_file.gpsd.enabled", gps_enabled);
43 std::string host =
"localhost";
44 _cfg.lookupValue(
"modem.measurement_file.gpsd.host", host);
46 std::string port = DEFAULT_GPSD_PORT;
47 _cfg.lookupValue(
"modem.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");
std::unique_ptr< gpsmm > _gps
std::thread _gps_reader_thread
const libconfig::Config & _cfg
static Config cfg
Global configuration object.
◆ ~MeasurementFileWriter()
MeasurementFileWriter::~MeasurementFileWriter |
( |
| ) |
|
|
virtual |
◆ ReadGps()
void MeasurementFileWriter::ReadGps |
( |
| ) |
|
|
private |
Definition at line 66 of file MeasurementFileWriter.cpp.
68 if (
_gps->is_open()) {
77 struct tm ts = *localtime(&
_gps_data->fix.time.tv_sec);
80 strftime(&buf[0], buf.size(),
"%FT%T", &ts);
95 _gps->stream(WATCH_ENABLE|WATCH_JSON);
const uint32_t kGpsWaitMicrosleep
const uint32_t kGpsWaitTimeout
const uint32_t kMaxTimestringSize
const uint32_t kGpsReconnectTimeout
std::string _last_gps_lat
std::string _last_gps_time
struct gps_data_t * _gps_data
std::string _last_gps_lng
◆ 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);
106 strftime(&buf[0], buf.size(),
"%FT%T", &ts);
112 for (
const auto& col : cols) {
117 for (
const auto& val : values) {
123 std::string file_loc =
"/tmp/modem_measurements.csv";
124 _cfg.lookupValue(
"modem.measurement_file.file_path", file_loc);
126 file.open(file_loc, std::ios_base::app);
127 file << line << std::endl;
◆ _cfg
const libconfig::Config& MeasurementFileWriter::_cfg |
|
private |
◆ _gps
std::unique_ptr<gpsmm> MeasurementFileWriter::_gps |
|
private |
◆ _gps_data
struct gps_data_t* MeasurementFileWriter::_gps_data {} |
|
private |
◆ _gps_reader_thread
std::thread MeasurementFileWriter::_gps_reader_thread |
|
private |
◆ _last_gps_lat
std::string MeasurementFileWriter::_last_gps_lat = "" |
|
private |
◆ _last_gps_lng
std::string MeasurementFileWriter::_last_gps_lng = "" |
|
private |
◆ _last_gps_time
std::string MeasurementFileWriter::_last_gps_time = "" |
|
private |
◆ _running
bool MeasurementFileWriter::_running = true |
|
private |
The documentation for this class was generated from the following files: