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/Tools/autotest/validate_board_list.py
Views: 1798
1
#!/usr/bin/env python
2
3
'''
4
Check Tools/bootloader/board_types.txt for problems
5
6
AP_FLAKE8_CLEAN
7
8
'''
9
10
import re
11
12
13
class ValidateBoardList(object):
14
15
class BoardType(object):
16
def __init__(self, name, board_id):
17
self.name = name
18
self.board_id = board_id
19
20
def __init__(self):
21
self.filepath = "Tools/AP_Bootloader/board_types.txt"
22
23
def read_filepath(self, filepath):
24
'''return contents of filepath'''
25
content = ""
26
with open(filepath) as fh:
27
content += fh.read()
28
fh.close()
29
return content
30
31
def parse_filepath_content(self, filepath):
32
'''read contents of filepath, returns a list of (id, name) tuples'''
33
content = self.read_filepath(filepath)
34
ret = []
35
for line in content.split("\n"):
36
# strip comments:
37
line = re.sub("#.*", "", line)
38
# remove empty lines:
39
if not len(line) or line.isspace():
40
continue
41
# remove trailing whitespace
42
line = line.rstrip()
43
m = re.match(r"^(.*?)\s+(\d+)$", line)
44
if m is None:
45
raise ValueError("Failed to match (%s)" % line)
46
print("line: (%s)" % str(line))
47
ret.append((int(m.group(2)), m.group(1)))
48
return ret
49
50
def validate_filepath_content(self, tuples):
51
'''validate a list of (id, name) tuples'''
52
53
# a list of board IDs which can map to multiple names for
54
# historical reasons:
55
board_id_whitelist = frozenset([
56
9, # fmuv2 and fmuv3
57
10, # TARGET_HW_PX4_FMU_V4_PRO and TARGET_HW_PX4_PIO_V3
58
13, # TARGET_HW_PX4_FMU_V4_PRO and TARGET_HW_PX4_PIO_V3
59
29, # TARGET_HW_AV_V1 and TARGET_HW_AV_X_V1
60
51, # TARGET_HW_PX4_FMU_V5X and Reserved PX4 [BL] FMU v5X.x
61
52, # TARGET_HW_PX4_FMU_V6 and Reserved "PX4 [BL] FMU v6.x"
62
53, # TARGET_HW_PX4_FMU_V6X and Reserved "PX4 [BL] FMU v6X.x"
63
57, # TARGET_HW_ARK_FMU_V6X and Reserved "ARK [BL] FMU v6X.x"
64
80, # TARGET_HW_ARK_CAN_FLOW and Reserved "ARK CAN FLOW"
65
20, # TARGET_HW_UVIFY_CORE and AP_HW_F4BY
66
])
67
68
dict_by_id = {}
69
dict_by_name = {}
70
for (board_id, name) in tuples:
71
print("Checking (%u, %s)" % (board_id, name))
72
if board_id in dict_by_id and board_id not in board_id_whitelist:
73
raise ValueError("Duplicate ID %s in file for (%s) and (%s)" %
74
(board_id, dict_by_id[board_id], name))
75
if name in dict_by_name:
76
raise ValueError("Duplicate name %s in file for (%s) and (%s)" %
77
(name, dict_by_name[name], board_id))
78
dict_by_name[name] = board_id
79
dict_by_id[board_id] = name
80
81
def run(self):
82
parsed = self.parse_filepath_content(self.filepath)
83
self.validate_filepath_content(parsed)
84
return 0
85
86
87
if __name__ == '__main__':
88
validator = ValidateBoardList()
89
validator.run()
90
91