Skip to content

Commit

Permalink
support loading AM32 amj files
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Oct 19, 2024
1 parent 1dd603d commit 9231483
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
22 changes: 21 additions & 1 deletion dronecan_gui_tool/widgets/file_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ def update_hit_count(self, _path, hit_count):
def reset_hit_counts(self):
self._hit_count_label.setText('0')

def hex2bin(heximage):
'''
Convert an Intel HEX format bytes array to binary format
'''
import intelhex
import io

hex_stream = io.StringIO(heximage.decode('utf-8'))
bin_stream = io.BytesIO()
intelhex.hex2bin(hex_stream, bin_stream)
bin_stream.seek(0)
return bin_stream.read()

class FileServerJson(dronecan.app.file_server.FileServer):
def __init__(self, node):
super(FileServerJson, self).__init__(node)
Expand All @@ -115,7 +128,14 @@ def _load_image(self, path):
if not 'image' in j:
print("Missing image in %s" % path)
return None
return bytearray(zlib.decompress(base64.b64decode(j['image'])))
return bytearray(zlib.decompress(base64.b64decode(j['image'].encode('utf-8'))))
if path.lower().endswith('.amj'):
# load JSON image as hex image
j = json.load(open(path,'r'))
if not 'hex' in j:
print("Missing hex image in %s" % path)
return None
return hex2bin(base64.b64decode(j['hex']))
return open(path,'rb').read()

def _check_path_change(self, path):
Expand Down
2 changes: 1 addition & 1 deletion dronecan_gui_tool/widgets/node_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def _do_firmware_update(self):

# Requesting the firmware path
fw_file = QFileDialog().getOpenFileName(self, 'Select firmware file', '',
'Binary images (*.bin);;ArduPilot Firmware (*.apj);;PX4 Firmware (*.px4);;All files (*.*)')
'Binary images (*.bin);;ArduPilot Firmware (*.apj);;AM32 Firmware (*.amj);;PX4 Firmware (*.px4);;All files (*.*)')
if not fw_file[0]:
self.window().show_message('Cancelled')
return
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
'pygments',
'qtpy',
'pyqtgraph',
'qtwidgets'
'qtwidgets',
'intelhex'
],
# We can't use "scripts" here, because generated shims don't work with multiprocessing pickler.
entry_points={
Expand Down

0 comments on commit 9231483

Please sign in to comment.