30 #include "spdlog/spdlog.h"
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");
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);
101 const std::vector<std::string>& values) {
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;
const uint32_t kGpsWaitMicrosleep
const uint32_t kGpsWaitTimeout
const uint32_t kMaxTimestringSize
const uint32_t kGpsReconnectTimeout
std::unique_ptr< gpsmm > _gps
std::thread _gps_reader_thread
virtual ~MeasurementFileWriter()
Default destructor.
const libconfig::Config & _cfg
void WriteLogValues(const std::vector< std::string > &values)
Write a line containing the passed values.
std::string _last_gps_lat
std::string _last_gps_time
MeasurementFileWriter(const libconfig::Config &cfg)
Default constructor.
struct gps_data_t * _gps_data
std::string _last_gps_lng
static Config cfg
Global configuration object.