services: capitalize constant service list (#534)

* rename services

* keep more unique name

* type this
This commit is contained in:
Shane Smiskol 2023-09-21 18:01:44 -07:00 committed by GitHub
parent 25cfa642e6
commit aed84aeedf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 11 deletions

View File

@ -11,7 +11,7 @@ from typing import Optional, List, Union, Dict, Deque
from collections import deque from collections import deque
from cereal import log from cereal import log
from cereal.services import service_list from cereal.services import SERVICE_LIST
assert MultiplePublishersError assert MultiplePublishersError
assert MessagingError assert MessagingError
@ -180,7 +180,7 @@ class SubMaster:
if addr is not None: if addr is not None:
p = self.poller if s not in self.non_polled_services else 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.sock[s] = sub_sock(s, poller=p, addr=addr, conflate=True)
self.freq[s] = service_list[s].frequency self.freq[s] = SERVICE_LIST[s].frequency
try: try:
data = new_message(s) data = new_message(s)

View File

@ -11,9 +11,9 @@ from parameterized import parameterized
from cereal import log, car from cereal import log, car
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal.services import service_list from cereal.services import SERVICE_LIST
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 SERVICE_LIST.keys()]
def random_sock(): def random_sock():
return random.choice(events) return random.choice(events)

View File

@ -6,21 +6,21 @@ import unittest
from parameterized import parameterized from parameterized import parameterized
import cereal.services as services import cereal.services as services
from cereal.services import service_list, RESERVED_PORT, STARTING_PORT from cereal.services import SERVICE_LIST, RESERVED_PORT, STARTING_PORT
class TestServices(unittest.TestCase): class TestServices(unittest.TestCase):
@parameterized.expand(service_list.keys()) @parameterized.expand(SERVICE_LIST.keys())
def test_services(self, s): def test_services(self, s):
service = service_list[s] service = SERVICE_LIST[s]
self.assertTrue(service.port != RESERVED_PORT) self.assertTrue(service.port != RESERVED_PORT)
self.assertTrue(service.port >= STARTING_PORT) self.assertTrue(service.port >= STARTING_PORT)
self.assertTrue(service.frequency <= 104) self.assertTrue(service.frequency <= 104)
def test_no_duplicate_port(self): def test_no_duplicate_port(self):
ports: Dict[int, str] = {} ports: Dict[int, str] = {}
for name, service in service_list.items(): for name, service in SERVICE_LIST.items():
self.assertFalse(service.port in ports.keys(), f"duplicate port {service.port}") self.assertFalse(service.port in ports.keys(), f"duplicate port {service.port}")
ports[service.port] = name ports[service.port] = name

View File

@ -18,7 +18,7 @@ class Service:
self.decimation = decimation self.decimation = decimation
services = { services: dict[str, tuple] = {
# service: (should_log, frequency, qlog decimation (optional)) # service: (should_log, frequency, qlog decimation (optional))
# note: the "EncodeIdx" packets will still be in the log # note: the "EncodeIdx" packets will still be in the log
"gyroscope": (True, 104., 104), "gyroscope": (True, 104., 104),
@ -96,7 +96,7 @@ services = {
"livestreamRoadEncodeData": (False, 20.), "livestreamRoadEncodeData": (False, 20.),
"livestreamDriverEncodeData": (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())} idx, (name, vals) in enumerate(services.items())}
@ -111,7 +111,7 @@ def build_header():
h += "struct service { std::string name; int port; bool should_log; int frequency; int decimation; };\n" h += "struct service { std::string name; int port; bool should_log; int frequency; int decimation; };\n"
h += "static std::map<std::string, service> services = {\n" h += "static std::map<std::string, service> services = {\n"
for k, v in service_list.items(): for k, v in SERVICE_LIST.items():
should_log = "true" if v.should_log else "false" should_log = "true" if v.should_log else "false"
decimation = -1 if v.decimation is None else v.decimation decimation = -1 if v.decimation is None else v.decimation
h += ' { "%s", {"%s", %d, %s, %d, %d}},\n' % \ h += ' { "%s", {"%s", %d, %s, %d, %d}},\n' % \