Skip to content

Commit

Permalink
[yarpdatadumper] Add small python helper script to yarpdatadumper
Browse files Browse the repository at this point in the history
Script to automatically generate yarpmanager applications.
It is installed only if python is found in the OS.
It should run fine also on Windows, but I did not test it.
Documentation of yarpdatadumper was also updated.
  • Loading branch information
traversaro committed Jan 26, 2016
1 parent 059822c commit a04ff78
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
53 changes: 52 additions & 1 deletion doc/yarpdatadumper.dox
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ by the \ref yarpdatadumper.
provided.

--connect \e portname
- The parameter \e portname specifies the name of the port to
- The parameter \e portname specifies the name of the port to
connect the dumper to at launch time (\e tcp is used).

--dir \e dirname
Expand Down Expand Up @@ -215,6 +215,57 @@ By pressing CTRL+C the acquisition is terminated.

So, now, have a look inside the directory ./log

\section application_sec Generate a yarpmanager application

To dump data from several yarp ports, it may be convenient
to launch several yarpdatadumper instances using the yarpmanager.

If you have Python installed on your machine, you can use the
yarpdatadumperAppGenerator.py utility script to generate a yarpmanager
application that will launch and connect as many yarpdatadumper as you need.

If for example you need to read the ports /icub/left_leg/stateExt:o and
/icub/left_leg/analog:o on the host icub15, you can run the generator
with the following option:

\code
yarpdatadumperAppGenerator.py --ports /icub/left_leg/analog:o /icub/left_leg/stateExt:o --host icub15 --name leftLegDumper
\endcode

This will generate the following yarpmanager application in the leftLegDumper.xml file:

\code
<application>
<name>leftLegDumper</name>
<dependencies>
<port>/icub/left_leg/analog:o</port>
<port>/icub/left_leg/stateExt:o</port>
</dependencies>
<module>
<name>yarpdatadumper</name>
<parameters>--name /dumper/icub/left_leg/analog:o --type bottle </parameters>
<node>icub15</node>
<tag>data-dumper-icub-left_leg-analog-o</tag>
</module>
<connection>
<from>/icub/left_leg/analog:o</from>
<to>/dumper/icub/left_leg/analog:o</to>
<protocol>udp</protocol>
</connection>
<module>
<name>yarpdatadumper</name>
<parameters>--name /dumper/icub/left_leg/stateExt:o --type bottle </parameters>
<node>icub15</node>
<tag>data-dumper-icub-left_leg-stateExt-o</tag>
</module>
<connection>
<from>/icub/left_leg/stateExt:o</from>
<to>/dumper/icub/left_leg/stateExt:o</to>
<protocol>udp</protocol>
</connection>
</application>
\endcode

\author Ugo Pattacini

\sa yarpdataplayer
Expand Down
11 changes: 11 additions & 0 deletions src/yarpdatadumper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ if(CREATE_YARPDATADUMPER)
install(TARGETS yarpdatadumper
COMPONENT utilities
DESTINATION ${CMAKE_INSTALL_BINDIR})

# install also the yarpdatadumperAppGenerator.py helper script
# if python is installed
find_package(PythonInterp)

if(PYTHONINTERP_FOUND)
yarp_install(PROGRAMS yarpdatadumperAppGenerator.py
COMPONENT utilities
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

endif()
60 changes: 60 additions & 0 deletions src/yarpdatadumper/yarpdatadumperAppGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/python

import argparse

def printPortTags(out_file, ports, port_type, host, additional_flags):
for port in ports:
# print datadumper launch
out_file.write("\t<module>\n");
out_file.write("\t\t<name>yarpdatadumper</name>\n");
out_file.write("\t\t<parameters>--name /dumper"+port+" --type "+port_type+" "+additional_flags+"</parameters>\n");
out_file.write("\t\t<node>"+host+"</node>\n");
out_file.write("\t\t<tag>data-dumper"+port.replace('/','-').replace(':','-')+"</tag>\n");

This comment has been minimized.

Copy link
@gsaponaro

gsaponaro Feb 10, 2016

Contributor

As far as I know, the <tag> part can be omitted nowadays from yarpmanager application XML files, am I right?

out_file.write("\t</module>\n");

# print connection between datadumper and port
out_file.write("\t<connection>\n");
out_file.write("\t\t<from>"+port+"</from>\n");
out_file.write("\t\t<to>/dumper"+port+"</to>\n");
out_file.write("\t\t<protocol>udp</protocol>\n");

This comment has been minimized.

Copy link
@gsaponaro

gsaponaro Feb 10, 2016

Contributor

Suggestion, maybe for future versions: use udp protocol for high-traffic types like images, tcp protocol otherwise (i.e., vectors of numbers).

out_file.write("\t</connection>\n");

def main():
parser = argparse.ArgumentParser(description='Tool for generating a YarpManager XML application for dumping a list of YARP ports using the yarpdatadumper.')
parser.add_argument('--ports', nargs='+', dest="ports", action='store', required=True, help='list of ports (serializable to bottles) to dump')
parser.add_argument('--imagePorts', nargs='+', dest="imagePorts", action='store', help='list of ports (of to dump')
parser.add_argument('--host', nargs=1, dest="host", action='store', required=True, help='host where to launch the dataDumpers')
parser.add_argument('--name', nargs=1, dest="name", action='store', required=True, help='name of the application, the file will be saved as name.xml')
parser.add_argument('--rxTime', action='store_true',help='pass --rxTime flag to the yarpdatadumpers')
parser.add_argument('--txTime', action='store_true',help='pass --txTime flag to the yarpdatadumpers')
parser.add_argument('--addVideo', action='store_true',help='pass --addVideo flag to the yarpdatadumpers')
args = parser.parse_args()

# open output file
filename = args.name[0] + ".xml";
out_file = open(filename,"w")

out_file.write("<application>\n");
out_file.write("\t<name>"+args.name[0]+"</name>\n");
out_file.write("\t<dependencies>\n");
for port in args.ports:
out_file.write("\t\t<port>"+port+"</port>\n");
out_file.write("\t</dependencies>\n");

additional_flags = "";
if(args.rxTime):
additional_flags += " --rxTime";
if(args.txTime):
additional_flags += " --txTime";
if(args.addVideo):
additional_flags += " --addVideo";

if( args.ports is not None):
printPortTags(out_file,args.ports,"bottle",args.host[0],additional_flags);
if( args.imagePorts is not None):
printPortTags(out_file,args.imagePorts,"image",args.host[0],additional_flags);

out_file.write("</application>\n");

if __name__ == "__main__":
main()

0 comments on commit a04ff78

Please sign in to comment.