(port, requestedBaudrate)
| 38 | |
| 39 | |
| 40 | def bf_passthrough_init(port, requestedBaudrate): |
| 41 | sys.stdout.flush() |
| 42 | dbg_print("======== PASSTHROUGH INIT ========") |
| 43 | dbg_print(" Trying to initialize %s @ %s" % (port, requestedBaudrate)) |
| 44 | |
| 45 | s = serial.Serial(port=port, baudrate=115200, |
| 46 | bytesize=8, parity='N', stopbits=1, |
| 47 | timeout=1, xonxoff=0, rtscts=0) |
| 48 | |
| 49 | rl = SerialHelper.SerialHelper(s, 3., ['CCC', "# "]) |
| 50 | rl.clear() |
| 51 | # Send start command '#' |
| 52 | rl.write_str("#", False) |
| 53 | start = rl.read_line(2.).strip() |
| 54 | #dbg_print("BF INIT: '%s'" % start.replace("\r", "")) |
| 55 | if "CCC" in start: |
| 56 | raise PassthroughEnabled("Passthrough already enabled and bootloader active") |
| 57 | elif not start or not start.endswith("#"): |
| 58 | raise PassthroughEnabled("No CLI available. Already in passthrough mode?, If this fails reboot FC and try again!") |
| 59 | |
| 60 | serial_check = [] |
| 61 | if not _validate_serialrx(rl, "serialrx_provider", ["CRSF", "ELRS"]): |
| 62 | serial_check.append("Serial Receiver Protocol is not set to CRSF! Hint: set serialrx_provider = CRSF") |
| 63 | if not _validate_serialrx(rl, "serialrx_inverted", "OFF"): |
| 64 | serial_check.append("Serial Receiver UART is inverted! Hint: set serialrx_inverted = OFF") |
| 65 | if not _validate_serialrx(rl, "serialrx_halfduplex", ["OFF", "AUTO"]): |
| 66 | serial_check.append("Serial Receiver UART is not in full duplex! Hint: set serialrx_halfduplex = OFF") |
| 67 | if _validate_serialrx(rl, "rx_spi_protocol", "EXPRESSLRS" ) and serial_check: |
| 68 | serial_check = [ "ExpressLRS SPI RX detected\n\nUpdate via betaflight to flash your RX\nhttps://www.expresslrs.org/2.0/hardware/spi-receivers/" ] |
| 69 | |
| 70 | if serial_check: |
| 71 | error = "\n\n [ERROR] Invalid serial RX configuration detected:\n" |
| 72 | for err in serial_check: |
| 73 | error += " !!! %s !!!\n" % err |
| 74 | error += "\n Please change the configuration and try again!\n" |
| 75 | raise PassthroughFailed(error) |
| 76 | |
| 77 | SerialRXindex = "" |
| 78 | |
| 79 | dbg_print("\nAttempting to detect FC UART configuration...") |
| 80 | |
| 81 | rl.set_delimiters(["\n"]) |
| 82 | rl.clear() |
| 83 | rl.write_str("serial") |
| 84 | |
| 85 | while True: |
| 86 | line = rl.read_line().strip() |
| 87 | #print("FC: '%s'" % line) |
| 88 | if not line or "#" in line: |
| 89 | break |
| 90 | |
| 91 | if line.startswith("serial"): |
| 92 | if SCRIPT_DEBUG: |
| 93 | dbg_print(" '%s'" % line) |
| 94 | config = re.search('serial ((?:UART)?[0-9]+) ([0-9]+) ', line) |
| 95 | if config and (int(config.group(2)) & 64 == 64): |
| 96 | dbg_print(" ** Serial RX config detected: '%s'" % line) |
| 97 | SerialRXindex = config.group(1) |
no test coverage detected