From 609b2d8a2134140513b1aa870cd8a7eb37da6839 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sun, 9 Jun 2024 10:32:02 +0200 Subject: [PATCH] Refactor sunnylink code for logs and ping timeouts The sunnylink ping and log statements have been refactored for clarity and optimization. Log levels were changed from debug to info, resulting in more visibility for important processes in sunnylinkd.py. The timeout before re-pinging in ws_ping() was also updated from 80% to 70% to ensure more consistent connections. --- selfdrive/athena/sunnylinkd.py | 8 ++++---- selfdrive/ui/qt/sidebar.cc | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/selfdrive/athena/sunnylinkd.py b/selfdrive/athena/sunnylinkd.py index 9c26dd42a1..1b993a534b 100755 --- a/selfdrive/athena/sunnylinkd.py +++ b/selfdrive/athena/sunnylinkd.py @@ -55,7 +55,7 @@ def handle_long_poll(ws: WebSocket, exit_event: threading.Event | None) -> None: raise finally: for thread in threads: - cloudlog.debug(f"athena.joining {thread.name}") + cloudlog.info(f"sunnylinkd athena.joining {thread.name}") thread.join() @@ -70,7 +70,7 @@ def ws_recv(ws: WebSocket, end_event: threading.Event) -> None: recv_queue.put_nowait(data) cloudlog.debug(f"sunnylinkd.ws_recv.recv {data}") elif opcode in (ABNF.OPCODE_PING, ABNF.OPCODE_PONG): - cloudlog.debug(f"sunnylinkd.ws_recv.pong {opcode}") + cloudlog.info(f"sunnylinkd.ws_recv.pong {opcode}") last_ping = int(time.monotonic() * 1e9) Params().put("LastSunnylinkPingTime", str(last_ping)) except WebSocketTimeoutException: @@ -88,11 +88,11 @@ def ws_ping(ws: WebSocket, end_event: threading.Event) -> None: while not end_event.is_set(): try: ws.ping() - cloudlog.debug(f"sunnylinkd.ws_recv.ws_ping: Pinging") + cloudlog.info(f"sunnylinkd.ws_recv.ws_ping: Pinging") except Exception: cloudlog.exception("sunnylinkd.ws_ping.exception") end_event.set() - time.sleep(RECONNECT_TIMEOUT_S * 0.8) # Sleep about 80% before a timeout + time.sleep(RECONNECT_TIMEOUT_S * 0.7) # Sleep about 70% before a timeout def ws_queue(end_event: threading.Event) -> None: resume_requested = False diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index 171058b48f..bc7a236b8b 100644 --- a/selfdrive/ui/qt/sidebar.cc +++ b/selfdrive/ui/qt/sidebar.cc @@ -156,7 +156,7 @@ void Sidebar::updateState(const UIState &s) { setProperty("pandaStatus", QVariant::fromValue(pandaStatus)); ItemStatus sunnylinkStatus; - auto last_sunnylink_ping = std::strtol(params.get("LastSunnylinkPingTime").c_str(), nullptr, 10); + auto last_sunnylink_ping = std::stoull(params.get("LastSunnylinkPingTime")); auto current_nanos = nanos_since_boot(); auto elapsed_sunnylink_ping = current_nanos - last_sunnylink_ping; auto sunnylink_enabled = params.getBool("SunnylinkEnabled"); @@ -165,7 +165,7 @@ void Sidebar::updateState(const UIState &s) { } else if (last_sunnylink_ping == 0) { sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("OFFLINE")}, warning_color}; } else { - if (static_cast(elapsed_sunnylink_ping) < 80e9) { + if (elapsed_sunnylink_ping < 80000000000ULL) { sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("ONLINE")}, good_color}; } else {