32 from std_msgs.msg
import String
41 from cStringIO
import StringIO
44 from novatel_span_driver
import translator
46 DEFAULT_IP =
'198.161.73.9' 49 SOCKET_TIMEOUT = 100.0
56 ip = rospy.get_param(
'~ip', DEFAULT_IP)
57 data_port = rospy.get_param(
'~port', DEFAULT_PORT)
61 pcap_file_name = rospy.get_param(
'~pcap_file',
False)
63 if not pcap_file_name:
72 for name, port
in ports.items():
74 rospy.loginfo(
"Port %s thread started." % name)
77 rospy.on_shutdown(shutdown)
82 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
85 rospy.loginfo(
"Successfully connected to %%s port at %s:%d" % ip_port % name)
86 except socket.error
as e:
87 rospy.logfatal(
"Couldn't connect to %%s port at %s:%d: %%s" % ip_port % (name, str(e)))
89 sock.settimeout(SOCKET_TIMEOUT)
100 import pure_pcapy
as pcapy
102 from StringIO
import StringIO
103 from impacket
import ImpactDecoder
106 if pcap_filename.endswith(
"gz"):
110 tmph, tmpf = tempfile.mkstemp()
111 tmph = open(tmpf,
'wb')
112 gfile = gzip.open(pcap_filename)
113 tmph.write(gfile.read())
118 cap = pcapy.open_offline(pcap_filename)
119 decoder = ImpactDecoder.EthDecoder()
122 header, payload = cap.next()
126 tcp = decoder.decode(payload).child().child()
127 body_list.append(tcp.child().get_packet())
128 except AttributeError:
129 print(decoder.decode(payload))
132 data_io = StringIO(
''.join(body_list))
134 class MockSocket(object):
135 def recv(self, byte_count):
137 data = data_io.read(byte_count)
139 rospy.signal_shutdown(
"Test completed.")
142 def settimeout(self, timeout):
149 receiver_config = rospy.get_param(
'~configuration',
None)
151 if receiver_config
is not None:
152 imu_connect = receiver_config.get(
'imu_connect',
None)
153 if imu_connect
is not None:
154 rospy.loginfo(
"Sending IMU connection string to SPAN system.")
155 port.send(
'connectimu ' + imu_connect[
'port'] +
' ' + imu_connect[
'type'] +
'\r\n')
157 logger = receiver_config.get(
'log_request', [])
158 rospy.loginfo(
"Enabling %i log outputs from SPAN system." % len(logger))
160 port.send(
'log ' + log +
' ontime ' + str(logger[log]) +
'\r\n')
162 commands = receiver_config.get(
'command', [])
163 rospy.loginfo(
"Sending %i user-specified initialization commands to SPAN system." % len(commands))
165 port.send(cmd +
' ' + str(commands[cmd]) +
'\r\n')
171 rospy.loginfo(
"Thread monitor finished.")
172 for name, port
in ports.items():
175 rospy.loginfo(
"Port %s thread finished." % name)
177 sock.shutdown(socket.SHUT_RDWR)
179 rospy.loginfo(
"Sockets closed.")
def create_test_sock(pcap_filename)
def configure_receiver(port)
def create_sock(name, ip, port)