aboutsummaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorJulian Oes <julian@oes.ch>2013-09-04 14:54:16 +0200
committerJulian Oes <julian@oes.ch>2013-09-04 14:54:16 +0200
commitd30ba44f463045aee47fe9ac06436d28c5b4800b (patch)
treeeb1404d845eeee0a3445d732dba956b579ef8d17 /Tools
parent59373399ff8fe08dfd0fb1cee59ed8c73ec75810 (diff)
downloadpx4-firmware-d30ba44f463045aee47fe9ac06436d28c5b4800b.tar.gz
px4-firmware-d30ba44f463045aee47fe9ac06436d28c5b4800b.tar.bz2
px4-firmware-d30ba44f463045aee47fe9ac06436d28c5b4800b.zip
The python uploader can now reboot the board
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/px_uploader.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Tools/px_uploader.py b/Tools/px_uploader.py
index c2ba6d034..cab3c2fd0 100755
--- a/Tools/px_uploader.py
+++ b/Tools/px_uploader.py
@@ -165,6 +165,12 @@ class uploader(object):
PROG_MULTI_MAX = 60 # protocol max is 255, must be multiple of 4
READ_MULTI_MAX = 60 # protocol max is 255, something overflows with >= 64
+
+ NSH_INIT = bytearray(b'\x0d\x0d\x0d')
+ NSH_REBOOT_BL = b"reboot -b\n"
+ NSH_REBOOT = b"reboot\n"
+ MAVLINK_REBOOT_ID1 = bytearray(b'\xfe\x21\x72\xff\x00\x4c\x00\x00\x80\x3f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\x00\x01\x00\x00\x48\xf0')
+ MAVLINK_REBOOT_ID0 = bytearray(b'\xfe\x21\x45\xff\x00\x4c\x00\x00\x80\x3f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\x00\x00\x00\x00\xd7\xac')
def __init__(self, portname, baudrate):
# open the port, keep the default timeout short so we can poll quickly
@@ -362,6 +368,18 @@ class uploader(object):
print("done, rebooting.")
self.__reboot()
self.port.close()
+
+ def send_reboot(self):
+ # try reboot via NSH first
+ self.__send(uploader.NSH_INIT)
+ self.__send(uploader.NSH_REBOOT_BL)
+ self.__send(uploader.NSH_INIT)
+ self.__send(uploader.NSH_REBOOT)
+ # then try MAVLINK command
+ self.__send(uploader.MAVLINK_REBOOT_ID1)
+ self.__send(uploader.MAVLINK_REBOOT_ID0)
+
+
# Detect python version
if sys.version_info[0] < 3:
@@ -414,7 +432,11 @@ while True:
print("Found board %x,%x bootloader rev %x on %s" % (up.board_type, up.board_rev, up.bl_rev, port))
except:
- # most probably a timeout talking to the port, no bootloader
+ # most probably a timeout talking to the port, no bootloader, try to reboot the board
+ print("attempting reboot on %s..." % port)
+ up.send_reboot()
+ # wait for the reboot, without we might run into Serial I/O Error 5
+ time.sleep(1.5)
continue
try: