FrogPilot features - Automatic updates

This commit is contained in:
FrogAi 2024-06-07 05:18:40 -07:00
parent 8995531c74
commit 992e2a53a9
3 changed files with 32 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import datetime
import http.client
import os
import socket
import urllib.error
import urllib.request
@ -8,6 +9,7 @@ from cereal import log, messaging
from openpilot.common.params import Params
from openpilot.common.realtime import Priority, config_realtime_process
from openpilot.common.time import system_time_valid
from openpilot.system.hardware import HARDWARE
from openpilot.selfdrive.frogpilot.controls.frogpilot_planner import FrogPilotPlanner
from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_functions import FrogPilotFunctions
@ -22,10 +24,26 @@ def github_pinged(url="https://github.com", timeout=5):
except (urllib.error.URLError, socket.timeout, http.client.RemoteDisconnected):
return False
def time_checks(deviceState, now, params, params_memory):
def automatic_update_check(params):
update_available = params.get_bool("UpdaterFetchAvailable")
update_ready = params.get_bool("UpdateAvailable")
update_state_idle = params.get("UpdaterState", encoding='utf8') == "idle"
if update_ready:
HARDWARE.reboot()
elif update_available:
os.system("pkill -SIGHUP -f system.updated.updated")
elif update_state_idle:
os.system("pkill -SIGUSR1 -f system.updated.updated")
def time_checks(automatic_updates, deviceState, now, params, params_memory):
screen_off = deviceState.screenBrightnessPercent == 0
wifi_connection = deviceState.networkType == WIFI
if screen_off and wifi_connection:
if automatic_updates:
automatic_update_check(params)
def frogpilot_thread(frogpilot_toggles):
config_realtime_process(5, Priority.CTRL_LOW)
@ -60,7 +78,7 @@ def frogpilot_thread(frogpilot_toggles):
if now.second == 0 or not time_validated:
if not started:
if github_pinged():
time_checks(deviceState, now, params, params_memory)
time_checks(frogpilot_toggles.automatic_updates, deviceState, maps_downloaded, now, params, params_memory)
if not time_validated:
time_validated = system_time_valid()

View File

@ -29,6 +29,12 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) {
versionLbl = new LabelControl(tr("Current Version"), "");
addItem(versionLbl);
// automatic updates toggle
ParamControl *automaticUpdatesToggle = new ParamControl("AutomaticUpdates", tr("Automatically Update FrogPilot"),
tr("FrogPilot will automatically update itself and it's assets when you're offroad and connected to Wi-Fi."), "");
connect(automaticUpdatesToggle, &ToggleControl::toggleFlipped, this, updateFrogPilotToggles);
addItem(automaticUpdatesToggle);
// download update btn
downloadBtn = new ButtonControl(tr("Download"), tr("CHECK"));
connect(downloadBtn, &ButtonControl::clicked, [=]() {
@ -38,6 +44,7 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) {
} else {
std::system("pkill -SIGHUP -f system.updated.updated");
}
paramsMemory.putBool("ManualUpdateInitiated", true);
});
addItem(downloadBtn);

View File

@ -470,11 +470,16 @@ def main() -> None:
params.put("InstallDate", datetime.datetime.now().astimezone(ZoneInfo('America/Phoenix')).strftime("%B %d, %Y - %I:%M%p").encode('utf8'))
install_date_set = True
if not (params.get_bool("AutomaticUpdates") or params_memory.get_bool("ManualUpdateInitiated")):
wait_helper.sleep(60*60*24*365*100)
continue
update_failed_count += 1
# check for update
params.put("UpdaterState", "checking...")
updater.check_for_update()
params_memory.put_bool("ManualUpdateInitiated", False)
# download update
last_fetch = read_time_from_param(params, "UpdaterLastFetchTime")