@@ -1626,7 +1626,37 @@ void Logger::write_format(LogType type, const orb_metadata &meta, WrittenFormats
1626
1626
PX4_DEBUG (" writing format for %s" , meta.o_name );
1627
1627
1628
1628
// Write the current format (we don't need to check if we already added it to written_formats)
1629
- int format_len = snprintf (msg.format , sizeof (msg.format ), " %s:%s" , meta.o_name , meta.o_fields );
1629
+ int format_len = snprintf (msg.format , sizeof (msg.format ), " %s:" , meta.o_name );
1630
+
1631
+ for (int format_idx = 0 ; meta.o_fields [format_idx] != 0 ;) {
1632
+ const char *end_field = strchr (meta.o_fields + format_idx, ' ;' );
1633
+
1634
+ if (!end_field) {
1635
+ PX4_ERR (" Format error in %s" , meta.o_fields );
1636
+ return ;
1637
+ }
1638
+
1639
+ const char *c_type = orb_get_c_type (meta.o_fields [format_idx]);
1640
+
1641
+ if (c_type) {
1642
+ format_len += snprintf (msg.format + format_len, sizeof (msg.format ) - format_len, " %s" , c_type);
1643
+ ++format_idx;
1644
+ }
1645
+
1646
+ int len = end_field - (meta.o_fields + format_idx) + 1 ;
1647
+
1648
+ if (len >= (int )sizeof (msg.format ) - format_len) {
1649
+ PX4_WARN (" skip topic %s, format string is too large, max is %zu" , meta.o_name ,
1650
+ sizeof (ulog_message_format_s::format));
1651
+ return ;
1652
+ }
1653
+
1654
+ memcpy (msg.format + format_len, meta.o_fields + format_idx, len);
1655
+ format_len += len;
1656
+ format_idx += len;
1657
+ }
1658
+
1659
+ msg.format [format_len] = ' \0 ' ;
1630
1660
size_t msg_size = sizeof (msg) - sizeof (msg.format ) + format_len;
1631
1661
msg.msg_size = msg_size - ULOG_MSG_HEADER_LEN;
1632
1662
@@ -1637,7 +1667,7 @@ void Logger::write_format(LogType type, const orb_metadata &meta, WrittenFormats
1637
1667
}
1638
1668
1639
1669
// Now go through the fields and check for nested type usages.
1640
- // o_fields looks like this for example: "uint64_t timestamp;uint8_t [5] array;"
1670
+ // o_fields looks like this for example: "<chr> timestamp;<chr> [5] array;"
1641
1671
const char *fmt = meta.o_fields ;
1642
1672
1643
1673
while (fmt && *fmt) {
@@ -1670,20 +1700,7 @@ void Logger::write_format(LogType type, const orb_metadata &meta, WrittenFormats
1670
1700
type_name[type_length] = ' \0 ' ;
1671
1701
1672
1702
// ignore built-in types
1673
- if (strcmp (type_name, " int8_t" ) != 0 &&
1674
- strcmp (type_name, " uint8_t" ) != 0 &&
1675
- strcmp (type_name, " int16_t" ) != 0 &&
1676
- strcmp (type_name, " uint16_t" ) != 0 &&
1677
- strcmp (type_name, " int16_t" ) != 0 &&
1678
- strcmp (type_name, " uint16_t" ) != 0 &&
1679
- strcmp (type_name, " int32_t" ) != 0 &&
1680
- strcmp (type_name, " uint32_t" ) != 0 &&
1681
- strcmp (type_name, " int64_t" ) != 0 &&
1682
- strcmp (type_name, " uint64_t" ) != 0 &&
1683
- strcmp (type_name, " float" ) != 0 &&
1684
- strcmp (type_name, " double" ) != 0 &&
1685
- strcmp (type_name, " bool" ) != 0 &&
1686
- strcmp (type_name, " char" ) != 0 ) {
1703
+ if (orb_get_c_type (type_name[0 ]) == nullptr ) {
1687
1704
1688
1705
// find orb meta for type
1689
1706
const orb_metadata *const *topics = orb_get_topics ();
0 commit comments