From de08126cee5da8abf10e60f9f42fdd308ff37c86 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 10 Feb 2021 15:41:14 +0800 Subject: [PATCH] 1.1.45 update --test --- docs/meshtastic/test.html | 95 +++++++++++++++++++++------------------ meshtastic/test.py | 5 ++- setup.py | 2 +- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/docs/meshtastic/test.html b/docs/meshtastic/test.html index 10e6833..25bd594 100644 --- a/docs/meshtastic/test.html +++ b/docs/meshtastic/test.html @@ -45,16 +45,19 @@ testsRunning = False testNumber = 0 +sendingInterface = None def onReceive(packet, interface): """Callback invoked when a packet arrives""" - print(f"From {interface.devPath}: {packet}") - p = DotMap(packet) - - if p.decoded.data.typ == "CLEAR_TEXT": - # We only care a about clear text packets - receivedPackets.append(p) + if sendingInterface == interface: + print("Ignoring sending interface") + else: + print(f"From {interface.stream.port}: {packet}") + p = DotMap(packet) + if p.decoded.data.portnum == "TEXT_MESSAGE_APP": + # We only care a about clear text packets + receivedPackets.append(p) def onNode(node): """Callback invoked when the node DB changes""" @@ -88,14 +91,19 @@ def testSend(fromInterface, toInterface, isBroadcast=False, asBinary=False): toNode = toInterface.myInfo.my_node_num logging.info(f"Sending test packet from {fromNode} to {toNode}") - wantAck = True + wantAck = False # Don't want any sort of reliaible sending + global sendingInterface + sendingInterface = fromInterface if not asBinary: fromInterface.sendText(f"Test {testNumber}", toNode, wantAck=wantAck) else: fromInterface.sendData((f"Binary {testNumber}").encode( "utf-8"), toNode, wantAck=wantAck) - time.sleep(45) - return (len(receivedPackets) >= 1) + for sec in range(45): # max of 45 secs before we timeout + time.sleep(1) + if (len(receivedPackets) >= 1): + return True + return False # Failed to send def testThread(numTests=50): @@ -106,8 +114,9 @@ def testThread(numTests=50): global testNumber testNumber = testNumber + 1 isBroadcast = True + # asBinary=(i % 2 == 0) success = testSend( - interfaces[0], interfaces[1], isBroadcast, asBinary=(i % 2 == 0)) + interfaces[0], interfaces[1], isBroadcast, asBinary = False) if not success: numFail = numFail + 1 logging.error( @@ -128,20 +137,11 @@ def onConnection(topic=pub.AUTO_TOPIC): """Callback invoked when we connect/disconnect from a radio""" print(f"Connection changed: {topic.getName()}") - global testsRunning - global interfaces - if (all(iface.isConnected for iface in interfaces) and not testsRunning): - testsRunning = True - t = threading.Thread(target=testThread, args=()) - t.start() - - def openDebugLog(portName): debugname = "log" + portName.replace("/", "_") logging.info(f"Writing serial debugging to {debugname}") return open(debugname, 'w+', buffering=1) - def testAll(): """ Run a series of tests using devices we can find. @@ -157,11 +157,14 @@ def testAll(): pub.subscribe(onReceive, "meshtastic.receive") global interfaces interfaces = list(map(lambda port: SerialInterface( - port, debugOut=openDebugLog(port), connectNow=False), ports)) - for i in interfaces: - i.connect() + port, debugOut=openDebugLog(port), connectNow=True), ports)) - logging.info("Ports opened, waiting for device to complete connection") + logging.info("Ports opened, starting test") + testThread() + + for i in interfaces: + i.close() +
@@ -189,14 +192,7 @@ def testAll():
def onConnection(topic=pub.AUTO_TOPIC):
     """Callback invoked when we connect/disconnect from a radio"""
-    print(f"Connection changed: {topic.getName()}")
-
-    global testsRunning
-    global interfaces
-    if (all(iface.isConnected for iface in interfaces) and not testsRunning):
-        testsRunning = True
-        t = threading.Thread(target=testThread, args=())
-        t.start()
+ print(f"Connection changed: {topic.getName()}")
@@ -224,12 +220,15 @@ def testAll():
def onReceive(packet, interface):
     """Callback invoked when a packet arrives"""
-    print(f"From {interface.devPath}: {packet}")
-    p = DotMap(packet)
+    if sendingInterface == interface:
+        print("Ignoring sending interface")
+    else:
+        print(f"From {interface.stream.port}: {packet}")
+        p = DotMap(packet)
 
-    if p.decoded.data.typ == "CLEAR_TEXT":
-        # We only care a about clear text packets
-        receivedPackets.append(p)
+ if p.decoded.data.portnum == "TEXT_MESSAGE_APP": + # We only care a about clear text packets + receivedPackets.append(p)
@@ -291,11 +290,13 @@ def testAll(): pub.subscribe(onReceive, "meshtastic.receive") global interfaces interfaces = list(map(lambda port: SerialInterface( - port, debugOut=openDebugLog(port), connectNow=False), ports)) - for i in interfaces: - i.connect() + port, debugOut=openDebugLog(port), connectNow=True), ports)) - logging.info("Ports opened, waiting for device to complete connection") + logging.info("Ports opened, starting test") + testThread() + + for i in interfaces: + i.close()
@@ -333,14 +334,19 @@ toInterface {[type]} – [description]

toNode = toInterface.myInfo.my_node_num logging.info(f"Sending test packet from {fromNode} to {toNode}") - wantAck = True + wantAck = False # Don't want any sort of reliaible sending + global sendingInterface + sendingInterface = fromInterface if not asBinary: fromInterface.sendText(f"Test {testNumber}", toNode, wantAck=wantAck) else: fromInterface.sendData((f"Binary {testNumber}").encode( "utf-8"), toNode, wantAck=wantAck) - time.sleep(45) - return (len(receivedPackets) >= 1)
+ for sec in range(45): # max of 45 secs before we timeout + time.sleep(1) + if (len(receivedPackets) >= 1): + return True + return False # Failed to send
@@ -360,8 +366,9 @@ toInterface {[type]} – [description]

global testNumber testNumber = testNumber + 1 isBroadcast = True + # asBinary=(i % 2 == 0) success = testSend( - interfaces[0], interfaces[1], isBroadcast, asBinary=(i % 2 == 0)) + interfaces[0], interfaces[1], isBroadcast, asBinary = False) if not success: numFail = numFail + 1 logging.error( diff --git a/meshtastic/test.py b/meshtastic/test.py index 43e3aeb..142d56f 100644 --- a/meshtastic/test.py +++ b/meshtastic/test.py @@ -114,7 +114,6 @@ def openDebugLog(portName): logging.info(f"Writing serial debugging to {debugname}") return open(debugname, 'w+', buffering=1) - def testAll(): """ Run a series of tests using devices we can find. @@ -134,3 +133,7 @@ def testAll(): logging.info("Ports opened, starting test") testThread() + + for i in interfaces: + i.close() + diff --git a/setup.py b/setup.py index 54cf04d..7f01ed4 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.44", + version="1.1.45", description="Python API & client shell for talking to Meshtastic devices", long_description=long_description, long_description_content_type="text/markdown",