-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdcm_uart_test.py
More file actions
83 lines (66 loc) · 2.58 KB
/
dcm_uart_test.py
File metadata and controls
83 lines (66 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import time
import argparse
from DCM.core.serial_interface import SerialInterface
# Example params for testing the microcontroller firmware
# Example params for testing the microcontroller firmware
TEST_PARAMS = {
# "MODE" is handled separately in send_parameters
"ARP": 250,
"VRP": 250,
"atrial_amp": 4.5,
"ventricular_amp": 4.5,
"atrial_width": 1, # Note: serial_interface casts to int. If this is ms, 5ms.
"ventricular_width": 1,
"atr_cmp_ref_pwm": 60,
"vent_cmp_ref_pwm": 90,
"reaction_time": 30,
"recovery_time": 5,
"PVARP": 250,
"AV_delay": 150, # FIXED_AV_DELAY -> AV_delay
"response_factor": 8,
"activity_threshold": 0,
"LRL": 60, # LOWER_RATE_LIMIT -> LRL
"URL": 120, # UPPER_RATE_LIMIT -> URL
"MSR": 160, # MAXIMUM_SENSOR_RATE -> MSR
"rate_smoothing": 0
}
TEST_MODE_ID = 8 # VOO
def on_ack():
print("[MCU] ACK received")
def on_egram(ch, val):
print(f"[MCU] EGRAM → ch={ch}, value={val}")
def main():
parser = argparse.ArgumentParser(description="DCM UART test tool for Simulink team")
parser.add_argument("port", help="Serial port connected to microcontroller")
parser.add_argument("--baud", type=int, default=115200, help="UART baudrate")
parser.add_argument("--send", action="store_true", help="Send parameter packet")
parser.add_argument("--egram", action="store_true", help="Request EGRAM")
args = parser.parse_args()
iface = SerialInterface(args.port, args.baud)
print(f"[INFO] Opening port {args.port} @ {args.baud} ...")
iface.ack_callback = on_ack
iface.egram_callback = on_egram
iface.connect()
time.sleep(0.5)
if args.send:
print("[INFO] Sending test parameters to microcontroller...")
iface.send_parameters(TEST_PARAMS, mode_id_val=TEST_MODE_ID)
if args.egram:
print("[INFO] Requesting EGRAM data stream from microcontroller...")
packet = iface._build_packet(0x02, b"") # CMD_REQUEST_EGRAM
iface.serial.write(packet)
print("[INFO] Running. Press CTRL+C to exit.")
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
print("\n[INFO] Exiting...")
iface.disconnect()
#to run first find the uart port thebn send params using
#python3 dcm_uart_test.py /dev/tty.usbmodem1101 --send
# py dcm_uart_test.py COM4 --send
#to check if ure sending data correctly
#python3 dcm_cli_uart_test.py /dev/tty.usbmodem1101 --egram
# py dcm_cli_uart_test.py COM4 --egram
if __name__ == "__main__":
main()