From 86005c0ddada2226e2e54ea8ad0c66a63477eafe Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 14 Dec 2020 07:44:30 +0800 Subject: [PATCH] 1.1.23 fix #41 pyserial also drives usb control signals wrong on windows --- docs/meshtastic/index.html | 12 +++++----- docs/meshtastic/portnums_pb2.html | 14 +++++++---- docs/meshtastic/remote_hardware.html | 36 ++++++++++++++++++++++++++-- meshtastic/__init__.py | 8 +++---- setup.py | 2 +- 5 files changed, 54 insertions(+), 18 deletions(-) diff --git a/docs/meshtastic/index.html b/docs/meshtastic/index.html index 6a948e1..ce62664 100644 --- a/docs/meshtastic/index.html +++ b/docs/meshtastic/index.html @@ -806,11 +806,11 @@ class SerialInterface(StreamInterface): # rts=False Needed to prevent TBEAMs resetting on OSX, because rts is connected to reset self.stream.port = devPath - # OS-X seems to have a bug in its serial driver. It ignores that we asked for no RTSCTS + # OS-X/Windows seems to have a bug in its serial driver. It ignores that we asked for no RTSCTS # 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() == 'Darwin': + if platform.system() != 'Linux': self.stream.rts = False self.stream.open() @@ -820,7 +820,7 @@ class SerialInterface(StreamInterface): def _disconnected(self): """We override the superclass implementation to close our port""" - if platform.system() == 'Darwin': + if platform.system() != 'Linux': self.stream.rts = True # Return RTS high, so that the reset button still works StreamInterface._disconnected(self) @@ -1822,11 +1822,11 @@ debugOut {stream} – If a stream is provided, any debug serial output from # rts=False Needed to prevent TBEAMs resetting on OSX, because rts is connected to reset self.stream.port = devPath - # OS-X seems to have a bug in its serial driver. It ignores that we asked for no RTSCTS + # OS-X/Windows seems to have a bug in its serial driver. It ignores that we asked for no RTSCTS # 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() == 'Darwin': + if platform.system() != 'Linux': self.stream.rts = False self.stream.open() @@ -1836,7 +1836,7 @@ 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() == 'Darwin': + if platform.system() != 'Linux': self.stream.rts = True # Return RTS high, so that the reset button still works StreamInterface._disconnected(self) diff --git a/docs/meshtastic/portnums_pb2.html b/docs/meshtastic/portnums_pb2.html index 085d2d2..83474a1 100644 --- a/docs/meshtastic/portnums_pb2.html +++ b/docs/meshtastic/portnums_pb2.html @@ -49,7 +49,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( syntax='proto3', serialized_options=b'\n\023com.geeksville.meshB\010PortnumsH\003', create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\x0eportnums.proto*\x93\x01\n\x07PortNum\x12\x0f\n\x0bUNKNOWN_APP\x10\x00\x12\x14\n\x10TEXT_MESSAGE_APP\x10\x01\x12\x17\n\x13REMOTE_HARDWARE_APP\x10\x02\x12\x10\n\x0cPOSITION_APP\x10\x03\x12\x10\n\x0cNODEINFO_APP\x10\x04\x12\x10\n\x0bPRIVATE_APP\x10\x80\x02\x12\x12\n\rIP_TUNNEL_APP\x10\x80\x08\x42!\n\x13\x63om.geeksville.meshB\x08PortnumsH\x03\x62\x06proto3' + serialized_pb=b'\n\x0eportnums.proto*\xa2\x01\n\x07PortNum\x12\x0f\n\x0bUNKNOWN_APP\x10\x00\x12\x14\n\x10TEXT_MESSAGE_APP\x10\x01\x12\x17\n\x13REMOTE_HARDWARE_APP\x10\x02\x12\x10\n\x0cPOSITION_APP\x10\x03\x12\x10\n\x0cNODEINFO_APP\x10\x04\x12\r\n\tREPLY_APP\x10 \x12\x10\n\x0bPRIVATE_APP\x10\x80\x02\x12\x12\n\rIP_TUNNEL_APP\x10\x80\x08\x42!\n\x13\x63om.geeksville.meshB\x08PortnumsH\x03\x62\x06proto3' ) _PORTNUM = _descriptor.EnumDescriptor( @@ -85,12 +85,17 @@ _PORTNUM = _descriptor.EnumDescriptor( type=None, create_key=_descriptor._internal_create_key), _descriptor.EnumValueDescriptor( - name='PRIVATE_APP', index=5, number=256, + name='REPLY_APP', index=5, number=32, serialized_options=None, type=None, create_key=_descriptor._internal_create_key), _descriptor.EnumValueDescriptor( - name='IP_TUNNEL_APP', index=6, number=1024, + name='PRIVATE_APP', index=6, number=256, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='IP_TUNNEL_APP', index=7, number=1024, serialized_options=None, type=None, create_key=_descriptor._internal_create_key), @@ -98,7 +103,7 @@ _PORTNUM = _descriptor.EnumDescriptor( containing_type=None, serialized_options=None, serialized_start=19, - serialized_end=166, + serialized_end=181, ) _sym_db.RegisterEnumDescriptor(_PORTNUM) @@ -108,6 +113,7 @@ TEXT_MESSAGE_APP = 1 REMOTE_HARDWARE_APP = 2 POSITION_APP = 3 NODEINFO_APP = 4 +REPLY_APP = 32 PRIVATE_APP = 256 IP_TUNNEL_APP = 1024 diff --git a/docs/meshtastic/remote_hardware.html b/docs/meshtastic/remote_hardware.html index 63aa6fc..a0ffd0b 100644 --- a/docs/meshtastic/remote_hardware.html +++ b/docs/meshtastic/remote_hardware.html @@ -70,7 +70,14 @@ class RemoteHardwareClient: r = remote_hardware_pb2.HardwareMessage() r.typ = remote_hardware_pb2.HardwareMessage.Type.READ_GPIOS r.gpio_mask = mask - return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True) + return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True) + + def watchGPIOs(self, nodeid, mask): + """Watch the specified bits from GPIO inputs on the device for changes""" + r = remote_hardware_pb2.HardwareMessage() + r.typ = remote_hardware_pb2.HardwareMessage.Type.WATCH_GPIOS + r.gpio_mask = mask + return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True)
@@ -152,7 +159,14 @@ code for how you can connect to your own custom meshtastic services

r = remote_hardware_pb2.HardwareMessage() r.typ = remote_hardware_pb2.HardwareMessage.Type.READ_GPIOS r.gpio_mask = mask - return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True) + return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True) + + def watchGPIOs(self, nodeid, mask): + """Watch the specified bits from GPIO inputs on the device for changes""" + r = remote_hardware_pb2.HardwareMessage() + r.typ = remote_hardware_pb2.HardwareMessage.Type.WATCH_GPIOS + r.gpio_mask = mask + return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True)

Methods

@@ -173,6 +187,23 @@ code for how you can connect to your own custom meshtastic services

return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True) +
+def watchGPIOs(self, nodeid, mask) +
+
+

Watch the specified bits from GPIO inputs on the device for changes

+
+ +Expand source code + +
def watchGPIOs(self, nodeid, mask):
+    """Watch the specified bits from GPIO inputs on the device for changes"""
+    r = remote_hardware_pb2.HardwareMessage()
+    r.typ = remote_hardware_pb2.HardwareMessage.Type.WATCH_GPIOS
+    r.gpio_mask = mask
+    return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True)        
+
+
def writeGPIOs(self, nodeid, mask, vals)
@@ -223,6 +254,7 @@ are 1 will be changed

RemoteHardwareClient

diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index 0d2cd03..1cc8021 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -614,8 +614,6 @@ class StreamInterface(MeshInterface): """Write an array of bytes to our stream and flush""" self.stream.write(b) self.stream.flush() - while self.stream.out_waiting != 0: - time.sleep(0.1) # It seems that on windows flush might return before all bytes actually sent? def _readBytes(self, len): """Read an array of bytes from our stream""" @@ -722,11 +720,11 @@ class SerialInterface(StreamInterface): # rts=False Needed to prevent TBEAMs resetting on OSX, because rts is connected to reset self.stream.port = devPath - # OS-X seems to have a bug in its serial driver. It ignores that we asked for no RTSCTS + # OS-X/Windows seems to have a bug in its serial driver. It ignores that we asked for no RTSCTS # 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() == 'Darwin': + if platform.system() != 'Linux': self.stream.rts = False self.stream.open() @@ -736,7 +734,7 @@ class SerialInterface(StreamInterface): def _disconnected(self): """We override the superclass implementation to close our port""" - if platform.system() == 'Darwin': + if platform.system() != 'Linux': self.stream.rts = True # Return RTS high, so that the reset button still works StreamInterface._disconnected(self) diff --git a/setup.py b/setup.py index 2804b80..ccd131d 100644 --- a/setup.py +++ b/setup.py @@ -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.22", + version="1.1.23", description="Python API & client shell for talking to Meshtastic devices", long_description=long_description, long_description_content_type="text/markdown",