#!/usr/bin/env python3 ############################################################################# # # Copyright (C) 2013-2022 PX4 Pro Development Team. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # 3. Neither the name PX4 nor the names of its contributors may be # used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ############################################################################# """ px_generate_uorb_topic_files.py Generates c/cpp header/source files for uorb topics from .msg message files """ import os import argparse import re import sys try: import em except ImportError as e: print("Failed to import em: " + str(e)) print("") print("You may need to install it using:") print(" pip3 install --user empy") print("") sys.exit(1) try: import genmsg.template_tools except ImportError as e: print("Failed to import genmsg: " + str(e)) print("") print("You may need to install it using:") print(" pip3 install --user pyros-genmsg") print("") sys.exit(1) __author__ = "Sergey Belash, Thomas Gubler, Beat Kueng" __copyright__ = "Copyright (C) 2013-2022 PX4 Development Team." __license__ = "BSD" __email__ = "thomasgubler@gmail.com" TEMPLATE_FILE = ['msg.h.em', 'msg.cpp.em', 'uorb_idl_header.h.em', 'msg.json.em'] TOPICS_LIST_TEMPLATE_FILE = ['uORBTopics.hpp.em', 'uORBTopics.cpp.em', None, None] INCL_DEFAULT = ['std_msgs:./msg/std_msgs'] PACKAGE = 'px4' TOPICS_TOKEN = '# TOPICS ' def get_topics(filename): """ Get TOPICS names from a "# TOPICS" line """ ofile = open(filename, 'r') text = ofile.read() result = [] for each_line in text.split('\n'): if each_line.startswith(TOPICS_TOKEN): topic_names_str = each_line.strip() topic_names_str = topic_names_str.replace(TOPICS_TOKEN, "") topic_names_list = topic_names_str.split(" ") for topic in topic_names_list: # topic name PascalCase (file name) to snake_case (topic name) topic_name = re.sub(r'(?