DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
wib_packet_receiver.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2import click
3import socket
4import time
5from rich.console import Console
6import fddetdataformats
7
8console = Console()
9
10CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
11@click.command(context_settings=CONTEXT_SETTINGS)
12@click.option('-p','--port', default=1234, help='Port number')
13
14
15def cli(port):
16 console.log(f"Preparing to receive WIB packets on port {port}.")
17 sock = socket.socket(socket.AF_INET, # Internet
18 socket.SOCK_DGRAM) # UDP
19 sock.bind(("0.0.0.0", port))
20
21 rcv_bytes = 0
22 rcv_pkts_tot = 0
23 rcv_pkts = 0
24 rcv_bytes = 0
25 start_time = time.time();
26 while True:
27 try:
28 data, addr = sock.recvfrom(8192)
29 rcv_bytes += len(data)
30 wf = fddetdataformats.WIBEthFrame(data)
31 rcv_pkts +=1
32 if rcv_pkts_tot % 100000 == 0:
33 stop_time = time.time()
34 interval = stop_time - start_time
35 console.log(f"Received {rcv_pkts} packets: throughput is {rcv_bytes*8/(interval*1000000000.):.2f} Gb/s")
36 rcv_pkts = 0
37 rcv_bytes = 0
38 start_time = stop_time
39 except KeyboardInterrupt:
40 break
41 except:
42 continue
43 console.log(f"Received {rcv_pkts_tot} messages; ending now.")
44
45if __name__ == '__main__':
46 try:
47 cli(show_default=True, standalone_mode=True)
48 except Exception as e:
49 console.print_exception()