Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/autotest/validate_board_list.py
9692 views
1
#!/usr/bin/env python3
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
59, # TARGET_HW_ARK_FPV and Reserved "ARK [BL] FPV"
65
80, # TARGET_HW_ARK_CAN_FLOW and Reserved "ARK CAN FLOW"
66
20, # TARGET_HW_UVIFY_CORE and AP_HW_F4BY
67
])
68
69
dict_by_id = {}
70
dict_by_name = {}
71
for (board_id, name) in tuples:
72
print("Checking (%u, %s)" % (board_id, name))
73
if board_id in dict_by_id and board_id not in board_id_whitelist:
74
raise ValueError("Duplicate ID %s in file for (%s) and (%s)" %
75
(board_id, dict_by_id[board_id], name))
76
if name in dict_by_name:
77
raise ValueError("Duplicate name %s in file for (%s) and (%s)" %
78
(name, dict_by_name[name], board_id))
79
dict_by_name[name] = board_id
80
dict_by_id[board_id] = name
81
82
def run(self):
83
parsed = self.parse_filepath_content(self.filepath)
84
self.validate_filepath_content(parsed)
85
return 0
86
87
88
if __name__ == '__main__':
89
validator = ValidateBoardList()
90
validator.run()
91
92