From 7b4d27ce89a3e3d3963469164d573af6f42bed42 Mon Sep 17 00:00:00 2001 From: andreika-git Date: Fri, 3 Nov 2017 00:10:00 +0200 Subject: [PATCH] Added support for Bluetooth SPP-C module (#483) --- firmware/console/binary/bluetooth.cpp | 11 ++++++++++- firmware/console/binary/bluetooth.h | 1 + firmware/console/binary/tunerstudio.cpp | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/firmware/console/binary/bluetooth.cpp b/firmware/console/binary/bluetooth.cpp index a160af4f70..037f9d3111 100644 --- a/firmware/console/binary/bluetooth.cpp +++ b/firmware/console/binary/bluetooth.cpp @@ -46,6 +46,8 @@ static void runCommands() { if (!btProcessIsStarted) return; + chThdSleepMilliseconds(1000); // safety + // Store current serial port speed - we're going to change it int savedSerialSpeed = boardConfiguration->tunerStudioSerialSpeed; @@ -90,7 +92,8 @@ static void runCommands() { // waiting for an answer bool wasAnswer = false; if (sr5ReadDataTimeout(tsChannel, buffer, 2, btModuleTimeout) == 2) { - wasAnswer = (buffer[0] == 'O' && buffer[1] == 'K'); + wasAnswer = (buffer[0] == 'O' && buffer[1] == 'K') || + (buffer[0] == '+' && (buffer[1] >= 'A' && buffer[1] <= 'Z')); } // wait 1 second and skip all remaining response bytes from the bluetooth module @@ -232,6 +235,12 @@ void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const c chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s", name); chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s", pinCode); break; + case BLUETOOTH_SPP: + chsnprintf(cmdHello, sizeof(cmdHello), "AT\r\n"); + chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+BAUD%c\r\n", '0' + setBaudIdx); + chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s\r\n", name); + chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s\r\n", pinCode); + break; default: // todo: add support for other BT module types scheduleMsg(&btLogger, "This Bluetooth module is currently not supported!"); diff --git a/firmware/console/binary/bluetooth.h b/firmware/console/binary/bluetooth.h index 1ee4415b87..5603fb6072 100644 --- a/firmware/console/binary/bluetooth.h +++ b/firmware/console/binary/bluetooth.h @@ -21,6 +21,7 @@ typedef enum { BLUETOOTH_HC_05, BLUETOOTH_HC_06, + BLUETOOTH_SPP, } bluetooth_module_e; /** diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index c1403a5d4e..f6c29833f1 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -177,6 +177,10 @@ static void bluetoothHC05(const char *baudRate, const char *name, const char *pi static void bluetoothHC06(const char *baudRate, const char *name, const char *pinCode) { bluetoothStart(&tsChannel, BLUETOOTH_HC_06, baudRate, name, pinCode); } +// Bluetooth SPP-C module initialization start (it waits for disconnect and then communicates to the module) +static void bluetoothSPP(const char *baudRate, const char *name, const char *pinCode) { + bluetoothStart(&tsChannel, BLUETOOTH_SPP, baudRate, name, pinCode); +} #endif /* EFI_BLUETOOTH_SETUP */ void tunerStudioDebug(const char *msg) { @@ -863,6 +867,7 @@ void startTunerStudioConnectivity(void) { // Example: "bluetooth_hc06 38400 rusefi 1234" addConsoleActionSSS("bluetooth_hc05", bluetoothHC05); addConsoleActionSSS("bluetooth_hc06", bluetoothHC06); + addConsoleActionSSS("bluetooth_spp", bluetoothSPP); addConsoleAction("bluetooth_cancel", bluetoothCancel); #endif /* EFI_BLUETOOTH_SETUP */