Add tlmConfirm to tlm_dl ota packet-structure (#2991)
[ExpressLRS.git] / src / python / bind.py
blob7b375e6ded31e4b5810ce7662cc202b4beeb8cbd
1 import serial, time
2 import argparse
3 import serials_find
4 import bootloader
5 from BFinitPassthrough import *
8 def send_bind_command(args):
9 dbg_print("======== SEND BIND COMMAND ========")
10 s = serial.Serial(port=args.port, baudrate=args.baud,
11 bytesize=8, parity='N', stopbits=1,
12 timeout=1, xonxoff=0, rtscts=0)
13 BindInitSeq = bootloader.get_bind_seq(args.type)
14 dbg_print(" * Using full duplex (CRSF)")
15 s.write(BindInitSeq)
16 s.flush()
17 time.sleep(.5)
18 s.close()
21 if __name__ == '__main__':
22 parser = argparse.ArgumentParser(
23 description="Initialize BetaFlight passthrough and send the 'enter bind mode' command")
24 parser.add_argument("-b", "--baud", type=int, default=420000,
25 help="Baud rate for passthrough communication")
26 parser.add_argument("-p", "--port", type=str,
27 help="Override serial port autodetection and use PORT")
28 parser.add_argument("-t", "--type", type=str, default="ESP82",
29 help="Defines flash target type which is sent to target in reboot command")
30 args = parser.parse_args()
32 if (args.port == None):
33 args.port = serials_find.get_serial_port()
35 try:
36 bf_passthrough_init(args.port, args.baud)
37 except PassthroughEnabled as err:
38 dbg_print(str(err))
40 send_bind_command(args)