mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-05 01:51:35 +08:00
microRTPS_bridge: structural change to make possible to generate pub/sub code for multi-topics/aliased msgs
This commit is contained in:
@@ -170,13 +170,24 @@ def generate_output_from_file(format_idx, filename, outputdir, package, template
|
||||
return generate_by_template(output_file, template_file, em_globals)
|
||||
|
||||
|
||||
def generate_idl_file(filename_msg, outputdir, templatedir, package, includepath, ids):
|
||||
def generate_idl_file(filename_msg, msg_dir, alias, outputdir, templatedir, package, includepath, ids):
|
||||
"""
|
||||
Generates an .idl from .msg file
|
||||
"""
|
||||
em_globals = get_em_globals(
|
||||
filename_msg, package, includepath, ids, MsgScope.NONE)
|
||||
spec_short_name = em_globals["spec"].short_name
|
||||
# Make sure input msg directory exists:
|
||||
if not os.path.isdir(msg_dir):
|
||||
os.makedirs(msg_dir)
|
||||
|
||||
msg = os.path.join(msg_dir, filename_msg + ".msg")
|
||||
|
||||
if (alias != ""):
|
||||
em_globals = get_em_globals(
|
||||
msg, alias , package, includepath, ids, MsgScope.NONE)
|
||||
spec_short_name = alias
|
||||
else:
|
||||
em_globals = get_em_globals(
|
||||
msg, "", package, includepath, ids, MsgScope.NONE)
|
||||
spec_short_name = em_globals["spec"].short_name
|
||||
|
||||
# Make sure output directory exists:
|
||||
if not os.path.isdir(outputdir):
|
||||
@@ -189,21 +200,39 @@ def generate_idl_file(filename_msg, outputdir, templatedir, package, includepath
|
||||
return generate_by_template(output_file, template_file, em_globals)
|
||||
|
||||
|
||||
def generate_uRTPS_general(filename_send_msgs, filename_received_msgs,
|
||||
outputdir, templatedir, package, includepath, ids, template_name):
|
||||
def generate_uRTPS_general(filename_send_msgs, filename_alias_send_msgs, filename_receive_msgs, filename_alias_receive_msgs,
|
||||
msg_dir, outputdir, templatedir, package, includepath, ids, template_name):
|
||||
"""
|
||||
Generates source file by msg content
|
||||
"""
|
||||
em_globals_list = []
|
||||
if filename_send_msgs:
|
||||
em_globals_list.extend([get_em_globals(
|
||||
f, package, includepath, ids, MsgScope.SEND) for f in filename_send_msgs])
|
||||
# Make sure input msg directory exists:
|
||||
if not os.path.isdir(msg_dir):
|
||||
os.makedirs(msg_dir)
|
||||
|
||||
if filename_received_msgs:
|
||||
send_msgs = list(os.path.join(msg_dir, msg + ".msg") for msg in filename_send_msgs)
|
||||
alias_send_msgs = list([os.path.join(msg_dir, msg[1] + ".msg"), msg[0].keys()[0]] for msg in filename_alias_send_msgs)
|
||||
receive_msgs = list(os.path.join(msg_dir, msg + ".msg") for msg in filename_receive_msgs)
|
||||
alias_receive_msgs = list([os.path.join(msg_dir, msg[1] + ".msg"), msg[0].keys()[0]] for msg in filename_alias_receive_msgs)
|
||||
|
||||
em_globals_list = []
|
||||
if send_msgs:
|
||||
em_globals_list.extend([get_em_globals(
|
||||
f, package, includepath, ids, MsgScope.RECEIVE) for f in filename_received_msgs])
|
||||
f, "", package, includepath, ids, MsgScope.SEND) for f in send_msgs])
|
||||
|
||||
if alias_send_msgs:
|
||||
em_globals_list.extend([get_em_globals(
|
||||
f[0], f[1], package, includepath, ids, MsgScope.SEND) for f in alias_send_msgs])
|
||||
|
||||
if receive_msgs:
|
||||
em_globals_list.extend([get_em_globals(
|
||||
f, "", package, includepath, ids, MsgScope.RECEIVE) for f in receive_msgs])
|
||||
|
||||
if alias_receive_msgs:
|
||||
em_globals_list.extend([get_em_globals(
|
||||
f[0], f[1], package, includepath, ids, MsgScope.RECEIVE) for f in alias_receive_msgs])
|
||||
|
||||
merged_em_globals = merge_em_globals_list(em_globals_list)
|
||||
|
||||
# Make sure output directory exists:
|
||||
if not os.path.isdir(outputdir):
|
||||
os.makedirs(outputdir)
|
||||
@@ -215,13 +244,24 @@ def generate_uRTPS_general(filename_send_msgs, filename_received_msgs,
|
||||
return generate_by_template(output_file, template_file, merged_em_globals)
|
||||
|
||||
|
||||
def generate_topic_file(filename_msg, outputdir, templatedir, package, includepath, ids, template_name):
|
||||
def generate_topic_file(filename_msg, msg_dir, alias, outputdir, templatedir, package, includepath, ids, template_name):
|
||||
"""
|
||||
Generates an .idl from .msg file
|
||||
Generates a sources and headers from .msg file
|
||||
"""
|
||||
em_globals = get_em_globals(
|
||||
filename_msg, package, includepath, ids, MsgScope.NONE)
|
||||
spec_short_name = em_globals["spec"].short_name
|
||||
# Make sure input msg directory exists:
|
||||
if not os.path.isdir(msg_dir):
|
||||
os.makedirs(msg_dir)
|
||||
|
||||
msg = os.path.join(msg_dir, filename_msg + ".msg")
|
||||
|
||||
if (alias):
|
||||
em_globals = get_em_globals(
|
||||
msg, alias, package, includepath, ids, MsgScope.NONE)
|
||||
spec_short_name = alias
|
||||
else:
|
||||
em_globals = get_em_globals(
|
||||
msg, "", package, includepath, ids, MsgScope.NONE)
|
||||
spec_short_name = em_globals["spec"].short_name
|
||||
|
||||
# Make sure output directory exists:
|
||||
if not os.path.isdir(outputdir):
|
||||
@@ -234,7 +274,7 @@ def generate_topic_file(filename_msg, outputdir, templatedir, package, includepa
|
||||
return generate_by_template(output_file, template_file, em_globals)
|
||||
|
||||
|
||||
def get_em_globals(filename_msg, package, includepath, ids, scope):
|
||||
def get_em_globals(filename_msg, alias, package, includepath, ids, scope):
|
||||
"""
|
||||
Generates em globals dictionary
|
||||
"""
|
||||
@@ -261,7 +301,8 @@ def get_em_globals(filename_msg, package, includepath, ids, scope):
|
||||
"topics": topics,
|
||||
"ids": ids,
|
||||
"scope": scope,
|
||||
"package": package
|
||||
"package": package,
|
||||
"alias": alias
|
||||
}
|
||||
|
||||
return em_globals
|
||||
|
||||
Reference in New Issue
Block a user