Commit ea9259e5 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by Operator for ID00
Browse files

test/packet.py: support FW v18

parent 871c5548
......@@ -4,17 +4,33 @@ import struct
import glob
from scipy import stats
from scapy.all import rdpcap, IP, UDP
HEADER_PACKET_SIZE = 40
DATA_PACKET_HEADER_SIZE = 48
DATA_PACKET_DATA_SIZE = 4096
DATA_PACKET_SIZE = DATA_PACKET_HEADER_SIZE + DATA_PACKET_DATA_SIZE
from subprocess import Popen, PIPE
cmd = 'detectorversion'
p = Popen(['sls_detector_get', cmd], stdout=PIPE)
l = p.stdout.readline().strip()
rcmd, val = l.split()
if rcmd != cmd:
raise ValueError('Invalid sls_detector_get response: %s' % l)
fw_ver = int(val, 16)
if fw_ver < 20:
HEADER_PACKET_SIZE = 48
DATA_PACKET_PRE_SIZE = 8
DATA_PACKET_DATA_SIZE = 4096
DATA_PACKET_POST_SIZE = 8
DATA_PACKET_SIZE = (DATA_PACKET_PRE_SIZE + DATA_PACKET_DATA_SIZE +
DATA_PACKET_POST_SIZE)
else:
HEADER_PACKET_SIZE = 40
DATA_PACKET_HEADER_SIZE = 48
DATA_PACKET_DATA_SIZE = 4096
DATA_PACKET_SIZE = DATA_PACKET_HEADER_SIZE + DATA_PACKET_DATA_SIZE
TSTAMP_CLOCK_FREQ = 10e6
NOMINAL_PACKET_XFER_TIME = 7.646e-6
pixel_depth = 16
frame_packets = 4 * pixel_depth
frame_packets = 0
addr_map = {}
for d in glob.glob('/sys/class/net/*'):
......@@ -52,19 +68,33 @@ for i, x in enumerate(capfile):
p = u.payload
if len(p) == HEADER_PACKET_SIZE:
f = '>' + 'L' * 10
d = struct.unpack(f, str(p))
fnum = d[5]
if fw_ver >= 20:
f = '>' + 'L' * 10
d = struct.unpack(f, str(p))
fnum = d[5]
continue
elif len(p) != DATA_PACKET_SIZE:
raise ValueError('Invalid packet')
h = str(p)[:DATA_PACKET_HEADER_SIZE]
f = '<' + 'QLLQQHHHHLHBB'
d = struct.unpack(f, h)
fnum, explen, pnum, bunchid, dtime, modid, cx, cy, cz = d[0:9]
debug, rrnum, dtype, ver = d[9:13]
if fw_ver < 20:
pre = str(p)[:DATA_PACKET_PRE_SIZE]
f = '<' + 'LL'
sub_fnum, not_req = struct.unpack(f, pre)
post = str(p)[DATA_PACKET_PRE_SIZE + DATA_PACKET_DATA_SIZE:]
f = '<' + 'LHH'
fnum_l, fnum_h, pnum = struct.unpack(f, post)
fnum = fnum_l + (fnum_h << 4)
pnum -= 1
explen, bunchid, dtime, modid, cx, cy, cz = [0] * 7
debug, rrnum, dtype, ver = [0] * 4
else:
h = str(p)[:DATA_PACKET_HEADER_SIZE]
f = '<' + 'QLLQQHHHHLHBB'
d = struct.unpack(f, h)
fnum, explen, pnum, bunchid, dtime, modid, cx, cy, cz = d[0:9]
debug, rrnum, dtype, ver = d[9:13]
frame_packets = max(frame_packets, pnum + 1)
dtime /= TSTAMP_CLOCK_FREQ
if idata['start_dtime'] is None:
......@@ -75,6 +105,9 @@ for i, x in enumerate(capfile):
ports[port]['packets'].append([fnum, pnum, t, dt])
if (frame_packets == 0) or (frame_packets % 4 != 0):
raise ValueError('Invalid frame_packets: %s' % frame_packets)
for iface, idata in ifaces.items():
for port, d in idata['ports'].items():
fnum, pnum, t, dt = d['packets'][-1]
......@@ -97,10 +130,12 @@ for iface, idata in ifaces.items():
continue
if data[0]:
xfer_time = (dt - data[1][-1]) / (x - data[0][-1])
err = abs((xfer_time - NOMINAL_PACKET_XFER_TIME) / xfer_time)
if err > 0.05:
calc_xfer_time(data)
data = [[], []]
if xfer_time > 0:
err = abs((xfer_time - NOMINAL_PACKET_XFER_TIME) /
xfer_time)
if err > 0.05:
calc_xfer_time(data)
data = [[], []]
data[0].append(x)
data[1].append(dt)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment