mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(terrain,ci): add lost-model GPS, GPX trace, inclinometer, throttle expo/crawl, relay ping, log rotation & release CI
This commit is contained in:
1 parent
c83f90570f
commit
9f0c64f873
20 files changed
+926
-78
No files matched your search
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tests unitaires pour le relais série <-> UDP Radxa Zero 3W (radxa_g29_relay.py)."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
import radxa_g29_relay as relay
|
||||
|
||||
|
||||
class TestRadxaG29Relay(unittest.TestCase):
|
||||
def test_is_allowed_peer(self) -> None:
|
||||
self.assertTrue(relay.is_allowed_peer("192.168.1.10", "192.168.1.10"))
|
||||
self.assertTrue(relay.is_allowed_peer("127.0.0.1", "192.168.1.10"))
|
||||
self.assertFalse(relay.is_allowed_peer("192.168.1.99", "192.168.1.10"))
|
||||
self.assertFalse(relay.is_allowed_peer("10.0.0.5", "192.168.1.10"))
|
||||
|
||||
def test_filter_inbound_blocks_cli_and_accepts_protocol(self) -> None:
|
||||
raw = (
|
||||
b"B\n"
|
||||
b"R\n"
|
||||
b"$HT,992,992,992*AB\n"
|
||||
b"$RC,992,1065,992,992,1,2*12\n"
|
||||
b"$SRC,EXT*34\n"
|
||||
b"$GEARS,1065,1100,1150,1220,905,800*56\n"
|
||||
b"$PING,42\n"
|
||||
b"DROP TABLE\n"
|
||||
)
|
||||
uart_lines, ping_lines = relay.filter_inbound_lines(raw)
|
||||
self.assertEqual(
|
||||
uart_lines,
|
||||
[
|
||||
b"$HT,992,992,992*AB\n",
|
||||
b"$RC,992,1065,992,992,1,2*12\n",
|
||||
b"$SRC,EXT*34\n",
|
||||
b"$GEARS,1065,1100,1150,1220,905,800*56\n",
|
||||
],
|
||||
)
|
||||
self.assertEqual(ping_lines, [b"$PING,42"])
|
||||
|
||||
def test_build_pong_reply(self) -> None:
|
||||
self.assertEqual(relay.build_pong_reply(b"$PING,123", True), b"$PONG,123,1\n")
|
||||
self.assertEqual(relay.build_pong_reply(b"$PING,7*FF", False), b"$PONG,7,0\n")
|
||||
self.assertIsNone(relay.build_pong_reply(b"$PING,abc", True))
|
||||
self.assertIsNone(relay.build_pong_reply(b"$HT,992,992,992", True))
|
||||
|
||||
def test_enqueue_tx_payload_drops_stale_on_overflow(self) -> None:
|
||||
buf = bytearray(b"A" * 10)
|
||||
relay.enqueue_tx_payload(buf, b"$HT,1,2,3\n", max_buf=15)
|
||||
self.assertEqual(bytes(buf), b"$HT,1,2,3\n")
|
||||
|
||||
def test_extract_outbound_serial_lines_filters_and_protects_oom(self) -> None:
|
||||
rx = bytearray(
|
||||
b"DEBUG boot ok\n"
|
||||
b"$G29,ARM=1,GEAR=2\n"
|
||||
b"$CRSF,C80A1400\n"
|
||||
b"$G29_EVT,CROSS\n"
|
||||
b"PARTIAL"
|
||||
)
|
||||
lines = relay.extract_outbound_serial_lines(rx)
|
||||
self.assertEqual(
|
||||
lines,
|
||||
[
|
||||
b"$G29,ARM=1,GEAR=2\n",
|
||||
b"$CRSF,C80A1400\n",
|
||||
b"$G29_EVT,CROSS\n",
|
||||
],
|
||||
)
|
||||
self.assertEqual(bytes(rx), b"PARTIAL")
|
||||
|
||||
# Anti-OOM sur bruit série sans \n
|
||||
noisy = bytearray(b"X" * 5000)
|
||||
self.assertEqual(relay.extract_outbound_serial_lines(noisy, max_buf=4096), [])
|
||||
self.assertEqual(len(noisy), 512)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user