ulog_parser.h
Go to the documentation of this file.
1 #ifndef ULOG_PARSER_H
2 #define ULOG_PARSER_H
3 
4 #include <iostream>
5 #include <vector>
6 #include <map>
7 #include <set>
8 
9 #include "string_view.hpp"
10 
11 typedef nonstd::string_view StringView;
12 
14 {
15 
16 
17 public:
18 
19  enum FormatType{
24  };
25 
26  struct Field{
27  Field(): array_size(1) {}
29  std::string field_name;
30  std::string other_type_ID;
32  };
33 
34  struct Parameter{
35  std::string name;
36  union{
37  int32_t val_int;
38  float val_real;
39  }value;
41  };
42 
43  struct Format
44  {
45  Format(): padding(0) {}
46  std::string name;
47  std::vector<Field> fields;
48  int padding;
49  };
50 
51  struct MessageLog
52  {
53  char level;
54  uint64_t timestamp;
55  std::string msg;
56  };
57 
58  struct Subscription
59  {
60  Subscription(): msg_id(0), multi_id(0), format(nullptr) {}
61 
62  uint16_t msg_id;
63  uint8_t multi_id;
64  std::string message_name;
65  const Format* format;
66  };
67 
68  struct Timeseries
69  {
70  std::vector<uint64_t> timestamps;
71  std::vector<std::pair<std::string,std::vector<double>>> data;
72  };
73 
74 public:
75 
76  ULogParser(const std::string& filename);
77 
78  const std::map<std::string, Timeseries> &getTimeseriesMap() const;
79 
80  const std::vector<Parameter> &getParameters() const;
81 
82  const std::map<std::string, std::string> &getInfo() const;
83 
84  const std::vector<MessageLog> &getLogs() const;
85 
86 private:
87  bool readFileHeader(std::ifstream &file);
88 
89  bool readFileDefinitions(std::ifstream &file);
90 
91  bool readFormat(std::ifstream &file, uint16_t msg_size);
92 
93  bool readFlagBits(std::ifstream &file, uint16_t msg_size);
94 
95  bool readInfo(std::ifstream &file, uint16_t msg_size);
96 
97  bool readParameter(std::ifstream &file, uint16_t msg_size);
98 
99  bool readSubscription(std::ifstream &file, uint16_t msg_size);
100 
101  size_t fieldsCount(const Format& format) const;
102 
103  Timeseries createTimeseries(const Format* format);
104 
106 
107  std::vector<Parameter> _parameters;
108 
109  std::vector<uint8_t> _read_buffer;
110 
111  std::streampos _data_section_start;
112 
113  int64_t _read_until_file_position = 1ULL << 60;
114 
115  std::set<std::string> _overridden_params;
116 
117  std::map<std::string, Format> _formats;
118 
119  std::map<std::string, std::string> _info;
120 
121  std::map<uint16_t,Subscription> _subscriptions;
122 
123  std::map<std::string, Timeseries> _timeseries;
124 
125  std::vector<StringView> splitString(const StringView& strToSplit, char delimeter);
126 
127  std::set<std::string> _message_name_with_multi_id;
128 
129  std::vector<MessageLog> _message_logs;
130 
131  void parseDataMessage(const Subscription& sub, char *message);
132 
133  char * parseSimpleDataMessage(Timeseries &timeseries, const Format* format, char *message, size_t* index);
134 };
135 
136 #endif // ULOG_PARSER_H
std::vector< uint64_t > timestamps
Definition: ulog_parser.h:70
const std::vector< MessageLog > & getLogs() const
Timeseries createTimeseries(const Format *format)
std::vector< Field > fields
Definition: ulog_parser.h:47
std::vector< MessageLog > _message_logs
Definition: ulog_parser.h:129
bool readSubscription(std::ifstream &file, uint16_t msg_size)
std::streampos _data_section_start
first ADD_LOGGED_MSG message
Definition: ulog_parser.h:111
bool readParameter(std::ifstream &file, uint16_t msg_size)
std::string message_name
Definition: ulog_parser.h:64
std::vector< std::pair< std::string, std::vector< double > > > data
Definition: ulog_parser.h:71
uint64_t _file_start_time
Definition: ulog_parser.h:105
std::vector< Parameter > _parameters
Definition: ulog_parser.h:107
std::map< std::string, Timeseries > _timeseries
Definition: ulog_parser.h:123
nonstd::string_view StringView
Definition: ulog_parser.h:11
std::string name
Definition: ulog_parser.h:46
const Format * format
Definition: ulog_parser.h:65
bool readFileHeader(std::ifstream &file)
std::vector< StringView > splitString(const StringView &strToSplit, char delimeter)
char padding[ABSL_CACHELINE_SIZE-2 *sizeof(int)]
bool readFileDefinitions(std::ifstream &file)
int64_t _read_until_file_position
read limit if log contains appended data
Definition: ulog_parser.h:113
std::set< std::string > _overridden_params
Definition: ulog_parser.h:115
const std::map< std::string, Timeseries > & getTimeseriesMap() const
T value
ULogParser(const std::string &filename)
Definition: ulog_parser.cpp:13
size_t fieldsCount(const Format &format) const
std::map< std::string, std::string > _info
Definition: ulog_parser.h:119
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
std::map< uint16_t, Subscription > _subscriptions
Definition: ulog_parser.h:121
const std::vector< Parameter > & getParameters() const
std::vector< uint8_t > _read_buffer
Definition: ulog_parser.h:109
std::set< std::string > _message_name_with_multi_id
Definition: ulog_parser.h:127
FormatType type
Definition: ulog_parser.h:28
bool readInfo(std::ifstream &file, uint16_t msg_size)
char * parseSimpleDataMessage(Timeseries &timeseries, const Format *format, char *message, size_t *index)
std::map< std::string, Format > _formats
Definition: ulog_parser.h:117
void parseDataMessage(const Subscription &sub, char *message)
bool readFormat(std::ifstream &file, uint16_t msg_size)
std::string field_name
Definition: ulog_parser.h:29
bool readFlagBits(std::ifstream &file, uint16_t msg_size)
const std::map< std::string, std::string > & getInfo() const
std::string other_type_ID
Definition: ulog_parser.h:30


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:18