OBECA Receive Process
Public Member Functions | List of all members
MeasurementFileWriter Class Reference

Writes measurement data / current reception parameters to a file. More...

#include <MeasurementFileWriter.h>

Public Member Functions

 MeasurementFileWriter (const libconfig::Config &cfg)
 Default constructor. More...
 
virtual ~MeasurementFileWriter ()
 Default destructor.
 
void WriteLogValues (const std::vector< std::string > &values)
 Write a line containing the passed values. More...
 

Detailed Description

Writes measurement data / current reception parameters to a file.

Definition at line 35 of file MeasurementFileWriter.h.

Constructor & Destructor Documentation

◆ MeasurementFileWriter()

MeasurementFileWriter::MeasurementFileWriter ( const libconfig::Config &  cfg)
explicit

Default constructor.

Parameters
cfgConfig singleton reference

Definition at line 37 of file MeasurementFileWriter.cpp.

38  : _cfg(cfg) {
39  bool gps_enabled = false;
40  _cfg.lookupValue("measurement_file.gpsd.enabled", gps_enabled);
41 
42  if (gps_enabled) {
43  std::string host = "localhost";
44  _cfg.lookupValue("measurement_file.gpsd.host", host);
45 
46  std::string port = DEFAULT_GPSD_PORT;
47  _cfg.lookupValue("measurement_file.gpsd.port", port);
48 
49  _gps = std::make_unique<gpsmm>(host.c_str(), port.c_str());
50 
51  if (_gps->stream(WATCH_ENABLE | WATCH_JSON) == nullptr) {
52  spdlog::error("No GPSD running, cannot start GPS stream.");
53  } else {
54  spdlog::info("GPS data stream started");
55  }
56 
57  _gps_reader_thread = std::thread{&MeasurementFileWriter::ReadGps, this};
58  }
59 }

Member Function Documentation

◆ 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.

101  {
102  time_t now = time(nullptr);
103  struct tm ts = *localtime(&now);
104  std::string buf;
105  buf.resize(kMaxTimestringSize);
106  strftime(&buf[0], buf.size(), "%FT%T", &ts);
107 
108  std::vector<std::string> cols = {buf, _last_gps_lat,
109  _last_gps_lng, _last_gps_time};
110 
111  std::string line;
112  for (const auto& col : cols) {
113  {
114  line += col + ";";
115  }
116  }
117  for (const auto& val : values) {
118  {
119  line += val + ";";
120  }
121  }
122 
123  std::string file_loc = "/tmp/rp_measurements.csv";
124  _cfg.lookupValue("measurement_file.file_path", file_loc);
125  std::ofstream file;
126  file.open(file_loc, std::ios_base::app);
127  file << line << std::endl;
128  file.close();
129 }

The documentation for this class was generated from the following files: