-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminicom-launcher.py
76 lines (60 loc) · 1.97 KB
/
minicom-launcher.py
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
import logging
import platform
import os
import subprocess
from subprocess import PIPE
import uart_utils
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('minicom-launcher')
def set_window_title(title):
if os.getenv('TERM') not in ('xterm-256color', 'tmux-256color'):
return
print(f'\033]2;{title}\007')
def check_minicom():
try:
minicom_version_raw = subprocess.run(["minicom", "-v"], check=False, stdout=PIPE).stdout
except FileNotFoundError:
print("Minicom is not installed")
exit(1)
minicom_version = minicom_version_raw.split()[2].decode()
return minicom_version
def open_minicom(device, baudrate):
set_window_title(device)
cmd = ["minicom", f"--device={device}", "--baudrate", f"{baudrate}"]
if platform.system() == "Darwin":
cmd.append("-m")
env = os.environ.copy()
env['LC_MESSAGES'] = 'en_US.UTF-8'
subprocess.run(cmd, env=env)
def baudrate(target_dev):
if 'Cypress' in target_dev or 'M432' in target_dev:
return 115200
else:
return 9600
def run_minicom(device_list: list):
minicom_version = check_minicom()
print(f"MSP430 Minicom Connector (minicom version {minicom_version})\n")
print("Found {} MSP430 UART Terminal(s)".format(len(device_list)))
for index, device in enumerate(device_list):
print(f"{index}\t{device}")
if len(device_list) > 1:
dev_num = input("Device to connect {}: ".format([n for n in range(len(device_list))]))
try:
dev_num = int(dev_num)
except ValueError:
print("Exit")
exit(0)
elif len(device_list) == 1:
dev_num = 0
else:
print("No devices found")
exit(0)
try:
target_dev = device_list[dev_num]
except IndexError as e:
print(e)
exit(1)
open_minicom(target_dev, baudrate(target_dev))
if __name__ == "__main__":
uart_devices = uart_utils.find_uart()
run_minicom(uart_devices)