diff --git a/common/basedir.py b/common/basedir.py index d98509ed6d..a131f0d1aa 100644 --- a/common/basedir.py +++ b/common/basedir.py @@ -4,7 +4,5 @@ BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__ from common.hardware import PC if PC: PERSIST = os.path.join(BASEDIR, "persist") - PARAMS = os.path.join(BASEDIR, "persist", "params") else: PERSIST = "/persist" - PARAMS = "/data/params" diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index ea76b95023..153875e5b4 100755 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -6,7 +6,8 @@ from params_pxd cimport Params as c_Params import os import threading -from common.basedir import PARAMS +from common.basedir import BASEDIR +os.environ['BASEDIR'] = BASEDIR cdef enum TxType: PERSISTENT = 1 @@ -84,9 +85,9 @@ class UnknownKeyName(Exception): cdef class Params: cdef c_Params* p - def __cinit__(self, d=PARAMS, bool persistent_params=False): - if persistent_params: - self.p = new c_Params(True) + def __cinit__(self, d=None, bool persistent_params=False): + if d is None: + self.p = new c_Params(persistent_params) else: self.p = new c_Params(d.encode()) @@ -150,7 +151,7 @@ cdef class Params: self.p.delete_db_value(key) -def put_nonblocking(key, val, d=PARAMS): +def put_nonblocking(key, val, d=None): def f(key, val): params = Params(d) params.put(key, val) diff --git a/common/params_pyx_setup.py b/common/params_pyx_setup.py index be91aabe88..28dd9ee50f 100644 --- a/common/params_pyx_setup.py +++ b/common/params_pyx_setup.py @@ -1,12 +1,24 @@ import os +import subprocess from distutils.core import Extension, setup from Cython.Build import cythonize + from common.cython_hacks import BuildExtWithoutPlatformSuffix from common.basedir import BASEDIR +from common.hardware import TICI + +ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg sourcefiles = ['params_pyx.pyx'] extra_compile_args = ["-std=c++11"] +if ARCH == "aarch64": + if TICI: + extra_compile_args += ["-DQCOM2"] + else: + extra_compile_args += ["-DQCOM"] + + setup(name='common', cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, ext_modules=cythonize( diff --git a/common/tests/test_params.py b/common/tests/test_params.py index 5aa5426631..386b7fdd60 100644 --- a/common/tests/test_params.py +++ b/common/tests/test_params.py @@ -21,6 +21,11 @@ class TestParams(unittest.TestCase): self.params.put("DongleId", "cb38263377b873ee") assert self.params.get("DongleId") == b"cb38263377b873ee" + def test_persist_params_put_and_get(self): + p = Params(persistent_params=True) + p.put("DongleId", "cb38263377b873ee") + assert p.get("DongleId") == b"cb38263377b873ee" + def test_params_non_ascii(self): st = b"\xe1\x90\xff" self.params.put("CarParams", st) diff --git a/selfdrive/boardd/tests/test_boardd_loopback.py b/selfdrive/boardd/tests/test_boardd_loopback.py index 8e1ec9ca25..d4b2fe398f 100755 --- a/selfdrive/boardd/tests/test_boardd_loopback.py +++ b/selfdrive/boardd/tests/test_boardd_loopback.py @@ -7,7 +7,7 @@ from functools import wraps import cereal.messaging as messaging from cereal import car -from common.basedir import PARAMS +from common.basedir import BASEDIR from common.hardware import ANDROID from common.params import Params from common.spinner import Spinner @@ -30,7 +30,7 @@ def reset_panda(fn): os.environ['STARTED'] = '1' os.environ['BOARDD_LOOPBACK'] = '1' -os.environ['PARAMS_PATH'] = PARAMS +os.environ['BASEDIR'] = BASEDIR @reset_panda @with_processes(['boardd']) diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index 6c01598bd2..2b78a0e11c 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -21,23 +21,27 @@ #include "common/utilpp.h" -namespace { - -std::string getenv_default(const char* env_var, const char* default_val) { +std::string getenv_default(const char* env_var, const char * suffix, const char* default_val) { const char* env_val = getenv(env_var); - return std::string(env_val != NULL ? env_val : default_val); + if (env_val != NULL){ + return std::string(env_val) + std::string(suffix); + } else{ + return std::string(default_val); + } } -const std::string default_params_path = getenv_default("PARAMS_PATH", "/data/params"); +#if defined(QCOM) || defined(QCOM2) +const std::string default_params_path = "/data/params"; +#else +const std::string default_params_path = getenv_default("BASEDIR", "persists/params", "/data/params"); +#endif -#ifdef QCOM -const std::string persistent_params_path = getenv_default("PERSISTENT_PARAMS_PATH", "/persist/comma/params"); +#if defined(QCOM) || defined(QCOM2) +const std::string persistent_params_path = "/persist/comma/params"; #else const std::string persistent_params_path = default_params_path; #endif -} //namespace - volatile sig_atomic_t params_do_exit = 0; void params_sig_handler(int signal) { diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 324e55b364..875c835ed6 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -13,12 +13,11 @@ from typing import Dict, List from selfdrive.swaglog import cloudlog, add_logentries_handler -from common.basedir import BASEDIR, PARAMS +from common.basedir import BASEDIR from common.hardware import HARDWARE, ANDROID, PC WEBCAM = os.getenv("WEBCAM") is not None sys.path.append(os.path.join(BASEDIR, "pyextra")) os.environ['BASEDIR'] = BASEDIR -os.environ['PARAMS_PATH'] = PARAMS TOTAL_SCONS_NODES = 1005 prebuilt = os.path.exists(os.path.join(BASEDIR, 'prebuilt')) diff --git a/tools/README.md b/tools/README.md index 2d5eacdcdb..810bb50907 100644 --- a/tools/README.md +++ b/tools/README.md @@ -108,7 +108,7 @@ Usage: python carcontrols/joystickd.py # In another terminal: -PARAMS_PATH=persist/params selfdrive/boardd/boardd +BASEDIR=$(pwd) selfdrive/boardd/boardd # In another terminal: python carcontrols/debug_controls.py