CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_DDS/gen_config_h.py
Views: 1798
1
#!/usr/bin/env python3
2
'''
3
process a *.h.in file to produce a *.h file
4
'''
5
6
# TODO move to AP_DDS_Client/tools
7
8
import re
9
import sys
10
11
config = {
12
'PROJECT_VERSION_MAJOR': 1,
13
'PROJECT_VERSION_MINOR': 0,
14
'PROJECT_VERSION_PATCH': 0,
15
'PROJECT_VERSION': 2,
16
'UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS': 4,
17
'UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS': 4,
18
'UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS': 4,
19
'UCLIENT_MAX_INPUT_RELIABLE_STREAMS': 2,
20
'UCLIENT_MAX_SESSION_CONNECTION_ATTEMPTS': 2,
21
'UCLIENT_MIN_SESSION_CONNECTION_INTERVAL': 1000,
22
'UCLIENT_MIN_HEARTBEAT_TIME_INTERVAL': 200,
23
'UCLIENT_UDP_TRANSPORT_MTU': 300,
24
'UCLIENT_TCP_TRANSPORT_MTU': 350,
25
'UCLIENT_SERIAL_TRANSPORT_MTU': 1024,
26
'UCLIENT_CUSTOM_TRANSPORT_MTU': 512,
27
'CONFIG_MACHINE_ENDIANNESS': 1, # little endian
28
'UCLIENT_SHARED_MEMORY_MAX_ENTITIES': 0,
29
'UCLIENT_SHARED_MEMORY_STATIC_MEM_SIZE': 0,
30
'UCLIENT_HARD_LIVELINESS_CHECK_TIMEOUT': 1000,
31
}
32
33
defines = {
34
"UCLIENT_PROFILE_UDP": 0,
35
"UCLIENT_PROFILE_TCP": 0,
36
"UCLIENT_PROFILE_CAN": 0,
37
"UCLIENT_PROFILE_SERIAL": 0,
38
"UCLIENT_PROFILE_CUSTOM_TRANSPORT": 1,
39
"UCLIENT_PROFILE_DISCOVERY": 0,
40
"UCLIENT_PLATFORM_POSIX": 0,
41
"UCLIENT_PLATFORM_POSIX_NOPOLL": 0,
42
"UCLIENT_PLATFORM_WINDOWS": 0,
43
"UCLIENT_PLATFORM_FREERTOS_PLUS_TCP": 0,
44
"UCLIENT_PLATFORM_ZEPHYR": 0,
45
"UCLIENT_EXTERNAL_TCP": 0,
46
"UCLIENT_EXTERNAL_UDP": 0,
47
"UCLIENT_EXTERNAL_SERIAL": 0,
48
"UCLIENT_PROFILE_MULTITHREAD": 0,
49
"UCLIENT_PROFILE_SHARED_MEMORY": 0,
50
"UCLIENT_PROFILE_STREAM_FRAMING": 1,
51
"UCLIENT_PLATFORM_RTEMS_BSD_NET": 0,
52
"UCLIENT_TWEAK_XRCE_WRITE_LIMIT": 0,
53
"UCLIENT_HARD_LIVELINESS_CHECK": 0,
54
}
55
56
h_in = sys.argv[1]
57
h = sys.argv[2]
58
print("Processing %s to %s" % (h_in, h))
59
60
txt = open(h_in, 'r').read()
61
62
for c in sorted(config.keys(), key=len, reverse=True):
63
txt = txt.replace("@%s@" % c, str(config[c]))
64
65
for c in sorted(defines.keys(), key=len, reverse=True):
66
if defines[c] != 0:
67
txt = txt.replace("#cmakedefine %s" % c, "#define %s %u" % (c, defines[c]))
68
else:
69
txt = txt.replace("#cmakedefine %s" % c, "// #define %s %u" % (c, defines[c]))
70
71
matches = re.findall(r'@(\w+)@', txt)
72
if len(matches) > 0:
73
print("Missing config elements: ", matches)
74
sys.exit(1)
75
76
matches = re.findall(r'#cmakedefine\s+\w+', txt)
77
if len(matches) > 0:
78
print("Missing #cmakedefine elements: ", matches)
79
sys.exit(1)
80
81
open(h, 'w').write(txt)
82
83