TS minor fixes (#178)

* ts: fix copy-paste

* TS: fallback to default baudrate if BT setup failed

* io_serial: BT setup: no goto

* ini: dual: fix typo

* ts: BT: fix baudrate switch when using JDY33
This commit is contained in:
Andrey G 2023-01-29 13:02:59 +03:00 committed by GitHub
parent a6052895e9
commit 8bfe7faecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 101 additions and 87 deletions

View File

@ -20,8 +20,9 @@
#endif #endif
// JDY-33 has 9: 128000 which we do not // JDY-33 has 9: 128000 which we do not
static const unsigned int baudRates[] = { 115200, 9600, 38400, 2400, 4800, 19200, 57600 }; #define N_BAUDRATES 7
static const unsigned int baudRateCodes[] = { 8, 4, 6, 2, 3, 5, 7 }; static const unsigned int baudRates[N_BAUDRATES] = { 115200, 9600, 38400, 2400, 4800, 19200, 57600 };
static const unsigned int baudRateCodes[N_BAUDRATES] = {8, 4, 6, 2, 3, 5, 7 };
static const unsigned int btModuleTimeout = TIME_MS2I(100); static const unsigned int btModuleTimeout = TIME_MS2I(100);
int SerialTsChannel::bt_read_line(char *str, size_t max_len) int SerialTsChannel::bt_read_line(char *str, size_t max_len)
@ -59,6 +60,7 @@ int SerialTsChannel::bt_disconnect(void)
} }
int SerialTsChannel::start(uint32_t baud) { int SerialTsChannel::start(uint32_t baud) {
int ret = 0;
SerialConfig cfg = { SerialConfig cfg = {
.speed = baud, .speed = baud,
.cr1 = 0, .cr1 = 0,
@ -70,14 +72,11 @@ int SerialTsChannel::start(uint32_t baud) {
/* try BT setup */ /* try BT setup */
int retry = 3; int retry = 3;
bool done = false; bool done = false;
size_t baudIdx = 0; size_t baudIdx;
do { do {
for (baudIdx = 0; baudIdx < 8 && !done; baudIdx++) { for (baudIdx = 0; baudIdx < N_BAUDRATES && !done; baudIdx++) {
cfg.speed = baudRates[baudIdx]; cfg.speed = baudRates[baudIdx];
baudIdx++;
if (baudIdx == 8)
baudIdx = 0;
sdStart(m_driver, &cfg); sdStart(m_driver, &cfg);
chprintf((BaseSequentialStream *)m_driver, "AT\r\n"); chprintf((BaseSequentialStream *)m_driver, "AT\r\n");
@ -95,20 +94,23 @@ int SerialTsChannel::start(uint32_t baud) {
} while ((!done) && (--retry)); } while ((!done) && (--retry));
if (retry <= 0) { if (retry <= 0) {
return -1; ret = -1;
} }
if (ret == 0) {
/* find expected baudrate */ /* find expected baudrate */
for (baudIdx = 0; baudIdx < 8; baudIdx++) { for (baudIdx = 0; baudIdx < N_BAUDRATES; baudIdx++) {
if (baud == baudRates[baudIdx]) { if (baud == baudRates[baudIdx]) {
break; break;
} }
} }
if (baudIdx == 8) { if (baudIdx == N_BAUDRATES) {
/* unknown baudrate */ /* unknown baudrate */
return -1; ret = -2;
}
} }
if (ret == 0) {
int len; int len;
char tmp[64]; char tmp[64];
/* setup */ /* setup */
@ -168,29 +170,41 @@ int SerialTsChannel::start(uint32_t baud) {
} while ((!done) && (--retry)); } while ((!done) && (--retry));
if (retry <= 0) { if (retry <= 0) {
return -1; ret = -3;
}
} }
/* switch baudrate */ /* switch to new baudrate? */
if (cfg.speed != baud) {
sdStop(m_driver); sdStop(m_driver);
if (ret == 0) {
/* switch baudrate */
cfg.speed = baud; cfg.speed = baud;
sdStart(m_driver, &cfg); sdStart(m_driver, &cfg);
chThdSleepMilliseconds(10); chThdSleepMilliseconds(10);
}
/* now reset BT to apply new settings */
chprintf((BaseSequentialStream *)m_driver, "AT+RESET\r\n", baudRateCodes[baudIdx]);
if (bt_wait_ok() != 0) {
return -1;
} }
/* ready to roll */ /* 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;
}
} else { } else {
/* Direct uart connetion */ /* Direct uart connetion */
sdStart(m_driver, &cfg); sdStart(m_driver, &cfg);
} }
return 0; if (ret < 0) {
/* set requested baudrate and wait for direct uart connection */
cfg.speed = baud;
sdStart(m_driver, &cfg);
}
return ret;
} }
void SerialTsChannel::stop() { void SerialTsChannel::stop() {

View File

@ -88,7 +88,7 @@ highSpeedOffsets = array, U16, 0, [32], "", 1, 0, 0, 65
; 11.2.3 Full Optimized High Speed ; 11.2.3 Full Optimized High Speed
scatteredOchGetCommand = "9" scatteredOchGetCommand = "9"
scatteredOffsetArray = highSpeedOffsets scatteredOffsetArray = highSpeedOffsets
scatteredGetEnabled = { 1 }s scatteredGetEnabled = { 1 }
; Common ; Common
VBatt = scalar, F32, 0, "V", 1, 0 VBatt = scalar, F32, 0, "V", 1, 0