From d8b3086fdec046077fd692c928d4d0b0a14a01ef Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 25 Apr 2019 11:28:44 +0200 Subject: [PATCH] Bluetooth::writeString() now adds CRLF automatically --- radio/src/bluetooth.cpp | 22 ++++++++++++---------- radio/src/cli.cpp | 4 +--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/radio/src/bluetooth.cpp b/radio/src/bluetooth.cpp index 4bb50f279..3b3e96e5a 100644 --- a/radio/src/bluetooth.cpp +++ b/radio/src/bluetooth.cpp @@ -52,6 +52,8 @@ void Bluetooth::writeString(const char * str) while (*str != 0) { btTxFifo.push(*str++); } + btTxFifo.push('\r'); + btTxFifo.push('\n'); bluetoothWriteWakeup(); } @@ -298,11 +300,11 @@ void Bluetooth::wakeup(void) for (int i = 0; i < len; i++) { *cur++ = zchar2char(g_eeGeneral.bluetoothName[i]); } + *cur = '\0'; } else { cur = strAppend(cur, "Taranis-X9E"); } - strAppend(cur, "\r\n"); writeString(command); state = BLUETOOTH_WAIT_TTM; waitEnd = get_tmr10ms() + 25; // 250ms @@ -366,7 +368,7 @@ void Bluetooth::wakeup() } if (state == BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT) { - writeString("AT+BAUD4\r\n"); + writeString("AT+BAUD4"); state = BLUETOOTH_STATE_BAUDRATE_SENT; wakeupTime = now + 10; /* 100ms */ } @@ -398,34 +400,34 @@ void Bluetooth::wakeup() for (int i = 0; i < len; i++) { *cur++ = zchar2char(g_eeGeneral.bluetoothName[i]); } + *cur = '\0'; } else { #if defined(PCBHORUS) cur = strAppend(cur, "Horus"); #else - cur = strAppend(cur, "taranis"); // TODO capital letter once allowed by BT module + cur = strAppend(cur, "Taranis"); #endif } - strAppend(cur, "\r\n"); writeString(command); state = BLUETOOTH_STATE_NAME_SENT; } else if (state == BLUETOOTH_STATE_NAME_SENT && (!strncmp(line, "OK+", 3) || !strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) { - writeString("AT+TXPW0\r\n"); + writeString("AT+TXPW0"); state = BLUETOOTH_STATE_POWER_SENT; } else if (state == BLUETOOTH_STATE_POWER_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) { if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH) - writeString("AT+ROLE1\r\n"); + writeString("AT+ROLE1"); else - writeString("AT+ROLE0\r\n"); + writeString("AT+ROLE0"); state = BLUETOOTH_STATE_ROLE_SENT; } else if (state == BLUETOOTH_STATE_ROLE_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) { state = BLUETOOTH_STATE_IDLE; } else if (state == BLUETOOTH_STATE_DISCOVER_REQUESTED) { - writeString("AT+DISC?\r\n"); + writeString("AT+DISC?"); state = BLUETOOTH_STATE_DISCOVER_SENT; } else if (state == BLUETOOTH_STATE_DISCOVER_SENT && !strcmp(line, "OK+DISCS")) { @@ -442,7 +444,7 @@ void Bluetooth::wakeup() } */ else if (state == BLUETOOTH_STATE_BIND_REQUESTED) { char command[32]; - strAppend(strAppend(strAppend(command, "AT+CON"), distantAddr), "\r\n"); + strAppend(strAppend(command, "AT+CON"), distantAddr); writeString(command); state = BLUETOOTH_STATE_CONNECT_SENT; } @@ -455,7 +457,7 @@ void Bluetooth::wakeup() } else if (state == BLUETOOTH_STATE_DISCONNECTED && !line) { char command[32]; - strAppend(strAppend(strAppend(command, "AT+CON"), distantAddr), "\r\n"); + strAppend(strAppend(command, "AT+CON"), distantAddr); writeString(command); wakeupTime = now + 200; /* 2s */ } diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index 3b402989b..bfc345922 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -1164,9 +1164,7 @@ int cliBlueTooth(const char ** argv) { int baudrate = 0; if (!strncmp(argv[1], "AT", 2) || !strncmp(argv[1], "TTM", 3)) { - char command[32]; - strAppend(strAppend(command, argv[1]), "\r\n"); - bluetooth.writeString(command); + bluetooth.writeString(argv[1]); char * line = bluetooth.readline(); serialPrint("