STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
send_sensor_config_manual.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""
3Manually send SENSOR_CONFIG to a board (e.g. 192.168.2.22:5005) to test if the board
4transitions from WaitingForServer to Active. Run with board powered and Serial monitor open.
5
6Usage: python3 scripts/test/send_sensor_config_manual.py [--ip 192.168.2.22] [--port 5005]
7"""
8import argparse
9import socket
10import struct
11import time
12
13
14def make_header(packet_type, version=0):
15 ts = int(time.time() * 1000) & 0xFFFFFFFF
16 return struct.pack("<BBI", packet_type, version, ts)
17
18
19def main():
20 ap = argparse.ArgumentParser()
21 ap.add_argument("--ip", default="192.168.2.22", help="Board IP")
22 ap.add_argument("--port", type=int, default=5005, help="Board config port")
23 ap.add_argument(
24 "--format",
25 choices=["simple", "full"],
26 default="simple",
27 help="simple=sense_testing_gui (no num_sensors). full=DAQv2 num_sensors+sensor_ids",
28 )
29 ap.add_argument("-n", type=int, default=5, help="Send N times")
30 args = ap.parse_args()
31
32 SENSOR_CONFIG = 5
33
34 if args.format == "simple":
35 # Legacy (sense_testing_gui) - boards expect DAQv2 format now, this will likely fail
36 pkt = (
37 make_header(SENSOR_CONFIG) + struct.pack("<BB", 0, 0) + struct.pack("<B", 1)
38 )
39 print("Format: simple (legacy) - may fail; use --format full")
40 else:
41 # DAQv2-Comms: num_sensors, sensor_ids, reference_voltage, necessary_for_abort, [controller_ip], enable_serial_printing
42 sensor_ids = [1, 2, 3, 4] # 1-based connectors
43 ref_voltage = 0
44 necessary_for_abort = 0
45 enable_serial = 1
46 pkt = make_header(SENSOR_CONFIG) + struct.pack("<B", len(sensor_ids))
47 for sid in sensor_ids:
48 pkt += struct.pack("<B", sid)
49 pkt += struct.pack("<BB", ref_voltage, necessary_for_abort)
50 # no controller_ip when necessary_for_abort=0
51 pkt += struct.pack("<B", enable_serial)
52 print(
53 "Format: full (DAQv2) num_sensors=4, ids=[1,2,3,4], ref=0, necessary=0, enable_serial=1"
54 )
55
56 print(f"Sending {len(pkt)} bytes to {args.ip}:{args.port}")
57 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
58
59 for i in range(args.n):
60 sock.sendto(pkt, (args.ip, args.port))
61 print(f" Sent #{i+1}")
62 time.sleep(0.5)
63
64 sock.close()
65 print(
66 "Done. Check board Serial: expect 'SENSOR_CONFIG received' and 'State -> Active'"
67 )
68
69
70if __name__ == "__main__":
71 main()
make_header(packet_type, version=0)
TOML_NODISCARD_CTOR time() noexcept=default