diff --git a/.gitignore b/.gitignore index c453432f78..881396fa2f 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ unittests/build *.pretty xcode src/platforms/linux/px4_messages/ +src/systemcmds/topic_listener.cpp diff --git a/Tools/generate_listener.py b/Tools/generate_listener.py new file mode 100644 index 0000000000..3fa4ea476f --- /dev/null +++ b/Tools/generate_listener.py @@ -0,0 +1,112 @@ +#!/usr/bin/python + +import glob + +raw_messages = glob.glob("../msg/*.msg") +messages = [] +message_floats = [] + + +for index,m in enumerate(raw_messages): + temp_list = [] + if("actuator_control" not in m and "pwm_input" not in m and "position_setpoint" not in m): + f = open(m,'r') + for line in f.readlines(): + if(line.split(' ')[0] == "float32"): + temp_list.append(line.split(' ')[1].split('\t')[0].split('\n')[0]) + f.close() + messages.append(m.split('/')[-1].split('.')[0]) + message_floats.append(temp_list) +num_messages = len(messages); + +print +print """ + +/**************************************************************************** + * + * Copyright (c) 2015 PX4 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. + * + ****************************************************************************/ + +/** + * @file topic_listener.cpp, autogenerated by Tools/generate_listener.py + * + * Tool for listening to topics when running flight stack on linux. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +""" +for m in messages: + print "#include " % m + + +print """ +extern "C" __EXPORT int listener_main(int argc, char *argv[]); + +int listener_main(int argc, char *argv[]) { + int sub = -1; + orb_id_t ID; + if(argc < 3) { + printf("need at least two arguments: topic name, number of messages to print\\n"); + return 1; + } +""" +print "\tuint32_t num_msgs = (uint32_t)std::stoi(argv[2],NULL,10);" +print "\tif(strncmp(argv[1],\"%s\",50)== 0) {" % messages[0] +print "\t\tsub = orb_subscribe(ORB_ID(%s));" % messages[0] +print "\t\tID = ORB_ID(%s);" % messages[0] +print "\t\tstruct %s_s container;" % messages[0] +print "\t\tmemset(&container, 0, sizeof(container));" +for index,m in enumerate(messages[1:]): + print "\t} else if(strncmp(argv[1],\"%s\",50) == 0) {" % m + print "\t\tsub = orb_subscribe(ORB_ID(%s));" % m + print "\t\tID = ORB_ID(%s);" % m + print "\t\tstruct %s_s container;" % m + print "\t\tmemset(&container, 0, sizeof(container));" + print "\t\tfor(uint32_t i = 0;i