From 60df619b08e5c1e1944515d204dd8e4c4b99b51d Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 16:53:24 -0700 Subject: [PATCH 1/3] rename services --- messaging/__init__.py | 4 ++-- messaging/tests/test_messaging.py | 4 ++-- messaging/tests/test_services.py | 8 ++++---- services.py | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/messaging/__init__.py b/messaging/__init__.py index fd9a48772..895f315ba 100644 --- a/messaging/__init__.py +++ b/messaging/__init__.py @@ -11,7 +11,7 @@ from collections import deque from cereal import log -from cereal.services import service_list +from cereal.services import SERVICES assert MultiplePublishersError assert MessagingError @@ -180,7 +180,7 @@ def __init__(self, services: List[str], poll: Optional[List[str]] = None, if addr is not None: p = self.poller if s not in self.non_polled_services else None self.sock[s] = sub_sock(s, poller=p, addr=addr, conflate=True) - self.freq[s] = service_list[s].frequency + self.freq[s] = SERVICES[s].frequency try: data = new_message(s) diff --git a/messaging/tests/test_messaging.py b/messaging/tests/test_messaging.py index 063351b75..032540a6b 100755 --- a/messaging/tests/test_messaging.py +++ b/messaging/tests/test_messaging.py @@ -11,9 +11,9 @@ from cereal import log, car import cereal.messaging as messaging -from cereal.services import service_list +from cereal.services import SERVICES -events = [evt for evt in log.Event.schema.union_fields if evt in service_list.keys()] +events = [evt for evt in log.Event.schema.union_fields if evt in SERVICES.keys()] def random_sock(): return random.choice(events) diff --git a/messaging/tests/test_services.py b/messaging/tests/test_services.py index 6452b5b6e..85dd42e34 100755 --- a/messaging/tests/test_services.py +++ b/messaging/tests/test_services.py @@ -6,21 +6,21 @@ from parameterized import parameterized import cereal.services as services -from cereal.services import service_list, RESERVED_PORT, STARTING_PORT +from cereal.services import SERVICES, RESERVED_PORT, STARTING_PORT class TestServices(unittest.TestCase): - @parameterized.expand(service_list.keys()) + @parameterized.expand(SERVICES.keys()) def test_services(self, s): - service = service_list[s] + service = SERVICES[s] self.assertTrue(service.port != RESERVED_PORT) self.assertTrue(service.port >= STARTING_PORT) self.assertTrue(service.frequency <= 104) def test_no_duplicate_port(self): ports: Dict[int, str] = {} - for name, service in service_list.items(): + for name, service in SERVICES.items(): self.assertFalse(service.port in ports.keys(), f"duplicate port {service.port}") ports[service.port] = name diff --git a/services.py b/services.py index 4e18d5971..769559ce9 100755 --- a/services.py +++ b/services.py @@ -96,8 +96,8 @@ def __init__(self, port: int, should_log: bool, frequency: float, decimation: Op "livestreamRoadEncodeData": (False, 20.), "livestreamDriverEncodeData": (False, 20.), } -service_list = {name: Service(new_port(idx), *vals) for # type: ignore - idx, (name, vals) in enumerate(services.items())} +SERVICES = {name: Service(new_port(idx), *vals) for # type: ignore + idx, (name, vals) in enumerate(services.items())} def build_header(): @@ -111,7 +111,7 @@ def build_header(): h += "struct service { std::string name; int port; bool should_log; int frequency; int decimation; };\n" h += "static std::map services = {\n" - for k, v in service_list.items(): + for k, v in SERVICES.items(): should_log = "true" if v.should_log else "false" decimation = -1 if v.decimation is None else v.decimation h += ' { "%s", {"%s", %d, %s, %d, %d}},\n' % \ From 288a60b5a21f79e00139f44b9f480b2d2c2a3b41 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 21 Sep 2023 17:48:09 -0700 Subject: [PATCH 2/3] keep more unique name --- messaging/__init__.py | 4 ++-- messaging/tests/test_messaging.py | 4 ++-- messaging/tests/test_services.py | 8 ++++---- services.py | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/messaging/__init__.py b/messaging/__init__.py index 895f315ba..57675212f 100644 --- a/messaging/__init__.py +++ b/messaging/__init__.py @@ -11,7 +11,7 @@ from collections import deque from cereal import log -from cereal.services import SERVICES +from cereal.services import SERVICE_LIST assert MultiplePublishersError assert MessagingError @@ -180,7 +180,7 @@ def __init__(self, services: List[str], poll: Optional[List[str]] = None, if addr is not None: p = self.poller if s not in self.non_polled_services else None self.sock[s] = sub_sock(s, poller=p, addr=addr, conflate=True) - self.freq[s] = SERVICES[s].frequency + self.freq[s] = SERVICE_LIST[s].frequency try: data = new_message(s) diff --git a/messaging/tests/test_messaging.py b/messaging/tests/test_messaging.py index 032540a6b..f9c85e0dc 100755 --- a/messaging/tests/test_messaging.py +++ b/messaging/tests/test_messaging.py @@ -11,9 +11,9 @@ from cereal import log, car import cereal.messaging as messaging -from cereal.services import SERVICES +from cereal.services import SERVICE_LIST -events = [evt for evt in log.Event.schema.union_fields if evt in SERVICES.keys()] +events = [evt for evt in log.Event.schema.union_fields if evt in SERVICE_LIST.keys()] def random_sock(): return random.choice(events) diff --git a/messaging/tests/test_services.py b/messaging/tests/test_services.py index 85dd42e34..f26bdbc5f 100755 --- a/messaging/tests/test_services.py +++ b/messaging/tests/test_services.py @@ -6,21 +6,21 @@ from parameterized import parameterized import cereal.services as services -from cereal.services import SERVICES, RESERVED_PORT, STARTING_PORT +from cereal.services import SERVICE_LIST, RESERVED_PORT, STARTING_PORT class TestServices(unittest.TestCase): - @parameterized.expand(SERVICES.keys()) + @parameterized.expand(SERVICE_LIST.keys()) def test_services(self, s): - service = SERVICES[s] + service = SERVICE_LIST[s] self.assertTrue(service.port != RESERVED_PORT) self.assertTrue(service.port >= STARTING_PORT) self.assertTrue(service.frequency <= 104) def test_no_duplicate_port(self): ports: Dict[int, str] = {} - for name, service in SERVICES.items(): + for name, service in SERVICE_LIST.items(): self.assertFalse(service.port in ports.keys(), f"duplicate port {service.port}") ports[service.port] = name diff --git a/services.py b/services.py index 769559ce9..6cf916b1e 100755 --- a/services.py +++ b/services.py @@ -96,8 +96,8 @@ def __init__(self, port: int, should_log: bool, frequency: float, decimation: Op "livestreamRoadEncodeData": (False, 20.), "livestreamDriverEncodeData": (False, 20.), } -SERVICES = {name: Service(new_port(idx), *vals) for # type: ignore - idx, (name, vals) in enumerate(services.items())} +SERVICE_LIST = {name: Service(new_port(idx), *vals) for # type: ignore + idx, (name, vals) in enumerate(services.items())} def build_header(): @@ -111,7 +111,7 @@ def build_header(): h += "struct service { std::string name; int port; bool should_log; int frequency; int decimation; };\n" h += "static std::map services = {\n" - for k, v in SERVICES.items(): + 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 += ' { "%s", {"%s", %d, %s, %d, %d}},\n' % \ From fb2fe006bc0fc4e31ba9ebc1c6f30dedb72ffa02 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 21 Sep 2023 17:51:07 -0700 Subject: [PATCH 3/3] type this --- services.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services.py b/services.py index 6cf916b1e..e9402f5cb 100755 --- a/services.py +++ b/services.py @@ -18,7 +18,7 @@ def __init__(self, port: int, should_log: bool, frequency: float, decimation: Op self.decimation = decimation -services = { +services: dict[str, tuple] = { # service: (should_log, frequency, qlog decimation (optional)) # note: the "EncodeIdx" packets will still be in the log "gyroscope": (True, 104., 104), @@ -96,7 +96,7 @@ def __init__(self, port: int, should_log: bool, frequency: float, decimation: Op "livestreamRoadEncodeData": (False, 20.), "livestreamDriverEncodeData": (False, 20.), } -SERVICE_LIST = {name: Service(new_port(idx), *vals) for # type: ignore +SERVICE_LIST = {name: Service(new_port(idx), *vals) for idx, (name, vals) in enumerate(services.items())}