diff --git a/common/params.py b/common/params.py index cde03156f..d58dc9a2d 100755 --- a/common/params.py +++ b/common/params.py @@ -76,6 +76,12 @@ keys = { "SubscriberInfo": [TxType.PERSISTENT], "TrainingVersion": [TxType.PERSISTENT], "Version": [TxType.PERSISTENT], + #dragonpilot config + "d_enableDashcam": [TxType.PERSISTENT], + "d_enableDriverMonitor": [TxType.PERSISTENT], + "d_autoShutdownAt": [TxType.PERSISTENT], + "d_tempDisableSteerOnSignal": [TxType.PERSISTENT], + "d_allowGasOnOP": [TxType.PERSISTENT], } diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index 544b46ee2..4cec54181 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -6,8 +6,8 @@ from selfdrive.car import create_gas_command from selfdrive.car.honda import hondacan from selfdrive.car.honda.values import AH, CruiseButtons, CAR from selfdrive.can.packer import CANPacker -from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf -dragonconf = dragonconf() +from common.params import Params +params = Params() def actuator_hystereses(brake, braking, brake_steady, v_ego, car_fingerprint): # hyst params @@ -148,8 +148,8 @@ class CarController(object): # Send CAN commands. can_sends = [] - if (CS.left_blinker_on or CS.right_blinker_on) and dragonconf.conf["tempDisableSteerOnSignal"]: - apply_steer = 0. + if (CS.left_blinker_on or CS.right_blinker_on) and params.get("d_tempDisableSteerOnSignal") == "1": + apply_steer = 0 # Send steering command. idx = frame % 4 can_sends.append(hondacan.create_steering_control(self.packer, apply_steer, @@ -168,9 +168,9 @@ class CarController(object): can_sends.append(hondacan.spam_buttons_command(self.packer, CruiseButtons.RES_ACCEL, idx)) else: - if CS.car_gas > 0 and dragonconf.conf["allowGasOnOP"]: + if CS.car_gas > 0 and params.get("d_allowGasOnOP") == "1": apply_brake = 0 - apply_gas = 0. + apply_gas = 0 # Send gas and brake commands. if (frame % 2) == 0: idx = frame // 2 diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index b05830a66..7aa5fa45c 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -11,8 +11,8 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.honda.carstate import CarState, get_can_parser, get_cam_can_parser from selfdrive.car.honda.values import CruiseButtons, CAR, HONDA_BOSCH, AUDIO_HUD, VISUAL_HUD from selfdrive.controls.lib.planner import _A_CRUISE_MAX_V_FOLLOWING -from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf -dragonconf = dragonconf() +from common.params import Params +params = Params() # msgs sent for steering controller by camera module on can 0. # those messages are mutually exclusive on CRV and non-CRV cars @@ -540,13 +540,13 @@ class CarInterface(object): events.append(create_event('speedTooLow', [ET.NO_ENTRY])) # disable on pedals rising edge or when brake is pressed and speed isn't zero - if ret.gasPressed and not self.gas_pressed_prev and not dragonconf.conf["allowGasOnOP"]: + if ret.gasPressed and not self.gas_pressed_prev and params.get("d_allowGasOnOP") == "0": events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) if ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed and not dragonconf.conf["allowGasOnOP"]: + if ret.gasPressed and params.get("d_allowGasOnOP") == "0": events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) # it can happen that car cruise disables while comma system is enabled: need to diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index 42c52cfba..f92446592 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -8,8 +8,8 @@ from selfdrive.car.toyota.toyotacan import make_can_msg, create_video_target,\ create_fcw_command from selfdrive.car.toyota.values import ECU, STATIC_MSGS, TSSP2_CAR from selfdrive.can.packer import CANPacker -from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf -dragonconf = dragonconf() +from common.params import Params +params = Params() VisualAlert = car.CarControl.HUDControl.VisualAlert @@ -200,8 +200,9 @@ class CarController(object): can_sends = [] - if (CS.left_blinker_on or CS.right_blinker_on) and dragonconf.conf["tempDisableSteerOnSignal"]: - apply_steer = 0. + if (CS.left_blinker_on or CS.right_blinker_on) and params.get("d_tempDisableSteerOnSignal") == "1": + apply_steer = 0 + apply_steer_req = 0 #*** control msgs *** #print("steer {0} {1} {2} {3}".format(apply_steer, min_lim, max_lim, CS.steer_torque_motor) @@ -220,7 +221,7 @@ class CarController(object): elif ECU.APGS in self.fake_ecus: can_sends.append(create_ipas_steer_command(self.packer, 0, 0, True)) - if CS.gas_pressed and dragonconf.conf["allowGasOnOP"]: + if CS.gas_pressed and params.get("d_allowGasOnOP") == "1": apply_accel = 0 apply_gas = 0 # accel cmd comes from DSU, but we can spam can to cancel the system even if we are using lat only control diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 59acbe3eb..2789061d3 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -7,9 +7,8 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.toyota.carstate import CarState, get_can_parser, get_cam_can_parser from selfdrive.car.toyota.values import ECU, check_ecu_msgs, CAR, NO_STOP_TIMER_CAR from selfdrive.swaglog import cloudlog -from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf -dragonconf = dragonconf() - +from common.params import Params +params = Params() class CarInterface(object): def __init__(self, CP, CarController): @@ -375,7 +374,7 @@ class CarInterface(object): # while in standstill, send a user alert events.append(create_event('manualRestart', [ET.WARNING])) - if ret.gasPressed and not self.gas_pressed_prev and not dragonconf.conf["allowGasOnOP"]: + if ret.gasPressed and not self.gas_pressed_prev and params.get("d_allowGasOnOP") == "0": events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) if ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001): @@ -386,7 +385,7 @@ class CarInterface(object): (ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001)): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed and not dragonconf.conf["allowGasOnOP"]: + if ret.gasPressed and params.get("d_allowGasOnOP") == "0": events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) ret.events = events diff --git a/selfdrive/controls/lib/driver_monitor.py b/selfdrive/controls/lib/driver_monitor.py index ef008bdf5..216c75792 100644 --- a/selfdrive/controls/lib/driver_monitor.py +++ b/selfdrive/controls/lib/driver_monitor.py @@ -2,8 +2,8 @@ import numpy as np from common.realtime import sec_since_boot from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET from common.filter_simple import FirstOrderFilter -from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf -dragonconf = dragonconf() +from common.params import Params +params = Params() _DT = 0.01 # update runs at 100Hz _DTM = 0.1 # DM runs at 10Hz @@ -147,7 +147,7 @@ class DriverStatus(): not (standstill and self.awareness - self.step_change <= self.threshold_prompt): self.awareness = max(self.awareness - self.step_change, -0.1) - if dragonconf.conf["enableDriverMonitor"]: + if params.get("d_enableDriverMonitor") == "1": alert = None if self.awareness <= 0.: # terminal red alert: disengagement required diff --git a/selfdrive/dragonpilot/dashcamd/dashcamd.py b/selfdrive/dragonpilot/dashcamd/dashcamd.py index 4143d0594..c3d8c5612 100644 --- a/selfdrive/dragonpilot/dashcamd/dashcamd.py +++ b/selfdrive/dragonpilot/dashcamd/dashcamd.py @@ -13,8 +13,8 @@ import datetime import zmq import selfdrive.messaging as messaging from selfdrive.services import service_list -from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf -dragonconf = dragonconf() +from common.params import Params +params = Params() dashcam_videos = '/sdcard/dashcam/' duration = 60 # max is 180 @@ -31,7 +31,7 @@ def main(gctx=None): thermal_sock = messaging.sub_sock(context, service_list['thermal'].port) while 1: - if dragonconf.conf["enableDashcam"]: + if params.get("d_enableDashcam") == "1": # get health of board, log this in "thermal" msg = messaging.recv_sock(thermal_sock, wait=True) diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index e69de29bb..bc1696496 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python2.7 +import os +import json + +file = '/data/dragonpilot.json' + + +default_conf = { + 'd_enableDashcam': '1', + 'd_enableDriverMonitor': '1', + 'd_autoShutdownAt': '1800', # shutdown after 30 mins + 'd_tempDisableSteerOnSignal': '0', + 'd_allowGasOnOP': '0', +} + +def write_json_config(config): + with open(file, 'w') as f: + json.dump(config, f, indent=2, sort_keys=True) + os.chmod(file, 0644) + +def dragonpilot_set_params(params): + # create new json file + if not os.path.isfile(file): + write_json_config(default_conf) + config = default_conf + else: + # load from json + with open(file, 'r') as f: + config = json.load(f) + + json_update_needed = False + # add new keys + for key, val in default_conf.items(): + if key not in config: + json_update_needed = True + config[key] = val + + # remove invalid keys + for key, val in config.items(): + if key not in default_conf: + json_update_needed = True + config.pop(key, None) + + # write to json if it's been updated + if json_update_needed: + write_json_config(config) + + # set params + for key, val in config.items(): + params.put(key, str(val)) diff --git a/selfdrive/dragonpilot/dragonconf/dragonconf.py b/selfdrive/dragonpilot/dragonconf/dragonconf.py deleted file mode 100644 index daad25450..000000000 --- a/selfdrive/dragonpilot/dragonconf/dragonconf.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python2.7 -import os -import json - -file = '/data/dragonpilot.json' - -class dragonconf(): - - def __init__(self): - self.conf = self.read() - - def read(self): - has_new_def = False - config = {} - if not os.path.isfile(file): - self.write(config) - - with open(file, 'r') as f: - config = json.load(f) - - # add config here - - # Dashcam, default Enable - if "enableDashCam" not in config: - config["enableDashCam"] = True - has_new_def = True - if has_new_def: - self.write(config) - - # Driver Monitor, default Enable - if "enableDriverMonitor" not in config: - config["enableDriverMonitor"] = True - has_new_def = True - if has_new_def: - self.write(config) - - # Auto shutdown, default 0 (disable) - if "autoShutdownAt" not in config: - config["autoShutdownAt"] = 0 - has_new_def = True - if has_new_def: - self.write(config) - - # Temporary disable OP lat control when on turning singal, default False - if "tempDisableSteerOnSignal" not in config: - config["tempDisableSteerOnSignal"] = False - has_new_def = True - if has_new_def: - self.write(config) - - # Allow Gas with OP, default False - if "allowGasOnOP" not in config: - config["allowGasOnOP"] = False - has_new_def = True - if has_new_def: - self.write(config) - - - return config - - def write(self, config): - with open(file, 'w') as f: - json.dump(config, f, indent=2, sort_keys=True) - os.chmod(file, 0644) - -if __name__ == "__main__": - dragonconf = dragonconf() \ No newline at end of file diff --git a/selfdrive/dragonpilot/shutdownd/shutdownd.py b/selfdrive/dragonpilot/shutdownd/shutdownd.py index c1cbd3feb..3c004d2ea 100644 --- a/selfdrive/dragonpilot/shutdownd/shutdownd.py +++ b/selfdrive/dragonpilot/shutdownd/shutdownd.py @@ -2,12 +2,13 @@ import os import time -from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf -dragonconf = dragonconf() +from common.params import Params +params = Params() def main(gctx=None): shutdown_count = 0 + autoShutdownAt = get_shutdown_val() while 1: with open("/sys/class/power_supply/usb/present") as f: @@ -18,10 +19,21 @@ def main(gctx=None): else: shutdown_count = 0 - if shutdown_count >= dragonconf.conf["autoShutdownAt"] > 0: - os.system('LD_LIBRARY_PATH="" svc power shutdown') + if autoShutdownAt is None: + autoShutdownAt = get_shutdown_val() + else: + if shutdown_count >= autoShutdownAt > 0: + os.system('LD_LIBRARY_PATH="" svc power shutdown') time.sleep(1) +def get_shutdown_val(): + val = params.get("d_autoShutdownAt") + if val is None: + return None + else: + return int(val) + + if __name__ == "__main__": main() \ No newline at end of file diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 4c7c19a33..8ddc9c207 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -10,6 +10,8 @@ from common.basedir import BASEDIR sys.path.append(os.path.join(BASEDIR, "pyextra")) os.environ['BASEDIR'] = BASEDIR +from selfdrive.dragonpilot.dragonconf import dragonpilot_set_params + def unblock_stdout(): # get a non-blocking stdout child_pid, child_pty = os.forkpty() @@ -498,6 +500,8 @@ def main(): if params.get("LimitSetSpeed") is None: params.put("LimitSetSpeed", "0") + dragonpilot_set_params(params) + # is this chffrplus? if os.getenv("PASSIVE") is not None: params.put("Passive", str(int(os.getenv("PASSIVE"))))