Uploader: Signal GCS or other connected devices that a FiFirmware upload is pending and requires device access.

This commit is contained in:
Lorenz Meier 2017-06-05 11:19:27 +02:00
parent e60fbccbee
commit 5f4fb744ca
1 changed files with 24 additions and 1 deletions

View File

@ -57,6 +57,7 @@ import sys
import argparse import argparse
import binascii import binascii
import serial import serial
import socket
import struct import struct
import json import json
import zlib import zlib
@ -203,9 +204,10 @@ class uploader(object):
self.port.close() self.port.close()
def open(self): def open(self):
# upload timeout
timeout = time.time() + 0.2 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: while self.port is not None:
portopen = True portopen = True
try: 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("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.") 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 # Spin waiting for a device to show up
try: try:
while True: while True: