mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-24 22:52:05 +08:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<double>(elapsed_sunnylink_ping) < 80e9) {
|
||||
if (elapsed_sunnylink_ping < 80000000000ULL) {
|
||||
sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("ONLINE")}, good_color};
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user