This commit is contained in:
Kevin Hester
2020-12-17 11:25:15 +08:00
parent 0079a725a2
commit 78bd9f4e92
2 changed files with 25 additions and 21 deletions

View File

@@ -194,8 +194,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
@@ -431,6 +430,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}")
@@ -626,7 +632,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()
@@ -706,7 +712,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()
@@ -795,7 +801,7 @@ class SerialInterface(StreamInterface):
raise Exception("No Meshtastic devices detected")
elif len(ports) > 1:
raise Exception(
f"Multiple ports detected, you must specify a device, such as {ports[0].device}")
f"Multiple ports detected, you must specify a device, such as {ports[0]}")
else:
devPath = ports[0]
@@ -811,8 +817,7 @@ class SerialInterface(StreamInterface):
# control and will always drive RTS either high or low (rather than letting the CP102 leave
# it as an open-collector floating pin). Since it is going to drive it anyways we want to make
# sure it is driven low, so that the TBEAM won't reset
if platform.system() != 'Linux':
self.stream.rts = False
self.stream.rts = False
self.stream.open()
StreamInterface.__init__(
@@ -821,9 +826,6 @@ class SerialInterface(StreamInterface):
def _disconnected(self):
"""We override the superclass implementation to close our port"""
if platform.system() != 'Linux':
self.stream.rts = True # Return RTS high, so that the reset button still works
StreamInterface._disconnected(self)
@@ -948,7 +950,7 @@ noProto – If True, don't try to run our protocol on the link - just be a d
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()
@@ -1039,8 +1041,7 @@ noProto – If True, don't try to run our protocol on the link - just be a d
self.nodes = None # FIXME
self.isConnected = threading.Event()
self.noProto = noProto
if not noProto:
self._startConfig()
self._startConfig()
def __enter__(self):
return self
@@ -1276,6 +1277,13 @@ noProto – If True, don't try to run our protocol on the link - just be a d
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}")
@@ -1812,7 +1820,7 @@ debugOut {stream} – If a stream is provided, any debug serial output from
raise Exception("No Meshtastic devices detected")
elif len(ports) > 1:
raise Exception(
f"Multiple ports detected, you must specify a device, such as {ports[0].device}")
f"Multiple ports detected, you must specify a device, such as {ports[0]}")
else:
devPath = ports[0]
@@ -1828,8 +1836,7 @@ debugOut {stream} – If a stream is provided, any debug serial output from
# control and will always drive RTS either high or low (rather than letting the CP102 leave
# it as an open-collector floating pin). Since it is going to drive it anyways we want to make
# sure it is driven low, so that the TBEAM won't reset
if platform.system() != 'Linux':
self.stream.rts = False
self.stream.rts = False
self.stream.open()
StreamInterface.__init__(
@@ -1838,9 +1845,6 @@ debugOut {stream} – If a stream is provided, any debug serial output from
def _disconnected(self):
"""We override the superclass implementation to close our port"""
if platform.system() != 'Linux':
self.stream.rts = True # Return RTS high, so that the reset button still works
StreamInterface._disconnected(self)</code></pre>
</details>
<h3>Ancestors</h3>
@@ -1950,7 +1954,7 @@ debugOut {stream} &ndash; If a stream is provided, any debug serial output from
&#34;&#34;&#34;Read an array of bytes from our stream&#34;&#34;&#34;
return self.stream.read(len)
def _sendToRadio(self, toRadio):
def _sendToRadioImpl(self, toRadio):
&#34;&#34;&#34;Send a ToRadio protobuf to the device&#34;&#34;&#34;
logging.debug(f&#34;Sending: {toRadio}&#34;)
b = toRadio.SerializeToString()

View File

@@ -12,7 +12,7 @@ with open("README.md", "r") as fh:
# This call to setup() does all the work
setup(
name="meshtastic",
version="1.1.24",
version="1.1.25",
description="Python API & client shell for talking to Meshtastic devices",
long_description=long_description,
long_description_content_type="text/markdown",