ulog_parser.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <vector>
5 #include <map>
6 #include <set>
7 #include <string.h>
8 #include <cstdint>
9 
10 #include "string_view.hpp"
11 
13 
15 {
16 public:
17  struct DataStream
18  {
19  const char* _data;
20  const size_t _length;
21  size_t offset;
22 
23  DataStream(char* data, int len) : _data(data), _length(len), offset(0)
24  {
25  }
26 
27  void read(char* dst, int len)
28  {
29  memcpy(dst, &_data[offset], len);
30  offset += len;
31  }
32 
33  operator bool()
34  {
35  return offset < _length;
36  }
37  };
38 
40  {
54  };
55 
56  struct Field
57  {
59  {
60  }
62  std::string field_name;
63  std::string other_type_ID;
65  };
66 
67  struct Parameter
68  {
69  std::string name;
70  union
71  {
72  int32_t val_int;
73  float val_real;
74  } value;
76 
77  bool readFromBuffer(const char* message);
78  };
79 
80  struct Format
81  {
82  Format() : padding(0)
83  {
84  }
85  std::string name;
86  std::vector<Field> fields;
87  int padding;
88  };
89 
90  struct MessageLog
91  {
92  char level;
93  uint64_t timestamp;
94  std::string msg;
95  };
96 
97  struct Subscription
98  {
100  {
101  }
102 
103  uint16_t msg_id;
104  uint8_t multi_id;
105  std::string message_name;
106  const Format* format;
107  };
108 
109  struct Timeseries
110  {
111  std::vector<uint64_t> timestamps;
112  std::vector<std::pair<std::string, std::vector<double>>> data;
113  };
114 
115 public:
116  ULogParser(DataStream& datastream);
117 
118  const std::map<std::string, Timeseries>& getTimeseriesMap() const;
119 
120  const std::vector<Parameter>& getParameters() const;
121 
122  const std::map<std::string, std::string>& getInfo() const;
123 
124  const std::vector<MessageLog>& getLogs() const;
125 
126 private:
127  bool readFileHeader(DataStream& datastream);
128 
129  bool readFileDefinitions(DataStream& datastream);
130 
131  bool readFormat(DataStream& datastream, uint16_t msg_size);
132 
133  bool readFlagBits(DataStream& datastream, uint16_t msg_size);
134 
135  bool readInfo(DataStream& datastream, uint16_t msg_size);
136 
137  bool readParameter(DataStream& datastream, uint16_t msg_size);
138 
139  bool readSubscription(DataStream& datastream, uint16_t msg_size);
140 
141  size_t fieldsCount(const Format& format) const;
142 
144 
146 
147  std::vector<Parameter> _parameters;
148 
149  std::vector<uint8_t> _read_buffer;
150 
151  std::streampos _data_section_start;
152 
154  1ULL << 60;
155 
156  std::set<std::string> _overridden_params;
157 
158  std::map<std::string, Format> _formats;
159 
160  std::map<std::string, std::string> _info;
161 
162  std::map<uint16_t, Subscription> _subscriptions;
163 
164  std::map<std::string, Timeseries> _timeseries;
165 
166  std::vector<StringView> splitString(const StringView& strToSplit, char delimeter);
167 
168  std::set<std::string> _message_name_with_multi_id;
169 
170  std::vector<MessageLog> _message_logs;
171 
172  void parseDataMessage(const Subscription& sub, char* message);
173 
174  char* parseSimpleDataMessage(Timeseries& timeseries, const Format* format,
175  char* message, size_t* index);
176 };
ULogParser::Format::fields
std::vector< Field > fields
Definition: ulog_parser.h:86
ULogParser::readParameter
bool readParameter(DataStream &datastream, uint16_t msg_size)
Definition: ulog_parser.cpp:737
ULogParser::readFileDefinitions
bool readFileDefinitions(DataStream &datastream)
Definition: ulog_parser.cpp:359
ULogParser::_file_start_time
uint64_t _file_start_time
Definition: ulog_parser.h:145
ULogParser::Timeseries::data
std::vector< std::pair< std::string, std::vector< double > > > data
Definition: ulog_parser.h:112
ULogParser::Parameter::val_type
FormatType val_type
Definition: ulog_parser.h:75
ULogParser::_subscriptions
std::map< uint16_t, Subscription > _subscriptions
Definition: ulog_parser.h:162
ULogParser::_timeseries
std::map< std::string, Timeseries > _timeseries
Definition: ulog_parser.h:164
ULogParser::Field::field_name
std::string field_name
Definition: ulog_parser.h:62
string_view.hpp
ULogParser
Definition: ulog_parser.h:14
ULogParser::UINT8
@ UINT8
Definition: ulog_parser.h:41
ULogParser::Format::name
std::string name
Definition: ulog_parser.h:85
ULogParser::getParameters
const std::vector< Parameter > & getParameters() const
Definition: ulog_parser.cpp:265
ULogParser::DataStream::_data
const char * _data
Definition: ulog_parser.h:19
ULogParser::FormatType
FormatType
Definition: ulog_parser.h:39
ULogParser::Field::type
FormatType type
Definition: ulog_parser.h:61
ULogParser::Subscription::multi_id
uint8_t multi_id
Definition: ulog_parser.h:104
ULogParser::createTimeseries
Timeseries createTimeseries(const Format *format)
Definition: ulog_parser.cpp:753
ULogParser::MessageLog::timestamp
uint64_t timestamp
Definition: ulog_parser.h:93
ULogParser::DataStream::offset
size_t offset
Definition: ulog_parser.h:21
ULogParser::Parameter::value
union ULogParser::Parameter::@57 value
ULogParser::UINT32
@ UINT32
Definition: ulog_parser.h:43
ULogParser::splitString
std::vector< StringView > splitString(const StringView &strToSplit, char delimeter)
Definition: ulog_parser.cpp:314
ULogParser::_message_logs
std::vector< MessageLog > _message_logs
Definition: ulog_parser.h:170
ULogParser::DataStream::read
void read(char *dst, int len)
Definition: ulog_parser.h:27
ULogParser::CHAR
@ CHAR
Definition: ulog_parser.h:52
ULogParser::_data_section_start
std::streampos _data_section_start
first ADD_LOGGED_MSG message
Definition: ulog_parser.h:151
ULogParser::Format
Definition: ulog_parser.h:80
ULogParser::fieldsCount
size_t fieldsCount(const Format &format) const
Definition: ulog_parser.cpp:296
ULogParser::_parameters
std::vector< Parameter > _parameters
Definition: ulog_parser.h:147
ULogParser::getTimeseriesMap
const std::map< std::string, Timeseries > & getTimeseriesMap() const
Definition: ulog_parser.cpp:260
ULogParser::UINT64
@ UINT64
Definition: ulog_parser.h:44
ULogParser::readSubscription
bool readSubscription(DataStream &datastream, uint16_t msg_size)
Definition: ulog_parser.cpp:280
ULogParser::INT32
@ INT32
Definition: ulog_parser.h:47
ULogParser::MessageLog
Definition: ulog_parser.h:90
ULogParser::Field::Field
Field()
Definition: ulog_parser.h:58
ULogParser::BOOL
@ BOOL
Definition: ulog_parser.h:51
StringView
nonstd::string_view StringView
Definition: ulog_parser.h:12
ULogParser::_info
std::map< std::string, std::string > _info
Definition: ulog_parser.h:160
ULogParser::Parameter::val_int
int32_t val_int
Definition: ulog_parser.h:72
ULogParser::Format::padding
int padding
Definition: ulog_parser.h:87
ULogParser::_read_until_file_position
int64_t _read_until_file_position
read limit if log contains appended data
Definition: ulog_parser.h:153
ULogParser::Timeseries
Definition: ulog_parser.h:109
ULogParser::Format::Format
Format()
Definition: ulog_parser.h:82
ULogParser::getLogs
const std::vector< MessageLog > & getLogs() const
Definition: ulog_parser.cpp:275
ULogParser::Timeseries::timestamps
std::vector< uint64_t > timestamps
Definition: ulog_parser.h:111
ULogParser::Field
Definition: ulog_parser.h:56
ULogParser::Subscription::message_name
std::string message_name
Definition: ulog_parser.h:105
ULogParser::Subscription
Definition: ulog_parser.h:97
ULogParser::UINT16
@ UINT16
Definition: ulog_parser.h:42
ULogParser::_overridden_params
std::set< std::string > _overridden_params
Definition: ulog_parser.h:156
ULogParser::INT8
@ INT8
Definition: ulog_parser.h:45
format
auto format(const text_style &ts, const S &format_str, const Args &... args) -> std::basic_string< Char >
Definition: color.h:543
string_view
basic_string_view< char > string_view
Definition: core.h:518
ULogParser::DataStream::_length
const size_t _length
Definition: ulog_parser.h:20
ULogParser::Field::other_type_ID
std::string other_type_ID
Definition: ulog_parser.h:63
ULogParser::_formats
std::map< std::string, Format > _formats
Definition: ulog_parser.h:158
ULogParser::Parameter::val_real
float val_real
Definition: ulog_parser.h:73
ULogParser::parseSimpleDataMessage
char * parseSimpleDataMessage(Timeseries &timeseries, const Format *format, char *message, size_t *index)
Definition: ulog_parser.cpp:164
ULogParser::ULogParser
ULogParser(DataStream &datastream)
Definition: ulog_parser.cpp:12
ULogParser::DataStream
Definition: ulog_parser.h:17
ULogParser::Parameter
Definition: ulog_parser.h:67
ULogParser::parseDataMessage
void parseDataMessage(const Subscription &sub, char *message)
Definition: ulog_parser.cpp:128
ULogParser::DOUBLE
@ DOUBLE
Definition: ulog_parser.h:50
ULogParser::Parameter::readFromBuffer
bool readFromBuffer(const char *message)
Definition: ulog_parser.cpp:795
ULogParser::readFlagBits
bool readFlagBits(DataStream &datastream, uint16_t msg_size)
Definition: ulog_parser.cpp:429
ULogParser::INT64
@ INT64
Definition: ulog_parser.h:48
ULogParser::_message_name_with_multi_id
std::set< std::string > _message_name_with_multi_id
Definition: ulog_parser.h:168
ULogParser::Field::array_size
int array_size
Definition: ulog_parser.h:64
ULogParser::readFileHeader
bool readFileHeader(DataStream &datastream)
Definition: ulog_parser.cpp:335
ULogParser::Subscription::Subscription
Subscription()
Definition: ulog_parser.h:99
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
ULogParser::_read_buffer
std::vector< uint8_t > _read_buffer
Definition: ulog_parser.h:149
ULogParser::readFormat
bool readFormat(DataStream &datastream, uint16_t msg_size)
Definition: ulog_parser.cpp:484
ULogParser::INT16
@ INT16
Definition: ulog_parser.h:46
dst
char * dst
Definition: lz4.h:792
ULogParser::Parameter::name
std::string name
Definition: ulog_parser.h:69
ULogParser::Subscription::format
const Format * format
Definition: ulog_parser.h:106
ULogParser::MessageLog::msg
std::string msg
Definition: ulog_parser.h:94
ULogParser::FLOAT
@ FLOAT
Definition: ulog_parser.h:49
ULogParser::getInfo
const std::map< std::string, std::string > & getInfo() const
Definition: ulog_parser.cpp:270
ULogParser::Subscription::msg_id
uint16_t msg_id
Definition: ulog_parser.h:103
ULogParser::readInfo
bool readInfo(DataStream &datastream, uint16_t msg_size)
Definition: ulog_parser.cpp:645
ULogParser::MessageLog::level
char level
Definition: ulog_parser.h:92
nullptr
#define nullptr
Definition: backward.hpp:386
ULogParser::OTHER
@ OTHER
Definition: ulog_parser.h:53
ULogParser::DataStream::DataStream
DataStream(char *data, int len)
Definition: ulog_parser.h:23


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