Skip to content

Commit ccfb047

Browse files
committed
Add a whitelist of known meshtastic USB VIDs to use a default serial ports.
Initially only RAK4631 and heltec tracker are listed
1 parent b58094b commit ccfb047

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

meshtastic/util.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@
2424
from meshtastic.supported_device import supported_devices
2525
from meshtastic.version import get_active_version
2626

27-
"""Some devices such as a seger jlink we never want to accidentally open"""
28-
blacklistVids = dict.fromkeys([0x1366])
27+
"""Some devices such as a seger jlink or st-link we never want to accidentally open"""
28+
blacklistVids = dict.fromkeys([0x1366, 0x0483])
29+
30+
"""Some devices are highly likely to be meshtastic.
31+
0x239a RAK4631
32+
0x303a Heltec tracker"""
33+
whitelistVids = dict.fromkeys([0x239a, 0x303a])
34+
2935

3036
def quoteBooleans(a_string):
3137
"""Quote booleans
@@ -130,19 +136,35 @@ def findPorts(eliminate_duplicates: bool=False) -> List[str]:
130136
Returns:
131137
list -- a list of device paths
132138
"""
133-
l = list(
139+
all_ports = serial.tools.list_ports.comports()
140+
141+
# look for 'likely' meshtastic devices
142+
ports = list(
134143
map(
135144
lambda port: port.device,
136145
filter(
137-
lambda port: port.vid is not None and port.vid not in blacklistVids,
138-
serial.tools.list_ports.comports(),
146+
lambda port: port.vid is not None and port.vid in whitelistVids,
147+
all_ports,
139148
),
140149
)
141150
)
142-
l.sort()
151+
152+
# if no likely devices, just list everything not blacklisted
153+
if len(ports) == 0:
154+
ports = list(
155+
map(
156+
lambda port: port.device,
157+
filter(
158+
lambda port: port.vid is not None and port.vid not in blacklistVids,
159+
all_ports,
160+
),
161+
)
162+
)
163+
164+
ports.sort()
143165
if eliminate_duplicates:
144-
l = eliminate_duplicate_port(l)
145-
return l
166+
ports = eliminate_duplicate_port(ports)
167+
return ports
146168

147169

148170
class dotdict(dict):

0 commit comments

Comments
 (0)