Skip to content

Commit a36758d

Browse files
define services in python (commaai#118)
* define services in python * rm * optional
1 parent e1b16fd commit a36758d

File tree

3 files changed

+95
-206
lines changed

3 files changed

+95
-206
lines changed

SConscript

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ env.SharedLibrary('cereal_shared', cereal_objects)
2727

2828
# Build messaging
2929

30-
services_h = env.Command(['services.h'],
31-
['service_list.yaml', 'services.py'],
32-
'python3 ' + cereal_dir.path + '/services.py > $TARGET')
30+
services_h = env.Command(['services.h'], ['services.py'], 'python3 ' + cereal_dir.path + '/services.py > $TARGET')
3331

3432
messaging_objects = env.SharedObject([
3533
'messaging/messaging.cc',

service_list.yaml

-181
This file was deleted.

services.py

+94-22
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,106 @@
11
#!/usr/bin/env python3
2-
import os
3-
import yaml
2+
from typing import Optional
43

5-
6-
class Service():
7-
def __init__(self, port, should_log, frequency, decimation=None):
4+
class Service:
5+
def __init__(self, port: int, should_log: bool, frequency: float, decimation: Optional[int] = None):
86
self.port = port
97
self.should_log = should_log
108
self.frequency = frequency
119
self.decimation = decimation
1210

11+
service_list = {
12+
"frame": Service(8002, True, 20., 1),
13+
"sensorEvents": Service(8003, True, 100., 100),
14+
"gpsNMEA": Service(8004, True, 9.),
15+
"thermal": Service(8005, True, 2., 1),
16+
"can": Service(8006, True, 100.),
17+
"controlsState": Service(8007, True, 100., 100),
18+
"model": Service(8009, True, 20., 5),
19+
"features": Service(8010, True, 0.),
20+
"health": Service(8011, True, 2., 1),
21+
"radarState": Service(8012, True, 20., 5),
22+
"encodeIdx": Service(8015, True, 20., 1),
23+
"liveTracks": Service(8016, True, 20.),
24+
"sendcan": Service(8017, True, 100.),
25+
"logMessage": Service(8018, True, 0.),
26+
"liveCalibration": Service(8019, True, 4., 4),
27+
"androidLog": Service(8020, True, 0.),
28+
"carState": Service(8021, True, 100., 10),
29+
"carControl": Service(8023, True, 100., 10),
30+
"longitudinalPlan": Service(8024, True, 20., 2),
31+
"liveLocation": Service(8025, True, 0., 1),
32+
"gpsLocation": Service(8026, True, 1., 1),
33+
"ethernetData": Service(8027, True, 0.),
34+
"navUpdate": Service(8028, True, 0.),
35+
"qcomGnss": Service(8029, True, 0.),
36+
"lidarPts": Service(8030, True, 0.),
37+
"procLog": Service(8031, True, 0.5),
38+
"gpsLocationExternal": Service(8032, True, 10., 1),
39+
"ubloxGnss": Service(8033, True, 10.),
40+
"clocks": Service(8034, True, 1., 1),
41+
"liveMpc": Service(8035, False, 20.),
42+
"liveLongitudinalMpc": Service(8036, False, 20.),
43+
"navStatus": Service(8038, True, 0.),
44+
"gpsLocationTrimble": Service(8039, True, 0.),
45+
"trimbleGnss": Service(8041, True, 0.),
46+
"ubloxRaw": Service(8042, True, 20.),
47+
"gpsPlannerPoints": Service(8043, True, 0.),
48+
"gpsPlannerPlan": Service(8044, True, 0.),
49+
"applanixRaw": Service(8046, True, 0.),
50+
"orbLocation": Service(8047, True, 0.),
51+
"trafficEvents": Service(8048, True, 0.),
52+
"liveLocationTiming": Service(8049, True, 0.),
53+
"orbslamCorrection": Service(8050, True, 0.),
54+
"liveLocationCorrected": Service(8051, True, 0.),
55+
"orbObservation": Service(8052, True, 0.),
56+
"applanixLocation": Service(8053, True, 0.),
57+
"liveLocationKalman": Service(8054, True, 20., 2),
58+
"uiNavigationEvent": Service(8055, True, 0.),
59+
"orbOdometry": Service(8057, True, 0.),
60+
"orbFeatures": Service(8058, False, 0.),
61+
"orbKeyFrame": Service(8059, True, 0.),
62+
"uiLayoutState": Service(8060, True, 0.),
63+
"frontEncodeIdx": Service(8061, True, 10., 1), # should be 20fps on tici
64+
"orbFeaturesSummary": Service(8062, True, 0.),
65+
"driverState": Service(8063, True, 5., 1),
66+
"liveParameters": Service(8064, True, 20., 2),
67+
"liveMapData": Service(8065, True, 0.),
68+
"cameraOdometry": Service(8066, True, 20., 5),
69+
"lateralPlan": Service(8067, True, 20., 2),
70+
"kalmanOdometry": Service(8068, True, 0.),
71+
"thumbnail": Service(8069, True, 0.2, 1),
72+
"carEvents": Service(8070, True, 1., 1),
73+
"carParams": Service(8071, True, 0.02, 1),
74+
"frontFrame": Service(8072, True, 10.),
75+
"driverMonitoringState": Service(8073, True, 5., 1),
76+
"offroadLayout": Service(8074, False, 0.),
77+
"wideEncodeIdx": Service(8075, True, 20., 1),
78+
"wideFrame": Service(8076, True, 20.),
79+
"modelV2": Service(8077, True, 20., 20),
80+
"managerState": Service(8078, True, 2., 1),
81+
82+
"testModel": Service(8040, False, 0.),
83+
"testLiveLocation": Service(8045, False, 0.),
84+
"testJoystick": Service(8056, False, 0.),
85+
}
1386

14-
service_list_path = os.path.join(os.path.dirname(__file__), "service_list.yaml")
1587

16-
service_list = {}
17-
with open(service_list_path, "r") as f:
18-
for k, v in yaml.safe_load(f).items():
19-
decimation = None
20-
if len(v) == 4:
21-
decimation = v[3]
88+
def build_header():
89+
h = ""
90+
h += "/* THIS IS AN AUTOGENERATED FILE, PLEASE EDIT services.py */\n"
91+
h += "#ifndef __SERVICES_H\n"
92+
h += "#define __SERVICES_H\n"
93+
h += "struct service { char name[0x100]; int port; bool should_log; int frequency; int decimation; };\n"
94+
h += "static struct service services[] = {\n"
95+
for k, v in service_list.items():
96+
should_log = "true" if v.should_log else "false"
97+
decimation = -1 if v.decimation is None else v.decimation
98+
h += ' { .name = "%s", .port = %d, .should_log = %s, .frequency = %d, .decimation = %d },\n' % \
99+
(k, v.port, should_log, v.frequency, decimation)
100+
h += "};\n"
101+
h += "#endif\n"
102+
return h
22103

23-
service_list[k] = Service(v[0], v[1], v[2], decimation)
24104

25105
if __name__ == "__main__":
26-
print("/* THIS IS AN AUTOGENERATED FILE, PLEASE EDIT service_list.yaml */")
27-
print("#ifndef __SERVICES_H")
28-
print("#define __SERVICES_H")
29-
print("struct service { char name[0x100]; int port; bool should_log; int frequency; int decimation; };")
30-
print("static struct service services[] = {")
31-
for k, v in service_list.items():
32-
print(' { .name = "%s", .port = %d, .should_log = %s, .frequency = %d, .decimation = %d },' % (k, v.port, "true" if v.should_log else "false", v.frequency, -1 if v.decimation is None else v.decimation))
33-
print("};")
34-
print("#endif")
106+
print(build_header())

0 commit comments

Comments
 (0)