From 21d3fd338591034b9a068d4dec192a022a0c2188 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sat, 8 Jun 2024 21:59:31 +0200 Subject: [PATCH 1/2] Add logging for Sunnylink offline issue The code updates include error logging for debugging when Sunnylink goes offline. Log includes information such as the last ping time and the current time to better understand the cause of possible issues. This logging will aid in resolving status discrepancies with the Sunnylink feature. --- selfdrive/ui/qt/sidebar.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index df9ebc45c0..171058b48f 100644 --- a/selfdrive/ui/qt/sidebar.cc +++ b/selfdrive/ui/qt/sidebar.cc @@ -3,6 +3,7 @@ #include #include +#include #include "selfdrive/ui/qt/util.h" #include "common/params.h" @@ -156,16 +157,21 @@ void Sidebar::updateState(const UIState &s) { ItemStatus sunnylinkStatus; auto last_sunnylink_ping = std::strtol(params.get("LastSunnylinkPingTime").c_str(), nullptr, 10); + auto current_nanos = nanos_since_boot(); + auto elapsed_sunnylink_ping = current_nanos - last_sunnylink_ping; auto sunnylink_enabled = params.getBool("SunnylinkEnabled"); if (!sunnylink_enabled) { sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("DISABLED")}, disabled_color}; - } else if (last_ping == 0) { + } else if (last_sunnylink_ping == 0) { sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("OFFLINE")}, warning_color}; } else { - if (nanos_since_boot() - last_sunnylink_ping < 80e9) + if (static_cast(elapsed_sunnylink_ping) < 80e9) { sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("ONLINE")}, good_color}; - else + } + else { + LOGE("Sunnylink is offline, last ping: [%ld]. Current time: [%ld], diff: [%ld]", last_sunnylink_ping, current_nanos, elapsed_sunnylink_ping); sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("ERROR")}, danger_color}; + } } setProperty("sunnylinkStatus", QVariant::fromValue(sunnylinkStatus)); } From 609b2d8a2134140513b1aa870cd8a7eb37da6839 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sun, 9 Jun 2024 10:32:02 +0200 Subject: [PATCH 2/2] 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 {