Skip to content

Commit 9231483

Browse files
committed
support loading AM32 amj files
1 parent 1dd603d commit 9231483

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

dronecan_gui_tool/widgets/file_server.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ def update_hit_count(self, _path, hit_count):
9595
def reset_hit_counts(self):
9696
self._hit_count_label.setText('0')
9797

98+
def hex2bin(heximage):
99+
'''
100+
Convert an Intel HEX format bytes array to binary format
101+
'''
102+
import intelhex
103+
import io
104+
105+
hex_stream = io.StringIO(heximage.decode('utf-8'))
106+
bin_stream = io.BytesIO()
107+
intelhex.hex2bin(hex_stream, bin_stream)
108+
bin_stream.seek(0)
109+
return bin_stream.read()
110+
98111
class FileServerJson(dronecan.app.file_server.FileServer):
99112
def __init__(self, node):
100113
super(FileServerJson, self).__init__(node)
@@ -115,7 +128,14 @@ def _load_image(self, path):
115128
if not 'image' in j:
116129
print("Missing image in %s" % path)
117130
return None
118-
return bytearray(zlib.decompress(base64.b64decode(j['image'])))
131+
return bytearray(zlib.decompress(base64.b64decode(j['image'].encode('utf-8'))))
132+
if path.lower().endswith('.amj'):
133+
# load JSON image as hex image
134+
j = json.load(open(path,'r'))
135+
if not 'hex' in j:
136+
print("Missing hex image in %s" % path)
137+
return None
138+
return hex2bin(base64.b64decode(j['hex']))
119139
return open(path,'rb').read()
120140

121141
def _check_path_change(self, path):

dronecan_gui_tool/widgets/node_properties.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def _do_firmware_update(self):
246246

247247
# Requesting the firmware path
248248
fw_file = QFileDialog().getOpenFileName(self, 'Select firmware file', '',
249-
'Binary images (*.bin);;ArduPilot Firmware (*.apj);;PX4 Firmware (*.px4);;All files (*.*)')
249+
'Binary images (*.bin);;ArduPilot Firmware (*.apj);;AM32 Firmware (*.amj);;PX4 Firmware (*.px4);;All files (*.*)')
250250
if not fw_file[0]:
251251
self.window().show_message('Cancelled')
252252
return

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
'pygments',
5757
'qtpy',
5858
'pyqtgraph',
59-
'qtwidgets'
59+
'qtwidgets',
60+
'intelhex'
6061
],
6162
# We can't use "scripts" here, because generated shims don't work with multiprocessing pickler.
6263
entry_points={

0 commit comments

Comments
 (0)