forked from vedderb/bldc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_firmware.py
executable file
·146 lines (129 loc) · 6.77 KB
/
package_firmware.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import shutil
import os
import subprocess
# https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script
def get_git_revision_short_hash() -> str:
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()
# Get the origin and destionation directories
build_dir = os.path.dirname(os.path.abspath(__file__)) + '/build'
package_dir = os.path.dirname(os.path.abspath(__file__)) + '/package'
# Get the short git hash
git_hash = get_git_revision_short_hash()
# Define default destination filenames
no_limits_name = "VESC_default_no_hw_limits.bin"
default_name = "VESC_default.bin"
# Add directories and targets to the dictionary
package_dict = {}
package_dict["46_o_47"] = [['46', default_name],
['46_33k', 'VESC_33k.bin'],
['46_0005ohm', 'VESC_0005ohm.bin']]
package_dict["48"] = [['48', default_name]]
package_dict["410_o_411_o_412"] = [['410', default_name],
['410_no_limits', no_limits_name],
['410_0005ohm', 'VESC_0005ohm.bin'],
['410_005ohm', 'VESC_005ohm.bin']]
package_dict["60"] = [['60', default_name],
['60_no_limits', no_limits_name]]
package_dict["60_MK3"] = [['60_mk3', default_name],
['60_mk3_no_limits', no_limits_name]]
package_dict["60_MK4"] = [['60_mk4', default_name],
['60_mk4_no_limits', no_limits_name]]
package_dict["60_MK5"] = [['60_mk5', default_name],
['60_mk5_no_limits', no_limits_name]]
package_dict["60_MK6"] = [['60_mk6', default_name],
['60_mk6_no_limits', no_limits_name]]
package_dict["DAS_RS"] = [['das_rs', default_name]]
package_dict["75_300"] = [['75_300', default_name],
['75_300_no_limits', no_limits_name]]
package_dict["75_300_R2"] = [['75_300_r2', default_name],
['75_300_r2_no_limits', no_limits_name]]
package_dict["75_300_R3"] = [['75_300_r3', default_name],
['75_300_r3_no_limits', no_limits_name]]
package_dict["AXIOM"] = [['axiom', default_name]]
package_dict["UAVC_OMEGA"] = [['uavc_omega', default_name]]
package_dict["HD60"] = [['hd60', default_name],
['hd60_no_limits', no_limits_name]]
package_dict["HD75"] = [['hd75', default_name],
['hd75_no_limits', no_limits_name]]
package_dict["A50S_6S"] = [['a50s_6s', default_name]]
package_dict["A50S_12S"] = [['a50s_12s', default_name]]
package_dict["A200S_v2.1"] = [['a200s_v2.1', default_name]]
package_dict["A200S_v2.2"] = [['a200s_v2.2', default_name]]
package_dict["100_250"] = [['100_250', default_name],
['100_250_no_limits', no_limits_name]]
package_dict["LUNA_BBSHD"] = [['luna_bbshd', default_name]]
package_dict["UNITY"] = [['unity', default_name],
['unity_no_limits', no_limits_name]]
package_dict["Cheap_FOCer_2"] = [['Cheap_FOCer_2', default_name]]
package_dict["STORMCORE_60D"] = [['stormcore_60d', default_name],
['stormcore_60d_no_limits', no_limits_name]]
package_dict["STORMCORE_60Dxs"] = [['stormcore_60dxs', default_name],
['stormcore_60dxs_no_limits', no_limits_name]]
package_dict["STORMCORE_60D+"] = [['stormcore_60d+', default_name],
['stormcore_60d+_no_limits', no_limits_name]]
package_dict["STORMCORE_100D"] = [['stormcore_100d', default_name],
['stormcore_100d_no_limits', no_limits_name]]
package_dict["STORMCORE_100D_V2"] = [['stormcore_100d_v2', default_name],
['stormcore_100d_v2_no_limits', no_limits_name]]
package_dict["STORMCORE_100DX"] = [['stormcore_100dx', default_name],
['stormcore_100dx_no_limits', no_limits_name]]
package_dict["STORMCORE_100S"] = [['stormcore_100s', default_name],
['stormcore_100s_no_limits', no_limits_name]]
package_dict["Little_FOCer"] = [['Little_FOCer', default_name]]
package_dict["Little_FOCer_V3"] = [['Little_FOCer_V3', default_name]]
package_dict["Little_FOCer_V3_1"] = [['Little_FOCer_V3_1', default_name]]
package_dict["UXV_SR"] = [['uxv_sr', default_name]]
package_dict["GESC"] = [['gesc', default_name]]
package_dict["Warrior6"] = [['warrior6', default_name]]
package_dict["Raiden7"] = [['raiden7', default_name]]
package_dict["UBOX_SINGLE"] = [['ubox_single', default_name]]
package_dict["100_500"] = [['100_500', default_name],
['100_500_no_limits', no_limits_name]]
package_dict["75_600"] = [['75_600', default_name],
['75_600_no_limits', no_limits_name]]
package_dict["60v2_alva"] = [['60v2_alva', default_name]]
package_dict["60v2_alva_mk2"] = [['60v2_alva_mk2', default_name]]
package_dict["60_75"] = [['60_75', default_name],
['60_75_no_limits', no_limits_name]]
package_dict["60_75_mk2"] = [['60_75_mk2', default_name],
['60_75_mk2_no_limits', no_limits_name]]
package_dict["UBOX_SINGLE_75"] = [['ubox_single_75', default_name]]
package_dict["UBOX_V1_75_MICRO"] = [['ubox_v1_75_micro', default_name]]
package_dict["UBOX_V1_75_TYPEC"] = [['ubox_v1_75_typec', default_name]]
package_dict["UBOX_V2_75"] = [['ubox_v2_75', default_name]]
package_dict["UBOX_SINGLE_100"] = [['ubox_single_100', default_name]]
package_dict["UBOX_V2_100"] = [['ubox_v2_100', default_name]]
package_dict["EDU"] = [['edu', default_name],
['edu_no_limits', no_limits_name]]
# This is the firmware stub string
res_firmwares_string = ' <file>TARGET_DESTINATION_DIRECTORY/TARGET_DESTINATION_FILENAME</file>\n'
# This is the XML stub string
resource_xml_stub_string = '''
<RCC>
<qresource prefix="/res/firmwares/">
REPLACEABLE_STRING
</qresource>
</RCC>
'''
# Declare an empty string
res_string = ""
# Iterate over all directories in the dictionary
for directory in package_dict:
# Set the destination path
destination_path = os.path.join(package_dir, directory)
# Create the destination directory
os.makedirs(destination_path, exist_ok=True)
# Iterate over each target
for target in package_dict[directory]:
# Shorthand variable
destination_file_name = target[1]
origin_file_name = target[0] + '.bin'
# Copy the file
shutil.copy(os.path.join(build_dir, target[0], origin_file_name), os.path.join(destination_path, destination_file_name))
# Replace the stub string with the target specifics
target_res_string = res_firmwares_string.replace("TARGET_DESTINATION_DIRECTORY", directory).replace("TARGET_DESTINATION_FILENAME", destination_file_name)
# Add this string to the master Qt resource string
res_string = res_string + target_res_string
# Print the QRC file
with open(os.path.join(package_dir, 'res_fw.qrc'), 'w') as f:
print(resource_xml_stub_string.replace("REPLACEABLE_STRING", res_string[:-1]), file=f)