18 throw std::runtime_error(
"ULog: wrong header");
23 throw std::runtime_error(
"ULog: error loading definitions");
35 datastream.
read(message, message_header.msg_size);
36 message[message_header.msg_size] =
'\0';
38 switch (message_header.msg_type)
43 sub.
multi_id = *
reinterpret_cast<uint8_t*
>(message);
44 sub.
msg_id = *
reinterpret_cast<uint16_t*
>(message + 1);
46 sub.
message_name.assign(message, message_header.msg_size - 3);
65 printf(
"REMOVE_LOGGED_MSG\n");
67 uint16_t msg_id = *
reinterpret_cast<uint16_t*
>(message);
72 uint16_t msg_id = *
reinterpret_cast<uint16_t*
>(message);
87 msg.level =
static_cast<char>(message[0]);
88 message +=
sizeof(char);
89 msg.timestamp = *
reinterpret_cast<uint64_t*
>(message);
90 message +=
sizeof(uint64_t);
91 msg.msg.assign(message, message_header.msg_size - 9);
112 if (prev_param.name == new_param.
name)
130 size_t other_fields_count = 0;
137 other_fields_count++;
145 ts_name += std::string(buff);
156 uint64_t time_val = *
reinterpret_cast<uint64_t*
>(message);
158 message +=
sizeof(uint64_t);
165 char* message,
size_t* index)
172 message +=
field.array_size;
176 for (
int array_pos = 0; array_pos <
field.array_size; array_pos++)
182 value =
static_cast<double>(*
reinterpret_cast<uint8_t*
>(message));
187 value =
static_cast<double>(*
reinterpret_cast<int8_t*
>(message));
192 value =
static_cast<double>(*
reinterpret_cast<uint16_t*
>(message));
197 value =
static_cast<double>(*
reinterpret_cast<int16_t*
>(message));
202 value =
static_cast<double>(*
reinterpret_cast<uint32_t*
>(message));
207 value =
static_cast<double>(*
reinterpret_cast<int32_t*
>(message));
212 value =
static_cast<double>(*
reinterpret_cast<uint64_t*
>(message));
217 value =
static_cast<double>(*
reinterpret_cast<int64_t*
>(message));
222 value =
static_cast<double>(*
reinterpret_cast<float*
>(message));
227 value = (*
reinterpret_cast<double*
>(message));
232 value =
static_cast<double>(*
reinterpret_cast<char*
>(message));
237 value =
static_cast<double>(*
reinterpret_cast<bool*
>(message));
244 message +=
sizeof(uint64_t);
253 timeseries.
data[(*index)++].second.push_back(value);
285 datastream.
read(message, msg_size);
286 message[msg_size] = 0;
317 std::vector<StringView> splitted_strings;
318 splitted_strings.reserve(4);
321 while (pos < strToSplit.size())
323 size_t new_pos = strToSplit.find_first_of(delimeter, pos);
324 if (new_pos == std::string::npos)
326 new_pos = strToSplit.size();
328 StringView sv = { &strToSplit.data()[pos], new_pos - pos };
329 splitted_strings.push_back(sv);
332 return splitted_strings;
338 datastream.
read((
char*)&msg_header,
sizeof(msg_header));
356 return memcmp(magic, msg_header.magic, 7) == 0;
376 switch (message_header.msg_type)
386 if (!
readFormat(datastream, message_header.msg_size))
407 if (!
readInfo(datastream, message_header.msg_size))
415 datastream.
offset += message_header.msg_size;
419 printf(
"unknown log definition type %i, size %i (offset %i)\n",
420 (
int)message_header.msg_type, (
int)message_header.msg_size,
422 datastream.
offset += message_header.msg_size;
433 printf(
"unsupported message length for FLAG_BITS message (%i)", msg_size);
439 datastream.
read((
char*)message, msg_size);
442 uint8_t* incompat_flags = message + 8;
445 bool contains_appended_data =
447 bool has_unknown_incompat_bits =
false;
449 if (incompat_flags[0] & ~0x1)
451 has_unknown_incompat_bits =
true;
454 for (
int i = 1; i < 8; ++i)
456 if (incompat_flags[i])
458 has_unknown_incompat_bits =
true;
462 if (has_unknown_incompat_bits)
464 printf(
"Log contains unknown incompat bits set. Refusing to parse");
468 if (contains_appended_data)
470 uint64_t appended_offsets[3];
471 memcpy(appended_offsets, message + 16,
sizeof(appended_offsets));
473 if (appended_offsets[0] > 0)
486 static int count = 0;
490 datastream.
read(buffer, msg_size);
491 buffer[msg_size] = 0;
501 if (pos == std::string::npos)
507 std::string fields =
str_format.substr(pos + 1);
511 format.fields.reserve(fields_split.size());
512 for (
auto field_section : fields_split)
516 auto field_name = field_pair.at(1);
586 while (!helper.ends_with(
"["))
588 helper.remove_suffix(1);
591 helper.remove_suffix(1);
592 field.other_type_ID = helper.to_string();
605 field.array_size = 1;
626 field.field_name = field_name.to_string();
637 template <
typename T>
640 std::stringstream stream;
641 stream <<
"0x" << std::setfill(
'0') << std::setw(
sizeof(T) * 2) << std::hex << i;
649 datastream.
read((
char*)message, msg_size);
655 uint8_t key_len = message[0];
657 std::string raw_key((
char*)message, key_len);
659 std::string raw_value((
char*)message, msg_size - key_len - 1);
663 std::string key = key_parts[1].to_string();
666 if (key_parts[0].starts_with(
"char["))
672 bool val = *
reinterpret_cast<const bool*
>(raw_value.data());
673 value = std::to_string(val);
675 else if (key_parts[0] ==
StringView(
"uint8_t"))
677 uint8_t val = *
reinterpret_cast<const uint8_t*
>(raw_value.data());
678 value = std::to_string(val);
680 else if (key_parts[0] ==
StringView(
"int8_t"))
682 int8_t val = *
reinterpret_cast<const int8_t*
>(raw_value.data());
683 value = std::to_string(val);
685 else if (key_parts[0] ==
StringView(
"uint16_t"))
687 uint16_t val = *
reinterpret_cast<const uint16_t*
>(raw_value.data());
688 value = std::to_string(val);
690 else if (key_parts[0] ==
StringView(
"int16_t"))
692 int16_t val = *
reinterpret_cast<const int16_t*
>(raw_value.data());
693 value = std::to_string(val);
695 else if (key_parts[0] ==
StringView(
"uint32_t"))
697 uint32_t val = *
reinterpret_cast<const uint32_t*
>(raw_value.data());
698 if (key_parts[1].starts_with(
"ver_") && key_parts[1].ends_with(
"_release"))
704 value = std::to_string(val);
707 else if (key_parts[0] ==
StringView(
"int32_t"))
709 int32_t val = *
reinterpret_cast<const int32_t*
>(raw_value.data());
710 value = std::to_string(val);
714 float val = *
reinterpret_cast<const float*
>(raw_value.data());
715 value = std::to_string(val);
717 else if (key_parts[0] ==
StringView(
"double"))
719 double val = *
reinterpret_cast<const double*
>(raw_value.data());
720 value = std::to_string(val);
722 else if (key_parts[0] ==
StringView(
"uint64_t"))
724 uint64_t val = *
reinterpret_cast<const uint64_t*
>(raw_value.data());
725 value = std::to_string(val);
727 else if (key_parts[0] ==
StringView(
"int64_t"))
729 int64_t val = *
reinterpret_cast<const int64_t*
>(raw_value.data());
730 value = std::to_string(val);
733 _info.insert({ key, value });
741 datastream.
read((
char*)message, msg_size);
748 param.readFromBuffer(message);
755 std::function<
void(
const Format&
format,
const std::string& prefix)> appendVector;
759 appendVector = [&appendVector,
this, ×eries](
const Format&
format,
760 const std::string& prefix) {
769 std::string new_prefix = prefix +
"/" +
field.field_name;
770 for (
int i = 0; i <
field.array_size; i++)
772 std::string array_suffix =
"";
773 if (
field.array_size > 1)
781 timeseries.
data.push_back({ new_prefix + array_suffix, std::vector<double>() });
785 appendVector(this->
_formats.at(
field.other_type_ID), new_prefix + array_suffix);
791 appendVector(*
format, {});
797 const uint8_t key_len =
static_cast<uint8_t
>(message[0]);
799 std::string key((
char*)message, key_len);
801 const size_t pos = key.find(
' ');
802 if (pos == std::string::npos)
807 const std::string
type = key.substr(0, pos);
808 this->
name = key.substr(pos + 1);
811 if (
type ==
"int32_t")
813 this->
value.val_int = *
reinterpret_cast<const int32_t*
>(message);
816 else if (type ==
"float")
818 this->
value.val_real = *
reinterpret_cast<const float*
>(message);
823 throw std::runtime_error(
"unknown parameter type");