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/scripts/create_OEM_board.py
Views: 1798
1
#!/usr/bin/env python
2
3
"""
4
script to automatically create a copy of a board for an OEM setup
5
usage example : ./Tools/scripts/create_OEM_board.py mRoPixracerPro mRoPixracerPro-MyCompany
6
7
AP_FLAKE8_CLEAN
8
"""
9
10
import sys
11
import os
12
import subprocess
13
14
import pathlib
15
16
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))
17
import chibios_hwdef # noqa
18
19
20
class OEMCreate:
21
def __init__(self, oem_board_name, board_name):
22
self.oem_board_name = oem_board_name
23
self.board_name = board_name
24
25
def run(self):
26
hwdef_dir = "libraries/AP_HAL_ChibiOS/hwdef"
27
oem_board_dirpath = f"{hwdef_dir}/{oem_board_name}"
28
29
if os.path.exists(oem_board_dirpath):
30
raise ValueError(f"{oem_board_dirpath} already exists") # FIXME exception type
31
32
hwdef_include_relpath = None
33
for extension in "dat", "inc":
34
tmp = f"../{board_name}/hwdef.{extension}"
35
tmp_norm = os.path.normpath(f"{oem_board_dirpath}/{tmp}")
36
if os.path.exists(tmp_norm):
37
hwdef_include_relpath = tmp
38
hwdef_include_normpath = tmp_norm
39
break
40
41
hwdef_content = f"include {hwdef_include_relpath}\n"
42
43
ch = chibios_hwdef.ChibiOSHWDef(hwdef_include_normpath)
44
use_bootloader_from_board = ch.get_config('USE_BOOTLOADER_FROM_BOARD', default=None, required=False)
45
if use_bootloader_from_board is None:
46
hwdef_content += "\n"
47
hwdef_content += f"USE_BOOTLOADER_FROM_BOARD {board_name}\n"
48
49
subprocess.run(["mkdir", oem_board_dirpath])
50
51
# create files and add reference to originals
52
new_hwdef = pathlib.Path(oem_board_dirpath, "hwdef.dat")
53
54
if hwdef_include_relpath is None:
55
raise ValueError(f"Could not find .inc or .dat for {board_name}")
56
57
new_hwdef.write_text(hwdef_content)
58
59
if os.path.exists(f"{hwdef_dir}/{board_name}/defaults.parm"):
60
path = pathlib.Path(f"{hwdef_dir}/{oem_board_name}/defaults.parm")
61
path.write_text(f"@include ../{board_name}/defaults.parm\n") # noqa
62
63
64
board_name = sys.argv[1]
65
oem_board_name = sys.argv[2]
66
67
oemcreate = OEMCreate(board_name, oem_board_name)
68
oemcreate.run()
69
70