mirror of https://github.com/commaai/cereal.git
34 lines
1.1 KiB
Python
Executable File
34 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import os
|
|
import yaml
|
|
|
|
class Service():
|
|
def __init__(self, port, should_log, frequency, decimation=None):
|
|
self.port = port
|
|
self.should_log = should_log
|
|
self.frequency = frequency
|
|
self.decimation = decimation
|
|
|
|
service_list_path = os.path.join(os.path.dirname(__file__), "service_list.yaml")
|
|
|
|
service_list = {}
|
|
with open(service_list_path, "r") as f:
|
|
for k, v in yaml.safe_load(f).items():
|
|
decimation = None
|
|
if len(v) == 4:
|
|
decimation = v[3]
|
|
|
|
service_list[k] = Service(v[0], v[1], v[2], decimation)
|
|
|
|
if __name__ == "__main__":
|
|
print("/* THIS IS AN AUTOGENERATED FILE, PLEASE EDIT service_list.yaml */")
|
|
print("#ifndef __SERVICES_H")
|
|
print("#define __SERVICES_H")
|
|
print("struct service { int port; bool should_log; int frequency; int decimation; char name[0x100]; };")
|
|
print("static struct service services[] = {")
|
|
for k, v in service_list.items():
|
|
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))
|
|
print("};")
|
|
print("#endif")
|
|
|