00001
00002 import roslib; roslib.load_manifest('cassandra_ros')
00003 import rospy
00004 from RosCassandra.CassandraTopic import CassandraFormats
00005 from RosCassandra.CassandraTopic_ import *
00006 import cassandra_ros.srv
00007
00008 import sys
00009 import argparse
00010
00011 def call_record(args):
00012 if args.start=='start':
00013 args.start=1
00014 elif args.start=='stop':
00015 args.start=0
00016 else:
00017 args.start=-1
00018 rospy.wait_for_service('/cassandra_record')
00019 try:
00020 call = rospy.ServiceProxy('/cassandra_record', cassandra_ros.srv.record)
00021
00022 infos = call(record = args.start,
00023 topics = args.topics,
00024 cassandra_format = args.cassandra_format,
00025 filter = args.filter,
00026 start_time = args.start_time,
00027 stop_time = args.stop_time,
00028 ttl = args.ttl,
00029 apply = args.apply )
00030
00031 print infos
00032 except rospy.ServiceException, e:
00033 print "Service call failed: %s"%e
00034
00035 def call_play(args):
00036 if args.start=='start':
00037 args.start=1
00038 elif args.start=='stop':
00039 args.start=0
00040 else:
00041 args.start=-1
00042
00043 rospy.wait_for_service('/cassandra_play')
00044 try:
00045 call = rospy.ServiceProxy('/cassandra_play', cassandra_ros.srv.play)
00046 infos = call(play = args.start,
00047 topics = args.topics,
00048 start_time = args.start_time,
00049 stop_time = args.stop_time,
00050 filter = args.filter,
00051 queuesize = args.queue,
00052 delay = args.delay,
00053 speed = args.speed,
00054 loop = args.loop)
00055
00056 print infos
00057 except rospy.ServiceException, e:
00058 print "Service call failed: %s"%e
00059
00060 def call_delete(args):
00061 rospy.wait_for_service('/cassandra_delete')
00062 try:
00063 call = rospy.ServiceProxy('/cassandra_delete', cassandra_ros.srv.delete)
00064 infos = call(topics = args.topics,
00065 start_time = args.start_time,
00066 stop_time = args.stop_time)
00067 print infos
00068 except rospy.ServiceException, e:
00069 print "Service call failed: %s"%e
00070
00071 def call_truncate(args):
00072 rospy.wait_for_service('/cassandra_truncate')
00073 try:
00074 call = rospy.ServiceProxy('/cassandra_truncate', cassandra_ros.srv.truncate)
00075 info = call(topics = args.topics)
00076 print info
00077 except rospy.ServiceException, e:
00078 print "Service call failed: %s"%e
00079
00080 def call_info(args):
00081 rospy.wait_for_service('/cassandra_info')
00082 try:
00083 call = rospy.ServiceProxy('/cassandra_info', cassandra_ros.srv.info)
00084 info = call(args.command, args.topics)
00085 print info
00086 except rospy.ServiceException, e:
00087 print "Service call failed: %s"%e
00088
00089
00090 if __name__ == "__main__":
00091 cl_parser = argparse.ArgumentParser()
00092 cl_subparser = cl_parser.add_subparsers()
00093
00094
00095 record = cl_subparser.add_parser('record')
00096 record.set_defaults(func=call_record)
00097 record.add_argument(dest="start", help="start|stop|pause recording", choices=['start','stop', 'pause'])
00098 record.add_argument("-f", "--format", dest="cassandra_format", help="store date in database either add "+str(CassandraFormats), choices=CassandraFormats, default=CassandraFormats[0])
00099 record.add_argument("-x", "--filter", dest="filter", help="write filter in python style, starting with (msg.header.seq%10==0)", default='')
00100 record.add_argument("-b", "--begin", dest="start_time", help="Start record at given time as int", type=int, default=0)
00101 record.add_argument("-e", "--end", dest="stop_time", help="Stop record at given time as int", type=int, default=4294967295)
00102 record.add_argument("-ttl", "--timetolive", dest="ttl", help="Stop record at given time as int", type=int, default=None)
00103 record.add_argument("-a", "--apply", dest="apply", help="apply some functions like msg.transforms.pop()", default=None)
00104 record.add_argument(metavar='TOPICS', nargs='+', dest="topics", help="Topics you want to record. Example: /turtle1/command_velocity")
00105
00106
00107 play = cl_subparser.add_parser('play')
00108 play.set_defaults(func=call_play)
00109 play.add_argument(dest="start", help="start|stop|pause playback", choices=['start','pause','stop'])
00110 play.add_argument("-x", "--filter", dest="filter", help="write filter in python style, starting with (msg.header.seq%10==0)", default='')
00111 play.add_argument("-s", "--speed", dest="speed", help="Playback speed as float. Default: 1.0", type=float, default=1.0)
00112 play.add_argument("-q", "--queue", dest="queue", help="Queue", type=int, default=100)
00113 play.add_argument("-d", "--delay", dest="delay", help="Delay in seconds", type=int, default=0)
00114 play.add_argument("-l", "--loop", dest="loop", help="Loop playback", action='store_true')
00115 play.add_argument("-b", "--begin", dest="start_time", help="Start play at given time as int", type=int, default=0)
00116 play.add_argument("-e", "--end", dest="stop_time", help="Stop play at given time as int", type=int, default=4294967295)
00117 play.add_argument(metavar='TOPICS', nargs='+', dest="topics", help="Topics you want to play. Example: /turtle1/command_velocity")
00118
00119
00120 delete = cl_subparser.add_parser('delete')
00121 delete.set_defaults(func=call_delete)
00122 delete.add_argument("-b", "--begin", dest="start_time", help="Start record/play at given time as int", type=int, default=1)
00123 delete.add_argument("-e", "--end", dest="stop_time", help="Stop record/play at given time as int", type=int, default=4294967295)
00124 delete.add_argument(metavar='TOPICS', nargs='+', dest="topics", help="Topics you want to delete. Example: /turtle1/command_velocity")
00125
00126
00127 truncate = cl_subparser.add_parser('truncate')
00128 truncate.set_defaults(func=call_truncate)
00129 truncate.add_argument(metavar='TOPICS', nargs='+', dest="topics", help="Topics you want to delete totally. Example: /turtle1/command_velocity")
00130
00131
00132 list = cl_subparser.add_parser('list')
00133 list.set_defaults(func=call_info)
00134 list.set_defaults(command="list")
00135 list.set_defaults(topics='')
00136
00137 status = cl_subparser.add_parser('status')
00138 status.set_defaults(func=call_info)
00139 status.set_defaults(command="status")
00140 status.set_defaults(topics='')
00141
00142 info = cl_subparser.add_parser('info')
00143 info.set_defaults(func=call_info)
00144 info.set_defaults(command="info")
00145 info.add_argument(metavar='TOPICS', nargs='+', dest="topics", help="Topics you want to have further information.")
00146
00147 info = cl_subparser.add_parser('cql')
00148 info.set_defaults(func=call_info)
00149 info.set_defaults(command="cql")
00150 info.add_argument(metavar='TOPICS', nargs='+', dest="topics", help="string")
00151
00152
00153 args = cl_parser.parse_args(sys.argv[1:])
00154
00155 args.func(args)