Skip to content

Commit 686a5ca

Browse files
committed
PcapWriter: Convert capture timestamp to nanoseconds
1 parent c6b93e9 commit 686a5ca

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

zbnt/PcapWriter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self, output):
3232
else:
3333
self.output = output
3434

35+
self.clk_period = 8
3536
self.if_count = 0
3637
self.if_map = dict()
3738

@@ -49,7 +50,9 @@ def __repr__(self):
4950

5051
def register_devices(self, client):
5152
for d in client.devices.values():
52-
if d.device_type == Devices.DEV_FRAME_DETECTOR:
53+
if d.device_type == Devices.DEV_SIMPLE_TIMER:
54+
self.clk_period = 1_000_000_000 // d.freq
55+
elif d.device_type == Devices.DEV_FRAME_DETECTOR:
5356
port_a, port_b = d.ports
5457

5558
self.if_map[d.id] = self.if_count
@@ -79,7 +82,7 @@ def __register_interface(self, name, snap_len):
7982
self.if_count += 1
8083

8184
def __write_frame(self, iface_id, time, number, match_flags, frame_flags, frame):
82-
time = time.to_bytes(8, "little")
85+
time = (self.clk_period * time).to_bytes(8, "little")
8386
flen = len(frame).to_bytes(4, "little")
8487
padding = b"\x00" * ((4 - len(frame) % 4) % 4)
8588
flags = ((match_flags << 8) | (frame_flags >> 1)).to_bytes(4, "little")

0 commit comments

Comments
 (0)