mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-04 22:15:42 +08:00
Merge branch 'background-sunnylink-register' into master-dev-c3
This commit is contained in:
+1
-1
@@ -87,7 +87,7 @@ function launch {
|
||||
./build.py
|
||||
fi
|
||||
|
||||
./sunnylink.py; ./mapd_installer.py; ./manager.py
|
||||
./mapd_installer.py; ./manager.py
|
||||
|
||||
# if broken, keep on screen error
|
||||
while true; do sleep 1; done
|
||||
|
||||
@@ -45,10 +45,10 @@ SunnylinkPanel::SunnylinkPanel(QWidget* parent) : QFrame(parent) {
|
||||
sunnylinkEnabledBtn->setDescription(shame_description);
|
||||
}
|
||||
|
||||
auto dialog_text = tr("A reboot is required to") + " " + (enabled ? tr("start") : tr("stop")) +" "+ tr("all connections and processes from sunnylink.") + "<br/><small>"+ tr("If that's not a problem for you, you can ignore this.")+ "</small>";
|
||||
if (ConfirmationDialog::confirm(dialog_text, tr("Reboot Now!"), this)) {
|
||||
Hardware::reboot();
|
||||
}
|
||||
//auto dialog_text = tr("A reboot is required to") + " " + (enabled ? tr("start") : tr("stop")) +" "+ tr("all connections and processes from sunnylink.") + "<br/><small>"+ tr("If that's not a problem for you, you can ignore this.")+ "</small>";
|
||||
//if (ConfirmationDialog::confirm(dialog_text, tr("Reboot Now!"), this)) {
|
||||
// Hardware::reboot();
|
||||
//}
|
||||
updateLabels();
|
||||
});
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ void Sidebar::updateState(const UIState &s) {
|
||||
setProperty("pandaStatus", QVariant::fromValue(pandaStatus));
|
||||
|
||||
ItemStatus sunnylinkStatus;
|
||||
auto sl_dongle_id = getSunnylinkDongleId();
|
||||
auto last_sunnylink_ping_str = params.get("LastSunnylinkPingTime");
|
||||
auto last_sunnylink_ping = std::stoull(last_sunnylink_ping_str.empty() ? "0" : last_sunnylink_ping_str);
|
||||
auto current_nanos = nanos_since_boot();
|
||||
@@ -162,6 +163,8 @@ void Sidebar::updateState(const UIState &s) {
|
||||
auto sunnylink_enabled = params.getBool("SunnylinkEnabled");
|
||||
if (!sunnylink_enabled) {
|
||||
sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("DISABLED")}, disabled_color};
|
||||
} else if(!sl_dongle_id.has_value()) {
|
||||
sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("REGIST...")}, progress_color};
|
||||
} else if (last_sunnylink_ping == 0) {
|
||||
sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("OFFLINE")}, warning_color};
|
||||
} else {
|
||||
|
||||
@@ -52,6 +52,7 @@ protected:
|
||||
const QRect home_btn = QRect(60, 860, 180, 180);
|
||||
const QRect settings_btn = QRect(50, 35, 200, 117);
|
||||
const QColor good_color = QColor(255, 255, 255);
|
||||
const QColor progress_color = QColor(3, 132, 252);
|
||||
const QColor warning_color = QColor(218, 202, 37);
|
||||
const QColor danger_color = QColor(201, 34, 49);
|
||||
const QColor disabled_color = QColor(128, 128, 128);
|
||||
|
||||
@@ -18,7 +18,7 @@ def main():
|
||||
|
||||
def manage_athenad(dongle_id_param, pid_param, process_name, target):
|
||||
params = Params()
|
||||
dongle_id = params.get(dongle_id_param).decode('utf-8')
|
||||
dongle_id = params.get(dongle_id_param, encoding='utf-8')
|
||||
build_metadata = get_build_metadata()
|
||||
|
||||
cloudlog.bind_global(dongle_id=dongle_id,
|
||||
|
||||
@@ -8,6 +8,7 @@ import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
from openpilot.common.api.sunnylink import UNREGISTERED_SUNNYLINK_DONGLE_ID
|
||||
from openpilot.system.athena.athenad import ws_send, jsonrpc_handler, \
|
||||
recv_queue, UploadQueueCache, upload_queue, cur_upload_items, backoff, ws_manage, log_handler
|
||||
from jsonrpc import dispatcher
|
||||
@@ -52,6 +53,10 @@ def handle_long_poll(ws: WebSocket, exit_event: threading.Event | None) -> None:
|
||||
thread.start()
|
||||
try:
|
||||
while not end_event.wait(0.1):
|
||||
if not params.get_bool("SunnylinkEnabled"):
|
||||
cloudlog.warning("Exiting sunnylinkd.handle_long_poll as SunnylinkEnabled is False")
|
||||
break
|
||||
|
||||
sm.update(0)
|
||||
if exit_event is not None and exit_event.is_set():
|
||||
end_event.set()
|
||||
@@ -185,12 +190,16 @@ def main(exit_event: threading.Event = None):
|
||||
except Exception:
|
||||
cloudlog.exception("failed to set core affinity")
|
||||
|
||||
while params.get_bool("SunnylinkEnabled") and not params.get("SunnylinkDongleId", encoding='utf-8') not in (None, UNREGISTERED_SUNNYLINK_DONGLE_ID):
|
||||
cloudlog.info("Waiting for sunnylink registration to complete")
|
||||
time.sleep(10)
|
||||
|
||||
UploadQueueCache.initialize(upload_queue)
|
||||
|
||||
ws_uri = SUNNYLINK_ATHENA_HOST
|
||||
conn_start = None
|
||||
conn_retries = 0
|
||||
while exit_event is None or not exit_event.is_set():
|
||||
while (exit_event is None or not exit_event.is_set()) and params.get_bool("SunnylinkEnabled"):
|
||||
try:
|
||||
if conn_start is None:
|
||||
conn_start = time.monotonic()
|
||||
@@ -221,6 +230,10 @@ def main(exit_event: threading.Event = None):
|
||||
|
||||
time.sleep(backoff(conn_retries))
|
||||
|
||||
if not params.get_bool("SunnylinkEnabled"):
|
||||
cloudlog.debug("Reached end of sunnylinkd.main while SunnylinkEnabled is False so will wait for 60 seconds before exiting")
|
||||
time.sleep(60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -8,6 +8,7 @@ import traceback
|
||||
from cereal import custom
|
||||
import cereal.messaging as messaging
|
||||
import openpilot.system.sentry as sentry
|
||||
from openpilot.common.api.sunnylink import UNREGISTERED_SUNNYLINK_DONGLE_ID
|
||||
from openpilot.common.params import Params, ParamKeyType
|
||||
from openpilot.common.text_window import TextWindow
|
||||
from openpilot.system.hardware import HARDWARE, PC
|
||||
@@ -108,7 +109,8 @@ def manager_init() -> None:
|
||||
("OsmDownloadedDate", "0"),
|
||||
("OSMDownloadProgress", "{}"),
|
||||
("SidebarTemperatureOptions", "0"),
|
||||
("SunnylinkEnabled", "0"),
|
||||
("SunnylinkEnabled", "1"),
|
||||
("SunnylinkDongleId", f"{UNREGISTERED_SUNNYLINK_DONGLE_ID}"),
|
||||
("CustomDrivingModel", "0"),
|
||||
("DrivingModelGeneration", "4"),
|
||||
("LastSunnylinkPingTime", "0"),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
from cereal import car
|
||||
from openpilot.common.api.sunnylink import UNREGISTERED_SUNNYLINK_DONGLE_ID
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.system.hardware import PC, TICI
|
||||
from openpilot.selfdrive.sunnypilot import get_model_generation
|
||||
@@ -47,6 +48,17 @@ def model_use_nav(started, params, CP: car.CarParams) -> bool:
|
||||
custom_model, model_gen = get_model_generation(params)
|
||||
return started and custom_model and model_gen not in (0, 4)
|
||||
|
||||
|
||||
def use_sunnylink(started, params, CP: car.CarParams) -> bool:
|
||||
is_sunnylink_enabled = params.get_bool("SunnylinkEnabled")
|
||||
is_registered = params.get("SunnylinkDongleId", encoding='utf-8') not in (None, UNREGISTERED_SUNNYLINK_DONGLE_ID)
|
||||
return is_sunnylink_enabled and is_registered
|
||||
|
||||
def sunnylink_need_register(started, params, CP: car.CarParams) -> bool:
|
||||
is_sunnylink_enabled = params.get_bool("SunnylinkEnabled")
|
||||
is_registered = params.get("SunnylinkDongleId", encoding='utf-8') not in (None, UNREGISTERED_SUNNYLINK_DONGLE_ID)
|
||||
return is_sunnylink_enabled and not is_registered
|
||||
|
||||
procs = [
|
||||
DaemonProcess("manage_athenad", "system.athena.manage_athenad", "AthenadPid"),
|
||||
|
||||
@@ -102,17 +114,16 @@ procs = [
|
||||
NativeProcess("bridge", "cereal/messaging", ["./bridge"], notcar),
|
||||
PythonProcess("webrtcd", "system.webrtc.webrtcd", notcar),
|
||||
PythonProcess("webjoystick", "tools.bodyteleop.web", notcar),
|
||||
|
||||
# Sunnylink <3
|
||||
DaemonProcess("manage_sunnylinkd", "system.athena.manage_sunnylinkd", "SunnylinkdPid"),
|
||||
PythonProcess("sunnylink_registration", "system.manager.sunnylink", sunnylink_need_register),
|
||||
]
|
||||
|
||||
if Params().get_bool("SunnylinkEnabled"):
|
||||
if os.path.exists("../athena/manage_sunnylinkd.py"):
|
||||
procs += [
|
||||
DaemonProcess("manage_sunnylinkd", "system.athena.manage_sunnylinkd", "SunnylinkdPid"),
|
||||
]
|
||||
if os.path.exists("../loggerd/sunnylink_uploader.py"):
|
||||
procs += [
|
||||
PythonProcess("sunnylink_uploader", "system.loggerd.sunnylink_uploader", always_run),
|
||||
]
|
||||
if os.path.exists("../loggerd/sunnylink_uploader.py"):
|
||||
procs += [
|
||||
PythonProcess("sunnylink_uploader", "system.loggerd.sunnylink_uploader", use_sunnylink),
|
||||
]
|
||||
|
||||
if os.path.exists("./gitlab_runner.sh") and not PC:
|
||||
# Only devs!
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
|
||||
from openpilot.common.api.sunnylink import SunnylinkApi
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.common.spinner import Spinner
|
||||
from openpilot.system.version import is_prebuilt
|
||||
import time
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
spinner = Spinner()
|
||||
def main():
|
||||
extra_args = {}
|
||||
|
||||
if not Params().get_bool("SunnylinkEnabled"):
|
||||
print("Sunnylink is not enabled. Exiting.")
|
||||
spinner.close()
|
||||
# spinner.close()
|
||||
exit(0)
|
||||
|
||||
if not is_prebuilt():
|
||||
@@ -21,6 +20,13 @@ if __name__ == "__main__":
|
||||
"timeout": 60
|
||||
}
|
||||
|
||||
sunnylink_id = SunnylinkApi(None).register_device(spinner, **extra_args)
|
||||
sunnylink_id = SunnylinkApi(None).register_device(None, **extra_args)
|
||||
print(f"SunnyLinkId: {sunnylink_id}")
|
||||
spinner.close()
|
||||
|
||||
# Set the last ping time to the current time since we just registered
|
||||
last_ping = int(time.monotonic() * 1e9)
|
||||
Params().put("LastSunnylinkPingTime", str(last_ping))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user