diff --git a/msg/templates/uorb/uORBTopics.cpp.em b/msg/templates/uorb/uORBTopics.cpp.em index b08950bb19..c71082e354 100644 --- a/msg/templates/uorb/uORBTopics.cpp.em +++ b/msg/templates/uorb/uORBTopics.cpp.em @@ -8,7 +8,7 @@ @# @# Context: @# - msgs (List) list of all msg files -@# - multi_topics (List) list of all multi-topic names +@# - topics (List) list of all topic names @############################################### /**************************************************************************** * @@ -48,17 +48,17 @@ @{ msg_names = [mn.replace(".msg", "") for mn in msgs] msgs_count = len(msg_names) -msg_names_all = list(set(msg_names + multi_topics)) # set() filters duplicates -msg_names_all.sort() -msgs_count_all = len(msg_names_all) +topics_all = topics +topics_all.sort() +topics_count_all = len(topics_all) }@ @[for msg_name in msg_names]@ #include @[end for] const constexpr struct orb_metadata *const uorb_topics_list[ORB_TOPICS_COUNT] = { -@[for idx, msg_name in enumerate(msg_names_all, 1)]@ - ORB_ID(@(msg_name))@[if idx != msgs_count_all], @[end if] +@[for idx, topic_name in enumerate(topics_all, 1)]@ + ORB_ID(@(topic_name))@[if idx != topics_count_all], @[end if] @[end for] }; diff --git a/msg/templates/uorb/uORBTopics.hpp.em b/msg/templates/uorb/uORBTopics.hpp.em index d278f06398..528b95acee 100644 --- a/msg/templates/uorb/uORBTopics.hpp.em +++ b/msg/templates/uorb/uORBTopics.hpp.em @@ -8,7 +8,7 @@ @# @# Context: @# - msgs (List) list of all msg files -@# - multi_topics (List) list of all multi-topic names +@# - topics (List) list of all topic names @############################################### /**************************************************************************** * @@ -46,9 +46,9 @@ @{ msg_names = [mn.replace(".msg", "") for mn in msgs] msgs_count = len(msg_names) -msg_names_all = list(set(msg_names + multi_topics)) # set() filters duplicates -msg_names_all.sort() -msgs_count_all = len(msg_names_all) +topics_all = topics +topics_all.sort() +topics_count_all = len(topics_all) }@ #pragma once @@ -57,7 +57,7 @@ msgs_count_all = len(msg_names_all) #include -static constexpr size_t ORB_TOPICS_COUNT{@(msgs_count_all)}; +static constexpr size_t ORB_TOPICS_COUNT{@(topics_count_all)}; static constexpr size_t orb_topics_count() { return ORB_TOPICS_COUNT; } /* @@ -66,7 +66,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 { -@[for idx, msg_name in enumerate(msg_names_all)]@ +@[for idx, msg_name in enumerate(topics_all)]@ @(msg_name) = @(idx), @[end for] INVALID diff --git a/msg/templates/uorb_microcdr/dds_topics.h.em b/msg/templates/uorb_microcdr/dds_topics.h.em index 77da2ac126..8d7b5e7a67 100644 --- a/msg/templates/uorb_microcdr/dds_topics.h.em +++ b/msg/templates/uorb_microcdr/dds_topics.h.em @@ -7,7 +7,7 @@ @# @# Context: @# - msgs (List) list of all RTPS messages -@# - multi_topics (List) list of all multi-topic names +@# - topics (List) list of all topic names @# - spec (msggen.MsgSpec) Parsed specification of the .msg file @############################################### @{ @@ -43,11 +43,11 @@ struct SendTopicsSubs { uORB::Subscription @(topic)_sub{ORB_ID(@(topic))}; uxrObjectId @(topic)_data_writer; @[ end for]@ - + uxrSession* session; uint32_t num_payload_sent{}; - + bool init(uxrSession* session_, uxrStreamId stream_id, uxrObjectId participant_id); void update(uxrStreamId stream_id); }; @@ -140,7 +140,7 @@ struct RcvTopicsPubs { uxrSession* session; uint32_t num_payload_received{}; - + bool init(uxrSession* session_, uxrStreamId stream_id, uxrStreamId input_stream, uxrObjectId participant_id); }; diff --git a/msg/templates/uorb_microcdr/microRTPS_client.cpp.em b/msg/templates/uorb_microcdr/microRTPS_client.cpp.em index 941073b17f..1ab5e56e0c 100644 --- a/msg/templates/uorb_microcdr/microRTPS_client.cpp.em +++ b/msg/templates/uorb_microcdr/microRTPS_client.cpp.em @@ -7,7 +7,7 @@ @# @# Context: @# - msgs (List) list of all RTPS messages -@# - multi_topics (List) list of all multi-topic names +@# - topics (List) list of all topic names @# - spec (msggen.MsgSpec) Parsed specification of the .msg file @############################################### @{ diff --git a/msg/tools/px_generate_uorb_topic_files.py b/msg/tools/px_generate_uorb_topic_files.py index 07a64eea4e..e7894bd92b 100755 --- a/msg/tools/px_generate_uorb_topic_files.py +++ b/msg/tools/px_generate_uorb_topic_files.py @@ -98,9 +98,11 @@ class MsgScope: RECEIVE = 2 -def get_multi_topics(filename): +def get_topics(filename, msg_name): """ - Get TOPICS names from a "# TOPICS" line + Get TOPICS names from a "# TOPICS" line. If there are no multi topics defined, + set topic name same as the message name, since the user doesn't expect any new + custom topic names. """ ofile = open(filename, 'r') text = ofile.read() @@ -111,6 +113,10 @@ def get_multi_topics(filename): topic_names_str = topic_names_str.replace(TOPICS_TOKEN, "") result.extend(topic_names_str.split(" ")) ofile.close() + + if len(result) == 0: + result.append(msg_name) + return result @@ -147,15 +153,16 @@ def generate_output_from_file(format_idx, filename, outputdir, package, template print("[ERROR] uORB topic files generator:\n\tgenerate_output_from_file:\t'timestamp' field in " + spec.short_name + " msg definition is not of type uint64 but rather of type " + field_name_and_type.get('timestamp') + "!") exit(1) - topics = get_multi_topics(filename) + + # Get topics used for the message + topics = get_topics(filename, spec.short_name) + if includepath: search_path = genmsg.command_line.includepath_to_dict(includepath) else: search_path = {} genmsg.msg_loader.load_depends(msg_context, spec, search_path) md5sum = genmsg.gentools.compute_md5(msg_context, spec) - if len(topics) == 0: - topics.append(spec.short_name) em_globals = { "file_name_in": filename, "md5sum": md5sum, @@ -288,15 +295,16 @@ def get_em_globals(filename_msg, alias, package, includepath, msgs, fastrtps_ver package, os.path.basename(filename_msg)) spec = genmsg.msg_loader.load_msg_from_file( msg_context, filename_msg, full_type_name) - topics = get_multi_topics(filename_msg) + + # Get topics used for the message + topics = get_topics(filename_msg, spec.short_name) + if includepath: search_path = genmsg.command_line.includepath_to_dict(includepath) else: search_path = {} genmsg.msg_loader.load_depends(msg_context, spec, search_path) md5sum = genmsg.gentools.compute_md5(msg_context, spec) - if len(topics) == 0: - topics.append(spec.short_name) em_globals = { "file_name_in": filename_msg, "md5sum": md5sum, @@ -452,24 +460,31 @@ def convert_dir_save(format_idx, inputdir, outputdir, package, templatedir, temp def generate_topics_list_file(msgdir, outputdir, template_filename, templatedir): # generate cpp file with topics list msgs = get_msgs_list(msgdir) - multi_topics = [] + topics = [] for msg in msgs: msg_filename = os.path.join(msgdir, msg) - multi_topics.extend(get_multi_topics(msg_filename)) - tl_globals = {"msgs": msgs, "multi_topics": multi_topics} + topics.extend(get_topics(msg_filename, msg)) + tl_globals = {"msgs": msgs, "topics": topics} tl_template_file = os.path.join(templatedir, template_filename) tl_out_file = os.path.join(outputdir, template_filename.replace(".em", "")) generate_by_template(tl_out_file, tl_template_file, tl_globals) def generate_topics_list_file_from_files(files, outputdir, template_filename, templatedir): - # generate cpp file with topics list - filenames = [os.path.basename( - p) for p in files if os.path.basename(p).endswith(".msg")] - multi_topics = [] - for msg_filename in files: - multi_topics.extend(get_multi_topics(msg_filename)) - tl_globals = {"msgs": filenames, "multi_topics": multi_topics} + # Get message file names ending with .msg only + msg_filenames = [p for p in files if os.path.basename(p).endswith(".msg")] + + # Get topics used in messages + topics = [] + for msg_filename in msg_filenames: + msg_name = os.path.basename(msg_filename).replace('.msg', '') + topics.extend(get_topics(msg_filename, msg_name)) + + # Get only the message file name for "msgs" component + msg_basenames = [os.path.basename(p) for p in msg_filenames] + + # Set the Template dictionary settings + tl_globals = {"msgs": msg_basenames, "topics": topics} tl_template_file = os.path.join(templatedir, template_filename) tl_out_file = os.path.join(outputdir, template_filename.replace(".em", "")) generate_by_template(tl_out_file, tl_template_file, tl_globals) @@ -529,8 +544,10 @@ if __name__ == "__main__": generate_output_from_file( generate_idx, f, args.temporarydir, args.package, args.templatedir, INCL_DEFAULT) + # Generate topics list header and source file if os.path.isfile(os.path.join(args.templatedir, TOPICS_LIST_TEMPLATE_FILE[generate_idx])): generate_topics_list_file_from_files(args.file, args.outputdir, TOPICS_LIST_TEMPLATE_FILE[generate_idx], args.templatedir) + copy_changed(args.temporarydir, args.outputdir, args.prefix, args.quiet) elif args.dir is not None: convert_dir_save(