mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-08-03 08:41:41 +08:00
params: fix auto type cast (#1127)
* params: fix auto type cast on put * literally * lint * pls comma why dis a string but actually json
This commit is contained in:
@@ -139,7 +139,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"CarParamsSP", {CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION, BYTES}},
|
||||
{"CarParamsSPCache", {CLEAR_ON_MANAGER_START, BYTES}},
|
||||
{"CarParamsSPPersistent", {PERSISTENT, BYTES}},
|
||||
{"CarPlatformBundle", {PERSISTENT | BACKUP, STRING}},
|
||||
{"CarPlatformBundle", {PERSISTENT | BACKUP, JSON}},
|
||||
{"ChevronInfo", {PERSISTENT | BACKUP, INT, "4"}},
|
||||
{"CustomAccIncrementsEnabled", {PERSISTENT | BACKUP, BOOL, "0"}},
|
||||
{"CustomAccLongPressIncrement", {PERSISTENT | BACKUP, INT, "5"}},
|
||||
@@ -162,11 +162,11 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"MadsUnifiedEngagementMode", {PERSISTENT | BACKUP, BOOL, "1"}},
|
||||
|
||||
// Model Manager params
|
||||
{"ModelManager_ActiveBundle", {PERSISTENT, STRING}},
|
||||
{"ModelManager_ActiveBundle", {PERSISTENT, JSON}},
|
||||
{"ModelManager_ClearCache", {CLEAR_ON_MANAGER_START, BOOL}},
|
||||
{"ModelManager_DownloadIndex", {CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION, INT, "0"}},
|
||||
{"ModelManager_LastSyncTime", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION, INT, "0"}},
|
||||
{"ModelManager_ModelsCache", {PERSISTENT | BACKUP, STRING}},
|
||||
{"ModelManager_ModelsCache", {PERSISTENT | BACKUP, JSON}},
|
||||
|
||||
// Neural Network Lateral Control
|
||||
{"NeuralNetworkLateralControl", {PERSISTENT | BACKUP, BOOL, "0"}},
|
||||
@@ -199,12 +199,12 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"MapAdvisorySpeedLimit", {CLEAR_ON_ONROAD_TRANSITION, FLOAT}},
|
||||
{"MapdVersion", {PERSISTENT, STRING, ""}},
|
||||
{"MapSpeedLimit", {CLEAR_ON_ONROAD_TRANSITION, FLOAT, "0.0"}},
|
||||
{"NextMapSpeedLimit", {CLEAR_ON_ONROAD_TRANSITION, STRING}},
|
||||
{"NextMapSpeedLimit", {CLEAR_ON_ONROAD_TRANSITION, JSON}},
|
||||
{"Offroad_OSMUpdateRequired", {CLEAR_ON_MANAGER_START, JSON}},
|
||||
{"OsmDbUpdatesCheck", {CLEAR_ON_MANAGER_START, BOOL}}, // mapd database update happens with device ON, reset on boot
|
||||
{"OSMDownloadBounds", {PERSISTENT, STRING}},
|
||||
{"OsmDownloadedDate", {PERSISTENT, STRING, "0.0"}},
|
||||
{"OSMDownloadLocations", {PERSISTENT, STRING}},
|
||||
{"OSMDownloadLocations", {PERSISTENT, JSON}},
|
||||
{"OSMDownloadProgress", {CLEAR_ON_MANAGER_START, JSON}},
|
||||
{"OsmLocal", {PERSISTENT, BOOL}},
|
||||
{"OsmLocationName", {PERSISTENT, STRING}},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
@@ -107,7 +106,7 @@ class Car:
|
||||
with car.CarParams.from_bytes(cached_params_raw) as _cached_params:
|
||||
cached_params = _cached_params
|
||||
|
||||
fixed_fingerprint = json.loads(self.params.get("CarPlatformBundle") or "{}").get("platform", None)
|
||||
fixed_fingerprint = (self.params.get("CarPlatformBundle") or {}).get("platform", None)
|
||||
|
||||
self.CI = get_car(*self.can_callbacks, obd_callback(self.params), alpha_long_allowed, is_release, num_pandas, cached_params, fixed_fingerprint)
|
||||
sunnypilot_interfaces.setup_interfaces(self.CI, self.params)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import capnp
|
||||
import json
|
||||
import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
@@ -265,12 +264,12 @@ def setup_settings_trips(click, pm: PubMaster, scroll=None):
|
||||
time.sleep(UI_DELAY)
|
||||
|
||||
def setup_settings_vehicle(click, pm: PubMaster, scroll=None):
|
||||
Params().put("CarPlatformBundle", json.dumps(
|
||||
Params().put("CarPlatformBundle",
|
||||
{
|
||||
"platform": "HONDA_CIVIC_2022",
|
||||
"name": "Honda Civic 2022-24"
|
||||
}
|
||||
))
|
||||
)
|
||||
|
||||
setup_settings_device(click, pm)
|
||||
scroll(-400, 278, 962)
|
||||
|
||||
@@ -38,7 +38,7 @@ class OsmMapData(BaseMapData):
|
||||
|
||||
def get_next_speed_limit_and_distance(self) -> tuple[float, float]:
|
||||
next_speed_limit_section_str = self.mem_params.get("NextMapSpeedLimit")
|
||||
next_speed_limit_section = json.loads(next_speed_limit_section_str) if next_speed_limit_section_str else {}
|
||||
next_speed_limit_section = next_speed_limit_section_str if next_speed_limit_section_str else {}
|
||||
next_speed_limit = next_speed_limit_section.get('speedlimit', 0.0)
|
||||
next_speed_limit_latitude = next_speed_limit_section.get('latitude')
|
||||
next_speed_limit_longitude = next_speed_limit_section.get('longitude')
|
||||
|
||||
@@ -59,12 +59,17 @@ def request_refresh_osm_location_data(nations: list[str], states: list[str] = No
|
||||
params.put("OsmDownloadedDate", str(time.monotonic()))
|
||||
params.put_bool("OsmDbUpdatesCheck", False)
|
||||
|
||||
osm_download_locations = json.dumps({
|
||||
osm_download_locations = {
|
||||
"nations": nations,
|
||||
"states": states or []
|
||||
}
|
||||
|
||||
osm_download_locations_dump = json.dumps({
|
||||
"nations": nations,
|
||||
"states": states or []
|
||||
})
|
||||
|
||||
print(f"Downloading maps for {osm_download_locations}")
|
||||
print(f"Downloading maps for {osm_download_locations_dump}")
|
||||
mem_params.put("OSMDownloadLocations", osm_download_locations)
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ This file is part of sunnypilot and is licensed under the MIT License.
|
||||
See the LICENSE.md file in the root directory for more details.
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
import requests
|
||||
@@ -102,14 +101,14 @@ class ModelCache:
|
||||
if not cached_data:
|
||||
cloudlog.warning("No cached model data available")
|
||||
return {}, True
|
||||
return json.loads(cached_data), self._is_expired()
|
||||
return cached_data, self._is_expired()
|
||||
except Exception as e:
|
||||
cloudlog.exception(f"Error retrieving cached model data: {str(e)}")
|
||||
return {}, True
|
||||
|
||||
def set(self, data: dict) -> None:
|
||||
"""Updates the cache with new model data"""
|
||||
self.params.put(self._CACHE_KEY, json.dumps(data))
|
||||
self.params.put(self._CACHE_KEY, data)
|
||||
self.params.put(self._LAST_SYNC_KEY, int(time.monotonic() * 1e9))
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import hashlib
|
||||
import os
|
||||
import pickle
|
||||
import numpy as np
|
||||
import json
|
||||
|
||||
from openpilot.common.params import Params
|
||||
from cereal import custom
|
||||
@@ -71,7 +70,7 @@ def get_active_bundle(params: Params = None) -> custom.ModelManagerSP.ModelBundl
|
||||
params = Params()
|
||||
|
||||
try:
|
||||
if (active_bundle := json.loads(params.get("ModelManager_ActiveBundle") or "{}")) and is_bundle_version_compatible(active_bundle):
|
||||
if (active_bundle := params.get("ModelManager_ActiveBundle") or {}) and is_bundle_version_compatible(active_bundle):
|
||||
return custom.ModelManagerSP.ModelBundle(**active_bundle)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -8,7 +8,6 @@ See the LICENSE.md file in the root directory for more details.
|
||||
import asyncio
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
|
||||
import aiohttp
|
||||
from openpilot.common.params import Params
|
||||
@@ -146,7 +145,7 @@ class ModelManagerSP:
|
||||
await asyncio.gather(*tasks)
|
||||
self.active_bundle = self.selected_bundle
|
||||
self.active_bundle.status = custom.ModelManagerSP.DownloadStatus.downloaded
|
||||
self.params.put("ModelManager_ActiveBundle", json.dumps(self.active_bundle.to_dict()))
|
||||
self.params.put("ModelManager_ActiveBundle", self.active_bundle.to_dict())
|
||||
self.selected_bundle = None
|
||||
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user