优化无线/有线CAN,以及控制指令解析

This commit is contained in:
minghanchen
2026-08-26 20:11:09 +08:00
parent 9ac8fdface
commit 4a0570706f
49 changed files with 8409 additions and 1289 deletions
+43 -1
View File
@@ -105,6 +105,17 @@ class Can1SemanticWhitelistTests(unittest.TestCase):
for temperature in (18, 32)
)
commands.extend(("ac control manual", "ac control auto"))
commands.extend(("ac cycle internal", "ac cycle external"))
commands.extend(
f"outlet {target} {state}"
for target in (
"driver-left",
"driver-right",
"passenger-left",
"passenger-right",
)
for state in ("open", "close")
)
commands.extend(
f"outlet {target} percent {horizontal} {vertical}"
for target in (
@@ -196,7 +207,7 @@ class Can1SemanticWhitelistTests(unittest.TestCase):
def test_every_documented_exact_command_parses_and_compiles(self) -> None:
commands = self._valid_exact_commands()
self.assertEqual(len(commands), 119)
self.assertEqual(len(commands), 129)
for command in commands:
with self.subTest(command=command):
@@ -223,6 +234,7 @@ class Can1SemanticWhitelistTests(unittest.TestCase):
"ac temp driver 33",
"ac temp driver 24.5",
"ac control off",
"outlet driver-left toggle",
"outlet driver-left percent -1 50",
"outlet driver-left percent 101 50",
"seat driver vent medium",
@@ -258,6 +270,32 @@ class Can1SemanticWhitelistTests(unittest.TestCase):
):
self.runtime.compile(config)
def test_individual_outlet_switches_use_observed_byte_exact_triplets(self) -> None:
cases = {
"outlet driver-left open": "02 FF FF FF FF 01 FF FF",
"outlet driver-left close": "02 FF FF FF FF 02 FF FF",
"outlet driver-right open": "02 FF FF FF FF 04 FF FF",
"outlet driver-right close": "02 FF FF FF FF 08 FF FF",
"outlet passenger-left open": "03 FF FF FF FF 01 00 00",
"outlet passenger-left close": "03 FF FF FF FF 02 00 00",
"outlet passenger-right open": "03 FF FF FF FF 04 00 00",
"outlet passenger-right close": "03 FF FF FF FF 08 00 00",
}
for command, expected_payload in cases.items():
with self.subTest(command=command):
plan = self._compile_exact(command)
compiled = plan["spec"]["commands"][0]
self.assertEqual(compiled["signals"]["frame_id"], "0x4EF")
self.assertEqual(compiled["signals"]["data_hex"], expected_payload)
self.assertTrue(compiled["signals"]["is_fd"])
self.assertTrue(compiled["signals"]["bitrate_switch"])
self.assertEqual(
compiled["repeat"], {"count": 3, "period_ms": 100}
)
self.assertEqual(
compiled["signals"]["feedback_ids"], "0x4BB,0x37B"
)
def test_representative_chinese_commands_cover_every_whitelist_family(self) -> None:
cases = (
("后排车门上锁", ["door rear lock"]),
@@ -281,6 +319,10 @@ class Can1SemanticWhitelistTests(unittest.TestCase):
("后排空调温度设为24度", ["ac temp rear 24"]),
("空调设置为自动控制", ["ac control auto"]),
("空调设置为手动控制", ["ac control manual"]),
("打开主驾左风口", ["outlet driver-left open"]),
("关闭主驾右风口", ["outlet driver-right close"]),
("打开副驾左吹面出风口", ["outlet passenger-left open"]),
("关闭副驾右吹面出风口", ["outlet passenger-right close"]),
("主驾左风口水平25%上下75%", ["outlet driver-left percent 25 75"]),
("副驾右风口左右25%垂直75%", ["outlet passenger-right percent 25 75"]),
("主驾左风口标定坐标左右-25上下-40", ["outlet driver-left position -25 -40"]),