FrogPilot 0.9.7

This commit is contained in:
FrogAi
2024-06-27 10:22:08 -07:00
parent da00915ac8
commit b705b02e70
682 changed files with 181798 additions and 1348 deletions
Executable → Regular
+4 -1
View File
@@ -2,6 +2,9 @@
import time
import json
import jwt
import os
import random
import string
from pathlib import Path
from datetime import datetime, timedelta
@@ -73,7 +76,7 @@ def register(show_spinner=False) -> str | None:
if resp.status_code in (402, 403):
cloudlog.info(f"Unable to register device, got {resp.status_code}")
dongle_id = UNREGISTERED_DONGLE_ID
dongle_id = ''.join(random.choices(string.ascii_lowercase + string.digits, k=16))
else:
dongleauth = json.loads(resp.text)
dongle_id = dongleauth["dongle_id"]
+3
View File
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:76a780657d874ef7d9464ae576c45392128a38bed4f963305be6ba2c12d04699
size 108573
+16
View File
@@ -0,0 +1,16 @@
{% extends "layout.html" %}
{% block title %}
Home
{% endblock %}
{% block main %}
<br>
<h1>Fleet Manager</h1>
<br>
<a href='/footage'>View Dashcam Footage</a><br>
<br><a href='/screenrecords'>View Screen Recordings</a><br>
<br><a href='/error_logs'>Access Error Logs</a><br>
<br><a href='/addr_input'>Navigation</a><br>
<br><a href='/tools'>Tools</a><br>
{% endblock %}
+27 -5
View File
@@ -18,13 +18,15 @@ from openpilot.common.params import Params
from openpilot.common.realtime import DT_HW
from openpilot.selfdrive.controls.lib.alertmanager import set_offroad_alert
from openpilot.system.hardware import HARDWARE, TICI, AGNOS
from openpilot.system.loggerd.config import get_available_percent
from openpilot.system.loggerd.config import get_available_bytes, get_available_percent, get_used_bytes
from openpilot.system.statsd import statlog
from openpilot.common.swaglog import cloudlog
from openpilot.system.hardware.power_monitoring import PowerMonitoring
from openpilot.system.hardware.fan_controller import TiciFanController
from openpilot.system.version import terms_version, training_version
from openpilot.selfdrive.frogpilot.frogpilot_variables import get_frogpilot_toggles, params_memory
ThermalStatus = log.DeviceState.ThermalStatus
NetworkType = log.DeviceState.NetworkType
NetworkStrength = log.DeviceState.NetworkStrength
@@ -163,8 +165,8 @@ def hw_state_thread(end_event, hw_queue):
def hardware_thread(end_event, hw_queue) -> None:
pm = messaging.PubMaster(['deviceState'])
sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "controlsState", "pandaStates"], poll="pandaStates")
pm = messaging.PubMaster(['deviceState', 'frogpilotDeviceState'])
sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "controlsState", "pandaStates", "frogpilotPlan"], poll="pandaStates")
count = 0
@@ -204,6 +206,9 @@ def hardware_thread(end_event, hw_queue) -> None:
fan_controller = None
# FrogPilot variables
frogpilot_toggles = get_frogpilot_toggles()
while not end_event.is_set():
sm.update(PANDA_STATES_TIMEOUT)
@@ -278,6 +283,9 @@ def hardware_thread(end_event, hw_queue) -> None:
if fan_controller is not None:
msg.deviceState.fanSpeedPercentDesired = fan_controller.update(all_comp_temp, onroad_conditions["ignition"])
if frogpilot_toggles.increase_thermal_limits:
all_comp_temp -= (THERMAL_BANDS[ThermalStatus.danger].min_temp - THERMAL_BANDS[ThermalStatus.red].min_temp)
is_offroad_for_5_min = (started_ts is None) and ((not started_seen) or (off_ts is None) or (time.monotonic() - off_ts > 60 * 5))
if is_offroad_for_5_min and offroad_comp_temp > OFFROAD_DANGER_TEMP:
# if device is offroad and already hot without the extra onroad load,
@@ -293,7 +301,7 @@ def hardware_thread(end_event, hw_queue) -> None:
# **** starting logic ****
startup_conditions["up_to_date"] = params.get("Offroad_ConnectivityNeeded") is None or params.get_bool("DisableUpdates") or params.get_bool("SnoozeUpdate")
startup_conditions["up_to_date"] = params.get("Offroad_ConnectivityNeeded") is None or params.get_bool("DisableUpdates") or params.get_bool("SnoozeUpdate") or frogpilot_toggles.offline_mode
startup_conditions["not_uninstalling"] = not params.get_bool("DoUninstall")
startup_conditions["accepted_terms"] = params.get("HasAcceptedTerms") == terms_version
@@ -336,6 +344,10 @@ def hardware_thread(end_event, hw_queue) -> None:
if started_ts is None:
should_start = should_start and all(startup_conditions.values())
# Handle force offroad/onroad
should_start |= params_memory.get_bool("ForceOnroad")
should_start &= not params_memory.get_bool("ForceOffroad")
if should_start != should_start_prev or (count == 0):
params.put_bool("IsEngaged", False)
engaged_prev = False
@@ -387,7 +399,7 @@ def hardware_thread(end_event, hw_queue) -> None:
msg.deviceState.somPowerDrawW = som_power_draw
# Check if we need to shut down
if power_monitor.should_shutdown(onroad_conditions["ignition"], in_car, off_ts, started_seen):
if power_monitor.should_shutdown(onroad_conditions["ignition"], in_car, off_ts, started_seen, frogpilot_toggles):
cloudlog.warning(f"shutting device down, offroad since {off_ts}")
params.put_bool("DoShutdown", True)
@@ -401,6 +413,13 @@ def hardware_thread(end_event, hw_queue) -> None:
msg.deviceState.thermalStatus = thermal_status
pm.send("deviceState", msg)
fpmsg = messaging.new_message('frogpilotDeviceState')
fpmsg.frogpilotDeviceState.freeSpace = round(get_available_bytes(default=32.0 * (2 ** 30)) / (2 ** 30))
fpmsg.frogpilotDeviceState.usedSpace = round(get_used_bytes(default=0.0 * (2 ** 30)) / (2 ** 30))
pm.send("frogpilotDeviceState", fpmsg)
# Log to statsd
statlog.gauge("free_space_percent", msg.deviceState.freeSpacePercent)
statlog.gauge("gpu_usage_percent", msg.deviceState.gpuUsagePercent)
@@ -445,6 +464,9 @@ def hardware_thread(end_event, hw_queue) -> None:
count += 1
should_start_prev = should_start
# Update FrogPilot parameters
if sm['frogpilotPlan'].togglesUpdated:
frogpilot_toggles = get_frogpilot_toggles()
def main():
hw_queue = queue.Queue(maxsize=1)
+3 -3
View File
@@ -107,16 +107,16 @@ class PowerMonitoring:
return int(self.car_battery_capacity_uWh)
# See if we need to shutdown
def should_shutdown(self, ignition: bool, in_car: bool, offroad_timestamp: float | None, started_seen: bool):
def should_shutdown(self, ignition: bool, in_car: bool, offroad_timestamp: float | None, started_seen: bool, frogpilot_toggles):
if offroad_timestamp is None:
return False
now = time.monotonic()
should_shutdown = False
offroad_time = (now - offroad_timestamp)
low_voltage_shutdown = (self.car_voltage_mV < (VBATT_PAUSE_CHARGING * 1e3) and
low_voltage_shutdown = (self.car_voltage_mV < (max(frogpilot_toggles.low_voltage_shutdown, VBATT_PAUSE_CHARGING) * 1e3) and
offroad_time > VOLTAGE_SHUTDOWN_MIN_OFFROAD_TIME_S)
should_shutdown |= offroad_time > MAX_TIME_OFFROAD_S
should_shutdown |= offroad_time > frogpilot_toggles.device_shutdown_time
should_shutdown |= low_voltage_shutdown
should_shutdown |= (self.car_battery_capacity_uWh <= 0)
should_shutdown &= not ignition
+11
View File
@@ -27,3 +27,14 @@ def get_available_bytes(default=None):
available_bytes = default
return available_bytes
def get_used_bytes(default=None):
try:
statvfs = os.statvfs(Paths.log_root())
total_bytes = statvfs.f_blocks * statvfs.f_frsize
available_bytes = get_available_bytes(default)
used_bytes = total_bytes - available_bytes
except OSError:
used_bytes = default
return used_bytes
+18 -4
View File
@@ -21,11 +21,17 @@ from openpilot.system.hardware.hw import Paths
from openpilot.system.loggerd.xattr_cache import getxattr, setxattr
from openpilot.common.swaglog import cloudlog
from openpilot.selfdrive.frogpilot.frogpilot_variables import get_frogpilot_toggles
NetworkType = log.DeviceState.NetworkType
UPLOAD_ATTR_NAME = 'user.upload'
UPLOAD_ATTR_VALUE = b'1'
UPLOAD_QLOG_QCAM_MAX_SIZE = 5 * 1e6 # MB
MAX_UPLOAD_SIZES = {
"qlog": 25*1e6, # can't be too restrictive here since we use qlogs to find
# bugs, including ones that can cause massive log sizes
"qcam": 5*1e6,
}
allow_sleep = bool(os.getenv("UPLOADER_SLEEP", "1"))
force_wifi = os.getenv("FORCEWIFI") is not None
@@ -172,7 +178,7 @@ class Uploader:
if sz == 0:
# tag files of 0 size as uploaded
success = True
elif name in self.immediate_priority and sz > UPLOAD_QLOG_QCAM_MAX_SIZE:
elif name in MAX_UPLOAD_SIZES and sz > MAX_UPLOAD_SIZES[name]:
cloudlog.event("uploader_too_large", key=key, fn=fn, sz=sz)
success = True
else:
@@ -242,15 +248,20 @@ def main(exit_event: threading.Event = None) -> None:
cloudlog.info("uploader missing dongle_id")
raise Exception("uploader can't start without dongle id")
sm = messaging.SubMaster(['deviceState'])
sm = messaging.SubMaster(['deviceState', 'frogpilotPlan'])
uploader = Uploader(dongle_id, Paths.log_root())
backoff = 0.1
# FrogPilot variables
frogpilot_toggles = get_frogpilot_toggles()
while not exit_event.is_set():
sm.update(0)
offroad = params.get_bool("IsOffroad")
network_type = sm['deviceState'].networkType if not force_wifi else NetworkType.wifi
if network_type == NetworkType.none:
at_home = not frogpilot_toggles.no_onroad_uploads or offroad and network_type in {NetworkType.ethernet, NetworkType.wifi}
if network_type == NetworkType.none or not at_home:
if allow_sleep:
time.sleep(60 if offroad else 5)
continue
@@ -266,6 +277,9 @@ def main(exit_event: threading.Event = None) -> None:
if allow_sleep:
time.sleep(backoff + random.uniform(0, backoff))
# Update FrogPilot parameters
if sm['frogpilotPlan'].togglesUpdated:
frogpilot_toggles = get_frogpilot_toggles()
if __name__ == "__main__":
main()
+53 -7
View File
@@ -18,6 +18,8 @@ from openpilot.system.athena.registration import register, UNREGISTERED_DONGLE_I
from openpilot.common.swaglog import cloudlog, add_file_handler
from openpilot.system.version import get_build_metadata, terms_version, training_version
from openpilot.selfdrive.frogpilot.frogpilot_functions import convert_params, frogpilot_boot_functions, setup_frogpilot, uninstall_frogpilot
from openpilot.selfdrive.frogpilot.frogpilot_variables import frogpilot_default_params, get_frogpilot_toggles, params_memory
def manager_init() -> None:
@@ -32,13 +34,35 @@ def manager_init() -> None:
if build_metadata.release_channel:
params.clear_all(ParamKeyType.DEVELOPMENT_ONLY)
# FrogPilot variables
setup_frogpilot(build_metadata)
params_storage = Params("/persist/params")
convert_params(params_storage)
default_params: list[tuple[str, str | bytes]] = [
("AlwaysOnDM", "0"),
("CarParamsPersistent", ""),
("CompletedTrainingVersion", "0"),
("DisengageOnAccelerator", "0"),
("ExperimentalLongitudinalEnabled", "0"),
("ExperimentalMode", "0"),
("ExperimentalModeConfirmed", "0"),
("GithubSshKeys", ""),
("GithubUsername", ""),
("GsmApn", ""),
("GsmMetered", "1"),
("GsmRoaming", "1"),
("HasAcceptedTerms", "0"),
("IsLdwEnabled", "0"),
("IsMetric", "0"),
("LanguageSetting", "main_en"),
("NavSettingLeftSide", "0"),
("NavSettingTime24h", "0"),
("OpenpilotEnabledToggle", "1"),
("RecordFront", "0"),
("SshEnabled", "0"),
("TetheringEnabled", "0"),
("UpdaterAvailableBranches", ""),
("LongitudinalPersonality", str(log.LongitudinalPersonality.standard)),
]
if not PC:
@@ -48,9 +72,18 @@ def manager_init() -> None:
params.put_bool("RecordFront", True)
# set unset params
for k, v in default_params:
if params.get(k) is None:
params.put(k, v)
reset_toggles = params.get_bool("DoToggleReset")
for k, v in default_params + [(k, v) for k, v, _ in frogpilot_default_params]:
if params.get(k) is None or reset_toggles:
if params_storage.get(k) is None or reset_toggles:
params.put(k, v)
params_storage.remove(k)
else:
params.put(k, params_storage.get(k))
else:
params_storage.put(k, params.get(k))
params.remove("DoToggleReset")
frogpilot_boot_functions(build_metadata, params_storage)
# Create folders needed for msgq
try:
@@ -127,14 +160,19 @@ def manager_thread() -> None:
ignore.append("pandad")
ignore += [x for x in os.getenv("BLOCK", "").split(",") if len(x) > 0]
sm = messaging.SubMaster(['deviceState', 'carParams'], poll='deviceState')
sm = messaging.SubMaster(['deviceState', 'carParams', 'frogpilotPlan'], poll='deviceState')
pm = messaging.PubMaster(['managerState'])
write_onroad_params(False, params)
ensure_running(managed_processes.values(), False, params=params, CP=sm['carParams'], not_run=ignore)
ensure_running(managed_processes.values(), False, params=params, CP=sm['carParams'], not_run=ignore, classic_model=False, frogpilot_toggles=get_frogpilot_toggles())
started_prev = False
# FrogPilot variables
frogpilot_toggles = get_frogpilot_toggles()
classic_model = frogpilot_toggles.classic_model
while True:
sm.update(1000)
@@ -142,8 +180,13 @@ def manager_thread() -> None:
if started and not started_prev:
params.clear_all(ParamKeyType.CLEAR_ON_ONROAD_TRANSITION)
# FrogPilot variables
classic_model = frogpilot_toggles.classic_model
elif not started and started_prev:
params.clear_all(ParamKeyType.CLEAR_ON_OFFROAD_TRANSITION)
params_memory.clear_all(ParamKeyType.CLEAR_ON_OFFROAD_TRANSITION)
# update onroad params, which drives pandad's safety setter thread
if started != started_prev:
@@ -151,7 +194,7 @@ def manager_thread() -> None:
started_prev = started
ensure_running(managed_processes.values(), started, params=params, CP=sm['carParams'], not_run=ignore)
ensure_running(managed_processes.values(), started, params=params, CP=sm['carParams'], not_run=ignore, classic_model=classic_model, frogpilot_toggles=frogpilot_toggles)
running = ' '.join("{}{}\u001b[0m".format("\u001b[32m" if p.proc.is_alive() else "\u001b[31m", p.name)
for p in managed_processes.values() if p.proc)
@@ -174,6 +217,9 @@ def manager_thread() -> None:
if shutdown:
break
# Update FrogPilot parameters
if sm['frogpilotPlan'].togglesUpdated:
frogpilot_toggles = get_frogpilot_toggles()
def main() -> None:
manager_init()
@@ -194,7 +240,7 @@ def main() -> None:
params = Params()
if params.get_bool("DoUninstall"):
cloudlog.warning("uninstalling")
HARDWARE.uninstall()
uninstall_frogpilot()
elif params.get_bool("DoReboot"):
cloudlog.warning("reboot")
HARDWARE.reboot()
+3 -3
View File
@@ -238,7 +238,7 @@ class DaemonProcess(ManagerProcess):
self.params = None
@staticmethod
def should_run(started, params, CP):
def should_run(started, params, CP, classic_model, frogpilot_toggles):
return True
def prepare(self) -> None:
@@ -274,13 +274,13 @@ class DaemonProcess(ManagerProcess):
def ensure_running(procs: ValuesView[ManagerProcess], started: bool, params=None, CP: car.CarParams=None,
not_run: list[str] | None=None) -> list[ManagerProcess]:
not_run: list[str] | None=None, classic_model=False, frogpilot_toggles=None) -> list[ManagerProcess]:
if not_run is None:
not_run = []
running = []
for p in procs:
if p.enabled and p.name not in not_run and p.should_run(started, params, CP):
if p.enabled and p.name not in not_run and p.should_run(started, params, CP, classic_model, frogpilot_toggles):
running.append(p)
else:
p.stop(block=False)
+40 -19
View File
@@ -7,55 +7,70 @@ from openpilot.system.manager.process import PythonProcess, NativeProcess, Daemo
WEBCAM = os.getenv("USE_WEBCAM") is not None
def driverview(started: bool, params: Params, CP: car.CarParams) -> bool:
def driverview(started: bool, params: Params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return started or params.get_bool("IsDriverViewEnabled")
def notcar(started: bool, params: Params, CP: car.CarParams) -> bool:
def notcar(started: bool, params: Params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return started and CP.notCar
def iscar(started: bool, params: Params, CP: car.CarParams) -> bool:
def iscar(started: bool, params: Params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return started and not CP.notCar
def logging(started, params, CP: car.CarParams) -> bool:
def logging(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
run = (not CP.notCar) or not params.get_bool("DisableLogging")
return started and run
def ublox_available() -> bool:
return os.path.exists('/dev/ttyHS0') and not os.path.exists('/persist/comma/use-quectel-gps')
def ublox(started, params, CP: car.CarParams) -> bool:
def ublox(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
use_ublox = ublox_available()
if use_ublox != params.get_bool("UbloxAvailable"):
params.put_bool("UbloxAvailable", use_ublox)
return started and use_ublox
def qcomgps(started, params, CP: car.CarParams) -> bool:
def qcomgps(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return started and not ublox_available()
def always_run(started, params, CP: car.CarParams) -> bool:
def always_run(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return True
def only_onroad(started: bool, params, CP: car.CarParams) -> bool:
def only_onroad(started: bool, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return started
def only_offroad(started, params, CP: car.CarParams) -> bool:
def only_offroad(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return not started
# FrogPilot functions
def allow_logging(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return not frogpilot_toggles.no_logging and logging(started, params, CP, classic_model, frogpilot_toggles)
def allow_uploads(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return not frogpilot_toggles.no_uploads
def run_classic_modeld(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return started and classic_model
def run_new_modeld(started, params, CP: car.CarParams, classic_model, frogpilot_toggles) -> bool:
return started and not classic_model
procs = [
DaemonProcess("manage_athenad", "system.athena.manage_athenad", "AthenadPid"),
NativeProcess("camerad", "system/camerad", ["./camerad"], driverview),
NativeProcess("logcatd", "system/logcatd", ["./logcatd"], only_onroad),
NativeProcess("proclogd", "system/proclogd", ["./proclogd"], only_onroad),
PythonProcess("logmessaged", "system.logmessaged", always_run),
NativeProcess("logcatd", "system/logcatd", ["./logcatd"], allow_logging),
NativeProcess("proclogd", "system/proclogd", ["./proclogd"], allow_logging),
PythonProcess("logmessaged", "system.logmessaged", allow_logging),
PythonProcess("micd", "system.micd", iscar),
PythonProcess("timed", "system.timed", always_run, enabled=not PC),
PythonProcess("dmonitoringmodeld", "selfdrive.modeld.dmonitoringmodeld", driverview, enabled=(not PC or WEBCAM)),
NativeProcess("encoderd", "system/loggerd", ["./encoderd"], only_onroad),
NativeProcess("encoderd", "system/loggerd", ["./encoderd"], allow_logging),
NativeProcess("stream_encoderd", "system/loggerd", ["./encoderd", "--stream"], notcar),
NativeProcess("loggerd", "system/loggerd", ["./loggerd"], logging),
NativeProcess("modeld", "selfdrive/modeld", ["./modeld"], only_onroad),
NativeProcess("loggerd", "system/loggerd", ["./loggerd"], allow_logging),
NativeProcess("modeld", "selfdrive/modeld", ["./modeld"], run_new_modeld),
NativeProcess("mapsd", "selfdrive/navd", ["./mapsd"], run_classic_modeld),
PythonProcess("navmodeld", "selfdrive.classic_modeld.navmodeld", run_classic_modeld),
NativeProcess("sensord", "system/sensord", ["./sensord"], only_onroad, enabled=not PC),
NativeProcess("ui", "selfdrive/ui", ["./ui"], always_run, watchdog_max_dt=(5 if not PC else None)),
PythonProcess("soundd", "selfdrive.ui.soundd", only_onroad),
@@ -69,7 +84,7 @@ procs = [
PythonProcess("dmonitoringd", "selfdrive.monitoring.dmonitoringd", driverview, enabled=(not PC or WEBCAM)),
PythonProcess("qcomgpsd", "system.qcomgpsd.qcomgpsd", qcomgps, enabled=TICI),
#PythonProcess("ugpsd", "system.ugpsd", only_onroad, enabled=TICI),
PythonProcess("navd", "selfdrive.navd.navd", only_onroad),
PythonProcess("navd", "selfdrive.navd.navd", run_classic_modeld),
PythonProcess("pandad", "selfdrive.pandad.pandad", always_run),
PythonProcess("paramsd", "selfdrive.locationd.paramsd", only_onroad),
NativeProcess("ubloxd", "system/ubloxd", ["./ubloxd"], ublox, enabled=TICI),
@@ -78,14 +93,20 @@ procs = [
PythonProcess("radard", "selfdrive.controls.radard", only_onroad),
PythonProcess("hardwared", "system.hardware.hardwared", always_run),
PythonProcess("tombstoned", "system.tombstoned", always_run, enabled=not PC),
PythonProcess("updated", "system.updated.updated", only_offroad, enabled=not PC),
PythonProcess("uploader", "system.loggerd.uploader", always_run),
PythonProcess("statsd", "system.statsd", always_run),
PythonProcess("updated", "system.updated.updated", always_run, enabled=not PC),
PythonProcess("uploader", "system.loggerd.uploader", allow_uploads),
PythonProcess("statsd", "system.statsd", allow_logging),
# debug procs
NativeProcess("bridge", "cereal/messaging", ["./bridge"], notcar),
PythonProcess("webrtcd", "system.webrtc.webrtcd", notcar),
PythonProcess("webjoystick", "tools.bodyteleop.web", notcar),
# FrogPilot processes
NativeProcess("classic_modeld", "selfdrive/classic_modeld", ["./classic_modeld"], run_classic_modeld),
PythonProcess("fleet_manager", "selfdrive.frogpilot.fleetmanager.fleet_manager", always_run),
PythonProcess("frogpilot_process", "selfdrive.frogpilot.frogpilot_process", always_run),
PythonProcess("mapd", "selfdrive.frogpilot.navigation.mapd", always_run),
]
managed_processes = {p.name: p for p in procs}
+129 -14
View File
@@ -1,20 +1,24 @@
"""Install exception handler for process crash."""
import sentry_sdk
import traceback
from datetime import datetime
from enum import Enum
from pathlib import Path
from sentry_sdk.integrations.threading import ThreadingIntegration
from openpilot.common.params import Params
from openpilot.common.params import Params, ParamKeyType
from openpilot.system.athena.registration import is_registered_device
from openpilot.system.hardware import HARDWARE, PC
from openpilot.common.swaglog import cloudlog
from openpilot.system.version import get_build_metadata, get_version
CRASHES_DIR = Path("/data/crashes")
class SentryProject(Enum):
# python project
SELFDRIVE = "https://6f3c7076c1e14b2aa10f5dde6dda0cc4@o33823.ingest.sentry.io/77924"
SELFDRIVE = "https://5ad1714d27324c74a30f9c538bff3b8d@o4505034923769856.ingest.us.sentry.io/4505034930651136"
# native project
SELFDRIVE_NATIVE = "https://3e4b586ed21a4479ad5d85083b639bc6@o33823.ingest.sentry.io/157615"
SELFDRIVE_NATIVE = "https://5ad1714d27324c74a30f9c538bff3b8d@o4505034923769856.ingest.us.sentry.io/4505034930651136"
def report_tombstone(fn: str, message: str, contents: str) -> None:
@@ -28,7 +32,18 @@ def report_tombstone(fn: str, message: str, contents: str) -> None:
def capture_exception(*args, **kwargs) -> None:
cloudlog.error("crash", exc_info=kwargs.get('exc_info', 1))
exc_text = traceback.format_exc()
phrases_to_check = [
"already exists. To overwrite it, set 'overwrite' to True",
"setup_quectel failed after retry",
]
if any(phrase in exc_text for phrase in phrases_to_check):
return
save_exception(exc_text)
cloudlog.error("crash", exc_info=kwargs.get("exc_info", 1))
try:
sentry_sdk.capture_exception(*args, **kwargs)
@@ -37,19 +52,121 @@ def capture_exception(*args, **kwargs) -> None:
cloudlog.exception("sentry exception")
def capture_fingerprint(frogpilot_toggles, params, params_tracking):
if frogpilot_toggles.block_user:
sentry_sdk.capture_message("Blocked user from using the development branch", level="warning")
sentry_sdk.flush()
return
else:
sentry_sdk.capture_message(f"User driving a: {frogpilot_toggles.car_model}", level="info")
sentry_sdk.flush()
if params.get_bool("FingerprintLogged"):
return
param_types = {
"FrogPilot Controls": ParamKeyType.FROGPILOT_CONTROLS,
"FrogPilot Vehicles": ParamKeyType.FROGPILOT_VEHICLES,
"FrogPilot Visuals": ParamKeyType.FROGPILOT_VISUALS,
"FrogPilot Other": ParamKeyType.FROGPILOT_OTHER,
"FrogPilot Tracking": ParamKeyType.FROGPILOT_TRACKING,
}
matched_params = {label: {} for label in param_types}
for key in params.all_keys():
for label, key_type in param_types.items():
if params.get_key_type(key) & key_type:
if key_type == ParamKeyType.FROGPILOT_TRACKING:
value = f"{params_tracking.get_int(key):,}"
else:
if isinstance(params.get(key), bytes):
value = params.get(key, encoding="utf-8")
else:
value = params.get(key) or "0"
if isinstance(value, str) and "." in value:
value = value.rstrip("0").rstrip(".")
matched_params[label][key.decode("utf-8")] = value
with sentry_sdk.push_scope() as scope:
for label, key_values in matched_params.items():
scope.set_context(label, key_values)
fingerprint = [params.get("DongleId", encoding="utf-8"), frogpilot_toggles.car_model]
scope.fingerprint = fingerprint
sentry_sdk.capture_message(f"Logged user: {fingerprint}", level="info")
sentry_sdk.flush()
params.put_bool("FingerprintLogged", True)
def capture_model(model_name):
sentry_sdk.capture_message(f"User using: {model_name}", level="info")
sentry_sdk.flush()
def capture_report(discord_user, report, frogpilot_toggles):
error_file_path = CRASHES_DIR / "error.txt"
error_content = "No error log found."
if error_file_path.exists():
error_content = error_file_path.read_text()
with sentry_sdk.push_scope() as scope:
scope.set_context("Error Log", {"content": error_content})
scope.set_context("Toggle Values", frogpilot_toggles)
sentry_sdk.capture_message(f"{discord_user} submitted report: {report}", level="fatal")
sentry_sdk.flush()
def capture_user(channel):
sentry_sdk.capture_message(f"Logged user on: {channel}", level="info")
sentry_sdk.flush()
def set_tag(key: str, value: str) -> None:
sentry_sdk.set_tag(key, value)
def save_exception(exc_text: str) -> None:
CRASHES_DIR.mkdir(parents=True, exist_ok=True)
files = [
CRASHES_DIR / datetime.now().strftime("%Y-%m-%d--%H-%M-%S.log"),
CRASHES_DIR / "error.txt"
]
for file_path in files:
if file_path.name == "error.txt":
lines = exc_text.splitlines()[-10:]
file_path.write_text("\n".join(lines))
else:
file_path.write_text(exc_text)
print(f"Logged current crash to {[str(file) for file in files]}")
def init(project: SentryProject) -> bool:
build_metadata = get_build_metadata()
# forks like to mess with this, so double check
comma_remote = build_metadata.openpilot.comma_remote and "commaai" in build_metadata.openpilot.git_origin
if not comma_remote or not is_registered_device() or PC:
FrogPilot = "frogai" in build_metadata.openpilot.git_origin.lower()
if not FrogPilot or PC:
return False
env = "release" if build_metadata.tested_channel else "master"
dongle_id = Params().get("DongleId", encoding='utf-8')
short_branch = build_metadata.channel
if short_branch == "FrogPilot-Development":
env = "Development"
elif build_metadata.release_channel:
env = "Release"
elif build_metadata.tested_channel:
env = "Staging"
else:
env = short_branch
params = Params()
dongle_id = params.get("DongleId", encoding="utf-8")
installed = params.get("InstallDate", encoding="utf-8")
updated = params.get("Updated", encoding="utf-8")
integrations = []
if project == SentryProject.SELFDRIVE:
@@ -63,14 +180,12 @@ def init(project: SentryProject) -> bool:
max_value_length=8192,
environment=env)
build_metadata = get_build_metadata()
sentry_sdk.set_user({"id": dongle_id})
sentry_sdk.set_tag("dirty", build_metadata.openpilot.is_dirty)
sentry_sdk.set_tag("origin", build_metadata.openpilot.git_origin)
sentry_sdk.set_tag("branch", build_metadata.channel)
sentry_sdk.set_tag("branch", short_branch)
sentry_sdk.set_tag("commit", build_metadata.openpilot.git_commit)
sentry_sdk.set_tag("device", HARDWARE.get_device_type())
sentry_sdk.set_tag("updated", updated)
sentry_sdk.set_tag("installed", installed)
if project == SentryProject.SELFDRIVE:
sentry_sdk.Hub.current.start_session()
Executable → Regular
+27 -12
View File
@@ -11,6 +11,7 @@ import time
import threading
from collections import defaultdict
from pathlib import Path
from zoneinfo import ZoneInfo
from openpilot.common.basedir import BASEDIR
from openpilot.common.params import Params
@@ -21,6 +22,8 @@ from openpilot.selfdrive.controls.lib.alertmanager import set_offroad_alert
from openpilot.system.hardware import AGNOS, HARDWARE
from openpilot.system.version import get_build_metadata
from openpilot.selfdrive.frogpilot.frogpilot_variables import get_frogpilot_toggles, params_memory
LOCK_FILE = os.getenv("UPDATER_LOCK_FILE", "/tmp/safe_staging_overlay.lock")
STAGING_ROOT = os.getenv("UPDATER_STAGING_ROOT", "/data/safe_staging")
@@ -271,7 +274,7 @@ class Updater:
def get_commit_hash(self, path: str = OVERLAY_MERGED) -> str:
return run(["git", "rev-parse", "HEAD"], path).rstrip()
def set_params(self, update_success: bool, failed_count: int, exception: str | None) -> None:
def set_params(self, update_success: bool, failed_count: int, exception: str | None, frogpilot_toggles: None) -> None:
self.params.put("UpdateFailedCount", str(failed_count))
self.params.put("UpdaterTargetBranch", self.target_branch)
@@ -307,7 +310,7 @@ class Updater:
with open(os.path.join(basedir, "common", "version.h")) as f:
version = f.read().split('"')[1]
commit_unix_ts = run(["git", "show", "-s", "--format=%ct", "HEAD"], basedir).rstrip()
commit_unix_ts = run(["git", "show", "-s", "--format=%ct", "HEAD"], basedir).split()[0]
dt = datetime.datetime.fromtimestamp(int(commit_unix_ts))
commit_date = dt.strftime("%b %d")
except Exception:
@@ -324,6 +327,8 @@ class Updater:
set_offroad_alert(alert, False)
now = datetime.datetime.utcnow()
if frogpilot_toggles.offline_mode:
last_update = now
dt = now - last_update
build_metadata = get_build_metadata()
if failed_count > 15 and exception is not None and self.has_internet:
@@ -405,14 +410,12 @@ class Updater:
finalize_update()
cloudlog.info("finalize success!")
# Format "Updated" to Phoenix time zone
self.params.put("Updated", datetime.datetime.now().astimezone(ZoneInfo('America/Phoenix')).strftime("%B %d, %Y - %I:%M%p").encode('utf8'))
def main() -> None:
params = Params()
if params.get_bool("DisableUpdates"):
cloudlog.warning("updates are disabled by the DisableUpdates param")
exit(0)
with open(LOCK_FILE, 'w') as ov_lock_fd:
try:
fcntl.flock(ov_lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
@@ -428,10 +431,6 @@ def main() -> None:
if Path(os.path.join(STAGING_ROOT, "old_openpilot")).is_dir():
cloudlog.event("update installed")
if not params.get("InstallDate"):
t = datetime.datetime.utcnow().isoformat()
params.put("InstallDate", t.encode('utf8'))
updater = Updater()
update_failed_count = 0 # TODO: Load from param?
wait_helper = WaitTimeHelper()
@@ -444,6 +443,12 @@ def main() -> None:
# Run the update loop
first_run = True
# FrogPilot variables
frogpilot_toggles = get_frogpilot_toggles()
install_date_set = params.get("InstallDate", encoding='utf-8') is not None and params.get("Updated", encoding='utf-8') is not None
while True:
wait_helper.ready_event.clear()
@@ -454,18 +459,28 @@ def main() -> None:
init_overlay()
# ensure we have some params written soon after startup
updater.set_params(False, update_failed_count, exception)
updater.set_params(False, update_failed_count, exception, frogpilot_toggles)
if not system_time_valid() or first_run:
first_run = False
wait_helper.sleep(60)
continue
# Format "InstallDate" to Phoenix time zone
if not install_date_set:
params.put("InstallDate", datetime.datetime.now().astimezone(ZoneInfo('America/Phoenix')).strftime("%B %d, %Y - %I:%M%p").encode('utf8'))
install_date_set = True
if not (frogpilot_toggles.automatic_updates or params_memory.get_bool("ManualUpdateInitiated")):
wait_helper.sleep(60*60*24*365*100)
continue
update_failed_count += 1
# check for update
params.put("UpdaterState", "checking...")
updater.check_for_update()
params_memory.remove("ManualUpdateInitiated")
# download update
last_fetch = read_time_from_param(params, "UpdaterLastFetchTime")
@@ -496,7 +511,7 @@ def main() -> None:
try:
params.put("UpdaterState", "idle")
update_successful = (update_failed_count == 0)
updater.set_params(update_successful, update_failed_count, exception)
updater.set_params(update_successful, update_failed_count, exception, frogpilot_toggles)
except Exception:
cloudlog.exception("uncaught updated exception while setting params, shouldn't happen")
+2 -2
View File
@@ -10,8 +10,8 @@ from openpilot.common.basedir import BASEDIR
from openpilot.common.swaglog import cloudlog
from openpilot.common.git import get_commit, get_origin, get_branch, get_short_branch, get_commit_date
RELEASE_BRANCHES = ['release3-staging', 'release3', 'nightly']
TESTED_BRANCHES = RELEASE_BRANCHES + ['devel', 'devel-staging']
RELEASE_BRANCHES = ['FrogPilot', 'FrogPilot-New']
TESTED_BRANCHES = RELEASE_BRANCHES + ['FrogPilot-Staging', 'FrogPilot-Testing']
BUILD_METADATA_FILENAME = "build.json"