mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-30 06:03:34 +08:00
Implement option to reboot px4 using protocol_splitter format when flashing.
This commit is contained in:
committed by
Beat Küng
parent
ffa5abbd65
commit
2e36fff31d
+37
-8
@@ -682,7 +682,28 @@ class uploader(object):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def send_reboot(self):
|
def send_protocol_splitter_format(self, data):
|
||||||
|
# Header Structure:
|
||||||
|
# bits: 1 2 3 4 5 6 7 8
|
||||||
|
# header[0] - | Magic | (='S')
|
||||||
|
# header[1] - |T| LenH | (T - 0: mavlink; 1: rtps)
|
||||||
|
# header[2] - | LenL |
|
||||||
|
# header[3] - | Checksum |
|
||||||
|
|
||||||
|
MAGIC = 83
|
||||||
|
|
||||||
|
len_bytes = len(data).to_bytes(2, "big")
|
||||||
|
LEN_H = len_bytes[0] & 127
|
||||||
|
LEN_L = len_bytes[1] & 255
|
||||||
|
CHECKSUM = MAGIC ^ LEN_H ^ LEN_L
|
||||||
|
|
||||||
|
header_ints = [MAGIC, LEN_H, LEN_L, CHECKSUM]
|
||||||
|
header_bytes = struct.pack("{}B".format(len(header_ints)), *header_ints)
|
||||||
|
|
||||||
|
self.__send(header_bytes)
|
||||||
|
self.__send(data)
|
||||||
|
|
||||||
|
def send_reboot(self, use_protocol_splitter_format=False):
|
||||||
if (not self.__next_baud_flightstack()):
|
if (not self.__next_baud_flightstack()):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -693,15 +714,19 @@ class uploader(object):
|
|||||||
print("If the board does not respond, unplug and re-plug the USB connector.", file=sys.stderr)
|
print("If the board does not respond, unplug and re-plug the USB connector.", file=sys.stderr)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
send_fct = self.__send
|
||||||
|
if use_protocol_splitter_format:
|
||||||
|
send_fct = self.send_protocol_splitter_format
|
||||||
|
|
||||||
# try MAVLINK command first
|
# try MAVLINK command first
|
||||||
self.port.flush()
|
self.port.flush()
|
||||||
self.__send(uploader.MAVLINK_REBOOT_ID1)
|
send_fct(uploader.MAVLINK_REBOOT_ID1)
|
||||||
self.__send(uploader.MAVLINK_REBOOT_ID0)
|
send_fct(uploader.MAVLINK_REBOOT_ID0)
|
||||||
# then try reboot via NSH
|
# then try reboot via NSH
|
||||||
self.__send(uploader.NSH_INIT)
|
send_fct(uploader.NSH_INIT)
|
||||||
self.__send(uploader.NSH_REBOOT_BL)
|
send_fct(uploader.NSH_REBOOT_BL)
|
||||||
self.__send(uploader.NSH_INIT)
|
send_fct(uploader.NSH_INIT)
|
||||||
self.__send(uploader.NSH_REBOOT)
|
send_fct(uploader.NSH_REBOOT)
|
||||||
self.port.flush()
|
self.port.flush()
|
||||||
self.port.baudrate = self.baudrate_bootloader
|
self.port.baudrate = self.baudrate_bootloader
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -726,9 +751,13 @@ def main():
|
|||||||
parser.add_argument('--baud-flightstack', action="store", default="57600", help="Comma-separated list of baud rate of the serial port (default is 57600) when communicating with flight stack (Mavlink or NSH), only required for true serial ports.")
|
parser.add_argument('--baud-flightstack', action="store", default="57600", help="Comma-separated list of baud rate of the serial port (default is 57600) when communicating with flight stack (Mavlink or NSH), only required for true serial ports.")
|
||||||
parser.add_argument('--force', action='store_true', default=False, help='Override board type check, or silicon errata checks and continue loading')
|
parser.add_argument('--force', action='store_true', default=False, help='Override board type check, or silicon errata checks and continue loading')
|
||||||
parser.add_argument('--boot-delay', type=int, default=None, help='minimum boot delay to store in flash')
|
parser.add_argument('--boot-delay', type=int, default=None, help='minimum boot delay to store in flash')
|
||||||
|
parser.add_argument('--use-protocol-splitter-format', action='store_true', help='use protocol splitter format for reboot')
|
||||||
parser.add_argument('firmware', action="store", help="Firmware file to be uploaded")
|
parser.add_argument('firmware', action="store", help="Firmware file to be uploaded")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.use_protocol_splitter_format:
|
||||||
|
print("Using protocol splitter format to reboot pixhawk!")
|
||||||
|
|
||||||
# warn people about ModemManager which interferes badly with Pixhawk
|
# warn people about ModemManager which interferes badly with Pixhawk
|
||||||
if os.path.exists("/usr/sbin/ModemManager"):
|
if os.path.exists("/usr/sbin/ModemManager"):
|
||||||
print("==========================================================================================================")
|
print("==========================================================================================================")
|
||||||
@@ -830,7 +859,7 @@ def main():
|
|||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
||||||
if not up.send_reboot():
|
if not up.send_reboot(args.use_protocol_splitter_format):
|
||||||
break
|
break
|
||||||
|
|
||||||
# wait for the reboot, without we might run into Serial I/O Error 5
|
# wait for the reboot, without we might run into Serial I/O Error 5
|
||||||
|
|||||||
Reference in New Issue
Block a user