From df91d5648313df260430aef6aba62743433000f7 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 25 Mar 2021 10:03:05 +0800 Subject: [PATCH] 1.2.15 --- docs/meshtastic/index.html | 80 +++++++++++++++++++++++------------ docs/meshtastic/mesh_pb2.html | 33 +++++++++++---- setup.py | 2 +- 3 files changed, 78 insertions(+), 37 deletions(-) diff --git a/docs/meshtastic/index.html b/docs/meshtastic/index.html index 74b82f5..02f1614 100644 --- a/docs/meshtastic/index.html +++ b/docs/meshtastic/index.html @@ -536,6 +536,10 @@ class MeshInterface: self.currentPacketId = random.randint(0, 0xffffffff) self._startConfig() + def close(self): + """Shutdown this interface""" + self._sendDisconnect() + def __enter__(self): return self @@ -743,7 +747,7 @@ class MeshInterface: def _waitConnected(self): """Block until the initial node db download is complete, or timeout and raise an exception""" - if not self.isConnected.wait(5.0): # timeout after 5 seconds + if not self.isConnected.wait(10.0): # timeout after 10 seconds raise Exception("Timed out waiting for connection completion") # If we failed while connecting, raise the connection to the client @@ -786,6 +790,12 @@ class MeshInterface: startConfig.want_config_id = self.configId self._sendToRadio(startConfig) + def _sendDisconnect(self): + """Tell device we are done using it""" + m = mesh_pb2.ToRadio() + m.disconnect = True + self._sendToRadio(m) + def _sendToRadio(self, toRadio): """Send a ToRadio protobuf to the device""" if self.noProto: @@ -1030,6 +1040,7 @@ class BLEInterface(MeshInterface): self.device.char_write(TORADIO_UUID, b) def close(self): + MeshInterface.close(self) self.adapter.stop() def _readFromRadio(self): @@ -1094,11 +1105,13 @@ class StreamInterface(MeshInterface): logging.debug("Closing our port") if not self.stream is None: self.stream.close() + self.stream = None def _writeBytes(self, b): """Write an array of bytes to our stream and flush""" - self.stream.write(b) - self.stream.flush() + if self.stream: # ignore writes when stream is closed + self.stream.write(b) + self.stream.flush() def _readBytes(self, len): """Read an array of bytes from our stream""" @@ -1116,6 +1129,7 @@ class StreamInterface(MeshInterface): def close(self): """Close a connection to the device""" logging.debug("Closing stream") + MeshInterface.close(self) # pyserial cancel_read doesn't seem to work, therefore we ask the reader thread to close things for us self._wantExit = True if self._rxThread != threading.current_thread(): @@ -1254,13 +1268,13 @@ class TCPInterface(StreamInterface): def close(self): """Close a connection to the device""" logging.debug("Closing TCP stream") + StreamInterface.close(self) # Sometimes the socket read might be blocked in the reader thread. Therefore we force the shutdown by closing # the socket here self._wantExit = True if not self.socket is None: self.socket.shutdown(socket.SHUT_RDWR) self.socket.close() - StreamInterface.close(self) def _writeBytes(self, b): """Write an array of bytes to our stream and flush""" @@ -1488,6 +1502,7 @@ noProto – If True, don't try to run our protocol on the link - just be a d self.device.char_write(TORADIO_UUID, b) def close(self): + MeshInterface.close(self) self.adapter.stop() def _readFromRadio(self): @@ -1502,26 +1517,11 @@ noProto – If True, don't try to run our protocol on the link - just be a d -

Methods

-
-
-def close(self) -
-
-
-
- -Expand source code - -
def close(self):
-    self.adapter.stop()
-
-
-

Inherited members