This commit is contained in:
geeksville
2020-08-11 18:19:54 -07:00
parent 0c9c8bca57
commit 848b52a437
3 changed files with 101 additions and 22 deletions

View File

@@ -65,7 +65,7 @@ def subscribe():
pub.subscribe(onNode, "meshtastic.node")
def testSend(fromInterface, toInterface, isBroadcast=False):
def testSend(fromInterface, toInterface, isBroadcast=False, asBinary=False):
"""
Sends one test packet between two nodes and then returns success or failure
@@ -86,7 +86,12 @@ def testSend(fromInterface, toInterface, isBroadcast=False):
toNode = toInterface.myInfo.my_node_num
logging.info(f"Sending test packet from {fromNode} to {toNode}")
fromInterface.sendText(f"Test {testNumber}", toNode, wantAck=True)
wantAck = True
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)
@@ -99,7 +104,8 @@ def testThread(numTests=50):
global testNumber
testNumber = testNumber + 1
isBroadcast = True
success = testSend(interfaces[0], interfaces[1], isBroadcast)
success = testSend(
interfaces[0], interfaces[1], isBroadcast, asBinary=(i % 2 == 0))
if not success:
numFail = numFail + 1
logging.error(
@@ -121,6 +127,7 @@ def onConnection(topic=pub.AUTO_TOPIC):
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=())
@@ -148,7 +155,10 @@ def testAll():
pub.subscribe(onReceive, "meshtastic.receive")
global interfaces
interfaces = list(map(lambda port: StreamInterface(
port, debugOut=openDebugLog(port)), ports))
port, debugOut=openDebugLog(port), connectNow=False), ports))
for i in interfaces:
i.connect()
logging.info(&#34;Ports opened, waiting for device to complete connection&#34;)</code></pre>
</details>
</section>
@@ -180,6 +190,7 @@ def testAll():
print(f&#34;Connection changed: {topic.getName()}&#34;)
global testsRunning
global interfaces
if (all(iface.isConnected for iface in interfaces) and not testsRunning):
testsRunning = True
t = threading.Thread(target=testThread, args=())
@@ -278,12 +289,15 @@ def testAll():
pub.subscribe(onReceive, &#34;meshtastic.receive&#34;)
global interfaces
interfaces = list(map(lambda port: StreamInterface(
port, debugOut=openDebugLog(port)), ports))
port, debugOut=openDebugLog(port), connectNow=False), ports))
for i in interfaces:
i.connect()
logging.info(&#34;Ports opened, waiting for device to complete connection&#34;)</code></pre>
</details>
</dd>
<dt id="meshtastic.test.testSend"><code class="name flex">
<span>def <span class="ident">testSend</span></span>(<span>fromInterface, toInterface, isBroadcast=False)</span>
<span>def <span class="ident">testSend</span></span>(<span>fromInterface, toInterface, isBroadcast=False, asBinary=False)</span>
</code></dt>
<dd>
<div class="desc"><p>Sends one test packet between two nodes and then returns success or failure</p>
@@ -299,7 +313,7 @@ toInterface {[type]} &ndash; [description]</p>
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def testSend(fromInterface, toInterface, isBroadcast=False):
<pre><code class="python">def testSend(fromInterface, toInterface, isBroadcast=False, asBinary=False):
&#34;&#34;&#34;
Sends one test packet between two nodes and then returns success or failure
@@ -320,7 +334,12 @@ toInterface {[type]} &ndash; [description]</p>
toNode = toInterface.myInfo.my_node_num
logging.info(f&#34;Sending test packet from {fromNode} to {toNode}&#34;)
fromInterface.sendText(f&#34;Test {testNumber}&#34;, toNode, wantAck=True)
wantAck = True
if not asBinary:
fromInterface.sendText(f&#34;Test {testNumber}&#34;, toNode, wantAck=wantAck)
else:
fromInterface.sendData((f&#34;Binary {testNumber}&#34;).encode(
&#34;utf-8&#34;), toNode, wantAck=wantAck)
time.sleep(45)
return (len(receivedPackets) &gt;= 1)</code></pre>
</details>
@@ -342,7 +361,8 @@ toInterface {[type]} &ndash; [description]</p>
global testNumber
testNumber = testNumber + 1
isBroadcast = True
success = testSend(interfaces[0], interfaces[1], isBroadcast)
success = testSend(
interfaces[0], interfaces[1], isBroadcast, asBinary=(i % 2 == 0))
if not success:
numFail = numFail + 1
logging.error(