From 9a78840e539171e008c293c79564ab225bdd68c4 Mon Sep 17 00:00:00 2001 From: "Mr.one" Date: Sat, 30 May 2026 13:38:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91c3=5Fclient.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selfdrive/c3_client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/selfdrive/c3_client.py b/selfdrive/c3_client.py index 64966656..7a02a2d8 100755 --- a/selfdrive/c3_client.py +++ b/selfdrive/c3_client.py @@ -365,6 +365,7 @@ async def handle_message(data, ws): result = await execute_tmux() elif msg_type == "ping": result = {"status": "ok", "output": "pong"} + else: result = {"status": "error", "output": f"未知指令类型: {msg_type}"} @@ -414,7 +415,19 @@ async def run(): while True: await asyncio.sleep(HEARTBEAT_INTERVAL) try: - await ws.send(json.dumps({"type": "heartbeat"})) + # 通过 panda ignition 判断 offroad(熄火且无 ignition = offroad) + offroad = True # 默认 offroad + try: + import subprocess + result = subprocess.run( + ["python3", "-c", "from panda import Panda; p=Panda(); h=p.health(); print('1' if not (h['ignition_line'] or h['ignition_can']) else '0')"], + capture_output=True, text=True, timeout=5 + ) + if result.returncode == 0: + offroad = result.stdout.strip() == "1" + except Exception: + offroad = True + await ws.send(json.dumps({"type": "heartbeat", "offroad": offroad})) except Exception: break