4 from jsk_network_tools.msg
import FC2OCSLargeData
6 from threading
import Lock
7 from StringIO
import StringIO
10 import diagnostic_updater
11 from diagnostic_msgs.msg
import DiagnosticStatus
13 from roslib.message
import get_message_class
14 from std_msgs.msg
import Time
15 from dynamic_reconfigure.server
import Server
16 from jsk_network_tools.cfg
import SilverhammerHighspeedStreamerConfig
20 message_class_str = rospy.get_param(
"~message",
21 "jsk_network_tools/FC2OCSLargeData")
25 raise Exception(
"invalid topic type: %s"%message_class_str)
31 self.diagnostic_updater.setHardwareID(
"none")
35 self.
send_ip = rospy.get_param(
"~to_ip",
"localhost")
40 "~last_input_received_time", Time)
42 self.
rate = rospy.get_param(
"~send_rate", 2)
60 stat.summary(DiagnosticStatus.OK,
"OK")
62 now = rospy.Time.now()
63 stat.add(
"Uptime [sec]",
65 stat.add(
"Time from the last sending [sec]",
67 stat.add(
"Number of transmission", self.
send_num)
68 stat.add(
"Time from the last input [sec]",
71 stat.add(
"UDP address", self.
send_ip)
73 stat.add(
"Expected Hz to send",
"%f Hz" % self.
rate)
74 stat.add(
"Packet size",
"%d bytes" % self.
packet_size)
76 stat.add(
"Latest nterval duration between packets",
82 self.diagnostic_updater.update()
88 self.last_send_time_pub.publish(Time(data=rospy.Time(0)))
90 self.last_input_received_time_pub.publish(
93 self.last_input_received_time_pub.publish(
94 Time(data=rospy.Time(0)))
100 for topic, message_class
in subscriber_info:
101 field_name = topic[1:].replace(
"/",
"__")
103 setattr(msg, field_name, self.
messages[topic])
104 rospy.msg.serialize_message(buffer, 0, msg)
107 self.
sendBuffer(buffer.getvalue(), buffer.len * 8)
112 total_sec = float(buffer_size) / self.
bandwidth 113 packet_interval = total_sec / len(packets)
115 rospy.loginfo(
"sending %d packets", len(packets))
116 rospy.loginfo(
"sending %d bits with %f interval" 117 % (buffer_size, packet_interval))
118 rospy.loginfo(
"total time to send is %f sec" % total_sec)
120 for p, i
in zip(packets, range(len(packets))):
129 for topic, message_class
in subscriber_infos:
130 sub = rospy.Subscriber(topic, message_class,
132 self.subscribers.append(sub)
140 if __name__ ==
"__main__":
141 rospy.init_node(
"silverhammer_highspeed_streamer")
def messageCallback(self, msg, topic)
def timeTimerCallback(self, event)
def genMessageCallback(self, topic)
def sendTimerCallback(self, event)
def diagnosticTimerCallback(self, event)
def diagnosticCallback(self, stat)
last_input_received_time_pub
def sendBuffer(self, buffer, buffer_size)
def subscribe(self, subscriber_infos)
def dynamicReconfigureCallback(self, config, level)