Go to the documentation of this file.00001 #ifndef ULOG_PARSER_H
00002 #define ULOG_PARSER_H
00003
00004 #include <iostream>
00005 #include <vector>
00006 #include <map>
00007 #include <set>
00008
00009 #include "string_view.hpp"
00010
00011 typedef nonstd::string_view StringView;
00012
00013 class ULogParser
00014 {
00015
00016
00017 public:
00018
00019 enum FormatType{
00020 UINT8, UINT16, UINT32, UINT64,
00021 INT8, INT16, INT32, INT64,
00022 FLOAT, DOUBLE,
00023 BOOL, CHAR, OTHER
00024 };
00025
00026 struct Field{
00027 Field(): array_size(1) {}
00028 FormatType type;
00029 std::string field_name;
00030 std::string other_type_ID;
00031 int array_size;
00032 };
00033
00034 struct Parameter{
00035 std::string name;
00036 union{
00037 int32_t val_int;
00038 float val_real;
00039 }value;
00040 FormatType val_type;
00041 };
00042
00043 struct Format
00044 {
00045 Format(): padding(0) {}
00046 std::string name;
00047 std::vector<Field> fields;
00048 int padding;
00049 };
00050
00051 struct MessageLog
00052 {
00053 char level;
00054 uint64_t timestamp;
00055 std::string msg;
00056 };
00057
00058 struct Subscription
00059 {
00060 Subscription(): msg_id(0), multi_id(0), format(nullptr) {}
00061
00062 uint16_t msg_id;
00063 uint8_t multi_id;
00064 std::string message_name;
00065 const Format* format;
00066 };
00067
00068 struct Timeseries
00069 {
00070 std::vector<uint64_t> timestamps;
00071 std::vector<std::pair<std::string,std::vector<double>>> data;
00072 };
00073
00074 public:
00075
00076 ULogParser(const std::string& filename);
00077
00078 const std::map<std::string, Timeseries> &getTimeseriesMap() const;
00079
00080 const std::vector<Parameter> &getParameters() const;
00081
00082 const std::map<std::string, std::string> &getInfo() const;
00083
00084 const std::vector<MessageLog> &getLogs() const;
00085
00086 private:
00087 bool readFileHeader(std::ifstream &file);
00088
00089 bool readFileDefinitions(std::ifstream &file);
00090
00091 bool readFormat(std::ifstream &file, uint16_t msg_size);
00092
00093 bool readFlagBits(std::ifstream &file, uint16_t msg_size);
00094
00095 bool readInfo(std::ifstream &file, uint16_t msg_size);
00096
00097 bool readParameter(std::ifstream &file, uint16_t msg_size);
00098
00099 bool readSubscription(std::ifstream &file, uint16_t msg_size);
00100
00101 size_t fieldsCount(const Format& format) const;
00102
00103 Timeseries createTimeseries(const Format* format);
00104
00105 uint64_t _file_start_time;
00106
00107 std::vector<Parameter> _parameters;
00108
00109 std::vector<uint8_t> _read_buffer;
00110
00111 std::streampos _data_section_start;
00112
00113 int64_t _read_until_file_position = 1ULL << 60;
00114
00115 std::set<std::string> _overridden_params;
00116
00117 std::map<std::string, Format> _formats;
00118
00119 std::map<std::string, std::string> _info;
00120
00121 std::map<uint16_t,Subscription> _subscriptions;
00122
00123 std::map<std::string, Timeseries> _timeseries;
00124
00125 std::vector<StringView> splitString(const StringView& strToSplit, char delimeter);
00126
00127 std::set<std::string> _message_name_with_multi_id;
00128
00129 std::vector<MessageLog> _message_logs;
00130
00131 void parseDataMessage(const Subscription& sub, char *message);
00132
00133 char * parseSimpleDataMessage(Timeseries ×eries, const Format* format, char *message, size_t* index);
00134 };
00135
00136 #endif // ULOG_PARSER_H