diff --git a/sunnypilot/mapd/__init__.py b/sunnypilot/mapd/__init__.py index e69de29bb..7ad6f7414 100644 --- a/sunnypilot/mapd/__init__.py +++ b/sunnypilot/mapd/__init__.py @@ -0,0 +1,5 @@ +import os +from openpilot.common.basedir import BASEDIR + +MAPD_BIN_DIR = os.path.join(BASEDIR, 'third_party/mapd_pfeiferj') +MAPD_PATH = os.path.join(MAPD_BIN_DIR, 'mapd') diff --git a/sunnypilot/mapd/mapd_installer.py b/sunnypilot/mapd/mapd_installer.py index a151dd480..c337b50c5 100755 --- a/sunnypilot/mapd/mapd_installer.py +++ b/sunnypilot/mapd/mapd_installer.py @@ -16,32 +16,39 @@ from urllib.request import urlopen from cereal import messaging from openpilot.common.params import Params -from openpilot.sunnypilot.mapd.mapd_manager import MAPD_PATH, MAPD_BIN_DIR from openpilot.system.hardware.hw import Paths from openpilot.common.spinner import Spinner from openpilot.system.version import is_prebuilt +from openpilot.sunnypilot.mapd import MAPD_PATH, MAPD_BIN_DIR import openpilot.system.sentry as sentry -VERSION = 'v1.9.0' +VERSION = 'v1.10.0' URL = f"https://github.com/pfeiferj/openpilot-mapd/releases/download/{VERSION}/mapd" +def update_installed_version(version: str, params: Params = None) -> None: + if params is None: + params = Params() + + params.put("MapdVersion", version) + + class MapdInstallManager: def __init__(self, spinner_ref: Spinner): self._spinner = spinner_ref + self._params = Params() def download(self) -> None: self.ensure_directories_exist() self._download_file() - self.update_installed_version(VERSION) + update_installed_version(VERSION, self._params) def check_and_download(self) -> None: if self.download_needed(): self.download() - @staticmethod - def download_needed() -> bool: - return not os.path.exists(MAPD_PATH) or MapdInstallManager.get_installed_version() != VERSION + def download_needed(self) -> bool: + return not os.path.exists(MAPD_PATH) or self.get_installed_version() != VERSION @staticmethod def ensure_directories_exist() -> None: @@ -82,13 +89,8 @@ class MapdInstallManager: temp_file.unlink() logging.error("Failed to download file after all retries") - @staticmethod - def update_installed_version(version: str) -> None: - Params().put("MapdVersion", version) - - @staticmethod - def get_installed_version() -> str: - return Params().get("MapdVersion", encoding="utf-8") or "" + def get_installed_version(self) -> str: + return self._params.get("MapdVersion", encoding="utf-8") or "" def wait_for_internet_connection(self, return_on_failure: bool = False) -> bool: max_retries = 10 @@ -122,7 +124,7 @@ class MapdInstallManager: return if self.wait_for_internet_connection(return_on_failure=True): - self._spinner.update(f"Downloading pfeiferj's mapd [{install_manager.get_installed_version()}] => [{VERSION}].") + self._spinner.update(f"Downloading pfeiferj's mapd [{self.get_installed_version()}] => [{VERSION}].") time.sleep(0.1) self.check_and_download() self._spinner.close() @@ -146,7 +148,7 @@ if __name__ == "__main__": if is_prebuilt(): debug_msg = f"[DEBUG] This is prebuilt, no mapd install required. VERSION: [{VERSION}], Param [{install_manager.get_installed_version()}]" spinner.update(debug_msg) - install_manager.update_installed_version(VERSION) + update_installed_version(VERSION) else: spinner.update(f"Checking if mapd is installed and valid. Prebuilt [{is_prebuilt()}]") install_manager.non_prebuilt_install() diff --git a/sunnypilot/mapd/mapd_manager.py b/sunnypilot/mapd/mapd_manager.py index 342ba3fe7..0cb0df23f 100755 --- a/sunnypilot/mapd/mapd_manager.py +++ b/sunnypilot/mapd/mapd_manager.py @@ -12,22 +12,20 @@ import os import glob import shutil -from openpilot.common.basedir import BASEDIR from openpilot.common.params import Params from openpilot.common.realtime import Ratekeeper, config_realtime_process from openpilot.common.swaglog import cloudlog from openpilot.selfdrive.selfdrived.alertmanager import set_offroad_alert from openpilot.sunnypilot.mapd.live_map_data.osm_map_data import OsmMapData from openpilot.system.hardware.hw import Paths +from openpilot.sunnypilot.mapd import MAPD_PATH +from openpilot.sunnypilot.mapd.mapd_installer import VERSION, update_installed_version # PFEIFER - MAPD {{ params = Params() mem_params = Params("/dev/shm/params") if platform.system() != "Darwin" else params # }} PFEIFER - MAPD -MAPD_BIN_DIR = os.path.join(BASEDIR, 'third_party/mapd_pfeiferj') -MAPD_PATH = os.path.join(MAPD_BIN_DIR, 'mapd') - def get_files_for_cleanup() -> list[str]: paths = [ @@ -117,6 +115,7 @@ def update_osm_db() -> None: def main_thread(): + update_installed_version(VERSION, params) config_realtime_process([0, 1, 2, 3], 5) rk = Ratekeeper(1, print_delay_threshold=None) diff --git a/system/manager/process_config.py b/system/manager/process_config.py index 2e3f754a7..487f0e970 100644 --- a/system/manager/process_config.py +++ b/system/manager/process_config.py @@ -88,6 +88,9 @@ def is_stock_model(started, params, CP: car.CarParams) -> bool: """Check if the active model runner is stock.""" return bool(get_active_model_runner(params, not started) == custom.ModelManagerSP.Runner.stock) +def mapd_ready(started: bool, params: Params, CP: car.CarParams) -> bool: + return bool(os.path.exists(Paths.mapd_root())) + def or_(*fns): return lambda *args: operator.or_(*(fn(*args) for fn in fns)) @@ -162,7 +165,7 @@ procs += [ PythonProcess("backup_manager", "sunnypilot.sunnylink.backups.manager", and_(only_offroad, sunnylink_ready_shim)), # mapd - NativeProcess("mapd", Paths.mapd_root(), [MAPD_PATH], always_run), + NativeProcess("mapd", Paths.mapd_root(), [MAPD_PATH], mapd_ready), PythonProcess("mapd_manager", "sunnypilot.mapd.mapd_manager", always_run), ] diff --git a/third_party/mapd_pfeiferj/mapd b/third_party/mapd_pfeiferj/mapd index d24d9b757..e5e45e2b9 100755 Binary files a/third_party/mapd_pfeiferj/mapd and b/third_party/mapd_pfeiferj/mapd differ