Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services: capitalize constant service list #534

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections import deque

from cereal import log
from cereal.services import service_list
from cereal.services import SERVICE_LIST

assert MultiplePublishersError
assert MessagingError
Expand Down Expand Up @@ -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] = SERVICE_LIST[s].frequency

try:
data = new_message(s)
Expand Down
4 changes: 2 additions & 2 deletions messaging/tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

from cereal import log, car
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():
return random.choice(events)
Expand Down
8 changes: 4 additions & 4 deletions messaging/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 SERVICE_LIST, RESERVED_PORT, STARTING_PORT


class TestServices(unittest.TestCase):

@parameterized.expand(service_list.keys())
@parameterized.expand(SERVICE_LIST.keys())
def test_services(self, s):
service = service_list[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 service_list.items():
for name, service in SERVICE_LIST.items():
self.assertFalse(service.port in ports.keys(), f"duplicate port {service.port}")
ports[service.port] = name

Expand Down
6 changes: 3 additions & 3 deletions services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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())}


Expand All @@ -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<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"
decimation = -1 if v.decimation is None else v.decimation
h += ' { "%s", {"%s", %d, %s, %d, %d}},\n' % \
Expand Down