From 9d5b1ef85fdfd71594ee61f864b03a81ea33d32e Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 4 Jun 2017 18:23:48 +0300 Subject: [PATCH 1/4] Bluetooth fix win32 simulator compile error --- simulator/simulator/efifeatures.h | 1 + 1 file changed, 1 insertion(+) diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 9ad90ff434..1f502d4fc9 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -85,6 +85,7 @@ #define EFI_HISTOGRAMS FALSE #define EFI_TUNER_STUDIO TRUE +#define EFI_BLUETOOTH_SETUP FALSE /** * This is the size of the MemoryStream used by chvprintf From 217662ec9dcf6613f63c57fa13710c85132030ec Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 5 Jun 2017 01:07:02 +0300 Subject: [PATCH 2/4] Bluetooth HC-05 draft --- firmware/console/binary/bluetooth.cpp | 35 +++++++++++++++++-------- firmware/console/binary/bluetooth.h | 1 + firmware/console/binary/tunerstudio.cpp | 5 ++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/firmware/console/binary/bluetooth.cpp b/firmware/console/binary/bluetooth.cpp index 8f83f97f7a..a160af4f70 100644 --- a/firmware/console/binary/bluetooth.cpp +++ b/firmware/console/binary/bluetooth.cpp @@ -15,7 +15,8 @@ static const char *commands[5]; static int numCommands = 0; static int setBaudIdx = -1; -static char cmdBaud[10]; +static char cmdHello[5]; +static char cmdBaud[25]; static char cmdName[30]; static char cmdPin[16]; @@ -166,12 +167,6 @@ void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const c return; } - // todo: add support for other BT module types - if (moduleType != BLUETOOTH_HC_06) { - scheduleMsg(&btLogger, "This Bluetooth module is currently not supported!"); - return; - } - numCommands = 0; // now check the arguments and add other commands: @@ -221,12 +216,30 @@ void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const c } // ok, add commands! - commands[numCommands++] = "AT"; // this command is added to test a connection - chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+BAUD%c", '0' + setBaudIdx); + switch (moduleType) { + case BLUETOOTH_HC_05: + chsnprintf(cmdHello, sizeof(cmdHello), "AT\r\n"); + chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+UART=%d,0,0\r\n", baud); // baud rate, 0=(1 stop bit), 0=(no parity bits) + chsnprintf(cmdName, sizeof(cmdName), "AT+NAME=%s\r\n", name); + chsnprintf(cmdPin, sizeof(cmdPin), "AT+PSWD=%s\r\n", pinCode); + // todo: add more commands? + // AT+RMAAD + // AT+ROLE=0 + break; + case BLUETOOTH_HC_06: + chsnprintf(cmdHello, sizeof(cmdHello), "AT"); + chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+BAUD%c", '0' + setBaudIdx); + chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s", name); + chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s", pinCode); + break; + default: + // todo: add support for other BT module types + scheduleMsg(&btLogger, "This Bluetooth module is currently not supported!"); + return; + } + commands[numCommands++] = cmdHello; // this command is added to test a connection commands[numCommands++] = cmdBaud; - chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s", name); commands[numCommands++] = cmdName; - chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s", pinCode); commands[numCommands++] = cmdPin; // create a thread to execute these commands later diff --git a/firmware/console/binary/bluetooth.h b/firmware/console/binary/bluetooth.h index 87e0b69b08..1ee4415b87 100644 --- a/firmware/console/binary/bluetooth.h +++ b/firmware/console/binary/bluetooth.h @@ -19,6 +19,7 @@ // Supported Bluetooth module types typedef enum { + BLUETOOTH_HC_05, BLUETOOTH_HC_06, } bluetooth_module_e; diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index d0377c59a3..945704c24d 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -169,6 +169,10 @@ static void setTsSpeed(int value) { } #if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__) +// Bluetooth HC-05 module initialization start (it waits for disconnect and then communicates to the module) +static void bluetoothHC05(const char *baudRate, const char *name, const char *pinCode) { + bluetoothStart(&tsChannel, BLUETOOTH_HC_05, baudRate, name, pinCode); +} // Bluetooth HC-06 module initialization start (it waits for disconnect and then communicates to the module) static void bluetoothHC06(const char *baudRate, const char *name, const char *pinCode) { bluetoothStart(&tsChannel, BLUETOOTH_HC_06, baudRate, name, pinCode); @@ -844,6 +848,7 @@ void startTunerStudioConnectivity(void) { #if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__) // Usage: "bluetooth_hc06 " // Example: "bluetooth_hc06 38400 rusefi 1234" + addConsoleActionSSS("bluetooth_hc05", bluetoothHC05); addConsoleActionSSS("bluetooth_hc06", bluetoothHC06); addConsoleAction("bluetooth_cancel", bluetoothCancel); #endif /* EFI_BLUETOOTH_SETUP */ From 19e6de9cb421286481a345ca7a561689bc24b62a Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 5 Jun 2017 01:10:48 +0300 Subject: [PATCH 3/4] Bluetooth HC-05 draft --- firmware/svnversion.h | 4 ++-- simulator/simulator/efifeatures.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 5404c5ece6..a5e4a9b2a9 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Fri Jun 02 23:03:47 EDT 2017 +// Mon Jun 05 01:08:50 EEST 2017 #ifndef VCS_VERSION -#define VCS_VERSION "14281" +#define VCS_VERSION "14309" #endif diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 1f502d4fc9..9ad90ff434 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -85,7 +85,6 @@ #define EFI_HISTOGRAMS FALSE #define EFI_TUNER_STUDIO TRUE -#define EFI_BLUETOOTH_SETUP FALSE /** * This is the size of the MemoryStream used by chvprintf From a14c6252731dfefe54f8114911893e3d5913501e Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 5 Jun 2017 01:12:09 +0300 Subject: [PATCH 4/4] Bluetooth HC-05 draft --- firmware/svnversion.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/svnversion.h b/firmware/svnversion.h index a5e4a9b2a9..5404c5ece6 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Mon Jun 05 01:08:50 EEST 2017 +// Fri Jun 02 23:03:47 EDT 2017 #ifndef VCS_VERSION -#define VCS_VERSION "14309" +#define VCS_VERSION "14281" #endif