mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-08-05 08:16:06 +08:00
services: capitalize constant service list (#30005)
* rename * bump * Apply suggestions from code review
This commit is contained in:
+1
-1
Submodule cereal updated: 4b334f6f10...aed84aeedf
@@ -29,7 +29,7 @@ from websocket import (ABNF, WebSocket, WebSocketException, WebSocketTimeoutExce
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal import log
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.common.api import Api
|
||||
from openpilot.common.basedir import PERSIST
|
||||
from openpilot.common.file_helpers import CallbackReader
|
||||
@@ -309,7 +309,7 @@ def _do_upload(upload_item: UploadItem, callback: Optional[Callable] = None) ->
|
||||
# security: user should be able to request any message from their car
|
||||
@dispatcher.add_method
|
||||
def getMessage(service: str, timeout: int = 1000) -> dict:
|
||||
if service is None or service not in service_list:
|
||||
if service is None or service not in SERVICE_LIST:
|
||||
raise Exception("invalid service")
|
||||
|
||||
socket = messaging.sub_sock(service, timeout=timeout)
|
||||
|
||||
@@ -969,7 +969,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = {
|
||||
|
||||
if __name__ == '__main__':
|
||||
# print all alerts by type and priority
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from collections import defaultdict, OrderedDict
|
||||
|
||||
event_names = {v: k for k, v in EventName.schema.enumerants.items()}
|
||||
@@ -977,7 +977,7 @@ if __name__ == '__main__':
|
||||
|
||||
CP = car.CarParams.new_message()
|
||||
CS = car.CarState.new_message()
|
||||
sm = messaging.SubMaster(list(service_list.keys()))
|
||||
sm = messaging.SubMaster(list(SERVICE_LIST.keys()))
|
||||
|
||||
for i, alerts in EVENTS.items():
|
||||
for et, alert in alerts.items():
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from typing import Dict
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
|
||||
TO_CHECK = ['carState']
|
||||
|
||||
@@ -20,7 +20,7 @@ if __name__ == "__main__":
|
||||
t = sm.logMonoTime[s] / 1e9
|
||||
|
||||
if s in prev_t:
|
||||
expected = 1.0 / (service_list[s].frequency)
|
||||
expected = 1.0 / (SERVICE_LIST[s].frequency)
|
||||
dt = t - prev_t[s]
|
||||
if dt > 10 * expected:
|
||||
print(t, s, dt)
|
||||
|
||||
@@ -7,7 +7,7 @@ from pprint import pprint
|
||||
from tqdm import tqdm
|
||||
from typing import List, Tuple, cast
|
||||
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.tools.lib.route import Route
|
||||
from openpilot.tools.lib.logreader import LogReader
|
||||
|
||||
@@ -17,7 +17,7 @@ if __name__ == "__main__":
|
||||
cnt_valid: Counter = Counter()
|
||||
cnt_events: Counter = Counter()
|
||||
|
||||
cams = [s for s in service_list if s.endswith('CameraState')]
|
||||
cams = [s for s in SERVICE_LIST if s.endswith('CameraState')]
|
||||
cnt_cameras = dict.fromkeys(cams, 0)
|
||||
|
||||
alerts: List[Tuple[float, str]] = []
|
||||
@@ -62,7 +62,7 @@ if __name__ == "__main__":
|
||||
print("\n")
|
||||
print("Cameras")
|
||||
for k, v in cnt_cameras.items():
|
||||
s = service_list[k]
|
||||
s = SERVICE_LIST[k]
|
||||
expected_frames = int(s.frequency * duration / cast(float, s.decimation))
|
||||
print(" ", k.ljust(20), f"{v}, {v/expected_frames:.1%} of expected")
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import cereal.messaging as messaging
|
||||
|
||||
from hexdump import hexdump
|
||||
from cereal import log
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
|
||||
codecs.register_error("strict", codecs.backslashreplace_errors)
|
||||
|
||||
@@ -31,7 +31,7 @@ if __name__ == "__main__":
|
||||
|
||||
poller = messaging.Poller()
|
||||
|
||||
for m in args.socket if len(args.socket) > 0 else service_list:
|
||||
for m in args.socket if len(args.socket) > 0 else SERVICE_LIST:
|
||||
messaging.sub_sock(m, poller, addr=args.addr)
|
||||
|
||||
values = None
|
||||
|
||||
@@ -5,7 +5,7 @@ from collections import defaultdict
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.tools.lib.logreader import LogReader
|
||||
from openpilot.tools.lib.route import Route
|
||||
|
||||
@@ -49,7 +49,7 @@ if __name__ == "__main__":
|
||||
msgs_by_type[m.which()].append(m.as_builder().to_bytes())
|
||||
|
||||
qlog_by_type = defaultdict(list)
|
||||
for name, service in service_list.items():
|
||||
for name, service in SERVICE_LIST.items():
|
||||
if service.decimation is None:
|
||||
continue
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import time
|
||||
import capnp
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.common.transformations.coordinates import ecef2geodetic
|
||||
|
||||
@@ -74,8 +74,8 @@ class TestLocationdProc(unittest.TestCase):
|
||||
msgs = []
|
||||
for sec in range(65):
|
||||
for name in self.LLD_MSGS:
|
||||
for j in range(int(service_list[name].frequency)):
|
||||
msgs.append(self.get_msg(name, int((sec + j / service_list[name].frequency) * 1e9)))
|
||||
for j in range(int(SERVICE_LIST[name].frequency)):
|
||||
msgs.append(self.get_msg(name, int((sec + j / SERVICE_LIST[name].frequency) * 1e9)))
|
||||
|
||||
for msg in sorted(msgs, key=lambda x: x.logMonoTime):
|
||||
self.pm.send(msg.which(), msg)
|
||||
|
||||
@@ -14,7 +14,7 @@ import capnp
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal import car
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from cereal.visionipc import VisionIpcServer, get_endpoint_name as vipc_get_endpoint_name
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.common.prefix import OpenpilotPrefix
|
||||
@@ -364,7 +364,7 @@ def controlsd_rcv_callback(msg, cfg, frame):
|
||||
|
||||
socks = [
|
||||
s for s in cfg.subs if
|
||||
frame % int(service_list[msg.which()].frequency / service_list[s].frequency) == 0
|
||||
frame % int(SERVICE_LIST[msg.which()].frequency / SERVICE_LIST[s].frequency) == 0
|
||||
]
|
||||
if "sendcan" in socks and (frame - 1) < 2000:
|
||||
socks.remove("sendcan")
|
||||
@@ -428,7 +428,7 @@ class FrequencyBasedRcvCallback:
|
||||
|
||||
resp_sockets = [
|
||||
s for s in cfg.subs
|
||||
if frame % max(1, int(service_list[msg.which()].frequency / service_list[s].frequency)) == 0
|
||||
if frame % max(1, int(SERVICE_LIST[msg.which()].frequency / SERVICE_LIST[s].frequency)) == 0
|
||||
]
|
||||
return bool(len(resp_sockets))
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from collections import defaultdict, deque
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
import cereal.messaging as messaging
|
||||
import capnp
|
||||
|
||||
@@ -67,7 +67,7 @@ class SubMaster(messaging.SubMaster):
|
||||
self.msgs = list(reversed(self.msgs))
|
||||
|
||||
for s in services:
|
||||
self.freq[s] = service_list[s].frequency
|
||||
self.freq[s] = SERVICE_LIST[s].frequency
|
||||
try:
|
||||
data = messaging.new_message(s)
|
||||
except capnp.lib.capnp.KjException:
|
||||
|
||||
@@ -13,7 +13,7 @@ from pathlib import Path
|
||||
|
||||
from cereal import car
|
||||
import cereal.messaging as messaging
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.common.basedir import BASEDIR
|
||||
from openpilot.common.timeout import Timeout
|
||||
from openpilot.common.params import Params
|
||||
@@ -179,7 +179,7 @@ class TestOnroad(unittest.TestCase):
|
||||
continue
|
||||
|
||||
with self.subTest(service=s):
|
||||
assert len(msgs) >= math.floor(service_list[s].frequency*55)
|
||||
assert len(msgs) >= math.floor(SERVICE_LIST[s].frequency*55)
|
||||
|
||||
def test_cloudlog_size(self):
|
||||
msgs = [m for m in self.lr if m.which() == 'logMessage']
|
||||
@@ -356,7 +356,7 @@ class TestOnroad(unittest.TestCase):
|
||||
raise Exception(f"missing {s}")
|
||||
|
||||
ts = np.diff(msgs) / 1e9
|
||||
dt = 1 / service_list[s].frequency
|
||||
dt = 1 / SERVICE_LIST[s].frequency
|
||||
|
||||
try:
|
||||
np.testing.assert_allclose(np.mean(ts), dt, rtol=0.03, err_msg=f"{s} - failed mean timing check")
|
||||
|
||||
@@ -6,7 +6,7 @@ from collections import defaultdict
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal import log
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.selfdrive.manager.process_config import managed_processes
|
||||
from openpilot.system.hardware import TICI
|
||||
|
||||
@@ -43,10 +43,10 @@ class TestCamerad(unittest.TestCase):
|
||||
for cam, msgs in cls.logs.items():
|
||||
if cls.sensor_type is None:
|
||||
cls.sensor_type = getattr(msgs[0], msgs[0].which()).sensor.raw
|
||||
expected_frames = service_list[cam].frequency * TEST_TIMESPAN
|
||||
expected_frames = SERVICE_LIST[cam].frequency * TEST_TIMESPAN
|
||||
assert expected_frames*0.95 < len(msgs) < expected_frames*1.05, f"unexpected frame count {cam}: {expected_frames=}, got {len(msgs)}"
|
||||
|
||||
dts = np.abs(np.diff([getattr(m, m.which()).timestampSof/1e6 for m in msgs]) - 1000/service_list[cam].frequency)
|
||||
dts = np.abs(np.diff([getattr(m, m.which()).timestampSof/1e6 for m in msgs]) - 1000/SERVICE_LIST[cam].frequency)
|
||||
assert (dts < FRAME_DELTA_TOLERANCE[cls.sensor_type]).all(), f"{cam} dts(ms) out of spec: max diff {dts.max()}, 99 percentile {np.percentile(dts, 99)}"
|
||||
|
||||
for m in msgs:
|
||||
|
||||
@@ -8,7 +8,7 @@ from tabulate import tabulate
|
||||
from typing import List
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.system.hardware import HARDWARE, TICI
|
||||
from openpilot.system.hardware.tici.power_monitor import get_power
|
||||
from openpilot.selfdrive.manager.process_config import managed_processes
|
||||
@@ -91,7 +91,7 @@ class TestPowerDraw(unittest.TestCase):
|
||||
cur = used[proc.name]
|
||||
expected = proc.power
|
||||
msgs_received = sum(msg_counts[msg] for msg in proc.msgs)
|
||||
msgs_expected = int(sum(SAMPLE_TIME * service_list[msg].frequency for msg in proc.msgs))
|
||||
msgs_expected = int(sum(SAMPLE_TIME * SERVICE_LIST[msg].frequency for msg in proc.msgs))
|
||||
tab.append([proc.name, round(expected, 2), round(cur, 2), msgs_expected, msgs_received])
|
||||
with self.subTest(proc=proc.name):
|
||||
self.assertTrue(math.isclose(cur, expected, rel_tol=proc.rtol, abs_tol=proc.atol))
|
||||
|
||||
@@ -12,7 +12,7 @@ from typing import Dict, List
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal import log
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.common.basedir import BASEDIR
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.common.timeout import Timeout
|
||||
@@ -27,8 +27,8 @@ from openpilot.common.transformations.camera import tici_f_frame_size, tici_d_fr
|
||||
|
||||
SentinelType = log.Sentinel.SentinelType
|
||||
|
||||
CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in service_list
|
||||
and service_list[f].should_log and "encode" not in f.lower()]
|
||||
CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in SERVICE_LIST
|
||||
and SERVICE_LIST[f].should_log and "encode" not in f.lower()]
|
||||
|
||||
|
||||
class TestLoggerd(unittest.TestCase):
|
||||
@@ -219,8 +219,8 @@ class TestLoggerd(unittest.TestCase):
|
||||
self.assertEqual(expected_val, bootlog_val)
|
||||
|
||||
def test_qlog(self):
|
||||
qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is not None]
|
||||
no_qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is None]
|
||||
qlog_services = [s for s in CEREAL_SERVICES if SERVICE_LIST[s].decimation is not None]
|
||||
no_qlog_services = [s for s in CEREAL_SERVICES if SERVICE_LIST[s].decimation is None]
|
||||
|
||||
services = random.sample(qlog_services, random.randint(2, min(10, len(qlog_services)))) + \
|
||||
random.sample(no_qlog_services, random.randint(2, min(10, len(no_qlog_services))))
|
||||
@@ -245,7 +245,7 @@ class TestLoggerd(unittest.TestCase):
|
||||
self.assertEqual(recv_cnt, 0, f"got {recv_cnt} {s} msgs in qlog")
|
||||
else:
|
||||
# check logged message count matches decimation
|
||||
expected_cnt = (len(msgs) - 1) // service_list[s].decimation + 1
|
||||
expected_cnt = (len(msgs) - 1) // SERVICE_LIST[s].decimation + 1
|
||||
self.assertEqual(recv_cnt, expected_cnt, f"expected {expected_cnt} msgs for {s}, got {recv_cnt}")
|
||||
|
||||
def test_rlog(self):
|
||||
|
||||
@@ -3,7 +3,7 @@ import time
|
||||
import unittest
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.common.gpio import gpio_read
|
||||
from openpilot.selfdrive.test.helpers import with_processes
|
||||
from openpilot.selfdrive.manager.process_config import managed_processes
|
||||
@@ -26,10 +26,10 @@ class TestPigeond(unittest.TestCase):
|
||||
sm = messaging.SubMaster(['ubloxRaw'])
|
||||
|
||||
# setup time
|
||||
for _ in range(int(5 * service_list['ubloxRaw'].frequency)):
|
||||
for _ in range(int(5 * SERVICE_LIST['ubloxRaw'].frequency)):
|
||||
sm.update()
|
||||
|
||||
for _ in range(int(10 * service_list['ubloxRaw'].frequency)):
|
||||
for _ in range(int(10 * SERVICE_LIST['ubloxRaw'].frequency)):
|
||||
sm.update()
|
||||
assert sm.all_checks()
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from collections import namedtuple, defaultdict
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal import log
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.common.gpio import get_irqs_for_action
|
||||
from openpilot.common.timeout import Timeout
|
||||
from openpilot.system.hardware import TICI
|
||||
@@ -172,7 +172,7 @@ class TestSensord(unittest.TestCase):
|
||||
for s, msgs in self.events.items():
|
||||
with self.subTest(sensor=s):
|
||||
freq = len(msgs) / self.sample_secs
|
||||
ef = service_list[s].frequency
|
||||
ef = SERVICE_LIST[s].frequency
|
||||
assert ef*0.85 <= freq <= ef*1.15
|
||||
|
||||
def test_logmonottime_timestamp_diff(self):
|
||||
|
||||
Reference in New Issue
Block a user