From bd8e12e9c6a8b7a1b92cb5a881ad5bf0664f2e9a Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 16 Dec 2020 11:07:22 +0800 Subject: [PATCH] if --noproto is used, never send anything to the device --- meshtastic/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index 5a6e640..3a4e2ce 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -108,8 +108,7 @@ class MeshInterface: self.nodes = None # FIXME self.isConnected = threading.Event() self.noProto = noProto - if not noProto: - self._startConfig() + self._startConfig() def __enter__(self): return self @@ -345,6 +344,13 @@ class MeshInterface: self._sendToRadio(startConfig) def _sendToRadio(self, toRadio): + """Send a ToRadio protobuf to the device""" + if self.noProto: + logging.warn(f"Not sending packet because protocol use is disabled by noProto") + else: + self._sendToRadioImpl(toRadio) + + def _sendToRadioImpl(self, toRadio): """Send a ToRadio protobuf to the device""" logging.error(f"Subclass must provide toradio: {toRadio}") @@ -540,7 +546,7 @@ class BLEInterface(MeshInterface): self.device.subscribe(FROMNUM_UUID, callback=handle_data) - def _sendToRadio(self, toRadio): + def _sendToRadioImpl(self, toRadio): """Send a ToRadio protobuf to the device""" logging.debug(f"Sending: {toRadio}") b = toRadio.SerializeToString() @@ -620,7 +626,7 @@ class StreamInterface(MeshInterface): """Read an array of bytes from our stream""" return self.stream.read(len) - def _sendToRadio(self, toRadio): + def _sendToRadioImpl(self, toRadio): """Send a ToRadio protobuf to the device""" logging.debug(f"Sending: {toRadio}") b = toRadio.SerializeToString()