Skip to content

Commit dcd077d

Browse files
authored
Merge pull request #839 from horrible-knots/master
Plumb timeout from --timeout through MeshInterface
2 parents 7554c03 + 2de7c30 commit dcd077d

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

meshtastic/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ def common():
13641364
debugOut=logfile,
13651365
noProto=args.noproto,
13661366
noNodes=args.no_nodes,
1367+
timeout=args.timeout,
13671368
)
13681369
elif args.host:
13691370
try:
@@ -1378,6 +1379,7 @@ def common():
13781379
debugOut=logfile,
13791380
noProto=args.noproto,
13801381
noNodes=args.no_nodes,
1382+
timeout=args.timeout,
13811383
)
13821384
except Exception as ex:
13831385
meshtastic.util.our_exit(f"Error connecting to {args.host}:{ex}", 1)
@@ -1388,6 +1390,7 @@ def common():
13881390
debugOut=logfile,
13891391
noProto=args.noproto,
13901392
noNodes=args.no_nodes,
1393+
timeout=args.timeout,
13911394
)
13921395
except FileNotFoundError:
13931396
# Handle the case where the serial device is not found
@@ -1425,6 +1428,7 @@ def common():
14251428
debugOut=logfile,
14261429
noProto=args.noproto,
14271430
noNodes=args.no_nodes,
1431+
timeout=args.timeout,
14281432
)
14291433
except Exception as ex:
14301434
meshtastic.util.our_exit(

meshtastic/ble_interface.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ class BLEInterface(MeshInterface):
3232
class BLEError(Exception):
3333
"""An exception class for BLE errors."""
3434

35-
def __init__(
35+
def __init__( # pylint: disable=R0917
3636
self,
3737
address: Optional[str],
3838
noProto: bool = False,
3939
debugOut: Optional[io.TextIOWrapper]=None,
4040
noNodes: bool = False,
41+
timeout: int = 300,
4142
) -> None:
4243
MeshInterface.__init__(
43-
self, debugOut=debugOut, noProto=noProto, noNodes=noNodes
44+
self, debugOut=debugOut, noProto=noProto, noNodes=noNodes, timeout=timeout
4445
)
4546

4647
self.should_read = False

meshtastic/mesh_interface.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(self, message):
9090
super().__init__(self.message)
9191

9292
def __init__(
93-
self, debugOut=None, noProto: bool = False, noNodes: bool = False
93+
self, debugOut=None, noProto: bool = False, noNodes: bool = False, timeout: int = 300
9494
) -> None:
9595
"""Constructor
9696
@@ -99,13 +99,14 @@ def __init__(
9999
link - just be a dumb serial client.
100100
noNodes -- If True, instruct the node to not send its nodedb
101101
on startup, just other configuration information.
102+
timeout -- How long to wait for replies (default: 300 seconds)
102103
"""
103104
self.debugOut = debugOut
104105
self.nodes: Optional[Dict[str, Dict]] = None # FIXME
105106
self.isConnected: threading.Event = threading.Event()
106107
self.noProto: bool = noProto
107108
self.localNode: meshtastic.node.Node = meshtastic.node.Node(
108-
self, -1
109+
self, -1, timeout=timeout
109110
) # We fixup nodenum later
110111
self.myInfo: Optional[
111112
mesh_pb2.MyNodeInfo
@@ -119,7 +120,7 @@ def __init__(
119120
self.failure = (
120121
None # If we've encountered a fatal exception it will be kept here
121122
)
122-
self._timeout: Timeout = Timeout()
123+
self._timeout: Timeout = Timeout(maxSecs=timeout)
123124
self._acknowledgment: Acknowledgment = Acknowledgment()
124125
self.heartbeatTimer: Optional[threading.Timer] = None
125126
random.seed() # FIXME, we should not clobber the random seedval here, instead tell user they must call it

meshtastic/serial_interface.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@
1818
class SerialInterface(StreamInterface):
1919
"""Interface class for meshtastic devices over a serial link"""
2020

21-
def __init__(self, devPath: Optional[str]=None, debugOut=None, noProto: bool=False, connectNow: bool=True, noNodes: bool=False) -> None:
21+
def __init__(
22+
self,
23+
devPath: Optional[str] = None,
24+
debugOut=None,
25+
noProto: bool = False,
26+
connectNow: bool = True,
27+
noNodes: bool = False,
28+
timeout: int = 300
29+
) -> None:
2230
"""Constructor, opens a connection to a specified serial port, or if unspecified try to
2331
find one Meshtastic device by probing
2432
2533
Keyword Arguments:
2634
devPath {string} -- A filepath to a device, i.e. /dev/ttyUSB0 (default: {None})
2735
debugOut {stream} -- If a stream is provided, any debug serial output from the device will be emitted to that stream. (default: {None})
36+
timeout -- How long to wait for replies (default: 300 seconds)
2837
"""
2938
self.noProto = noProto
3039

@@ -57,7 +66,7 @@ def __init__(self, devPath: Optional[str]=None, debugOut=None, noProto: bool=Fal
5766
time.sleep(0.1)
5867

5968
StreamInterface.__init__(
60-
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes
69+
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes, timeout=timeout
6170
)
6271

6372
def _set_hupcl_with_termios(self, f: TextIOWrapper):

meshtastic/stream_interface.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@
2323
class StreamInterface(MeshInterface):
2424
"""Interface class for meshtastic devices over a stream link (serial, TCP, etc)"""
2525

26-
def __init__(self, debugOut: Optional[io.TextIOWrapper]=None, noProto: bool=False, connectNow: bool=True, noNodes: bool=False) -> None:
26+
def __init__( # pylint: disable=R0917
27+
self,
28+
debugOut: Optional[io.TextIOWrapper] = None,
29+
noProto: bool = False,
30+
connectNow: bool = True,
31+
noNodes: bool = False,
32+
timeout: int = 300
33+
) -> None:
2734
"""Constructor, opens a connection to self.stream
2835
2936
Keyword Arguments:
3037
debugOut {stream} -- If a stream is provided, any debug serial output from the
3138
device will be emitted to that stream. (default: {None})
39+
timeout -- How long to wait for replies (default: 300 seconds)
3240
3341
Raises:
3442
Exception: [description]
@@ -49,7 +57,7 @@ def __init__(self, debugOut: Optional[io.TextIOWrapper]=None, noProto: bool=Fals
4957
# FIXME, figure out why daemon=True causes reader thread to exit too early
5058
self._rxThread = threading.Thread(target=self.__reader, args=(), daemon=True, name="stream reader")
5159

52-
MeshInterface.__init__(self, debugOut=debugOut, noProto=noProto, noNodes=noNodes)
60+
MeshInterface.__init__(self, debugOut=debugOut, noProto=noProto, noNodes=noNodes, timeout=timeout)
5361

5462
# Start the reader thread after superclass constructor completes init
5563
if connectNow:

meshtastic/tcp_interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ def __init__(
2323
connectNow: bool=True,
2424
portNumber: int=DEFAULT_TCP_PORT,
2525
noNodes:bool=False,
26+
timeout: int = 300,
2627
):
2728
"""Constructor, opens a connection to a specified IP address/hostname
2829
2930
Keyword Arguments:
3031
hostname {string} -- Hostname/IP address of the device to connect to
32+
timeout -- How long to wait for replies (default: 300 seconds)
3133
"""
3234

3335
self.stream = None
@@ -42,7 +44,7 @@ def __init__(
4244
else:
4345
self.socket = None
4446

45-
super().__init__(debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes)
47+
super().__init__(debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes, timeout=timeout)
4648

4749
def __repr__(self):
4850
rep = f"TCPInterface({self.hostname!r}"

0 commit comments

Comments
 (0)