mirror of https://github.com/commaai/cereal.git
services: capitalize constant service list (#534)
* rename services * keep more unique name * type this
This commit is contained in:
parent
25cfa642e6
commit
aed84aeedf
|
@ -11,7 +11,7 @@ from typing import Optional, List, Union, Dict, Deque
|
|||
from collections import deque
|
||||
|
||||
from cereal import log
|
||||
from cereal.services import service_list
|
||||
from cereal.services import SERVICE_LIST
|
||||
|
||||
assert MultiplePublishersError
|
||||
assert MessagingError
|
||||
|
@ -180,7 +180,7 @@ class SubMaster:
|
|||
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)
|
||||
|
|
|
@ -11,9 +11,9 @@ from parameterized import parameterized
|
|||
|
||||
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)
|
||||
|
|
|
@ -6,21 +6,21 @@ import unittest
|
|||
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
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class Service:
|
|||
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 @@ services = {
|
|||
"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())}
|
||||
|
||||
|
||||
|
@ -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' % \
|
||||
|
|
Loading…
Reference in New Issue