-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialtest.py
More file actions
executable file
·112 lines (97 loc) · 2.91 KB
/
serialtest.py
File metadata and controls
executable file
·112 lines (97 loc) · 2.91 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
"""Serial communication test tool with client/server roles.
This is a thin entrypoint that delegates to client/server runners.
"""
import argparse
import logging
import sys
from client.runner import run_client
from server.runner import run_server
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
DEFAULT_BAUDRATE = 115200
DEFAULT_HANDSHAKE_TIMEOUT_S = 30
DEFAULT_MSG_COUNT = 100
def main() -> int:
parser = argparse.ArgumentParser(
description="Serial communication test with client/server roles",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
Server (RPi): %(prog)s -d /dev/ttyAMA4 -r server
Client (workstation): %(prog)s -d /dev/ttyUSB0 -r client -n 100
Server waits for client connections (send SIGTERM/SIGINT to stop).
Client initiates peering and exits.
""",
)
parser.add_argument(
"-d",
"--device",
type=str,
required=True,
help="Serial device path (e.g., /dev/ttyAMA4)",
)
parser.add_argument(
"-r",
"--role",
type=str,
choices=["client", "server"],
required=True,
help="Role: 'client' (initiates connection) or 'server' (waits for client)",
)
parser.add_argument(
"-f",
"--flow-control",
type=str,
choices=["none", "rtscts"],
default="none",
help="Flow control (default: none)",
)
parser.add_argument(
"-b",
"--baudrate",
type=int,
default=DEFAULT_BAUDRATE,
help=f"Baud rate (default: {DEFAULT_BAUDRATE})",
)
parser.add_argument(
"-n",
"--msg-count",
type=int,
default=DEFAULT_MSG_COUNT,
help=f"Message count for session test (client only, default: {DEFAULT_MSG_COUNT})",
)
parser.add_argument(
"-w",
"--handshake-timeout",
type=int,
default=DEFAULT_HANDSHAKE_TIMEOUT_S,
help=f"Handshake timeout in seconds (default: {DEFAULT_HANDSHAKE_TIMEOUT_S})",
)
parser.add_argument(
"--no-latency-fix",
action="store_true",
help="Disable automatic FTDI latency timer configuration",
)
args = parser.parse_args()
logger.info(f"Serial device: {args.device}, role={args.role}")
# Convert flow control string to boolean
rtscts = args.flow_control == "rtscts"
if args.role == "client":
return run_client(
device=args.device,
baudrate=args.baudrate,
rtscts=rtscts,
handshake_timeout_s=args.handshake_timeout,
msg_count=args.msg_count,
no_latency_fix=args.no_latency_fix,
)
else:
return run_server(
device=args.device,
baudrate=args.baudrate,
rtscts=rtscts,
no_latency_fix=args.no_latency_fix,
)
if __name__ == "__main__":
sys.exit(main())