diff --git a/common/basedir.py b/common/basedir.py index a131f0d1a..a728eaac1 100644 --- a/common/basedir.py +++ b/common/basedir.py @@ -1,7 +1,7 @@ import os BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) -from common.hardware import PC +from selfdrive.hardware import PC if PC: PERSIST = os.path.join(BASEDIR, "persist") else: diff --git a/common/gpio.py b/common/gpio.py index 73603f262..cb0322146 100644 --- a/common/gpio.py +++ b/common/gpio.py @@ -1,11 +1,3 @@ -GPIO_HUB_RST_N = 30 -GPIO_UBLOX_RST_N = 32 -GPIO_UBLOX_SAFEBOOT_N = 33 -GPIO_UBLOX_PWR_EN = 34 -GPIO_STM_RST_N = 124 -GPIO_STM_BOOT0 = 134 - - def gpio_init(pin, output): try: with open(f"/sys/class/gpio/gpio{pin}/direction", 'wb') as f: diff --git a/common/realtime.py b/common/realtime.py index 0f0d9a9e7..f702cd6d3 100644 --- a/common/realtime.py +++ b/common/realtime.py @@ -4,8 +4,8 @@ import os import time import multiprocessing -from common.hardware import PC, TICI from common.clock import sec_since_boot # pylint: disable=no-name-in-module, import-error +from selfdrive.hardware import PC, TICI # time step for each process diff --git a/common/transformations/camera.py b/common/transformations/camera.py index e1fbcb546..9c365dc7e 100644 --- a/common/transformations/camera.py +++ b/common/transformations/camera.py @@ -1,7 +1,7 @@ import numpy as np import common.transformations.orientation as orient -from common.hardware import TICI +from selfdrive.hardware import TICI ## -- hardcoded hardware params -- eon_f_focal_length = 910.0 diff --git a/launch_chffrplus.sh b/launch_chffrplus.sh index d94784e01..8fe3cbf61 100755 --- a/launch_chffrplus.sh +++ b/launch_chffrplus.sh @@ -74,6 +74,12 @@ function two_init { chrt -f -p 52 $pid done + # the flippening! + LD_LIBRARY_PATH="" content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1 + + # disable bluetooth + service call bluetooth_manager 8 + # Check for NEOS update if [ $(< /VERSION) != "$REQUIRED_NEOS_VERSION" ]; then if [ -f "$DIR/scripts/continue.sh" ]; then diff --git a/release/files_common b/release/files_common index a5de5996f..f53abcf84 100644 --- a/release/files_common +++ b/release/files_common @@ -18,10 +18,6 @@ apk/ai.comma*.apk common/.gitignore common/__init__.py -common/hardware.py -common/hardware_android.py -common/hardware_tici.py -common/hardware_base.py common/gpio.py common/realtime.py common/clock.pyx @@ -41,7 +37,6 @@ common/stat_live.py common/spinner.py common/text_window.py common/cython_hacks.py -common/apk.py common/SConscript common/kalman/.gitignore @@ -274,6 +269,17 @@ selfdrive/controls/lib/longitudinal_mpc_model/generator.cpp selfdrive/controls/lib/longitudinal_mpc_model/libmpc_py.py selfdrive/controls/lib/longitudinal_mpc_model/longitudinal_mpc.c +selfdrive/hardware/__init__.py +selfdrive/hardware/base.py +selfdrive/hardware/eon/__init__.py +selfdrive/hardware/eon/apk.py +selfdrive/hardware/eon/hardware.py +selfdrive/hardware/tici/__init__.py +selfdrive/hardware/tici/hardware.py +selfdrive/hardware/tici/pins.py +selfdrive/hardware/pc/__init__.py +selfdrive/hardware/pc/hardware.py + selfdrive/locationd/__init__.py selfdrive/locationd/.gitignore selfdrive/locationd/SConscript diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index d475f86da..27e8b587f 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -20,11 +20,11 @@ from websocket import ABNF, WebSocketTimeoutException, create_connection import cereal.messaging as messaging from cereal.services import service_list -from common.hardware import HARDWARE from common.api import Api from common.basedir import PERSIST from common.params import Params from common.realtime import sec_since_boot +from selfdrive.hardware import HARDWARE from selfdrive.loggerd.config import ROOT from selfdrive.swaglog import cloudlog diff --git a/selfdrive/camerad/test/test_camerad.py b/selfdrive/camerad/test/test_camerad.py index 4b02f6c12..a8af0082b 100755 --- a/selfdrive/camerad/test/test_camerad.py +++ b/selfdrive/camerad/test/test_camerad.py @@ -9,8 +9,8 @@ import cereal.messaging as messaging from selfdrive.test.helpers import with_processes from selfdrive.camerad.snapshot.visionipc import VisionIPC -from common.hardware import EON, TICI # only tests for EON and TICI +from selfdrive.hardware import EON, TICI TEST_TIMESPAN = random.randint(60, 180) # seconds SKIP_FRAME_TOLERANCE = 0 diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 2f347dd4b..77e24b4b5 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -1,11 +1,11 @@ import os from common.params import Params from common.basedir import BASEDIR -from common.hardware import ANDROID from selfdrive.version import comma_remote, tested_branch from selfdrive.car.fingerprints import eliminate_incompatible_cars, all_known_cars from selfdrive.car.vin import get_vin, VIN_UNKNOWN from selfdrive.car.fw_versions import get_fw_versions, match_fw_to_car +from selfdrive.hardware import EON from selfdrive.swaglog import cloudlog import cereal.messaging as messaging from selfdrive.car import gen_empty_fingerprint @@ -24,7 +24,7 @@ def get_startup_event(car_recognized, controller_available): event = EventName.startupNoCar elif car_recognized and not controller_available: event = EventName.startupNoControl - elif ANDROID and "letv" not in open("/proc/cmdline").read(): + elif EON and "letv" not in open("/proc/cmdline").read(): event = EventName.startupOneplus return event diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 22e63a798..184077c20 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import os from cereal import car, log -from common.hardware import HARDWARE from common.numpy_fast import clip from common.realtime import sec_since_boot, config_realtime_process, Priority, Ratekeeper, DT_CTRL from common.profiler import Profiler @@ -21,6 +20,7 @@ from selfdrive.controls.lib.alertmanager import AlertManager from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.controls.lib.planner import LON_MPC_STEP from selfdrive.locationd.calibrationd import Calibration +from selfdrive.hardware import HARDWARE LDW_MIN_SPEED = 31 * CV.MPH_TO_MS LANE_DEPARTURE_THRESHOLD = 0.1 diff --git a/selfdrive/crash.py b/selfdrive/crash.py index 1bf57d199..3bc000d2e 100644 --- a/selfdrive/crash.py +++ b/selfdrive/crash.py @@ -5,8 +5,8 @@ import threading import capnp from selfdrive.version import version, dirty, origin, branch +from selfdrive.hardware import PC from selfdrive.swaglog import cloudlog -from common.hardware import PC if os.getenv("NOLOG") or os.getenv("NOCRASH") or PC: def capture_exception(*args, **kwargs): diff --git a/selfdrive/hardware/__init__.py b/selfdrive/hardware/__init__.py new file mode 100644 index 000000000..3babf1bb5 --- /dev/null +++ b/selfdrive/hardware/__init__.py @@ -0,0 +1,19 @@ +import os +from typing import cast + +from selfdrive.hardware.base import HardwareBase +from selfdrive.hardware.eon.hardware import Android +from selfdrive.hardware.tici.hardware import Tici +from selfdrive.hardware.pc.hardware import Pc + +EON = os.path.isfile('/EON') +TICI = os.path.isfile('/TICI') +PC = not (EON or TICI) + + +if EON: + HARDWARE = cast(HardwareBase, Android()) +elif TICI: + HARDWARE = cast(HardwareBase, Tici()) +else: + HARDWARE = cast(HardwareBase, Pc()) diff --git a/common/hardware_base.py b/selfdrive/hardware/base.py similarity index 100% rename from common/hardware_base.py rename to selfdrive/hardware/base.py diff --git a/selfdrive/hardware/eon/__init__.py b/selfdrive/hardware/eon/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/common/apk.py b/selfdrive/hardware/eon/apk.py similarity index 100% rename from common/apk.py rename to selfdrive/hardware/eon/apk.py diff --git a/common/hardware_android.py b/selfdrive/hardware/eon/hardware.py similarity index 99% rename from common/hardware_android.py rename to selfdrive/hardware/eon/hardware.py index dc18d3292..3622f06c4 100644 --- a/common/hardware_android.py +++ b/selfdrive/hardware/eon/hardware.py @@ -6,7 +6,7 @@ import struct import subprocess from cereal import log -from common.hardware_base import HardwareBase +from selfdrive.hardware.base import HardwareBase NetworkType = log.ThermalData.NetworkType NetworkStrength = log.ThermalData.NetworkStrength diff --git a/selfdrive/hardware/pc/__init__.py b/selfdrive/hardware/pc/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/common/hardware.py b/selfdrive/hardware/pc/hardware.py similarity index 73% rename from common/hardware.py rename to selfdrive/hardware/pc/hardware.py index f4e502ea5..310c3193b 100644 --- a/common/hardware.py +++ b/selfdrive/hardware/pc/hardware.py @@ -1,17 +1,7 @@ -import os import random -from typing import cast from cereal import log -from common.hardware_android import Android -from common.hardware_tici import Tici -from common.hardware_base import HardwareBase - -EON = os.path.isfile('/EON') -TICI = os.path.isfile('/TICI') -PC = not (EON or TICI) -ANDROID = EON - +from selfdrive.hardware.base import HardwareBase NetworkType = log.ThermalData.NetworkType NetworkStrength = log.ThermalData.NetworkStrength @@ -71,11 +61,3 @@ class Pc(HardwareBase): def get_current_power_draw(self): return 0 - - -if EON: - HARDWARE = cast(HardwareBase, Android()) -elif TICI: - HARDWARE = cast(HardwareBase, Tici()) -else: - HARDWARE = cast(HardwareBase, Pc()) diff --git a/selfdrive/hardware/tici/__init__.py b/selfdrive/hardware/tici/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/common/hardware_tici.py b/selfdrive/hardware/tici/hardware.py similarity index 98% rename from common/hardware_tici.py rename to selfdrive/hardware/tici/hardware.py index 2aec9b2e5..f1fbf14e2 100644 --- a/common/hardware_tici.py +++ b/selfdrive/hardware/tici/hardware.py @@ -1,7 +1,8 @@ -from common.hardware_base import HardwareBase -from cereal import log import subprocess +from cereal import log +from selfdrive.hardware.base import HardwareBase + NM = 'org.freedesktop.NetworkManager' NM_CON_ACT = NM + '.Connection.Active' NM_DEV_WL = NM + '.Device.Wireless' diff --git a/selfdrive/hardware/tici/pins.py b/selfdrive/hardware/tici/pins.py new file mode 100644 index 000000000..7139f5e95 --- /dev/null +++ b/selfdrive/hardware/tici/pins.py @@ -0,0 +1,8 @@ +# TODO: these are also defined in a header +# GPIO pin definitions +GPIO_HUB_RST_N = 30 +GPIO_UBLOX_RST_N = 32 +GPIO_UBLOX_SAFEBOOT_N = 33 +GPIO_UBLOX_PWR_EN = 34 +GPIO_STM_RST_N = 124 +GPIO_STM_BOOT0 = 134 diff --git a/selfdrive/loggerd/tests/test_loggerd.py b/selfdrive/loggerd/tests/test_loggerd.py index 6b55295cf..4b7e23f7b 100755 --- a/selfdrive/loggerd/tests/test_loggerd.py +++ b/selfdrive/loggerd/tests/test_loggerd.py @@ -11,8 +11,8 @@ from pathlib import Path from tqdm import trange from common.params import Params -from common.hardware import EON, TICI from common.timeout import Timeout +from selfdrive.hardware import EON, TICI from selfdrive.test.helpers import with_processes from selfdrive.loggerd.config import ROOT, CAMERA_FPS diff --git a/selfdrive/loggerd/uploader.py b/selfdrive/loggerd/uploader.py index 456712f2b..d2cbb94ee 100644 --- a/selfdrive/loggerd/uploader.py +++ b/selfdrive/loggerd/uploader.py @@ -10,9 +10,9 @@ import time import traceback from cereal import log -from common.hardware import HARDWARE from common.api import Api from common.params import Params +from selfdrive.hardware import HARDWARE from selfdrive.loggerd.xattr_cache import getxattr, setxattr from selfdrive.loggerd.config import ROOT from selfdrive.swaglog import cloudlog diff --git a/selfdrive/manager.py b/selfdrive/manager.py index a225384bc..63cc5a488 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -14,7 +14,7 @@ from selfdrive.swaglog import cloudlog, add_logentries_handler from common.basedir import BASEDIR -from common.hardware import HARDWARE, ANDROID, PC +from selfdrive.hardware import HARDWARE, EON, PC WEBCAM = os.getenv("WEBCAM") is not None sys.path.append(os.path.join(BASEDIR, "pyextra")) os.environ['BASEDIR'] = BASEDIR @@ -30,7 +30,7 @@ except FileExistsError: except PermissionError: print("WARNING: failed to make /dev/shm") -if ANDROID: +if EON: os.chmod("/dev/shm", 0o777) def unblock_stdout(): @@ -157,7 +157,7 @@ from selfdrive.registration import register from selfdrive.version import version, dirty from selfdrive.loggerd.config import ROOT from selfdrive.launcher import launcher -from common.apk import update_apks, pm_apply_packages, start_offroad +from selfdrive.hardware.eon.apk import update_apks, pm_apply_packages, start_offroad ThermalStatus = cereal.log.ThermalData.ThermalStatus @@ -258,7 +258,7 @@ if not PC: 'dmonitoringmodeld', ] -if ANDROID: +if EON: car_started_processes += [ 'gpsd', 'rtshield', @@ -385,7 +385,7 @@ def kill_managed_process(name): def cleanup_all_processes(signal, frame): cloudlog.info("caught ctrl-c %s %s" % (signal, frame)) - if ANDROID: + if EON: pm_apply_packages('disable') for name in list(running.keys()): @@ -433,7 +433,7 @@ def manager_init(should_register=True): pass # ensure shared libraries are readable by apks - if ANDROID: + if EON: os.chmod(BASEDIR, 0o755) os.chmod(os.path.join(BASEDIR, "cereal"), 0o755) os.chmod(os.path.join(BASEDIR, "cereal", "libmessaging_shared.so"), 0o755) @@ -459,7 +459,7 @@ def manager_thread(): start_managed_process(p) # start offroad - if ANDROID: + if EON: pm_apply_packages('enable') start_offroad() @@ -534,13 +534,6 @@ def uninstall(): HARDWARE.reboot(reason="recovery") def main(): - if ANDROID: - # the flippening! - os.system('LD_LIBRARY_PATH="" content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1') - - # disable bluetooth - os.system('service call bluetooth_manager 8') - params = Params() params.manager_start() @@ -572,7 +565,7 @@ def main(): if params.get("Passive") is None: raise Exception("Passive must be set to continue") - if ANDROID: + if EON: update_apks() manager_init() manager_prepare(spinner) diff --git a/selfdrive/pandad.py b/selfdrive/pandad.py index 05fdeea69..cb630eabe 100755 --- a/selfdrive/pandad.py +++ b/selfdrive/pandad.py @@ -3,9 +3,10 @@ import os import time -from common.hardware import TICI -from common.gpio import GPIO_HUB_RST_N, GPIO_STM_BOOT0, GPIO_STM_RST_N, gpio_init, gpio_set from panda import BASEDIR, Panda, PandaDFU, build_st +from common.gpio import gpio_init, gpio_set +from selfdrive.hardware import TICI +from selfdrive.hardware.tici.pins import GPIO_HUB_RST_N, GPIO_STM_BOOT0, GPIO_STM_RST_N from selfdrive.swaglog import cloudlog def is_legacy_panda_reset(): diff --git a/selfdrive/registration.py b/selfdrive/registration.py index de2231a45..07c1e374c 100644 --- a/selfdrive/registration.py +++ b/selfdrive/registration.py @@ -2,13 +2,14 @@ import os import json from datetime import datetime, timedelta -from selfdrive.swaglog import cloudlog -from selfdrive.version import version, terms_version, training_version, get_git_commit, get_git_branch, get_git_remote -from common.hardware import HARDWARE from common.api import api_get from common.params import Params from common.file_helpers import mkdirs_exists_ok from common.basedir import PERSIST +from selfdrive.hardware import HARDWARE +from selfdrive.swaglog import cloudlog +from selfdrive.version import version, terms_version, training_version, get_git_commit, \ + get_git_branch, get_git_remote def register(): diff --git a/selfdrive/test/helpers.py b/selfdrive/test/helpers.py index ff4645574..de8b15b3b 100644 --- a/selfdrive/test/helpers.py +++ b/selfdrive/test/helpers.py @@ -3,8 +3,8 @@ import subprocess from functools import wraps from nose.tools import nottest -from common.hardware import PC -from common.apk import update_apks, start_offroad, pm_apply_packages, android_packages +from selfdrive.hardware.eon.apk import update_apks, start_offroad, pm_apply_packages, android_packages +from selfdrive.hardware import PC from selfdrive.version import training_version, terms_version from selfdrive.manager import start_managed_process, kill_managed_process, get_running diff --git a/selfdrive/test/process_replay/camera_replay.py b/selfdrive/test/process_replay/camera_replay.py index f64d615b9..69f34a665 100755 --- a/selfdrive/test/process_replay/camera_replay.py +++ b/selfdrive/test/process_replay/camera_replay.py @@ -5,10 +5,7 @@ import time from typing import Any from tqdm import tqdm -from common.hardware import ANDROID -os.environ['CI'] = "1" -if ANDROID: - os.environ['QCOM_REPLAY'] = "1" +os.environ['QCOM_REPLAY'] = '1' from common.spinner import Spinner from common.timeout import Timeout diff --git a/selfdrive/test/test_sounds.py b/selfdrive/test/test_sounds.py index da6419ef6..d9c150e02 100755 --- a/selfdrive/test/test_sounds.py +++ b/selfdrive/test/test_sounds.py @@ -5,8 +5,8 @@ import subprocess from cereal import log, car import cereal.messaging as messaging from selfdrive.test.helpers import phone_only, with_processes -from common.hardware import HARDWARE from common.realtime import DT_CTRL +from selfdrive.hardware import HARDWARE AudibleAlert = car.CarControl.HUDControl.AudibleAlert diff --git a/selfdrive/thermald/power_monitoring.py b/selfdrive/thermald/power_monitoring.py index 477b834d7..5d59cf387 100644 --- a/selfdrive/thermald/power_monitoring.py +++ b/selfdrive/thermald/power_monitoring.py @@ -4,9 +4,9 @@ import time from statistics import mean from cereal import log -from common.realtime import sec_since_boot from common.params import Params, put_nonblocking -from common.hardware import HARDWARE +from common.realtime import sec_since_boot +from selfdrive.hardware import HARDWARE from selfdrive.swaglog import cloudlog CAR_VOLTAGE_LOW_PASS_K = 0.091 # LPF gain for 5s tau (dt/tau / (dt/tau + 1)) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 400d71860..843f9fa1e 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -11,11 +11,11 @@ from smbus2 import SMBus import cereal.messaging as messaging from cereal import log from common.filter_simple import FirstOrderFilter -from common.hardware import EON, HARDWARE, TICI from common.numpy_fast import clip, interp from common.params import Params from common.realtime import DT_TRML, sec_since_boot from selfdrive.controls.lib.alertmanager import set_offroad_alert +from selfdrive.hardware import EON, HARDWARE, TICI from selfdrive.loggerd.config import get_available_percent from selfdrive.pandad import get_expected_signature from selfdrive.swaglog import cloudlog diff --git a/selfdrive/updated.py b/selfdrive/updated.py index f8f540efc..04458beb4 100755 --- a/selfdrive/updated.py +++ b/selfdrive/updated.py @@ -34,9 +34,9 @@ import threading from pathlib import Path from typing import List, Tuple, Optional -from common.hardware import ANDROID, TICI from common.basedir import BASEDIR from common.params import Params +from selfdrive.hardware import EON, TICI from selfdrive.swaglog import cloudlog from selfdrive.controls.lib.alertmanager import set_offroad_alert @@ -292,7 +292,7 @@ def fetch_update(wait_helper: WaitTimeHelper) -> bool: ] cloudlog.info("git reset success: %s", '\n'.join(r)) - if ANDROID: + if EON: handle_neos_update(wait_helper) # Create the finalized, ready-to-swap update @@ -312,10 +312,10 @@ def main(): # TODO: enable this before 0.8.1 release #leon = "letv" in open("/proc/cmdline").read() - #if ANDROID and not leon: + #if EON and not leon: # raise RuntimeError("updates are disabled due to device deprecation") - if ANDROID and os.geteuid() != 0: + if EON and os.geteuid() != 0: raise RuntimeError("updated must be launched as root!") # Set low io priority diff --git a/tools/lib/auth_config.py b/tools/lib/auth_config.py index 082c3f513..4863430c7 100644 --- a/tools/lib/auth_config.py +++ b/tools/lib/auth_config.py @@ -1,7 +1,7 @@ import json import os -from common.hardware import PC from common.file_helpers import mkdirs_exists_ok +from selfdrive.hardware import PC class MissingAuthConfigError(Exception):