mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
Tools: apj_tool.py: python3 fixes
This commit is contained in:
parent
54a505dade
commit
bec9b6dda4
@ -87,8 +87,11 @@ class embedded_defaults(object):
|
|||||||
def find(self):
|
def find(self):
|
||||||
'''find defaults in firmware'''
|
'''find defaults in firmware'''
|
||||||
# these are the magic headers from AP_Param.cpp
|
# these are the magic headers from AP_Param.cpp
|
||||||
magic_str = "PARMDEF"
|
magic_str = "PARMDEF".encode('ascii')
|
||||||
param_magic = [ 0x55, 0x37, 0xf4, 0xa0, 0x38, 0x5d, 0x48, 0x5b ]
|
param_magic = [ 0x55, 0x37, 0xf4, 0xa0, 0x38, 0x5d, 0x48, 0x5b ]
|
||||||
|
def u_ord(c):
|
||||||
|
return ord(c) if sys.version_info.major < 3 else c
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
i = self.firmware[self.offset:].find(magic_str)
|
i = self.firmware[self.offset:].find(magic_str)
|
||||||
if i == -1:
|
if i == -1:
|
||||||
@ -96,7 +99,7 @@ class embedded_defaults(object):
|
|||||||
return None
|
return None
|
||||||
matched = True
|
matched = True
|
||||||
for j in range(len(param_magic)):
|
for j in range(len(param_magic)):
|
||||||
if ord(self.firmware[self.offset+i+j+8]) != param_magic[j]:
|
if u_ord(self.firmware[self.offset+i+j+8]) != param_magic[j]:
|
||||||
matched = False
|
matched = False
|
||||||
break
|
break
|
||||||
if not matched:
|
if not matched:
|
||||||
@ -121,7 +124,7 @@ class embedded_defaults(object):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
new_fw = self.firmware[:self.offset+18]
|
new_fw = self.firmware[:self.offset+18]
|
||||||
new_fw += struct.pack("<H", length)
|
new_fw += struct.pack("<H", length)
|
||||||
new_fw += contents
|
new_fw += contents.encode('ascii')
|
||||||
new_fw += self.firmware[self.offset+20+length:]
|
new_fw += self.firmware[self.offset+20+length:]
|
||||||
self.firmware = new_fw
|
self.firmware = new_fw
|
||||||
self.length = len(contents)
|
self.length = len(contents)
|
||||||
|
Loading…
Reference in New Issue
Block a user