mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 13:33:42 +08:00
b06f37e2c7
Define persistent settings, typed schema fields and storage migrations before feature owners consume them. Keep calibration and parameter readers aligned with the shared data contracts.
145 lines
5.3 KiB
Python
Executable File
145 lines
5.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
from enum import IntEnum
|
|
|
|
|
|
# TODO: this should be automatically determined using the capnp schema
|
|
class QueueSize(IntEnum):
|
|
BIG = 10 * 1024 * 1024 # 10MB - video frames, large AI outputs
|
|
MEDIUM = 2 * 1024 * 1024 # 2MB - high freq (CAN), livestream
|
|
SMALL = 250 * 1024 # 250KB - most services
|
|
|
|
|
|
class Service:
|
|
def __init__(self, should_log: bool, frequency: float, decimation: int | None = None,
|
|
queue_size: QueueSize = QueueSize.SMALL):
|
|
self.should_log = should_log
|
|
self.frequency = frequency
|
|
self.decimation = decimation
|
|
self.queue_size = queue_size
|
|
|
|
|
|
_services: dict[str, tuple] = {
|
|
"starpilotNavigation": (True, 1., 1),
|
|
# service: (should_log, frequency, qlog decimation (optional))
|
|
# note: the "EncodeIdx" packets will still be in the log
|
|
"gyroscope": (True, 104., 104),
|
|
"accelerometer": (True, 104., 104),
|
|
"temperatureSensor": (True, 2., 200),
|
|
"deviceState": (True, 2., 1),
|
|
"chestnutState": (True, 10., 1),
|
|
"chestnutGpuState": (False, 10.),
|
|
"touch": (True, 20., 1),
|
|
"can": (True, 100., 2053, QueueSize.BIG), # decimation gives ~3 msgs in a full segment
|
|
"controlsState": (True, 100., 10, QueueSize.MEDIUM),
|
|
"starpilotLateralState": (True, 100., 10),
|
|
"selfdriveState": (True, 100., 10),
|
|
"starpilotSelfdriveState": (True, 100., 10),
|
|
"pandaStates": (True, 10., 1),
|
|
"peripheralState": (True, 2., 1),
|
|
"radarState": (True, 20., 5),
|
|
"starpilotRadarState": (True, 20., 5),
|
|
# Sparse, gated camera observations; freshness is qualified from payload
|
|
# clocks, never inferred from a nominal service frequency.
|
|
"spotMonitorState": (True, 0., 1),
|
|
"narrowRoadEncodeIdx": (False, 20., 1),
|
|
"radarTracks": (True, 20.),
|
|
"sendcan": (True, 100., 139, QueueSize.MEDIUM),
|
|
"logMessage": (True, 0., None, QueueSize.BIG),
|
|
# Recorder-only transport carrying Event.logMessage, retained in qlog.
|
|
"modelIdentity": (True, 0.2, 1),
|
|
"errorLogMessage": (True, 0., 1, QueueSize.BIG),
|
|
"extrinsicsCalibration": (True, 4., 4),
|
|
"lateralTorqueParameters": (True, 4., 1),
|
|
"lateralDelay": (True, 4., 1),
|
|
"operatingSystemLog": (True, 0.),
|
|
"carState": (True, 100., 10),
|
|
"carControl": (True, 100., 10),
|
|
"carOutput": (True, 100., 10),
|
|
"longitudinalPlan": (True, 20., 10),
|
|
"slcState": (True, 20., 10),
|
|
"slcAction": (True, 0., 1),
|
|
"slcCruiseEvent": (True, 0., 1),
|
|
"slcDashboardObservation": (True, 100., 10),
|
|
"slcVisionObservation": (True, 6., 6),
|
|
"slcCruiseCommand": (True, 20., 1),
|
|
"aolAxisState": (True, 100., 10),
|
|
"aolSafetyWire": (True, 10., 10),
|
|
"aolIntentWire": (True, 100., 10),
|
|
"laneChangeAssistWire": (True, 20., 10),
|
|
"mapdOut": (True, 20., 10),
|
|
"mapdExtendedOut": (True, 1., 1),
|
|
"mapdIn": (True, 1., 1),
|
|
"lateralManeuverPlan": (True, 20.),
|
|
"driverAssistance": (True, 20., 20),
|
|
"procLog": (True, 0.5, 15, QueueSize.BIG),
|
|
"gpsLocationExternal": (True, 10., 10),
|
|
"gpsLocation": (True, 1., 1),
|
|
"ubloxGnss": (True, 10.),
|
|
"qcomGnss": (True, 2.),
|
|
"clocks": (True, 0.1, 1),
|
|
"ubloxRaw": (True, 20.),
|
|
"deviceMotion": (True, 20., 4),
|
|
"vehicleParameters": (True, 20., 5),
|
|
"cameraOdometry": (True, 20., 10),
|
|
"thumbnail": (True, 1 / 60., 1),
|
|
"onroadEvents": (True, 1., 1),
|
|
"carParams": (True, 0.02, 1),
|
|
"narrowRoadCameraState": (True, 20., 20),
|
|
"cabinCameraState": (True, 20., 20),
|
|
"cabinEncodeIdx": (False, 20., 1),
|
|
"driverStateV2": (True, 20., 10),
|
|
"driverMonitoringState": (True, 20., 10),
|
|
"wideRoadEncodeIdx": (False, 20., 1),
|
|
"wideRoadCameraState": (True, 20., 20),
|
|
"drivingModelData": (True, 20., 10),
|
|
"modelV2": (True, 20., None, QueueSize.BIG),
|
|
"managerState": (True, 2., 1),
|
|
"qNarrowRoadEncodeIdx": (False, 20.),
|
|
"userBookmark": (True, 0., 1),
|
|
"soundPressure": (True, 10., 10),
|
|
"rawAudioData": (False, 20.),
|
|
"bookmarkButton": (True, 0., 1),
|
|
"narrowRoadEncodeData": (False, 20., None, QueueSize.BIG),
|
|
"cabinEncodeData": (False, 20., None, QueueSize.BIG),
|
|
"wideRoadEncodeData": (False, 20., None, QueueSize.BIG),
|
|
"qNarrowRoadEncodeData": (False, 20., None, QueueSize.BIG),
|
|
|
|
# debug
|
|
"uiDebug": (True, 0., 1),
|
|
"testJoystick": (True, 0.),
|
|
"alertDebug": (True, 20., 5),
|
|
"livestreamWideRoadEncodeIdx": (False, 20.),
|
|
"livestreamNarrowRoadEncodeIdx": (False, 20.),
|
|
"livestreamCabinEncodeIdx": (False, 20.),
|
|
"livestreamWideRoadEncodeData": (False, 20., None, QueueSize.MEDIUM),
|
|
"livestreamNarrowRoadEncodeData": (False, 20., None, QueueSize.MEDIUM),
|
|
"livestreamCabinEncodeData": (False, 20., None, QueueSize.MEDIUM),
|
|
}
|
|
SERVICE_LIST = {name: Service(*vals) for
|
|
idx, (name, vals) in enumerate(_services.items())}
|
|
|
|
|
|
def build_header():
|
|
h = ""
|
|
h += "/* THIS IS AN AUTOGENERATED FILE, PLEASE EDIT services.py */\n"
|
|
h += "#ifndef __SERVICES_H\n"
|
|
h += "#define __SERVICES_H\n"
|
|
|
|
h += "#include <map>\n"
|
|
h += "#include <string>\n"
|
|
|
|
h += "struct service { std::string name; bool should_log; float frequency; int decimation; size_t queue_size; };\n"
|
|
h += "static std::map<std::string, service> services = {\n"
|
|
for k, v in SERVICE_LIST.items():
|
|
should_log = "true" if v.should_log else "false"
|
|
decimation = -1 if v.decimation is None else v.decimation
|
|
h += f' {{ "{k}", {{"{k}", {should_log}, {v.frequency:f}, {decimation:d}, {v.queue_size:d}}}}},\n'
|
|
h += "};\n"
|
|
|
|
h += "#endif\n"
|
|
return h
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(build_header())
|