mirror of https://github.com/rusefi/wideband.git
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:
parent
a6052895e9
commit
8bfe7faecb
|
@ -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,102 +94,117 @@ int SerialTsChannel::start(uint32_t baud) {
|
||||||
} while ((!done) && (--retry));
|
} while ((!done) && (--retry));
|
||||||
|
|
||||||
if (retry <= 0) {
|
if (retry <= 0) {
|
||||||
return -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find expected baudrate */
|
if (ret == 0) {
|
||||||
for (baudIdx = 0; baudIdx < 8; baudIdx++) {
|
/* find expected baudrate */
|
||||||
if (baud == baudRates[baudIdx]) {
|
for (baudIdx = 0; baudIdx < N_BAUDRATES; baudIdx++) {
|
||||||
break;
|
if (baud == baudRates[baudIdx]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (baudIdx == N_BAUDRATES) {
|
||||||
|
/* unknown baudrate */
|
||||||
|
ret = -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (baudIdx == 8) {
|
|
||||||
/* unknown baudrate */
|
if (ret == 0) {
|
||||||
return -1;
|
int len;
|
||||||
|
char tmp[64];
|
||||||
|
/* setup */
|
||||||
|
done = false;
|
||||||
|
do {
|
||||||
|
/* just a curious */
|
||||||
|
chprintf((BaseSequentialStream *)m_driver, "AT+VERSION\r\n");
|
||||||
|
len = bt_read_line(tmp, sizeof(tmp));
|
||||||
|
if (len < 0) {
|
||||||
|
/* retry */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset settings to defaults */
|
||||||
|
chprintf((BaseSequentialStream *)m_driver, "AT+DEFAULT\r\n");
|
||||||
|
if (bt_wait_ok() != 0) {
|
||||||
|
/* retry */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SPP Broadcast name: up to 18 bytes */
|
||||||
|
chprintf((BaseSequentialStream *)m_driver, "AT+NAME%s\r\n", BT_BROADCAST_NAME);
|
||||||
|
if (bt_wait_ok() != 0) {
|
||||||
|
/* retry */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BLE Broadcast name: up to 18 bytes */
|
||||||
|
chprintf((BaseSequentialStream *)m_driver, "AT+NAMB%s\r\n", BT_BROADCAST_NAME " BLE");
|
||||||
|
if (bt_wait_ok() != 0) {
|
||||||
|
/* retry */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SPP connection with no password */
|
||||||
|
chprintf((BaseSequentialStream *)m_driver, "AT+TYPE%d\r\n", 0);
|
||||||
|
if (bt_wait_ok() != 0) {
|
||||||
|
/* retry */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disable serial port status output */
|
||||||
|
chprintf((BaseSequentialStream *)m_driver, "AT+ENLOG%d\r\n", 0);
|
||||||
|
if (bt_wait_ok() != 0) {
|
||||||
|
/* retry */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
chprintf((BaseSequentialStream *)m_driver, "AT+BAUD%d\r\n", baudRateCodes[baudIdx]);
|
||||||
|
if (bt_wait_ok() != 0) {
|
||||||
|
/* retry */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BT module changes baud rate here */
|
||||||
|
done = true;
|
||||||
|
} while ((!done) && (--retry));
|
||||||
|
|
||||||
|
if (retry <= 0) {
|
||||||
|
ret = -3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int len;
|
/* switch to new baudrate? */
|
||||||
char tmp[64];
|
if (cfg.speed != baud) {
|
||||||
/* setup */
|
sdStop(m_driver);
|
||||||
done = false;
|
|
||||||
do {
|
if (ret == 0) {
|
||||||
/* just a curious */
|
/* switch baudrate */
|
||||||
chprintf((BaseSequentialStream *)m_driver, "AT+VERSION\r\n");
|
cfg.speed = baud;
|
||||||
len = bt_read_line(tmp, sizeof(tmp));
|
sdStart(m_driver, &cfg);
|
||||||
if (len < 0) {
|
|
||||||
/* retry */
|
chThdSleepMilliseconds(10);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset settings to defaults */
|
|
||||||
chprintf((BaseSequentialStream *)m_driver, "AT+DEFAULT\r\n");
|
|
||||||
if (bt_wait_ok() != 0) {
|
|
||||||
/* retry */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SPP Broadcast name: up to 18 bytes */
|
|
||||||
chprintf((BaseSequentialStream *)m_driver, "AT+NAME%s\r\n", BT_BROADCAST_NAME);
|
|
||||||
if (bt_wait_ok() != 0) {
|
|
||||||
/* retry */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* BLE Broadcast name: up to 18 bytes */
|
|
||||||
chprintf((BaseSequentialStream *)m_driver, "AT+NAMB%s\r\n", BT_BROADCAST_NAME " BLE");
|
|
||||||
if (bt_wait_ok() != 0) {
|
|
||||||
/* retry */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SPP connection with no password */
|
|
||||||
chprintf((BaseSequentialStream *)m_driver, "AT+TYPE%d\r\n", 0);
|
|
||||||
if (bt_wait_ok() != 0) {
|
|
||||||
/* retry */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Disable serial port status output */
|
|
||||||
chprintf((BaseSequentialStream *)m_driver, "AT+ENLOG%d\r\n", 0);
|
|
||||||
if (bt_wait_ok() != 0) {
|
|
||||||
/* retry */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
chprintf((BaseSequentialStream *)m_driver, "AT+BAUD%d\r\n", baudRateCodes[baudIdx]);
|
|
||||||
if (bt_wait_ok() != 0) {
|
|
||||||
/* retry */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* BT module changes baud rate here */
|
|
||||||
done = true;
|
|
||||||
} while ((!done) && (--retry));
|
|
||||||
|
|
||||||
if (retry <= 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* switch baudrate */
|
|
||||||
sdStop(m_driver);
|
|
||||||
cfg.speed = baud;
|
|
||||||
sdStart(m_driver, &cfg);
|
|
||||||
|
|
||||||
chThdSleepMilliseconds(10);
|
|
||||||
|
|
||||||
/* now reset BT to apply new settings */
|
/* now reset BT to apply new settings */
|
||||||
chprintf((BaseSequentialStream *)m_driver, "AT+RESET\r\n", baudRateCodes[baudIdx]);
|
chprintf((BaseSequentialStream *)m_driver, "AT+RESET\r\n");
|
||||||
if (bt_wait_ok() != 0) {
|
if (bt_wait_ok() != 0) {
|
||||||
return -1;
|
sdStop(m_driver);
|
||||||
|
ret = -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ready to roll */
|
|
||||||
} 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() {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue