def getSimInfo(): sim_state = android.getprop("gsm.sim.state").split(",") network_type = android.getprop("gsm.network.type").split(',') mcc_mnc = android.getprop("gsm.sim.operator.numeric") or None sim_id = android.parse_service_call_string(['iphonesubinfo', '11']) cell_data_state = android.parse_service_call_unpack(['phone', '46'], ">q") cell_data_connected = (cell_data_state == 2) return { 'sim_id': sim_id, 'mcc_mnc': mcc_mnc, 'network_type': network_type, 'sim_state': sim_state, 'data_connected': cell_data_connected }
def confd_thread(): sm = messaging.SubMaster(['thermal']) pm = messaging.PubMaster(['dragonConf']) last_dp_msg = None last_modified = None update_params = False frame = 0 locale = getprop("persist.sys.locale").rstrip('\n') last_autoshutdown = False last_sec = None autoshutdown_frame = 0 last_charging_ctrl = False last_started = False dashcam_next_frame = 0 dashcam_folder_exists = False dashcam_mkdir_retry = 0 # thermal started = False free_space = 0. online = False battery_percent = 0. overheat = False while True: start_sec = sec_since_boot() if frame % 6 == 0: sm.update() if sm.updated['thermal']: started = sm['thermal'].started free_space = sm['thermal'].freeSpace online = sm['thermal'].usbOnline battery_percent = sm['thermal'].batteryPercent overheat = sm['thermal'].thermalStatus >= 2 msg = messaging.new_message('dragonConf') if last_dp_msg is not None: msg.dragonConf = last_dp_msg ''' =================================================== force update when start status changed =================================================== ''' if last_started != started: update_params = True ''' =================================================== we only need to check last_modified every 3 seconds if val is modified, we then proceed to read params =================================================== ''' if not update_params and frame % 6 == 0: try: modified = params.get('dp_last_modified', encoding='utf8').rstrip('\x00') except AttributeError: modified = str(floor(time.time())) if last_modified != modified: update_params = True last_modified = modified ''' =================================================== push param vals to message =================================================== ''' if update_params: for conf in confs: conf_type = conf.get('conf_type') if 'param' in conf_type and 'struct' in conf_type: update_this_conf = True update_once = conf.get('update_once') if update_once is not None and update_once is True and frame > 0: update_this_conf = False if frame > 0 and update_this_conf: dependencies = conf.get('depends') # if has dependency and the depend param val is not in depend_vals, we dont update that conf val # this should reduce chance of reading all params if dependencies is not None: for dependency in dependencies: if getattr(msg.dragonConf, get_struct_name(dependency['name']) ) not in dependency['vals']: update_this_conf = False if update_this_conf: val = params.get(conf['name'], encoding='utf8') if val is not None: val = val.rstrip('\x00') struct_val = to_struct_val(conf['name'], val) orig_val = struct_val if conf.get('min') is not None: struct_val = max(struct_val, conf.get('min')) if conf.get('max') is not None: struct_val = min(struct_val, conf.get('max')) if orig_val != struct_val: params.put(conf['name'], str(struct_val)) setattr(msg.dragonConf, get_struct_name(conf['name']), struct_val) ''' =================================================== push ip addr every 10 secs to message =================================================== ''' if frame % 20 == 0: val = 'N/A' try: result = subprocess.check_output(["ifconfig", "wlan0"], encoding='utf8') val = re.findall(r"inet addr:((\d+\.){3}\d+)", result)[0][0] except: pass msg.dragonConf.dpIpAddr = val ''' =================================================== push is_updating status every 5 secs to message =================================================== ''' if frame % 10 == 0: val = params.get('dp_is_updating', encoding='utf8').rstrip('\x00') setattr(msg.dragonConf, get_struct_name('dp_is_updating'), to_struct_val('dp_is_updating', val)) ''' =================================================== push once =================================================== ''' if frame == 0: setattr(msg.dragonConf, get_struct_name('dp_locale'), locale) put_nonblocking('dp_is_updating', '0') ''' =================================================== we can have some logic here =================================================== ''' if msg.dragonConf.dpAssistedLcMinMph > msg.dragonConf.dpAutoLcMinMph: put_nonblocking('dp_auto_lc_min_mph', str(msg.dragonConf.dpAssistedLcMinMph)) msg.dragonConf.dpAutoLcMinMph = msg.dragonConf.dpAssistedLcMinMph if msg.dragonConf.dpAtl: msg.dragonConf.dpAllowGas = True msg.dragonConf.dpDynamicFollow = 0 msg.dragonConf.dpAccelProfile = 0 msg.dragonConf.dpGearCheck = False if msg.dragonConf.dpAppWaze: msg.dragonConf.dpDrivingUi = False if not msg.dragonConf.dpDriverMonitor: msg.dragonConf.dpUiFace = False msg.dragonConf.dpThermalStarted = started msg.dragonConf.dpThermalOverheat = overheat ''' =================================================== publish msg =================================================== ''' last_dp_msg = msg.dragonConf update_params = False pm.send('dragonConf', msg) ''' =================================================== hotspot on boot we do it after 30 secs just in case =================================================== ''' if frame == 60 and params.get("dp_hotspot_on_boot") == b'1': os.system("service call wifi 37 i32 0 i32 1 &") ''' =================================================== dashcam =================================================== ''' dashcam = msg.dragonConf.dpDashcam if frame % 2 == 0 and dashcam: while not dashcam_folder_exists and dashcam_mkdir_retry <= 5: try: if not os.path.exists(DASHCAM_VIDEOS_PATH): os.makedirs(DASHCAM_VIDEOS_PATH) else: dashcam_folder_exists = True except OSError: pass dashcam_mkdir_retry += 1 if dashcam_folder_exists: if started: if frame >= dashcam_next_frame - 2: now = datetime.datetime.now() file_name = now.strftime("%Y-%m-%d_%H-%M-%S") os.system( "screenrecord --bit-rate %s --time-limit %s %s%s.mp4 &" % (DASHCAM_BIT_RATES, DASHCAM_DURATION, DASHCAM_VIDEOS_PATH, file_name)) dashcam_next_frame = frame + DASHCAM_DURATION * 2 else: dashcam_next_frame = 0 if frame % 120 == 0 and ((free_space < DASHCAM_FREESPACE_LIMIT) or (get_used_spaces() > DASHCAM_KEPT)): try: files = [ f for f in sorted(os.listdir(DASHCAM_VIDEOS_PATH)) if os.path.isfile(DASHCAM_VIDEOS_PATH + f) ] os.system("rm -fr %s &" % (DASHCAM_VIDEOS_PATH + files[0])) except (IndexError, FileNotFoundError, OSError): pass ''' =================================================== auto shutdown =================================================== ''' autoshutdown = msg.dragonConf.dpAutoShutdown if frame % 20 == 0 and autoshutdown: sec = msg.dragonConf.dpAutoShutdownIn * 60 * 2 if last_autoshutdown != autoshutdown or last_sec != sec or started or online: autoshutdown_frame = frame + sec if not started and not online and sec > 0 and frame >= autoshutdown_frame: os.system('LD_LIBRARY_PATH="" svc power shutdown') last_sec = sec last_autoshutdown = autoshutdown ''' =================================================== battery ctrl every 30 secs PowerMonitor in thermald turns back on every mins so lets turn it off more frequent =================================================== ''' charging_ctrl = msg.dragonConf.dpChargingCtrl if last_charging_ctrl != charging_ctrl: set_battery_charging(True) if charging_ctrl and frame % 60 == 0: if battery_percent >= msg.dragonConf.dpDischargingAt and get_battery_charging( ): set_battery_charging(False) elif battery_percent <= msg.dragonConf.dpChargingAt and not get_battery_charging( ): set_battery_charging(True) last_charging_ctrl = charging_ctrl ''' =================================================== make it 2 hz =================================================== ''' last_started = started frame += 1 sleep = 0.5 - (sec_since_boot() - start_sec) if sleep > 0: time.sleep(sleep)
import gettext from common import android from common.params import put_nonblocking is_android = android.ANDROID locale_dir = '/data/openpilot/selfdrive/assets/locales' supported_language = ['en-US', 'zh-TW', 'zh-CN'] locale = android.getprop("persist.sys.locale") if is_android else 'en-US' def alerts(): i18n = gettext.translation('alerts', localedir=locale_dir, fallback=True, languages=[locale]) i18n.install() return i18n.gettext
{'name': 'dp_toyota_zss', 'default': False, 'type': 'Bool', 'conf_type': ['param']}, {'name': 'dp_toyota_lowest_cruise_override', 'default': False, 'type': 'Bool', 'depends': [{'name': 'dp_atl', 'vals': [False]}], 'conf_type': ['param', 'struct']}, {'name': 'dp_toyota_lowest_cruise_override_at', 'default': 44, 'type': 'Float32', 'depends': [{'name': 'dp_toyota_lowest_cruise_override', 'vals': [True]}], 'min': 0, 'max': 255., 'conf_type': ['param', 'struct']}, {'name': 'dp_toyota_lowest_cruise_override_speed', 'default': 32, 'type': 'Float32', 'depends': [{'name': 'dp_toyota_lowest_cruise_override_speed', 'vals': [True]}], 'min': 0, 'max': 255., 'conf_type': ['param', 'struct']}, # custom car {'name': 'dp_car_selected', 'default': '', 'type': 'Text', 'conf_type': ['param']}, {'name': 'dp_car_list', 'default': '', 'type': 'Text', 'conf_type': ['param']}, {'name': 'dp_car_detected', 'default': '', 'type': 'Text', 'conf_type': ['param']}, #misc {'name': 'dp_ip_addr', 'default': '', 'type': 'Text', 'conf_type': ['struct']}, {'name': 'dp_full_speed_fan', 'default': False, 'type': 'Bool', 'conf_type': ['param']}, {'name': 'dp_uno_fan_mode', 'default': False, 'type': 'Bool', 'conf_type': ['param']}, {'name': 'dp_last_modified', 'default': str(floor(time.time())), 'type': 'Text', 'conf_type': ['param']}, {'name': 'dp_camera_offset', 'default': 6, 'type': 'Int8', 'min': -255, 'max': 255, 'conf_type': ['param', 'struct']}, {'name': 'dp_locale', 'default': getprop("persist.sys.locale").rstrip('\n'), 'type': 'Text', 'conf_type': ['param', 'struct'], 'update_once': True}, {'name': 'dp_disable_relay', 'default': False, 'type': 'Bool', 'conf_type': ['param']}, {'name': 'dp_charging_ctrl', 'default': False, 'type': 'Bool', 'conf_type': ['param', 'struct']}, {'name': 'dp_charging_at', 'default': 60, 'type': 'UInt8', 'min': 0, 'max': 100, 'depends': [{'name': 'dp_charging_ctrl', 'vals': [True]}], 'conf_type': ['param', 'struct']}, {'name': 'dp_discharging_at', 'default': 70, 'type': 'UInt8', 'min': 0, 'max': 100, 'depends': [{'name': 'dp_charging_ctrl', 'vals': [True]}], 'conf_type': ['param', 'struct']}, {'name': 'dp_reg', 'default': True, 'type': 'Bool', 'conf_type': ['param']}, {'name': 'dp_is_updating', 'default': False, 'type': 'Bool', 'conf_type': ['param', 'struct']}, {'name': 'dp_sr_learner', 'default': True, 'type': 'Bool', 'conf_type': ['param']}, {'name': 'dp_lqr', 'default': False, 'type': 'Bool', 'conf_type': ['param']}, {'name': 'dp_reset_live_param_on_start', 'default': False, 'type': 'Bool', 'conf_type': ['param']}, # including thermal data {'name': 'dp_thermal_started', 'default': False, 'type': 'Bool', 'conf_type': ['struct']}, {'name': 'dp_thermal_overheat', 'default': False, 'type': 'Bool', 'conf_type': ['struct']}, ]