updated: persist more state between runs for UI (#30963)

* persist branches and more

* fix target

* typo

---------

Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: b92e71a2b6
chrysler-long2
Adeeb Shihadeh 1 year ago committed by GitHub
parent 05abdcdf38
commit f4242f188b
  1. 2
      common/params.cc
  2. 15
      selfdrive/updated.py

@ -199,7 +199,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"UbloxAvailable", PERSISTENT}, {"UbloxAvailable", PERSISTENT},
{"UpdateAvailable", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION}, {"UpdateAvailable", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION},
{"UpdateFailedCount", CLEAR_ON_MANAGER_START}, {"UpdateFailedCount", CLEAR_ON_MANAGER_START},
{"UpdaterAvailableBranches", CLEAR_ON_MANAGER_START}, {"UpdaterAvailableBranches", PERSISTENT},
{"UpdaterCurrentDescription", CLEAR_ON_MANAGER_START}, {"UpdaterCurrentDescription", CLEAR_ON_MANAGER_START},
{"UpdaterCurrentReleaseNotes", CLEAR_ON_MANAGER_START}, {"UpdaterCurrentReleaseNotes", CLEAR_ON_MANAGER_START},
{"UpdaterFetchAvailable", CLEAR_ON_MANAGER_START}, {"UpdaterFetchAvailable", CLEAR_ON_MANAGER_START},

@ -230,7 +230,6 @@ class Updater:
b: Union[str, None] = self.params.get("UpdaterTargetBranch", encoding='utf-8') b: Union[str, None] = self.params.get("UpdaterTargetBranch", encoding='utf-8')
if b is None: if b is None:
b = self.get_branch(BASEDIR) b = self.get_branch(BASEDIR)
self.params.put("UpdaterTargetBranch", b)
return b return b
@property @property
@ -245,7 +244,7 @@ class Updater:
@property @property
def update_available(self) -> bool: def update_available(self) -> bool:
if os.path.isdir(OVERLAY_MERGED): if os.path.isdir(OVERLAY_MERGED) and len(self.branches) > 0:
hash_mismatch = self.get_commit_hash(OVERLAY_MERGED) != self.branches[self.target_branch] hash_mismatch = self.get_commit_hash(OVERLAY_MERGED) != self.branches[self.target_branch]
branch_mismatch = self.get_branch(OVERLAY_MERGED) != self.target_branch branch_mismatch = self.get_branch(OVERLAY_MERGED) != self.target_branch
return hash_mismatch or branch_mismatch return hash_mismatch or branch_mismatch
@ -259,9 +258,11 @@ class Updater:
def set_params(self, update_success: bool, failed_count: int, exception: Optional[str]) -> None: def set_params(self, update_success: bool, failed_count: int, exception: Optional[str]) -> None:
self.params.put("UpdateFailedCount", str(failed_count)) self.params.put("UpdateFailedCount", str(failed_count))
self.params.put("UpdaterTargetBranch", self.target_branch)
self.params.put_bool("UpdaterFetchAvailable", self.update_available) self.params.put_bool("UpdaterFetchAvailable", self.update_available)
self.params.put("UpdaterAvailableBranches", ','.join(self.branches.keys())) if len(self.branches):
self.params.put("UpdaterAvailableBranches", ','.join(self.branches.keys()))
last_update = datetime.datetime.utcnow() last_update = datetime.datetime.utcnow()
if update_success: if update_success:
@ -428,10 +429,11 @@ def main() -> None:
# invalidate old finalized update # invalidate old finalized update
set_consistent_flag(False) set_consistent_flag(False)
# wait a bit before first cycle # set initial state
wait_helper.sleep(60) params.put("UpdaterState", "idle")
# Run the update loop # Run the update loop
first_run = True
while True: while True:
wait_helper.ready_event.clear() wait_helper.ready_event.clear()
@ -444,7 +446,8 @@ def main() -> None:
# ensure we have some params written soon after startup # ensure we have some params written soon after startup
updater.set_params(False, update_failed_count, exception) updater.set_params(False, update_failed_count, exception)
if not system_time_valid(): if not system_time_valid() or first_run:
first_run = False
wait_helper.sleep(60) wait_helper.sleep(60)
continue continue

Loading…
Cancel
Save