Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support loading AM32 amj files #67

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading