Bluetooth::writeString() now adds CRLF automatically

This commit is contained in:
Bertrand Songis
2019-04-25 11:28:55 +02:00
parent a75548c360
commit d8b3086fde
2 changed files with 13 additions and 13 deletions
+12 -10
View File
@@ -52,6 +52,8 @@ void Bluetooth::writeString(const char * str)
while (*str != 0) { while (*str != 0) {
btTxFifo.push(*str++); btTxFifo.push(*str++);
} }
btTxFifo.push('\r');
btTxFifo.push('\n');
bluetoothWriteWakeup(); bluetoothWriteWakeup();
} }
@@ -298,11 +300,11 @@ void Bluetooth::wakeup(void)
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
*cur++ = zchar2char(g_eeGeneral.bluetoothName[i]); *cur++ = zchar2char(g_eeGeneral.bluetoothName[i]);
} }
*cur = '\0';
} }
else { else {
cur = strAppend(cur, "Taranis-X9E"); cur = strAppend(cur, "Taranis-X9E");
} }
strAppend(cur, "\r\n");
writeString(command); writeString(command);
state = BLUETOOTH_WAIT_TTM; state = BLUETOOTH_WAIT_TTM;
waitEnd = get_tmr10ms() + 25; // 250ms waitEnd = get_tmr10ms() + 25; // 250ms
@@ -366,7 +368,7 @@ void Bluetooth::wakeup()
} }
if (state == BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT) { if (state == BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT) {
writeString("AT+BAUD4\r\n"); writeString("AT+BAUD4");
state = BLUETOOTH_STATE_BAUDRATE_SENT; state = BLUETOOTH_STATE_BAUDRATE_SENT;
wakeupTime = now + 10; /* 100ms */ wakeupTime = now + 10; /* 100ms */
} }
@@ -398,34 +400,34 @@ void Bluetooth::wakeup()
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
*cur++ = zchar2char(g_eeGeneral.bluetoothName[i]); *cur++ = zchar2char(g_eeGeneral.bluetoothName[i]);
} }
*cur = '\0';
} }
else { else {
#if defined(PCBHORUS) #if defined(PCBHORUS)
cur = strAppend(cur, "Horus"); cur = strAppend(cur, "Horus");
#else #else
cur = strAppend(cur, "taranis"); // TODO capital letter once allowed by BT module cur = strAppend(cur, "Taranis");
#endif #endif
} }
strAppend(cur, "\r\n");
writeString(command); writeString(command);
state = BLUETOOTH_STATE_NAME_SENT; state = BLUETOOTH_STATE_NAME_SENT;
} }
else if (state == BLUETOOTH_STATE_NAME_SENT && (!strncmp(line, "OK+", 3) || !strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) { 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; state = BLUETOOTH_STATE_POWER_SENT;
} }
else if (state == BLUETOOTH_STATE_POWER_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) { 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) if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH)
writeString("AT+ROLE1\r\n"); writeString("AT+ROLE1");
else else
writeString("AT+ROLE0\r\n"); writeString("AT+ROLE0");
state = BLUETOOTH_STATE_ROLE_SENT; state = BLUETOOTH_STATE_ROLE_SENT;
} }
else if (state == BLUETOOTH_STATE_ROLE_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) { else if (state == BLUETOOTH_STATE_ROLE_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) {
state = BLUETOOTH_STATE_IDLE; state = BLUETOOTH_STATE_IDLE;
} }
else if (state == BLUETOOTH_STATE_DISCOVER_REQUESTED) { else if (state == BLUETOOTH_STATE_DISCOVER_REQUESTED) {
writeString("AT+DISC?\r\n"); writeString("AT+DISC?");
state = BLUETOOTH_STATE_DISCOVER_SENT; state = BLUETOOTH_STATE_DISCOVER_SENT;
} }
else if (state == BLUETOOTH_STATE_DISCOVER_SENT && !strcmp(line, "OK+DISCS")) { 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) { else if (state == BLUETOOTH_STATE_BIND_REQUESTED) {
char command[32]; char command[32];
strAppend(strAppend(strAppend(command, "AT+CON"), distantAddr), "\r\n"); strAppend(strAppend(command, "AT+CON"), distantAddr);
writeString(command); writeString(command);
state = BLUETOOTH_STATE_CONNECT_SENT; state = BLUETOOTH_STATE_CONNECT_SENT;
} }
@@ -455,7 +457,7 @@ void Bluetooth::wakeup()
} }
else if (state == BLUETOOTH_STATE_DISCONNECTED && !line) { else if (state == BLUETOOTH_STATE_DISCONNECTED && !line) {
char command[32]; char command[32];
strAppend(strAppend(strAppend(command, "AT+CON"), distantAddr), "\r\n"); strAppend(strAppend(command, "AT+CON"), distantAddr);
writeString(command); writeString(command);
wakeupTime = now + 200; /* 2s */ wakeupTime = now + 200; /* 2s */
} }
+1 -3
View File
@@ -1164,9 +1164,7 @@ int cliBlueTooth(const char ** argv)
{ {
int baudrate = 0; int baudrate = 0;
if (!strncmp(argv[1], "AT", 2) || !strncmp(argv[1], "TTM", 3)) { if (!strncmp(argv[1], "AT", 2) || !strncmp(argv[1], "TTM", 3)) {
char command[32]; bluetooth.writeString(argv[1]);
strAppend(strAppend(command, argv[1]), "\r\n");
bluetooth.writeString(command);
char * line = bluetooth.readline(); char * line = bluetooth.readline();
serialPrint("<BT %s", line); serialPrint("<BT %s", line);
} }