mirror of
https://github.com/meshtastic/python.git
synced 2026-05-19 05:46:14 -04:00
1.2.0 release to pypi
This commit is contained in:
@@ -47,6 +47,7 @@ testNumber = 0
|
||||
|
||||
sendingInterface = None
|
||||
|
||||
|
||||
def onReceive(packet, interface):
|
||||
"""Callback invoked when a packet arrives"""
|
||||
if sendingInterface == interface:
|
||||
@@ -55,10 +56,11 @@ def onReceive(packet, interface):
|
||||
print(f"From {interface.stream.port}: {packet}")
|
||||
p = DotMap(packet)
|
||||
|
||||
if p.decoded.data.portnum == "TEXT_MESSAGE_APP":
|
||||
if p.decoded.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"""
|
||||
print(f"Node changed: {node}")
|
||||
@@ -91,7 +93,7 @@ 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 = False # Don't want any sort of reliaible sending
|
||||
wantAck = False # Don't want any sort of reliaible sending
|
||||
global sendingInterface
|
||||
sendingInterface = fromInterface
|
||||
if not asBinary:
|
||||
@@ -99,11 +101,11 @@ def testSend(fromInterface, toInterface, isBroadcast=False, asBinary=False):
|
||||
else:
|
||||
fromInterface.sendData((f"Binary {testNumber}").encode(
|
||||
"utf-8"), toNode, wantAck=wantAck)
|
||||
for sec in range(45): # max of 45 secs before we timeout
|
||||
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
|
||||
return False # Failed to send
|
||||
|
||||
|
||||
def testThread(numTests=50):
|
||||
@@ -116,14 +118,15 @@ def testThread(numTests=50):
|
||||
isBroadcast = True
|
||||
# asBinary=(i % 2 == 0)
|
||||
success = testSend(
|
||||
interfaces[0], interfaces[1], isBroadcast, asBinary = False)
|
||||
interfaces[0], interfaces[1], isBroadcast, asBinary=False)
|
||||
if not success:
|
||||
numFail = numFail + 1
|
||||
logging.error(
|
||||
f"Test failed, expected packet not received ({numFail} failures so far)")
|
||||
else:
|
||||
numSuccess = numSuccess + 1
|
||||
logging.info(f"Test succeeded ({numSuccess} successes ({numFail} failures) so far)")
|
||||
logging.info(
|
||||
f"Test succeeded ({numSuccess} successes ({numFail} failures) so far)")
|
||||
|
||||
if numFail >= 3:
|
||||
for i in interfaces:
|
||||
@@ -137,11 +140,13 @@ def onConnection(topic=pub.AUTO_TOPIC):
|
||||
"""Callback invoked when we connect/disconnect from a radio"""
|
||||
print(f"Connection changed: {topic.getName()}")
|
||||
|
||||
|
||||
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.
|
||||
@@ -163,8 +168,7 @@ def testAll():
|
||||
testThread()
|
||||
|
||||
for i in interfaces:
|
||||
i.close()
|
||||
</code></pre>
|
||||
i.close()</code></pre>
|
||||
</details>
|
||||
</section>
|
||||
<section>
|
||||
@@ -226,7 +230,7 @@ def testAll():
|
||||
print(f"From {interface.stream.port}: {packet}")
|
||||
p = DotMap(packet)
|
||||
|
||||
if p.decoded.data.portnum == "TEXT_MESSAGE_APP":
|
||||
if p.decoded.portnum == "TEXT_MESSAGE_APP":
|
||||
# We only care a about clear text packets
|
||||
receivedPackets.append(p)</code></pre>
|
||||
</details>
|
||||
@@ -334,7 +338,7 @@ toInterface {[type]} – [description]</p>
|
||||
toNode = toInterface.myInfo.my_node_num
|
||||
|
||||
logging.info(f"Sending test packet from {fromNode} to {toNode}")
|
||||
wantAck = False # Don't want any sort of reliaible sending
|
||||
wantAck = False # Don't want any sort of reliaible sending
|
||||
global sendingInterface
|
||||
sendingInterface = fromInterface
|
||||
if not asBinary:
|
||||
@@ -342,11 +346,11 @@ toInterface {[type]} – [description]</p>
|
||||
else:
|
||||
fromInterface.sendData((f"Binary {testNumber}").encode(
|
||||
"utf-8"), toNode, wantAck=wantAck)
|
||||
for sec in range(45): # max of 45 secs before we timeout
|
||||
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</code></pre>
|
||||
return False # Failed to send</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.test.testThread"><code class="name flex">
|
||||
@@ -368,14 +372,15 @@ toInterface {[type]} – [description]</p>
|
||||
isBroadcast = True
|
||||
# asBinary=(i % 2 == 0)
|
||||
success = testSend(
|
||||
interfaces[0], interfaces[1], isBroadcast, asBinary = False)
|
||||
interfaces[0], interfaces[1], isBroadcast, asBinary=False)
|
||||
if not success:
|
||||
numFail = numFail + 1
|
||||
logging.error(
|
||||
f"Test failed, expected packet not received ({numFail} failures so far)")
|
||||
else:
|
||||
numSuccess = numSuccess + 1
|
||||
logging.info(f"Test succeeded ({numSuccess} successes ({numFail} failures) so far)")
|
||||
logging.info(
|
||||
f"Test succeeded ({numSuccess} successes ({numFail} failures) so far)")
|
||||
|
||||
if numFail >= 3:
|
||||
for i in interfaces:
|
||||
|
||||
Reference in New Issue
Block a user