STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
capture_raw_packets.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""
3Raw UDP packet capture - bypasses DAQ bridge to see what's actually arriving
4"""
5
6import socket
7import sys
8import time
9from datetime import datetime
10
11PORT = 5006
12TIMEOUT = 30
13
14print(f"=== Raw UDP Packet Capture on Port {PORT} ===")
15print(f"Listening for {TIMEOUT} seconds...")
16print("")
17
18# Create UDP socket
19sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
20sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
21sock.bind(("0.0.0.0", PORT))
22sock.settimeout(1.0) # 1 second timeout for checking
23
24print(f"✅ Socket bound to 0.0.0.0:{PORT}")
25print("")
26
27packet_count = 0
28start_time = time.time()
29
30try:
31 while time.time() - start_time < TIMEOUT:
32 try:
33 data, addr = sock.recvfrom(4096)
34 packet_count += 1
35
36 print(f"[Packet #{packet_count}] From: {addr[0]}:{addr[1]}")
37 print(f" Size: {len(data)} bytes")
38 print(f" Time: {datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
39
40 # Show first 32 bytes in hex
41 hex_str = " ".join(f"{b:02x}" for b in data[:32])
42 print(f" First 32 bytes: {hex_str}")
43
44 # Show first 32 bytes as ASCII (if printable)
45 ascii_str = "".join(chr(b) if 32 <= b < 127 else "." for b in data[:32])
46 print(f" ASCII: {ascii_str}")
47
48 # Check if it looks like DiabloAvionics packet
49 if len(data) >= 1:
50 first_byte = data[0]
51 if first_byte == 3:
52 print(f" ✅ Looks like SENSOR_DATA packet (type=3)")
53 elif 1 <= first_byte <= 9:
54 print(f" ⚠️ Valid packet type ({first_byte}) but not SENSOR_DATA")
55 else:
56 print(f" ⚠️ Unknown packet type: 0x{first_byte:02x}")
57
58 print("")
59
60 except socket.timeout:
61 continue
62 except KeyboardInterrupt:
63 break
64
65except Exception as e:
66 print(f"Error: {e}")
67
68finally:
69 sock.close()
70
71print(f"\n=== Summary ===")
72print(f"Total packets received: {packet_count}")
73
74if packet_count == 0:
75 print("\n⚠️ No packets received!")
76 print("\nTroubleshooting:")
77 print(" 1. Check board is sending to correct IP and port")
78 print(" 2. Check firewall: sudo ufw status")
79 print(" 3. Check network connectivity")
80 print(" 4. Verify board is actually sending (check Serial monitor)")
TOML_NODISCARD_CTOR time() noexcept=default