@@ -95,6 +95,19 @@ def update_hit_count(self, _path, hit_count):
95
95
def reset_hit_counts (self ):
96
96
self ._hit_count_label .setText ('0' )
97
97
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
+
98
111
class FileServerJson (dronecan .app .file_server .FileServer ):
99
112
def __init__ (self , node ):
100
113
super (FileServerJson , self ).__init__ (node )
@@ -115,7 +128,14 @@ def _load_image(self, path):
115
128
if not 'image' in j :
116
129
print ("Missing image in %s" % path )
117
130
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' ]))
119
139
return open (path ,'rb' ).read ()
120
140
121
141
def _check_path_change (self , path ):
0 commit comments