mirror of
https://github.com/meshtastic/python.git
synced 2025-12-30 11:27:53 -05:00
1.1.45 update --test
This commit is contained in:
@@ -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")</code></pre>
|
||||
logging.info("Ports opened, starting test")
|
||||
testThread()
|
||||
|
||||
for i in interfaces:
|
||||
i.close()
|
||||
</code></pre>
|
||||
</details>
|
||||
</section>
|
||||
<section>
|
||||
@@ -189,14 +192,7 @@ def testAll():
|
||||
</summary>
|
||||
<pre><code class="python">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()</code></pre>
|
||||
print(f"Connection changed: {topic.getName()}")</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.test.onNode"><code class="name flex">
|
||||
@@ -224,12 +220,15 @@ def testAll():
|
||||
</summary>
|
||||
<pre><code class="python">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)</code></pre>
|
||||
if p.decoded.data.portnum == "TEXT_MESSAGE_APP":
|
||||
# We only care a about clear text packets
|
||||
receivedPackets.append(p)</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.test.openDebugLog"><code class="name flex">
|
||||
@@ -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")</code></pre>
|
||||
logging.info("Ports opened, starting test")
|
||||
testThread()
|
||||
|
||||
for i in interfaces:
|
||||
i.close()</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.test.testSend"><code class="name flex">
|
||||
@@ -333,14 +334,19 @@ toInterface {[type]} – [description]</p>
|
||||
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)</code></pre>
|
||||
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>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.test.testThread"><code class="name flex">
|
||||
@@ -360,8 +366,9 @@ toInterface {[type]} – [description]</p>
|
||||
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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
2
setup.py
2
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",
|
||||
|
||||
Reference in New Issue
Block a user