More than 256 uORB topics

Is 256 uORB topics the maximum? When I add more than 256 topics (msg/*.msg) to my build, the ORB_ID enum outputs an error because it is of type uint8_t.

A possible fix is this but not sure if the underlying message structure is only a byte for the ID as well:

diff --git a/Tools/msg/templates/uorb/uORBTopics.hpp.em b/Tools/msg/templates/uorb/uORBTopics.hpp.em
index aea7015cc7..38fff6f3e7 100644
--- a/Tools/msg/templates/uorb/uORBTopics.hpp.em
+++ b/Tools/msg/templates/uorb/uORBTopics.hpp.em
@@ -62,7 +62,7 @@ static constexpr size_t orb_topics_count() { return ORB_TOPICS_COUNT; }
  */
 extern const struct orb_metadata *const *orb_get_topics() __EXPORT;
 
-enum class ORB_ID : uint8_t {
+enum class ORB_ID : uint16_t {
 @[for idx, topic_name in enumerate(topic_names_all)]@
        @(topic_name) = @(idx),
 @[end for]

Thanks for your help

1 Like

I need to change the following files as well:

diff --git a/Tools/msg/templates/uorb/msg.cpp.em b/Tools/msg/templates/uorb/msg.cpp.em
index e613d9511f..0e0b329343 100644
--- a/Tools/msg/templates/uorb/msg.cpp.em
+++ b/Tools/msg/templates/uorb/msg.cpp.em
@@ -77,7 +77,7 @@ topic_fields = ["%s %s" % (convert_type(field.type, True), field.name) for field
 constexpr char __orb_@(name_snake_case)_fields[] = "@( ";".join(topic_fields) );";
 
 @[for topic in topics]@
-ORB_DEFINE(@topic, struct @uorb_struct, @(struct_size-padding_end_size), __orb_@(name_snake_case)_fields, static_cast<uint8_t>(ORB_ID::@topic));
+ORB_DEFINE(@topic, struct @uorb_struct, @(struct_size-padding_end_size), __orb_@(name_snake_case)_fields, static_cast<uint16_t>(ORB_ID::@topic));
 @[end for]
 
 void print_message(const orb_metadata *meta, const @uorb_struct& message)
diff --git a/Tools/msg/templates/uorb/uORBTopics.cpp.em b/Tools/msg/templates/uorb/uORBTopics.cpp.em
index c8b1c88397..d3c02b97a1 100644
--- a/Tools/msg/templates/uorb/uORBTopics.cpp.em
+++ b/Tools/msg/templates/uorb/uORBTopics.cpp.em
@@ -76,5 +76,5 @@ const struct orb_metadata *get_orb_meta(ORB_ID id)
 		return nullptr;
 	}
 
-	return uorb_topics_list[static_cast<uint8_t>(id)];
+	return uorb_topics_list[static_cast<uint16_t>(id)];
 }
diff --git a/platforms/common/uORB/uORB.h b/platforms/common/uORB/uORB.h
index c96f3c08d4..2d02971b77 100644
--- a/platforms/common/uORB/uORB.h
+++ b/platforms/common/uORB/uORB.h
@@ -51,7 +51,7 @@ struct orb_metadata {
 	const uint16_t o_size;		/**< object size */
 	const uint16_t o_size_no_padding;	/**< object size w/o padding at the end (for logger) */
 	const char *o_fields;		/**< semicolon separated list of fields (with type) */
-	uint8_t o_id;			/**< ORB_ID enum */
+	uint16_t o_id;			/**< ORB_ID enum */
 };
 
 typedef const struct orb_metadata *orb_id_t;

Thanks for raising this! There currently already is a PR to address this (not merged yet):

Cold you check it out? I think this would be a plausible solution :thinking:

1 Like

PR uorb: allow for more than 255 uORB messages by bkueng ยท Pull Request #21923 ยท PX4/PX4-Autopilot ยท GitHub fixes this. Merged after PX4 v1.14.