1 import serial
, time
, sys
, re
6 from BFinitPassthrough
import *
10 def send_bind_command(args
):
11 dbg_print("======== SEND BIND COMMAND ========")
12 s
= serial
.Serial(port
=args
.port
, baudrate
=args
.baud
,
13 bytesize
=8, parity
='N', stopbits
=1,
14 timeout
=1, xonxoff
=0, rtscts
=0)
16 BindInitSeq
= bootloader
.get_bind_seq('GHST', args
.type)
17 dbg_print(" * Using half duplex (GHST)")
19 BindInitSeq
= bootloader
.get_bind_seq('CRSF', args
.type)
20 dbg_print(" * Using full duplex (CRSF)")
27 if __name__
== '__main__':
28 parser
= argparse
.ArgumentParser(
29 description
="Initialize BetaFlight passthrough and send the 'enter bind mode' command")
30 parser
.add_argument("-b", "--baud", type=int, default
=420000,
31 help="Baud rate for passthrough communication")
32 parser
.add_argument("-p", "--port", type=str,
33 help="Override serial port autodetection and use PORT")
34 parser
.add_argument("-hd", "--half-duplex", action
="store_true",
35 dest
="half_duplex", help="Use half duplex mode")
36 parser
.add_argument("-t", "--type", type=str, default
="ESP82",
37 help="Defines flash target type which is sent to target in reboot command")
38 args
= parser
.parse_args()
40 if (args
.port
== None):
41 args
.port
= serials_find
.get_serial_port()
44 bf_passthrough_init(args
.port
, args
.baud
)
45 except PassthroughEnabled
as err
:
48 send_bind_command(args
)