Skip to content

Commit 377bdc7

Browse files
authored
fix(ulog): the index of the timestamp may be non-zero (#1016)
The previous parsing assumed that the timestamp for a ulog data series was always at index 0, which is often, but not necessarily the case. The parser now store the correct index when parsing the definition.
1 parent 4aa9074 commit 377bdc7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

plotjuggler_plugins/DataLoadULog/ulog_parser.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ void ULogParser::parseDataMessage(const ULogParser::Subscription& sub, char* mes
153153
}
154154
Timeseries& timeseries = ts_it->second;
155155

156-
uint64_t time_val = *reinterpret_cast<uint64_t*>(message);
157-
timeseries.timestamps.push_back(time_val);
158-
message += sizeof(uint64_t);
159-
160156
size_t index = 0;
161157
parseSimpleDataMessage(timeseries, sub.format, message, &index);
162158
}
@@ -173,8 +169,16 @@ char* ULogParser::parseSimpleDataMessage(Timeseries& timeseries, const Format* f
173169
continue;
174170
}
175171

172+
bool timestamp_done = false;
176173
for (int array_pos = 0; array_pos < field.array_size; array_pos++)
177174
{
175+
if (*index == format->timestamp_idx && !timestamp_done)
176+
{
177+
timestamp_done = true;
178+
uint64_t time_val = *reinterpret_cast<uint64_t*>(message);
179+
timeseries.timestamps.push_back(time_val);
180+
message += sizeof(uint64_t);
181+
}
178182
double value = 0;
179183
switch (field.type)
180184
{
@@ -619,7 +623,7 @@ bool ULogParser::readFormat(DataStream& datastream, uint16_t msg_size)
619623

620624
if (field.type == UINT64 && field_name == StringView("timestamp"))
621625
{
622-
// skip
626+
format.timestamp_idx = format.fields.size();
623627
}
624628
else
625629
{
@@ -628,6 +632,12 @@ bool ULogParser::readFormat(DataStream& datastream, uint16_t msg_size)
628632
}
629633
}
630634

635+
if (format.timestamp_idx < 0)
636+
{
637+
// Required timestamp is not found in definition
638+
return false;
639+
}
640+
631641
format.name = name;
632642
_formats[name] = std::move(format);
633643

plotjuggler_plugins/DataLoadULog/ulog_parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ class ULogParser
7979

8080
struct Format
8181
{
82-
Format() : padding(0)
82+
Format() : padding(0), timestamp_idx(-1)
8383
{
8484
}
8585
std::string name;
8686
std::vector<Field> fields;
8787
int padding;
88+
int timestamp_idx;
8889
};
8990

9091
struct MessageLog

0 commit comments

Comments
 (0)