|
| 1 | +# Copyright 2016 Open Source Robotics Foundation, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import os |
| 16 | + |
| 17 | +from rosidl_cmake import convert_camel_case_to_lower_case_underscore |
| 18 | +from rosidl_cmake import expand_template |
| 19 | +from rosidl_cmake import extract_message_types |
| 20 | +from rosidl_cmake import get_newest_modification_time |
| 21 | +from rosidl_parser import parse_message_file |
| 22 | +from rosidl_parser import parse_service_file |
| 23 | +from rosidl_parser import validate_field_types |
| 24 | +from pathlib import Path |
| 25 | + |
| 26 | + |
| 27 | +def generate_micro_ros_agent_xml_support(args): |
| 28 | + pkg_name = args['package_name'] |
| 29 | + known_msg_types = extract_message_types( |
| 30 | + pkg_name, args['ros_interface_files'], args.get('ros_interface_dependencies', [])) |
| 31 | + |
| 32 | + functions = { |
| 33 | + 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, |
| 34 | + } |
| 35 | + |
| 36 | + for idl_file in args['ros_interface_files']: |
| 37 | + extension = os.path.splitext(idl_file)[1] |
| 38 | + if extension == '.msg': |
| 39 | + spec = parse_message_file(pkg_name, idl_file) |
| 40 | + validate_field_types(spec, known_msg_types) |
| 41 | + subfolder = os.path.basename(os.path.dirname(idl_file)) |
| 42 | + |
| 43 | + data = { |
| 44 | + 'spec': spec, |
| 45 | + 'pkg': spec.base_type.pkg_name, |
| 46 | + 'msg': spec.msg_name, |
| 47 | + 'type': spec.base_type.type, |
| 48 | + 'subfolder': subfolder, |
| 49 | + } |
| 50 | + data.update(functions) |
| 51 | + |
| 52 | + |
| 53 | + # Make destinatino dir |
| 54 | + if not os.path.exists(args['output_dir']): |
| 55 | + os.makedirs(args['output_dir']) |
| 56 | + |
| 57 | + # Check if publixher exists |
| 58 | + pub_file_path = "/root/install/publisher.xml" |
| 59 | + pub_file = Path(pub_file_path) |
| 60 | + if not pub_file.is_file(): |
| 61 | + publ = open(pub_file_path, 'a') |
| 62 | + publ.write("<profiles>\n") |
| 63 | + else: |
| 64 | + publ = open(pub_file_path) |
| 65 | + lines = publ.readlines() |
| 66 | + publ.close() |
| 67 | + publ = open(pub_file_path,'w') |
| 68 | + publ.writelines([item for item in lines[:-1]]) |
| 69 | + |
| 70 | + |
| 71 | + #publ = open(os.path.join(args['output_dir'], 'publisher.xml'), 'w+') |
| 72 | + #publ = open('/root/install/publisher.xml', 'a') |
| 73 | + publ.write(" <publisher profile_name=\"default_xrce_publisher_profile\">\n") |
| 74 | + publ.write(" <topic>\n") |
| 75 | + publ.write(" <kind>NO_KEY</kind>\n") |
| 76 | + publ.write(" <name>%sPubSubTopic</name>\n" % (spec.msg_name)) |
| 77 | + publ.write(" <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)) |
| 78 | + publ.write(" <historyQos>\n") |
| 79 | + publ.write(" <kind>KEEP_LAST</kind>\n") |
| 80 | + publ.write(" <depth>5</depth>\n") |
| 81 | + publ.write(" </historyQos>\n") |
| 82 | + publ.write(" <durability>\n") |
| 83 | + publ.write(" <kind>TRANSIENT_LOCAL</kind>\n") |
| 84 | + publ.write(" </durability>\n") |
| 85 | + publ.write(" </topic>\n") |
| 86 | + publ.write(" </publisher>\n") |
| 87 | + publ.write("</profiles>\n") |
| 88 | + publ.close() |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + # Check if subcriber exists |
| 93 | + subs_file_path = "/root/install/subscriber.xml" |
| 94 | + subs_file = Path(subs_file_path) |
| 95 | + if not subs_file.is_file(): |
| 96 | + subs = open(subs_file_path, 'a') |
| 97 | + subs.write("<profiles>\n") |
| 98 | + else: |
| 99 | + subs = open(subs_file_path) |
| 100 | + lines = subs.readlines() |
| 101 | + subs.close() |
| 102 | + subs = open(subs_file_path,'w') |
| 103 | + subs.writelines([item for item in lines[:-1]]) |
| 104 | + |
| 105 | + |
| 106 | + #subs = open(os.path.join(args['output_dir'], 'subscriber.xml'), 'w+') |
| 107 | + #subs = open('/root/install/subscriber.xml', 'a') |
| 108 | + #subs.write("<profiles>\n") |
| 109 | + subs.write(" <subscriber profile_name=\"default_xrce_subscriber_profile\">\n") |
| 110 | + subs.write(" <topic>\n") |
| 111 | + subs.write(" <kind>NO_KEY</kind>\n") |
| 112 | + subs.write(" <name>%sPubSubTopic</name>\n" % (spec.msg_name)) |
| 113 | + subs.write(" <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)) |
| 114 | + subs.write(" <historyQos>\n") |
| 115 | + subs.write(" <kind>KEEP_LAST</kind>\n") |
| 116 | + subs.write(" <depth>5</depth>\n") |
| 117 | + subs.write(" </historyQos>\n") |
| 118 | + subs.write(" <durability>\n") |
| 119 | + subs.write(" <kind>TRANSIENT_LOCAL</kind>\n") |
| 120 | + subs.write(" </durability>\n") |
| 121 | + subs.write(" </topic>\n") |
| 122 | + subs.write(" </subscriber>\n") |
| 123 | + subs.write("</profiles>\n") |
| 124 | + subs.close() |
| 125 | + |
| 126 | + |
| 127 | + # Check if topic exists |
| 128 | + topi_file_path = "/root/install/topic.xml" |
| 129 | + topi_file = Path(topi_file_path) |
| 130 | + if not topi_file.is_file(): |
| 131 | + topi = open(topi_file_path, 'a') |
| 132 | + topi.write("<dds>\n") |
| 133 | + else: |
| 134 | + topi = open(topi_file_path) |
| 135 | + lines = topi.readlines() |
| 136 | + topi.close() |
| 137 | + topi = open(topi_file_path,'w') |
| 138 | + topi.writelines([item for item in lines[:-1]]) |
| 139 | + |
| 140 | + |
| 141 | + #topi = open(os.path.join(args['output_dir'], 'topic.xml'), 'w+') |
| 142 | + #topi = open('/root/install/topic.xml', 'a') |
| 143 | + #topi.write("<dds>\n") |
| 144 | + topi.write(" <topic>\n") |
| 145 | + topi.write(" <name>%sPubSubTopic</name>\n" % (spec.msg_name)) |
| 146 | + topi.write(" <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)) |
| 147 | + topi.write(" </topic>\n") |
| 148 | + topi.write("</dds>\n") |
| 149 | + topi.close() |
| 150 | + |
| 151 | + #elif extension == '.srv': |
| 152 | + |
| 153 | + #data = {'spec': spec} |
| 154 | + #data.update(functions) |
| 155 | + |
| 156 | + #if not os.path.exists(args['output_dir']): |
| 157 | + # os.makedirs(args['output_dir']) |
| 158 | + |
| 159 | + #f = open(os.path.join(args['output_dir'], 'demofile.txt'), 'w+') |
| 160 | + #f.write("%s\n" % spec) |
| 161 | + #f.close() |
| 162 | + return 0 |
0 commit comments