STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_udp_simple.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""
3Super simple UDP test - bind to USB interface specifically
4"""
5
6import socket
7import sys
8
9# Get USB interface IP
10import subprocess
11
12result = subprocess.run(
13 ["ip", "addr", "show", "enx00e04c680240"], capture_output=True, text=True
14)
15usb_ip = None
16for line in result.stdout.split("\n"):
17 if "inet " in line and "192.168" in line:
18 usb_ip = line.split()[1].split("/")[0]
19 break
20
21if not usb_ip:
22 print("❌ USB interface (enx00e04c680240) has no IP!")
23 print("Assign one: sudo ip addr add 192.168.2.201/24 dev enx00e04c680240")
24 sys.exit(1)
25
26print(f"=== Simple UDP Test ===")
27print(f"USB Interface IP: {usb_ip}")
28print(f"Binding to: {usb_ip}:5006")
29print("")
30
31sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
32sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
33
34try:
35 sock.bind((usb_ip, 5006))
36 print(f"✅ Bound to {usb_ip}:5006")
37 print("")
38 print("Listening for packets (30 seconds)...")
39 print("Send packets from your board now!")
40 print("")
41
42 sock.settimeout(1.0)
43 packet_count = 0
44
45 import time
46
47 start = time.time()
48 while time.time() - start < 30:
49 try:
50 data, addr = sock.recvfrom(4096)
51 packet_count += 1
52 print(f"[{packet_count}] From {addr[0]}:{addr[1]}, size: {len(data)} bytes")
53 if len(data) <= 32:
54 hex_str = " ".join(f"{b:02x}" for b in data)
55 print(f" Data: {hex_str}")
56 except socket.timeout:
57 continue
58
59 print("")
60 if packet_count > 0:
61 print(f"✅ Received {packet_count} packet(s)!")
62 else:
63 print("❌ No packets received")
64 print("")
65 print("Troubleshooting:")
66 print(f" 1. Verify board sends to: {usb_ip}:5006")
67 print(f" 2. Check interface: ip addr show enx00e04c680240")
68 print(f" 3. Test ping: ping {usb_ip} (from board)")
69
70except OSError as e:
71 print(f"❌ Error: {e}")
72 print("")
73 print("Try binding to 0.0.0.0 instead:")
74 print(
75 " python3 -c \"import socket; s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.bind(('0.0.0.0', 5006)); print('Bound to 0.0.0.0:5006'); data, addr = s.recvfrom(4096); print(f'Received from {addr}: {len(data)} bytes')\""
76 )
77
78finally:
79 sock.close()
static std::vector< string_t > split(const string_t &reference_string)
split the string input to reference tokens
Definition json.hpp:14471
TOML_NODISCARD_CTOR time() noexcept=default