Index: scripts/MsgUtils/msgutils/MsgCpp.py =================================================================== diff -u -rbde1243eb2ff6af2868f6c6ad0cb4f5760aaf68b -r402926738e7394ee2d3dc7add2e6d755f06a289d --- scripts/MsgUtils/msgutils/MsgCpp.py (.../MsgCpp.py) (revision bde1243eb2ff6af2868f6c6ad0cb4f5760aaf68b) +++ scripts/MsgUtils/msgutils/MsgCpp.py (.../MsgCpp.py) (revision 402926738e7394ee2d3dc7add2e6d755f06a289d) @@ -37,14 +37,12 @@ # \param[in] device_name name of the device used to name the output message definitions header file # \param[in] output_dir directory where the output header file will be written # \param[in] namespace namespace to use in the header file, if namespace is blank then no namespace will be added - # \param[in] proto flag to add protobuf utility function to generated header file - def write_msg_defs_header(self, device_name, output_dir, namespace=None, proto=False): + def write_msg_defs_header(self, device_name, output_dir, namespace=None): env = Environment(loader = FileSystemLoader(f'{Path(__file__).parent.absolute()}/templates')) template = env.get_template('MsgDefs_h.jinja') render = template.render({ 'msg_cpp': self, 'cpp_namespace': namespace, - 'proto': proto, 'device_name': device_name }) header_path = Path(output_dir).joinpath(f"{device_name}MsgDefs.h") @@ -58,15 +56,13 @@ # \param[in] device_name name of the device used to name the output message definitions source file # \param[in] output_dir directory where the output header file will be written # \param[in] namespace namespace to use in the header file, if namespace is blank then no namespace will be added - # \param[in] proto flag to add protobuf utility function to generated header file - def write_msg_defs_source(self, device_name, output_dir, namespace=None, proto=False): + def write_msg_defs_source(self, device_name, output_dir, namespace=None): env = Environment(loader = FileSystemLoader(f'{Path(__file__).parent.absolute()}/templates')) template = env.get_template('MsgDefs_cpp.jinja') render = template.render({ 'msg_cpp': self, 'msg_defs_header': f"{device_name}MsgDefs.h", 'cpp_namespace': namespace, - 'proto': proto, }) srcPath = Path(output_dir).joinpath(f"{device_name}MsgDefs.cpp") with open(srcPath, mode='w', encoding='utf-8', newline='\n') as out_file: @@ -75,6 +71,44 @@ print(f"Wrote C++ message definitions source file {srcPath}") + # \brief Write the protobuf utility C++ header file (struct <-> protobuf conversions) + # \param[in] device_name name of the device used to name the output files + # \param[in] output_dir directory where the output header file will be written + # \param[in] namespace namespace to use in the header file, if blank then no namespace + def write_msg_proto_utils_header(self, device_name, output_dir, namespace=None): + env = Environment(loader = FileSystemLoader(f'{Path(__file__).parent.absolute()}/templates')) + template = env.get_template('MsgProtoUtils_h.jinja') + render = template.render({ + 'msg_cpp': self, + 'cpp_namespace': namespace, + 'device_name': device_name + }) + header_path = Path(output_dir).joinpath(f"{device_name}MsgProtoUtils.h") + with open(header_path, mode='w', encoding='utf-8', newline='\n') as out_file: + out_file.write(render) + out_file.close() + print(f"Wrote C++ protobuf utilities header file {header_path}") + + + # \brief Write the protobuf utility C++ source file (struct <-> protobuf conversions) + # \param[in] device_name name of the device used to name the output files + # \param[in] output_dir directory where the output source file will be written + # \param[in] namespace namespace to use in the source file, if blank then no namespace + def write_msg_proto_utils_source(self, device_name, output_dir, namespace=None): + env = Environment(loader = FileSystemLoader(f'{Path(__file__).parent.absolute()}/templates')) + template = env.get_template('MsgProtoUtils_cpp.jinja') + render = template.render({ + 'msg_cpp': self, + 'msg_proto_utils_header': f"{device_name}MsgProtoUtils.h", + 'cpp_namespace': namespace, + }) + srcPath = Path(output_dir).joinpath(f"{device_name}MsgProtoUtils.cpp") + with open(srcPath, mode='w', encoding='utf-8', newline='\n') as out_file: + out_file.write(render) + out_file.close() + print(f"Wrote C++ protobuf utilities source file {srcPath}") + + def write_log_parser(self, basename, header_dir, source_dir, namespace, msg_defs_header): with open((header_dir.rstrip('/') + "/" if header_dir else "") + basename + '.h', mode='w', encoding='utf-8', newline='\n') as out_file: includes = set()