mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 02:41:35 +08:00
Tools/px_uploader: exit if unsuitable board is connected
Avoids endless looping, and is mostly useful when used in automated upload scripts.
This commit is contained in:
+18
-3
@@ -74,6 +74,9 @@ if sys.version_info[0] < 3:
|
|||||||
else:
|
else:
|
||||||
runningPython3 = True
|
runningPython3 = True
|
||||||
|
|
||||||
|
class FirmwareNotSuitableException(Exception):
|
||||||
|
def __init__(self, message):
|
||||||
|
super(FirmwareNotSuitableException, self).__init__(message)
|
||||||
|
|
||||||
class firmware(object):
|
class firmware(object):
|
||||||
'''Loads a firmware file'''
|
'''Loads a firmware file'''
|
||||||
@@ -567,13 +570,13 @@ class uploader(object):
|
|||||||
# Make sure we are doing the right thing
|
# Make sure we are doing the right thing
|
||||||
start = time.time()
|
start = time.time()
|
||||||
if self.board_type != fw.property('board_id'):
|
if self.board_type != fw.property('board_id'):
|
||||||
msg = "Firmware not suitable for this board (board_type=%u board_id=%u)" % (
|
msg = "Firmware not suitable for this board (Firmware board_type=%u board_id=%u)" % (
|
||||||
self.board_type, fw.property('board_id'))
|
self.board_type, fw.property('board_id'))
|
||||||
print("WARNING: %s" % msg)
|
print("WARNING: %s" % msg)
|
||||||
if force:
|
if force:
|
||||||
print("FORCED WRITE, FLASHING ANYWAY!")
|
print("FORCED WRITE, FLASHING ANYWAY!")
|
||||||
else:
|
else:
|
||||||
raise IOError(msg)
|
raise FirmwareNotSuitableException(msg)
|
||||||
|
|
||||||
# Prevent uploads where the image would overflow the flash
|
# Prevent uploads where the image would overflow the flash
|
||||||
if self.fw_maxsize < fw.property('image_size'):
|
if self.fw_maxsize < fw.property('image_size'):
|
||||||
@@ -798,6 +801,7 @@ def main():
|
|||||||
baud_flightstack = [int(x) for x in args.baud_flightstack.split(',')]
|
baud_flightstack = [int(x) for x in args.baud_flightstack.split(',')]
|
||||||
|
|
||||||
successful = False
|
successful = False
|
||||||
|
unsuitable_board = False
|
||||||
for port in portlist:
|
for port in portlist:
|
||||||
|
|
||||||
# print("Trying %s" % port)
|
# print("Trying %s" % port)
|
||||||
@@ -828,7 +832,7 @@ def main():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
found_bootloader = False
|
found_bootloader = False
|
||||||
while (True):
|
while True:
|
||||||
up.open()
|
up.open()
|
||||||
|
|
||||||
# port is open, try talking to it
|
# port is open, try talking to it
|
||||||
@@ -869,6 +873,11 @@ def main():
|
|||||||
# print the error
|
# print the error
|
||||||
print("\nERROR: %s" % ex.args)
|
print("\nERROR: %s" % ex.args)
|
||||||
|
|
||||||
|
except FirmwareNotSuitableException:
|
||||||
|
unsuitable_board = True
|
||||||
|
up.close()
|
||||||
|
continue
|
||||||
|
|
||||||
except IOError:
|
except IOError:
|
||||||
up.close()
|
up.close()
|
||||||
continue
|
continue
|
||||||
@@ -883,6 +892,12 @@ def main():
|
|||||||
else:
|
else:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if unsuitable_board:
|
||||||
|
# If we land here, we went through all ports, did not flash any
|
||||||
|
# board and found at least one unsuitable board.
|
||||||
|
# Exit with 2, so a caller can distinguish from other errors
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
# Delay retries to < 20 Hz to prevent spin-lock from hogging the CPU
|
# Delay retries to < 20 Hz to prevent spin-lock from hogging the CPU
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user