dataload_ulog.cpp
Go to the documentation of this file.
1 #include "dataload_ulog.h"
2 #include <QTextStream>
3 #include <QFile>
4 #include <QMessageBox>
5 #include <QDebug>
6 #include <QWidget>
7 #include <QSettings>
8 #include <QMainWindow>
9 
10 #include "ulog_parser.h"
11 #include "ulog_parameters_dialog.h"
12 
14 {
15  for (QWidget* widget : qApp->topLevelWidgets())
16  {
17  if (widget->inherits("QMainWindow"))
18  {
19  _main_win = widget;
20  break;
21  }
22  }
23 }
24 
25 const std::vector<const char*>& DataLoadULog::compatibleFileExtensions() const
26 {
27  static std::vector<const char*> extensions = { "ulg" };
28  return extensions;
29 }
30 
32  PlotDataMapRef& plot_data)
33 {
34  const auto& filename = fileload_info->filename;
35 
36  QFile file(filename);
37 
38  if (!file.open(QIODevice::ReadOnly))
39  {
40  throw std::runtime_error("ULog: Failed to open file");
41  }
42  QByteArray file_array = file.readAll();
43  ULogParser::DataStream datastream(file_array.data(), file_array.size());
44 
45  ULogParser parser(datastream);
46 
47  const auto& timeseries_map = parser.getTimeseriesMap();
48  auto min_msg_time = std::numeric_limits<double>::max();
49  for (const auto& it : timeseries_map)
50  {
51  const std::string& sucsctiption_name = it.first;
52  const ULogParser::Timeseries& timeseries = it.second;
53 
54  for (const auto& data : timeseries.data)
55  {
56  std::string series_name = sucsctiption_name + data.first;
57 
58  auto series = plot_data.addNumeric(series_name);
59 
60  for (size_t i = 0; i < data.second.size(); i++)
61  {
62  double msg_time = static_cast<double>(timeseries.timestamps[i]) * 0.000001;
63  min_msg_time = std::min(min_msg_time, msg_time);
64  PlotData::Point point(msg_time, data.second[i]);
65  series->second.pushBack(point);
66  }
67  }
68  }
69 
70  // store parameters as a timeseries with a single point
71  for (const auto& param : parser.getParameters())
72  {
73  auto series = plot_data.addNumeric("_parameters/" + param.name);
74  double value = (param.val_type == ULogParser::FLOAT) ? double(param.value.val_real) :
75  double(param.value.val_int);
76  series->second.pushBack({ min_msg_time, value });
77  }
78 
80  dialog->setWindowTitle(QString("ULog file %1").arg(filename));
81  dialog->setAttribute(Qt::WA_DeleteOnClose);
82  dialog->restoreSettings();
83  dialog->show();
84 
85  return true;
86 }
87 
89 {
90 }
91 
92 bool DataLoadULog::xmlSaveState(QDomDocument& doc, QDomElement& parent_element) const
93 {
94  return true;
95 }
96 
97 bool DataLoadULog::xmlLoadState(const QDomElement&)
98 {
99  return true;
100 }
DataLoadULog::xmlLoadState
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Definition: dataload_ulog.cpp:97
ULogParser::Timeseries::data
std::vector< std::pair< std::string, std::vector< double > > > data
Definition: ulog_parser.h:112
PJ::FileLoadInfo
Definition: dataloader_base.h:18
ULogParser
Definition: ulog_parser.h:14
PJ::PlotDataMapRef::addNumeric
TimeseriesMap::iterator addNumeric(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:51
arg
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1875
DataLoadULog::~DataLoadULog
~DataLoadULog() override
Definition: dataload_ulog.cpp:88
DataLoadULog::_main_win
QWidget * _main_win
Definition: dataload_ulog.h:37
DataLoadULog::readDataFromFile
bool readDataFromFile(PJ::FileLoadInfo *fileload_info, PlotDataMapRef &destination) override
Definition: dataload_ulog.cpp:31
ULogParametersDialog::restoreSettings
void restoreSettings()
Definition: ulog_parameters_dialog.cpp:82
ULogParametersDialog
Definition: ulog_parameters_dialog.h:12
DataLoadULog::xmlSaveState
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
Definition: dataload_ulog.cpp:92
ULogParser::Timeseries
Definition: ulog_parser.h:109
ulog_parameters_dialog.h
ULogParser::Timeseries::timestamps
std::vector< uint64_t > timestamps
Definition: ulog_parser.h:111
PJ::TimeseriesBase::Point
typename PlotDataBase< double, Value >::Point Point
Definition: timeseries.h:23
dataload_ulog.h
udp_client.parser
parser
Definition: udp_client.py:9
DataLoadULog::compatibleFileExtensions
const std::vector< const char * > & compatibleFileExtensions() const override
Provide a list of file extensions that this plugin can open.
Definition: dataload_ulog.cpp:25
ULogParser::DataStream
Definition: ulog_parser.h:17
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
param
T param(const std::string &param_name, const T &default_val)
PJ::PlotDataMapRef
Definition: plotdata.h:34
ulog_parser.h
DataLoadULog::DataLoadULog
DataLoadULog()
Definition: dataload_ulog.cpp:13
ULogParser::FLOAT
@ FLOAT
Definition: ulog_parser.h:49
nullptr
#define nullptr
Definition: backward.hpp:386
PJ::FileLoadInfo::filename
QString filename
name of the file to open
Definition: dataloader_base.h:21


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:44