From 5f4fb744caf30ee3f86fe37ab5651bf17dfba738 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 5 Jun 2017 11:19:27 +0200 Subject: [PATCH] Uploader: Signal GCS or other connected devices that a FiFirmware upload is pending and requires device access. --- Tools/px_uploader.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Tools/px_uploader.py b/Tools/px_uploader.py index af78be5e87..97799a71f0 100755 --- a/Tools/px_uploader.py +++ b/Tools/px_uploader.py @@ -57,6 +57,7 @@ import sys import argparse import binascii import serial +import socket import struct import json import zlib @@ -203,9 +204,10 @@ class uploader(object): self.port.close() def open(self): + # upload timeout timeout = time.time() + 0.2 - # Attempt to open the port while it exists and until timeout occurs + # attempt to open the port while it exists and until timeout occurs while self.port is not None: portopen = True try: @@ -605,6 +607,27 @@ def main(): print("Loaded firmware for %x,%x, size: %d bytes, waiting for the bootloader..." % (fw.property('board_id'), fw.property('board_revision'), fw.property('image_size'))) print("If the board does not respond within 1-2 seconds, unplug and re-plug the USB connector.") + # tell any GCS that might be connected to the autopilot to give up + # control of the serial port + + # send to localhost and default GCS port + ipaddr = '127.0.0.1' + portnum = 14550 + + # COMMAND_LONG in MAVLink 1 + heartbeatpacket = 'fe097001010000000100020c5103033c8a'.decode('hex') + commandpacket = 'fe210101014c00000000000000000000000000000000000000000000803f00000000f6000000008459'.decode('hex') + + # initialize an UDP socket + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + + # send heartbeat to initialize connection and command to free the link + s.sendto(heartbeatpacket, (ipaddr, portnum)) + s.sendto(commandpacket, (ipaddr, portnum)) + + # close the socket + s.close() + # Spin waiting for a device to show up try: while True: