From 21202975b99cbe1a9e7a8a30adfb2330e7594744 Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Thu, 20 Apr 2023 14:22:59 -0400 Subject: [PATCH] TS: serial: do not disable serial after failed BT init attemp (#231) Instead enable it on default baudrate and wait for direct connection (cherry picked from commit 4f2aa57bee6a50195768ffb0e7d7d2ff374048e4) Co-authored-by: Andrey Gusakov --- .../console/binary/tunerstudio_io_serial.cpp | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/firmware/console/binary/tunerstudio_io_serial.cpp b/firmware/console/binary/tunerstudio_io_serial.cpp index 6e812ab..4a2a2d1 100644 --- a/firmware/console/binary/tunerstudio_io_serial.cpp +++ b/firmware/console/binary/tunerstudio_io_serial.cpp @@ -191,28 +191,39 @@ int SerialTsChannel::reStart() { } while ((!done) && (--retry)); if (retry <= 0) { + sdStop(m_driver); ret = -3; } } - /* switch to new baudrate? */ - if (cfg.speed != baud) { - sdStop(m_driver); + if (ret == 0) { + /* switch to new baudrate? */ + if (cfg.speed != baud) { + sdStop(m_driver); - if (ret == 0) { - /* switch baudrate */ - cfg.speed = baud; - sdStart(m_driver, &cfg); + if (ret == 0) { + /* switch baudrate */ + cfg.speed = baud; + sdStart(m_driver, &cfg); - chThdSleepMilliseconds(10); + chThdSleepMilliseconds(10); + } } } - /* now reset BT to apply new settings */ - chprintf((BaseSequentialStream *)m_driver, "AT+RESET\r\n"); - if (bt_wait_ok() != 0) { - sdStop(m_driver); - ret = -4; + if (ret == 0) { + /* now reset BT to apply new settings */ + chprintf((BaseSequentialStream *)m_driver, "AT+RESET\r\n"); + if (bt_wait_ok() != 0) { + sdStop(m_driver); + ret = -4; + } + } + + if (ret < 0) { + /* set requested baudrate and wait for direct uart connection */ + cfg.speed = baud; + sdStart(m_driver, &cfg); } } else { /* Direct uart connetion */