Skip to content

Commit

Permalink
fix(ulog): the index of the timestamp may be non-zero
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kibidev committed Nov 11, 2024
1 parent f4f9d41 commit c1549fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 15 additions & 5 deletions plotjuggler_plugins/DataLoadULog/ulog_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ void ULogParser::parseDataMessage(const ULogParser::Subscription& sub, char* mes
}
Timeseries& timeseries = ts_it->second;

uint64_t time_val = *reinterpret_cast<uint64_t*>(message);
timeseries.timestamps.push_back(time_val);
message += sizeof(uint64_t);

size_t index = 0;
parseSimpleDataMessage(timeseries, sub.format, message, &index);
}
Expand All @@ -173,8 +169,16 @@ char* ULogParser::parseSimpleDataMessage(Timeseries& timeseries, const Format* f
continue;
}

bool timestamp_done = false;
for (int array_pos = 0; array_pos < field.array_size; array_pos++)
{
if (*index == format->timestamp_idx && !timestamp_done)
{
timestamp_done = true;
uint64_t time_val = *reinterpret_cast<uint64_t*>(message);
timeseries.timestamps.push_back(time_val);
message += sizeof(uint64_t);
}
double value = 0;
switch (field.type)
{
Expand Down Expand Up @@ -619,7 +623,7 @@ bool ULogParser::readFormat(DataStream& datastream, uint16_t msg_size)

if (field.type == UINT64 && field_name == StringView("timestamp"))
{
// skip
format.timestamp_idx = format.fields.size();
}
else
{
Expand All @@ -628,6 +632,12 @@ bool ULogParser::readFormat(DataStream& datastream, uint16_t msg_size)
}
}

if (format.timestamp_idx < 0)
{
// Required timestamp is not found in definition
return false;
}

format.name = name;
_formats[name] = std::move(format);

Expand Down
3 changes: 2 additions & 1 deletion plotjuggler_plugins/DataLoadULog/ulog_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ class ULogParser

struct Format
{
Format() : padding(0)
Format() : padding(0), timestamp_idx(-1)
{
}
std::string name;
std::vector<Field> fields;
int padding;
int timestamp_idx;
};

struct MessageLog
Expand Down

0 comments on commit c1549fe

Please sign in to comment.