From bf085ab1d41d725c7c6955be705e3e7e1deec42a Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 22 May 2020 11:04:31 -0700 Subject: [PATCH] doc updates --- docs/meshtastic/index.html | 35 ++++++++++++++++++++------------- docs/meshtastic/test.html | 40 +++++++++++++++++++++----------------- docs/meshtastic/util.html | 7 +++++-- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/docs/meshtastic/index.html b/docs/meshtastic/index.html index d7d8d53..15cf58e 100644 --- a/docs/meshtastic/index.html +++ b/docs/meshtastic/index.html @@ -158,7 +158,7 @@ class MeshInterface: self.isConnected = False self._startConfig() - def sendText(self, text, destinationId=BROADCAST_ADDR, wantAck=False): + def sendText(self, text, destinationId=BROADCAST_ADDR, wantAck=False, wantResponse=False): """Send a utf8 string to some other node, if the node has a display it will also be shown on the device. Arguments: @@ -168,13 +168,14 @@ class MeshInterface: destinationId {nodeId or nodeNum} -- where to send this message (default: {BROADCAST_ADDR}) """ self.sendData(text.encode("utf-8"), destinationId, - dataType=mesh_pb2.Data.CLEAR_TEXT, wantAck=wantAck) + dataType=mesh_pb2.Data.CLEAR_TEXT, wantAck=wantAck, wantResponse=wantResponse) - def sendData(self, byteData, destinationId=BROADCAST_ADDR, dataType=mesh_pb2.Data.OPAQUE, wantAck=False): + def sendData(self, byteData, destinationId=BROADCAST_ADDR, dataType=mesh_pb2.Data.OPAQUE, wantAck=False, wantResponse=False): """Send a data packet to some other node""" meshPacket = mesh_pb2.MeshPacket() meshPacket.decoded.data.payload = byteData meshPacket.decoded.data.typ = dataType + meshPacket.decoded.want_response = wantResponse self.sendPacket(meshPacket, destinationId, wantAck=wantAck) def sendPacket(self, meshPacket, destinationId=BROADCAST_ADDR, wantAck=False): @@ -245,7 +246,10 @@ class MeshInterface: self.radioConfig = fromRadio.radio elif fromRadio.HasField("node_info"): node = asDict["nodeInfo"] - self._fixupPosition(node["position"]) + try: + self._fixupPosition(node["position"]) + except: + logging.debug("Node without position") self._nodesByNum[node["num"]] = node self.nodes[node["user"]["id"]] = node elif fromRadio.config_complete_id == MY_CONFIG_ID: @@ -616,7 +620,7 @@ debugOut

self.isConnected = False self._startConfig() - def sendText(self, text, destinationId=BROADCAST_ADDR, wantAck=False): + def sendText(self, text, destinationId=BROADCAST_ADDR, wantAck=False, wantResponse=False): """Send a utf8 string to some other node, if the node has a display it will also be shown on the device. Arguments: @@ -626,13 +630,14 @@ debugOut

destinationId {nodeId or nodeNum} -- where to send this message (default: {BROADCAST_ADDR}) """ self.sendData(text.encode("utf-8"), destinationId, - dataType=mesh_pb2.Data.CLEAR_TEXT, wantAck=wantAck) + dataType=mesh_pb2.Data.CLEAR_TEXT, wantAck=wantAck, wantResponse=wantResponse) - def sendData(self, byteData, destinationId=BROADCAST_ADDR, dataType=mesh_pb2.Data.OPAQUE, wantAck=False): + def sendData(self, byteData, destinationId=BROADCAST_ADDR, dataType=mesh_pb2.Data.OPAQUE, wantAck=False, wantResponse=False): """Send a data packet to some other node""" meshPacket = mesh_pb2.MeshPacket() meshPacket.decoded.data.payload = byteData meshPacket.decoded.data.typ = dataType + meshPacket.decoded.want_response = wantResponse self.sendPacket(meshPacket, destinationId, wantAck=wantAck) def sendPacket(self, meshPacket, destinationId=BROADCAST_ADDR, wantAck=False): @@ -703,7 +708,10 @@ debugOut

self.radioConfig = fromRadio.radio elif fromRadio.HasField("node_info"): node = asDict["nodeInfo"] - self._fixupPosition(node["position"]) + try: + self._fixupPosition(node["position"]) + except: + logging.debug("Node without position") self._nodesByNum[node["num"]] = node self.nodes[node["user"]["id"]] = node elif fromRadio.config_complete_id == MY_CONFIG_ID: @@ -793,7 +801,7 @@ debugOut

Methods

-def sendData(self, byteData, destinationId='all', dataType=0, wantAck=False) +def sendData(self, byteData, destinationId='all', dataType=0, wantAck=False, wantResponse=False)

Send a data packet to some other node

@@ -801,11 +809,12 @@ debugOut

Expand source code -
def sendData(self, byteData, destinationId=BROADCAST_ADDR, dataType=mesh_pb2.Data.OPAQUE, wantAck=False):
+
def sendData(self, byteData, destinationId=BROADCAST_ADDR, dataType=mesh_pb2.Data.OPAQUE, wantAck=False, wantResponse=False):
     """Send a data packet to some other node"""
     meshPacket = mesh_pb2.MeshPacket()
     meshPacket.decoded.data.payload = byteData
     meshPacket.decoded.data.typ = dataType
+    meshPacket.decoded.want_response = wantResponse
     self.sendPacket(meshPacket, destinationId, wantAck=wantAck)
@@ -839,7 +848,7 @@ You probably don't want this - use sendData instead.

-def sendText(self, text, destinationId='all', wantAck=False) +def sendText(self, text, destinationId='all', wantAck=False, wantResponse=False)

Send a utf8 string to some other node, if the node has a display it will also be shown on the device.

@@ -851,7 +860,7 @@ destinationId {nodeId or nodeNum} – where to send this message (default: { Expand source code -
def sendText(self, text, destinationId=BROADCAST_ADDR, wantAck=False):
+
def sendText(self, text, destinationId=BROADCAST_ADDR, wantAck=False, wantResponse=False):
     """Send a utf8 string to some other node, if the node has a display it will also be shown on the device.
 
     Arguments:
@@ -861,7 +870,7 @@ destinationId {nodeId or nodeNum} – where to send this message (default: {
         destinationId {nodeId or nodeNum} -- where to send this message (default: {BROADCAST_ADDR})
     """
     self.sendData(text.encode("utf-8"), destinationId,
-                  dataType=mesh_pb2.Data.CLEAR_TEXT, wantAck=wantAck)
+ dataType=mesh_pb2.Data.CLEAR_TEXT, wantAck=wantAck, wantResponse=wantResponse)
diff --git a/docs/meshtastic/test.html b/docs/meshtastic/test.html index 1a06436..27a1b8f 100644 --- a/docs/meshtastic/test.html +++ b/docs/meshtastic/test.html @@ -65,7 +65,7 @@ def subscribe(): pub.subscribe(onNode, "meshtastic.node") -def testSend(fromInterface, toInterface): +def testSend(fromInterface, toInterface, isBroadcast=False): """ Sends one test packet between two nodes and then returns success or failure @@ -79,25 +79,27 @@ def testSend(fromInterface, toInterface): global receivedPackets receivedPackets = [] fromNode = fromInterface.myInfo.my_node_num - toNode = toInterface.myInfo.my_node_num - # FIXME, hack to test broadcast - # toNode = 255 + if isBroadcast: + toNode = 255 + else: + toNode = toInterface.myInfo.my_node_num logging.info(f"Sending test packet from {fromNode} to {toNode}") fromInterface.sendText(f"Test {testNumber}", toNode, wantAck=True) - time.sleep(30) + time.sleep(45) return (len(receivedPackets) >= 1) -def testThread(): +def testThread(numTests=50): logging.info("Found devices, starting tests...") numFail = 0 numSuccess = 0 - while True: + for i in range(numTests): global testNumber testNumber = testNumber + 1 - success = testSend(interfaces[0], interfaces[1]) + isBroadcast = True + success = testSend(interfaces[0], interfaces[1], isBroadcast) if not success: numFail = numFail + 1 logging.error( @@ -281,7 +283,7 @@ def testAll():
-def testSend(fromInterface, toInterface) +def testSend(fromInterface, toInterface, isBroadcast=False)

Sends one test packet between two nodes and then returns success or failure

@@ -297,7 +299,7 @@ toInterface {[type]} – [description]

Expand source code -
def testSend(fromInterface, toInterface):
+
def testSend(fromInterface, toInterface, isBroadcast=False):
     """
     Sends one test packet between two nodes and then returns success or failure
 
@@ -311,19 +313,20 @@ toInterface {[type]} – [description]

global receivedPackets receivedPackets = [] fromNode = fromInterface.myInfo.my_node_num - toNode = toInterface.myInfo.my_node_num - # FIXME, hack to test broadcast - # toNode = 255 + if isBroadcast: + toNode = 255 + else: + toNode = toInterface.myInfo.my_node_num logging.info(f"Sending test packet from {fromNode} to {toNode}") fromInterface.sendText(f"Test {testNumber}", toNode, wantAck=True) - time.sleep(30) + time.sleep(45) return (len(receivedPackets) >= 1)
-def testThread() +def testThread(numTests=50)
@@ -331,14 +334,15 @@ toInterface {[type]} – [description]

Expand source code -
def testThread():
+
def testThread(numTests=50):
     logging.info("Found devices, starting tests...")
     numFail = 0
     numSuccess = 0
-    while True:
+    for i in range(numTests):
         global testNumber
         testNumber = testNumber + 1
-        success = testSend(interfaces[0], interfaces[1])
+        isBroadcast = True
+        success = testSend(interfaces[0], interfaces[1], isBroadcast)
         if not success:
             numFail = numFail + 1
             logging.error(
diff --git a/docs/meshtastic/util.html b/docs/meshtastic/util.html
index 78fcc66..ad78c09 100644
--- a/docs/meshtastic/util.html
+++ b/docs/meshtastic/util.html
@@ -28,6 +28,9 @@
 import serial
 import serial.tools.list_ports
 
+"""Some devices such as a seger jlink we never want to accidentally open"""
+blacklistVids = dict.fromkeys([0x1366])
+
 
 def findPorts():
     """Find all ports that might have meshtastic devices
@@ -36,7 +39,7 @@ def findPorts():
         list -- a list of device paths
     """
     l = list(map(lambda port: port.device,
-                 filter(lambda port: port.vid != None,
+                 filter(lambda port: port.vid != None and port.vid not in blacklistVids,
                         serial.tools.list_ports.comports())))
     l.sort()
     return l
@@ -77,7 +80,7 @@ class dotdict(dict):
         list -- a list of device paths
     """
     l = list(map(lambda port: port.device,
-                 filter(lambda port: port.vid != None,
+                 filter(lambda port: port.vid != None and port.vid not in blacklistVids,
                         serial.tools.list_ports.comports())))
     l.sort()
     return l