From eadedbf5d9bcdc4461fb1d0e2ace02e245e520f3 Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Wed, 23 Dec 2020 14:20:28 +0100 Subject: [PATCH 01/15] zoe --- CarRenaultZoe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CarRenaultZoe.cpp b/CarRenaultZoe.cpp index 2fba9da..30498d9 100644 --- a/CarRenaultZoe.cpp +++ b/CarRenaultZoe.cpp @@ -6,8 +6,8 @@ #include "LiveData.h" #include "CarRenaultZoe.h" -#define commandQueueCountRenaultZoe 83 -#define commandQueueLoopFromRenaultZoe 9 +#define commandQueueCountRenaultZoe 34 +#define commandQueueLoopFromRenaultZoe 8 /** activateCommandQueue From dc2bab754a3c767c6342039256fed9d4111e6d8f Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Wed, 23 Dec 2020 16:29:31 +0100 Subject: [PATCH 02/15] sdcard --- Board320_240.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Board320_240.cpp b/Board320_240.cpp index f54d0e4..5739dc4 100644 --- a/Board320_240.cpp +++ b/Board320_240.cpp @@ -1369,15 +1369,16 @@ bool Board320_240::sdcardMount() { while (1) { Serial.print("Initializing SD card..."); - + #ifdef BOARD_TTGO_T4 + Serial.print(" TTGO-T4 "); SPIClass * hspi = new SPIClass(HSPI); spiSD.begin(pinSdcardSclk, pinSdcardMiso, pinSdcardMosi, pinSdcardCs); //SCK,MISO,MOSI,ss SdState = SD.begin(pinSdcardCs, *hspi, SPI_FREQUENCY); -#endif // BOARD_TTGO_T4 -#ifdef BOARD_M5STACK_CORE +#endif BOARD_TTGO_T4 + + Serial.print(" M5STACK "); SdState = SD.begin(pinSdcardCs); -#endif // BOARD_M5STACK_CORE if (SdState) { From 1f20e5042419648c045228cd0e2715f0057e5079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kolac=C3=AD?= Date: Wed, 23 Dec 2020 17:44:38 +0100 Subject: [PATCH 03/15] FlowControl timeout to 20ms; Speaker fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kolací --- BoardM5stackCore.cpp | 2 +- CommObd2Can.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BoardM5stackCore.cpp b/BoardM5stackCore.cpp index e41afd0..523a067 100644 --- a/BoardM5stackCore.cpp +++ b/BoardM5stackCore.cpp @@ -21,7 +21,7 @@ void BoardM5stackCore::initBoard() { // Mute speaker //ledcWriteTone(TONE_PIN_CHANNEL, 0); - digitalWrite(SPEAKER_PIN, 0); + dacWrite(SPEAKER_PIN, 0); // Board320_240::initBoard(); diff --git a/CommObd2Can.cpp b/CommObd2Can.cpp index 6607d9b..ba3881c 100644 --- a/CommObd2Can.cpp +++ b/CommObd2Can.cpp @@ -196,7 +196,7 @@ void CommObd2Can::sendPID(const uint16_t pid, const String& cmd) { */ void CommObd2Can::sendFlowControlFrame() { - uint8_t txBuf[8] = { 0x30, requestFramesCount /*request count*/, 14 /*ms between frames*/ , 0, 0, 0, 0, 0 }; + uint8_t txBuf[8] = { 0x30, requestFramesCount /*request count*/, 20 /*ms between frames*/ , 0, 0, 0, 0, 0 }; // insert 0x07 into beginning for BMW i3 if (liveData->settings.carType == CAR_BMW_I3_2014) { From ff9e968d697e4acdb3e117498e7dc04e29918dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kolac=C3=AD?= Date: Wed, 23 Dec 2020 22:37:50 +0100 Subject: [PATCH 04/15] chargingOn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kolací --- CarHyundaiIoniq.cpp | 3 +++ LiveData.cpp | 1 + LiveData.h | 1 + 3 files changed, 5 insertions(+) diff --git a/CarHyundaiIoniq.cpp b/CarHyundaiIoniq.cpp index 8154c06..a2a945f 100644 --- a/CarHyundaiIoniq.cpp +++ b/CarHyundaiIoniq.cpp @@ -174,6 +174,9 @@ void CarHyundaiIoniq::parseRowMerged() { //liveData->params.batMaxC = liveData->hexToDecFromResponse(32, 34, 1, true); //liveData->params.batMinC = liveData->hexToDecFromResponse(34, 36, 1, true); + tempByte = liveData->hexToDecFromResponse(104, 106, 1, false); + liveData->params.chargingOn = (bitRead(tempByte, 2) == 1); + // This is more accurate than min/max from BMS. It's required to detect kona/eniro cold gates (min 15C is needed > 43kW charging, min 25C is needed > 58kW charging) liveData->params.batInletC = liveData->hexToDecFromResponse(48, 50, 1, true); if (liveData->params.speedKmh < 10 && liveData->params.batPowerKw >= 1 && liveData->params.socPerc > 0 && liveData->params.socPerc <= 100) { diff --git a/LiveData.cpp b/LiveData.cpp index ad4d478..0ba42ef 100644 --- a/LiveData.cpp +++ b/LiveData.cpp @@ -27,6 +27,7 @@ void LiveData::initParams() { params.lastIgnitionOnTime = 0; params.operationTimeSec = 0; params.chargingStartTime = params.currentTime = 0; + params.chargingOn = false; params.lightInfo = 0; params.headLights = false; params.dayLights = false; diff --git a/LiveData.h b/LiveData.h index cacfa2d..ad04119 100644 --- a/LiveData.h +++ b/LiveData.h @@ -58,6 +58,7 @@ typedef struct { char sdcardFilename[32]; // Car params bool ignitionOn; + bool chargingOn; time_t lastIgnitionOnTime; uint64_t operationTimeSec; bool sdcardCanNotify; From dfcaec7fe1e11d92a8808550c3b5940f3fe802e1 Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Wed, 23 Dec 2020 23:12:58 +0100 Subject: [PATCH 05/15] bms ignition --- Board320_240.cpp | 8 ++++---- CarHyundaiIoniq.cpp | 2 +- CarKiaEniro.cpp | 4 +++- CarRenaultZoe.cpp | 4 +++- LiveData.h | 8 ++++++++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Board320_240.cpp b/Board320_240.cpp index 5739dc4..c82eb59 100644 --- a/Board320_240.cpp +++ b/Board320_240.cpp @@ -1166,8 +1166,8 @@ void Board320_240::redrawScreen() { // SDCARD recording /*liveData->params.sdcardRecording*/ if (liveData->settings.sdcardEnabled == 1) { - spr.fillCircle((displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED) ? 160 : 310, 10, 4, TFT_BLACK); - spr.fillCircle((displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED) ? 160 : 310, 10, 3, + spr.fillCircle((displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED) ? 140 : 310, 10, 4, TFT_BLACK); + spr.fillCircle((displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED) ? 140 : 310, 10, 3, (liveData->params.sdcardInit == 1) ? (liveData->params.sdcardRecording) ? (strlen(liveData->params.sdcardFilename) != 0) ? @@ -1178,12 +1178,12 @@ void Board320_240::redrawScreen() { ); } if (gpsHwUart != NULL && (displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED)) { - spr.drawCircle(180, 10, 5, (gps.location.isValid()) ? TFT_GREEN : TFT_RED); + spr.drawCircle(160, 10, 5, (gps.location.isValid()) ? TFT_GREEN : TFT_RED); spr.setTextSize(1); spr.setTextColor((gps.location.isValid()) ? TFT_GREEN : TFT_WHITE, TFT_BLACK); spr.setTextDatum(TL_DATUM); sprintf(tmpStr1, "%d", liveData->params.gpsSat); - spr.drawString(tmpStr1, 194, 2, 2); + spr.drawString(tmpStr1, 174, 2, 2); } diff --git a/CarHyundaiIoniq.cpp b/CarHyundaiIoniq.cpp index a2a945f..f382ffd 100644 --- a/CarHyundaiIoniq.cpp +++ b/CarHyundaiIoniq.cpp @@ -111,7 +111,7 @@ void CarHyundaiIoniq::parseRowMerged() { liveData->params.lastIgnitionOnTime = liveData->params.currentTime; } int32_t secDiff = liveData->params.currentTime - liveData->params.currentTime; - if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn) + if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn && !liveData->params.chargingOn) liveData->params.automaticShutdownTimer = liveData->params.currentTime; liveData->params.lightInfo = liveData->hexToDecFromResponse(18, 20, 1, false); liveData->params.headLights = (bitRead(liveData->params.lightInfo, 5) == 1); diff --git a/CarKiaEniro.cpp b/CarKiaEniro.cpp index ddd1f46..742c7fe 100644 --- a/CarKiaEniro.cpp +++ b/CarKiaEniro.cpp @@ -129,7 +129,7 @@ void CarKiaEniro::parseRowMerged() { liveData->params.lastIgnitionOnTime = liveData->params.currentTime; } int32_t secDiff = liveData->params.currentTime - liveData->params.currentTime; - if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn) + if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn && !liveData->params.chargingOn) liveData->params.automaticShutdownTimer = liveData->params.currentTime; liveData->params.lightInfo = liveData->hexToDecFromResponse(18, 20, 1, false); liveData->params.headLights = (bitRead(liveData->params.lightInfo, 5) == 1); @@ -207,6 +207,8 @@ void CarKiaEniro::parseRowMerged() { //liveData->params.batTempC = liveData->hexToDecFromResponse(36, 38, 1, true); //liveData->params.batMaxC = liveData->hexToDecFromResponse(34, 36, 1, true); //liveData->params.batMinC = liveData->hexToDecFromResponse(36, 38, 1, true); + tempByte = liveData->hexToDecFromResponse(106, 108, 1, false); + liveData->params.chargingOn = (bitRead(tempByte, 2) == 1); // This is more accurate than min/max from BMS. It's required to detect kona/eniro cold gates (min 15C is needed > 43kW charging, min 25C is needed > 58kW charging) liveData->params.batMinC = liveData->params.batMaxC = liveData->params.batModuleTempC[0]; diff --git a/CarRenaultZoe.cpp b/CarRenaultZoe.cpp index 30498d9..f0bfca5 100644 --- a/CarRenaultZoe.cpp +++ b/CarRenaultZoe.cpp @@ -108,7 +108,9 @@ void CarRenaultZoe::activateCommandQueue() { // liveData->params.batModuleTempCount = 12; // 24, 12 is display limit - liveData->params.batteryTotalAvailableKWh = 28; + liveData->params.batteryTotalAvailableKWh = 22; + // usable 22, total 26 + // Empty and fill command queue for (int i = 0; i < 300; i++) { diff --git a/LiveData.h b/LiveData.h index ad04119..a2930de 100644 --- a/LiveData.h +++ b/LiveData.h @@ -194,6 +194,14 @@ typedef struct { // ================================= byte gpsHwSerialPort; // 255-off, 0,1,2 - hw serial byte gprsHwSerialPort; // 255-off, 0,1,2 - hw serial + // === settings version 6 + // ================================= + byte serialConsolePort; // 255-off, 0 - hw serial (std) + byte debugLevel; // 0 - info only, 1 - debug communication (BLE/CAN), 2 - debug GSM, 3 - debug SDcard + uint16_t sdcardLogIntervalSec; // every x seconds + uint16_t gprsLogIntervalSec; // every x seconds + + // } SETTINGS_STRUC; From fecc4866ce2740292488146f170e4c242fd158dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kolac=C3=AD?= Date: Wed, 23 Dec 2020 23:36:17 +0100 Subject: [PATCH 06/15] Add packet filtering (Ioniq only) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kolací --- CommObd2Can.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CommObd2Can.cpp b/CommObd2Can.cpp index ba3881c..8b7ccbc 100644 --- a/CommObd2Can.cpp +++ b/CommObd2Can.cpp @@ -222,7 +222,7 @@ void CommObd2Can::sendFlowControlFrame() { Receive PID */ uint8_t CommObd2Can::receivePID() { - + if (!digitalRead(pinCanInt)) // If CAN0_INT pin is low, read receive buffer { lastDataSent = millis(); @@ -237,6 +237,16 @@ uint8_t CommObd2Can::receivePID() { Serial.print(msgString); + // Filter received messages (Ioniq only) + if(liveData->settings.carType == CAR_HYUNDAI_IONIQ_2018) { + long unsigned int atsh_response = liveData->hexToDec(liveData->currentAtshRequest.substring(4), 2, false) + 8; + + if(rxId != atsh_response) { + Serial.println(" [Filtered packet]"); + return 0xff; + } + } + if ((rxId & 0x40000000) == 0x40000000) { // Determine if message is a remote request frame. sprintf(msgString, " REMOTE REQUEST FRAME"); Serial.print(msgString); From 01cbd4592cc5359bff2d21d6ef0f9a950e5bc29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kolac=C3=AD?= Date: Wed, 23 Dec 2020 23:55:14 +0100 Subject: [PATCH 07/15] Add packet filtering (Ioniq only) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kolací --- CommObd2Can.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CommObd2Can.cpp b/CommObd2Can.cpp index 8b7ccbc..56b8231 100644 --- a/CommObd2Can.cpp +++ b/CommObd2Can.cpp @@ -237,16 +237,6 @@ uint8_t CommObd2Can::receivePID() { Serial.print(msgString); - // Filter received messages (Ioniq only) - if(liveData->settings.carType == CAR_HYUNDAI_IONIQ_2018) { - long unsigned int atsh_response = liveData->hexToDec(liveData->currentAtshRequest.substring(4), 2, false) + 8; - - if(rxId != atsh_response) { - Serial.println(" [Filtered packet]"); - return 0xff; - } - } - if ((rxId & 0x40000000) == 0x40000000) { // Determine if message is a remote request frame. sprintf(msgString, " REMOTE REQUEST FRAME"); Serial.print(msgString); @@ -263,6 +253,16 @@ uint8_t CommObd2Can::receivePID() { Serial.println(" [Ignored packet]"); return 0xff; } + + // Filter received messages (Ioniq only) + if(liveData->settings.carType == CAR_HYUNDAI_IONIQ_2018) { + long unsigned int atsh_response = liveData->hexToDec(liveData->currentAtshRequest.substring(4), 2, false) + 8; + + if(rxId != atsh_response) { + Serial.println(" [Filtered packet]"); + return 0xff; + } + } Serial.println(); processFrameBytes(); From e3d0b2c5c2ff9f94dce77cdc53c862bd8398a1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kolac=C3=AD?= Date: Thu, 24 Dec 2020 00:40:23 +0100 Subject: [PATCH 08/15] Fix - Ioniq AUX percent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kolací --- CarHyundaiIoniq.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CarHyundaiIoniq.cpp b/CarHyundaiIoniq.cpp index a2a945f..c429ab2 100644 --- a/CarHyundaiIoniq.cpp +++ b/CarHyundaiIoniq.cpp @@ -97,7 +97,7 @@ void CarHyundaiIoniq::parseRowMerged() { liveData->params.speedKmh = 0; } if (liveData->commandRequest.equals("2102")) { - liveData->params.auxPerc = liveData->hexToDecFromResponse(50, 52, 1, false); + liveData->params.auxPerc = liveData->hexToDecFromResponse(38, 40, 1, false); liveData->params.auxCurrentAmp = - liveData->hexToDecFromResponse(46, 50, 2, true) / 1000.0; } } From ba63abcecfa7711a21557a0f4781000dca18ef5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kolac=C3=AD?= Date: Thu, 24 Dec 2020 08:39:28 +0100 Subject: [PATCH 09/15] Ioniq auxPercent Workaround MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kolací --- CarHyundaiIoniq.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CarHyundaiIoniq.cpp b/CarHyundaiIoniq.cpp index b537d5c..0e16094 100644 --- a/CarHyundaiIoniq.cpp +++ b/CarHyundaiIoniq.cpp @@ -97,7 +97,6 @@ void CarHyundaiIoniq::parseRowMerged() { liveData->params.speedKmh = 0; } if (liveData->commandRequest.equals("2102")) { - liveData->params.auxPerc = liveData->hexToDecFromResponse(38, 40, 1, false); liveData->params.auxCurrentAmp = - liveData->hexToDecFromResponse(46, 50, 2, true) / 1000.0; } } @@ -157,6 +156,11 @@ void CarHyundaiIoniq::parseRowMerged() { liveData->params.batFanStatus = liveData->hexToDecFromResponse(58, 60, 2, true); liveData->params.batFanFeedbackHz = liveData->hexToDecFromResponse(60, 62, 2, true); liveData->params.auxVoltage = liveData->hexToDecFromResponse(62, 64, 2, true) / 10.0; + if(liveData->params.ignitionOn) { + liveData->params.auxPerc = map(liveData->params.auxVoltage, 12.8, 14.8, 0, 100); + } else { + liveData->params.auxPerc = map(liveData->params.auxVoltage, 11.6, 12.8, 0, 100); + } liveData->params.batPowerAmp = - liveData->hexToDecFromResponse(24, 28, 2, true) / 10.0; liveData->params.batVoltage = liveData->hexToDecFromResponse(28, 32, 2, false) / 10.0; liveData->params.batPowerKw = (liveData->params.batPowerAmp * liveData->params.batVoltage) / 1000.0; From b69c44c0b8d508bd3911ff542845beb5b15f1b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kolac=C3=AD?= Date: Thu, 24 Dec 2020 16:41:35 +0100 Subject: [PATCH 10/15] Ioniq auxPerc workaround - fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kolací --- CarHyundaiIoniq.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CarHyundaiIoniq.cpp b/CarHyundaiIoniq.cpp index 0e16094..5f3ec73 100644 --- a/CarHyundaiIoniq.cpp +++ b/CarHyundaiIoniq.cpp @@ -156,11 +156,20 @@ void CarHyundaiIoniq::parseRowMerged() { liveData->params.batFanStatus = liveData->hexToDecFromResponse(58, 60, 2, true); liveData->params.batFanFeedbackHz = liveData->hexToDecFromResponse(60, 62, 2, true); liveData->params.auxVoltage = liveData->hexToDecFromResponse(62, 64, 2, true) / 10.0; + float tmpAuxPerc; if(liveData->params.ignitionOn) { - liveData->params.auxPerc = map(liveData->params.auxVoltage, 12.8, 14.8, 0, 100); + tmpAuxPerc = map(liveData->params.auxVoltage * 10, 128, 148, 0, 1000) / 10; } else { - liveData->params.auxPerc = map(liveData->params.auxVoltage, 11.6, 12.8, 0, 100); + tmpAuxPerc = map(liveData->params.auxVoltage * 10, 116, 128, 0, 1000) / 10; } + if(tmpAuxPerc > 100) { + liveData->params.auxPerc = 100; + } else if(tmpAuxPerc < 0) { + liveData->params.auxPerc = 0; + } else { + liveData->params.auxPerc = tmpAuxPerc; + } + liveData->params.batPowerAmp = - liveData->hexToDecFromResponse(24, 28, 2, true) / 10.0; liveData->params.batVoltage = liveData->hexToDecFromResponse(28, 32, 2, false) / 10.0; liveData->params.batPowerKw = (liveData->params.batPowerAmp * liveData->params.batVoltage) / 1000.0; From 662ae3ae7a22754729abf9beada23aaad3c8ffb7 Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Thu, 24 Dec 2020 18:00:18 +0100 Subject: [PATCH 11/15] settings v6 --- Board320_240.cpp | 6 +++++- BoardInterface.cpp | 23 +++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Board320_240.cpp b/Board320_240.cpp index c82eb59..c9a48a8 100644 --- a/Board320_240.cpp +++ b/Board320_240.cpp @@ -73,8 +73,12 @@ void Board320_240::afterSetup() { // Init GPS if (liveData->settings.gpsHwSerialPort <= 2) { - Serial.print("GPS initialization on hw uart: "); + Serial.print("GPS initialization on hwUart: "); Serial.println(liveData->settings.gpsHwSerialPort); + if (liveData->settings.gpsHwSerialPort == 0) { + Serial.println("hwUart0 collision with serial console! Disabling serial console"); + Serial.end(); + } gpsHwUart = new HardwareSerial(liveData->settings.gpsHwSerialPort); gpsHwUart->begin(9600); } diff --git a/BoardInterface.cpp b/BoardInterface.cpp index 849208b..b058aa5 100644 --- a/BoardInterface.cpp +++ b/BoardInterface.cpp @@ -38,7 +38,7 @@ void BoardInterface::shutdownDevice() { } #ifdef SIM800L_ENABLED - if(sim800l->isConnectedGPRS()) { + if (sim800l->isConnectedGPRS()) { sim800l->disconnectGPRS(); } sim800l->setPowerMode(MINIMUM); @@ -49,7 +49,7 @@ void BoardInterface::shutdownDevice() { //WiFi.disconnect(true); //WiFi.mode(WIFI_OFF); - commInterface->disconnectDevice(); + commInterface->disconnectDevice(); //adc_power_off(); //esp_wifi_stop(); esp_bt_controller_disable(); @@ -137,6 +137,10 @@ void BoardInterface::loadSettings() { liveData->settings.headlightsReminder = 0; liveData->settings.gpsHwSerialPort = 255; // off liveData->settings.gprsHwSerialPort = 255; // off + liveData->settings.serialConsolePort = 0; // hwuart0 + liveData->settings.debugLevel = 1; // 0 - info only, 1 - debug communication (BLE/CAN), 2 - debug GSM, 3 - debug SDcard + liveData->settings.sdcardLogIntervalSec = 2; + liveData->settings.gprsLogIntervalSec = 60; // Load settings and replace default values Serial.println("Reading settings from eeprom."); @@ -191,6 +195,13 @@ void BoardInterface::loadSettings() { liveData->tmpSettings.settingsVersion = 5; liveData->tmpSettings.gpsHwSerialPort = 255; // off } + if (liveData->tmpSettings.settingsVersion == 5) { + liveData->tmpSettings.settingsVersion = 6; + liveData->tmpSettings.serialConsolePort = 0; // hwuart0 + liveData->tmpSettings.debugLevel = 1; // 1 - debug communication (BLE/CAN) + liveData->tmpSettings.sdcardLogIntervalSec = 2; + liveData->tmpSettings.gprsLogIntervalSec = 60; + } // Save upgraded structure liveData->settings = liveData->tmpSettings; @@ -210,7 +221,7 @@ void BoardInterface::afterSetup() { // Init Comm iterface Serial.print("Init communication device: "); Serial.println(liveData->settings.commType); - + if (liveData->settings.commType == COMM_TYPE_OBD2BLE4) { commInterface = new CommObd2Ble4(); } else if (liveData->settings.commType == COMM_TYPE_OBD2CAN) { @@ -247,10 +258,10 @@ void BoardInterface::customConsoleCommand(String cmd) { } /** - * Parser response from obd2/can - */ + Parser response from obd2/can +*/ void BoardInterface::parseRowMerged() { - + carInterface->parseRowMerged(); } From 5904f3ef392b7a19a24e81ea12f6c8665e776c2f Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Thu, 24 Dec 2020 18:28:28 +0100 Subject: [PATCH 12/15] . --- Board320_240.cpp | 3 ++- evDash.ino | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Board320_240.cpp b/Board320_240.cpp index c9a48a8..a99e805 100644 --- a/Board320_240.cpp +++ b/Board320_240.cpp @@ -1,4 +1,4 @@ -#include +//#include #include #include #include @@ -77,6 +77,7 @@ void Board320_240::afterSetup() { Serial.println(liveData->settings.gpsHwSerialPort); if (liveData->settings.gpsHwSerialPort == 0) { Serial.println("hwUart0 collision with serial console! Disabling serial console"); + Serial.flush(); Serial.end(); } gpsHwUart = new HardwareSerial(liveData->settings.gpsHwSerialPort); diff --git a/evDash.ino b/evDash.ino index ec6c300..175d1be 100644 --- a/evDash.ino +++ b/evDash.ino @@ -1,4 +1,4 @@ -/* + /* Project renamed from eNiroDashboard to evDash Serial console commands From ca22d1b192151e28ea9bd224454549d032c1efeb Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Thu, 24 Dec 2020 19:55:54 +0100 Subject: [PATCH 13/15] door status --- Board320_240.cpp | 45 ++++++++++++++++++++++++++++++++++++++------- CarHyundaiIoniq.cpp | 12 ++++++------ CarKiaEniro.cpp | 40 +++++++++++++++++++++++++--------------- LiveData.cpp | 9 ++++++--- LiveData.h | 10 ++++++++-- 5 files changed, 83 insertions(+), 33 deletions(-) diff --git a/Board320_240.cpp b/Board320_240.cpp index a99e805..0efce0b 100644 --- a/Board320_240.cpp +++ b/Board320_240.cpp @@ -73,13 +73,13 @@ void Board320_240::afterSetup() { // Init GPS if (liveData->settings.gpsHwSerialPort <= 2) { - Serial.print("GPS initialization on hwUart: "); + Serial.print("GPS initialization on hwUart: "); Serial.println(liveData->settings.gpsHwSerialPort); if (liveData->settings.gpsHwSerialPort == 0) { Serial.println("hwUart0 collision with serial console! Disabling serial console"); Serial.flush(); Serial.end(); - } + } gpsHwUart = new HardwareSerial(liveData->settings.gpsHwSerialPort); gpsHwUart->begin(9600); } @@ -1063,7 +1063,24 @@ void Board320_240::menuItemClick() { // Save settings case 9: saveSettings(); break; // Version - case 10: hideMenu(); return; + case 10: + /* commInterface->executeCommand("ATSH770"); + delay(50); + commInterface->executeCommand("3E"); + delay(50); + commInterface->executeCommand("1003"); + delay(50); + commInterface->executeCommand("2FBC1003"); + delay(5000); + commInterface->executeCommand("ATSH770"); + delay(50); + commInterface->executeCommand("3E"); + delay(50); + commInterface->executeCommand("1003"); + delay(50); + commInterface->executeCommand("2FBC1103"); + delay(5000);*/ + hideMenu(); return; // Shutdown case 11: shutdownDevice(); return; default: @@ -1182,6 +1199,7 @@ void Board320_240::redrawScreen() { TFT_YELLOW /* failed to initialize sdcard */ ); } + // GPS state if (gpsHwUart != NULL && (displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED)) { spr.drawCircle(160, 10, 5, (gps.location.isValid()) ? TFT_GREEN : TFT_RED); spr.setTextSize(1); @@ -1189,9 +1207,22 @@ void Board320_240::redrawScreen() { spr.setTextDatum(TL_DATUM); sprintf(tmpStr1, "%d", liveData->params.gpsSat); spr.drawString(tmpStr1, 174, 2, 2); - } + // Door status + if (liveData->params.trunkDoorOpen) + spr.fillRect(20, 0, 320 - 40, 20, TFT_YELLOW); + if (liveData->params.leftFrontDoorOpen) + spr.fillRect(0, 20, 20, 98, TFT_YELLOW); + if (liveData->params.rightFrontDoorOpen) + spr.fillRect(0, 122, 20, 98, TFT_YELLOW); + if (liveData->params.leftRearDoorOpen) + spr.fillRect(320 - 20, 20, 20, 98, TFT_YELLOW); + if (liveData->params.rightRearDoorOpen) + spr.fillRect(320 - 20, 122, 20, 98, TFT_YELLOW); + if (liveData->params.hoodOpen) + spr.fillRect(20, 240 - 20, 320 - 40, 20, TFT_YELLOW); + // BLE not connected if (!liveData->commConnected && liveData->bleConnect && liveData->tmpSettings.commType == COMM_TYPE_OBD2BLE4) { // Print message @@ -1213,7 +1244,7 @@ void Board320_240::redrawScreen() { void Board320_240::loadTestData() { Serial.println("Loading test data"); - + testDataMode = true; // skip lights off message carInterface->loadTestData(); redrawScreen(); @@ -1374,7 +1405,7 @@ bool Board320_240::sdcardMount() { while (1) { Serial.print("Initializing SD card..."); - + #ifdef BOARD_TTGO_T4 Serial.print(" TTGO-T4 "); SPIClass * hspi = new SPIClass(HSPI); @@ -1490,7 +1521,7 @@ bool Board320_240::sim800lSetup() { // SIM800L DebugMode: //sim800l = new SIM800L((Stream *)gprsHwUart, SIM800L_RST, 512 , 512, (Stream *)&Serial); - bool sim800l_ready = sim800l->isReady(); + bool sim800l_ready = sim800l->isReady(); for (uint8_t i = 0; i < 5 && !sim800l_ready; i++) { Serial.println("Problem to initialize SIM800L module, retry in 1 sec"); delay(1000); diff --git a/CarHyundaiIoniq.cpp b/CarHyundaiIoniq.cpp index 5f3ec73..a15a9c2 100644 --- a/CarHyundaiIoniq.cpp +++ b/CarHyundaiIoniq.cpp @@ -85,7 +85,7 @@ void CarHyundaiIoniq::activateCommandQueue() { */ void CarHyundaiIoniq::parseRowMerged() { - bool tempByte; + uint8_t tempByte; float tempFloat; String tmpStr; @@ -112,13 +112,13 @@ void CarHyundaiIoniq::parseRowMerged() { int32_t secDiff = liveData->params.currentTime - liveData->params.currentTime; if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn && !liveData->params.chargingOn) liveData->params.automaticShutdownTimer = liveData->params.currentTime; - liveData->params.lightInfo = liveData->hexToDecFromResponse(18, 20, 1, false); - liveData->params.headLights = (bitRead(liveData->params.lightInfo, 5) == 1); - liveData->params.dayLights = (bitRead(liveData->params.lightInfo, 3) == 1); + tempByte = liveData->hexToDecFromResponse(18, 20, 1, false); + liveData->params.headLights = (bitRead(tempByte, 5) == 1); + liveData->params.dayLights = (bitRead(tempByte, 3) == 1); } if (liveData->commandRequest.equals("22BC06")) { - liveData->params.brakeLightInfo = liveData->hexToDecFromResponse(14, 16, 1, false); - liveData->params.brakeLights = (bitRead(liveData->params.brakeLightInfo, 5) == 1); + tempByte = liveData->hexToDecFromResponse(14, 16, 1, false); + liveData->params.brakeLights = (bitRead(tempByte, 5) == 1); } } diff --git a/CarKiaEniro.cpp b/CarKiaEniro.cpp index 742c7fe..8f51af2 100644 --- a/CarKiaEniro.cpp +++ b/CarKiaEniro.cpp @@ -1,12 +1,12 @@ -/* - * eNiro/Kona chargings limits depending on battery temperature (min.value of 01-04 battery module) +/* + eNiro/Kona chargings limits depending on battery temperature (min.value of 01-04 battery module) >= 35°C BMS allows max 180A >= 25°C without limit (200A) >= 15°C BMS allows max 120A >= 5°C BMS allows max 90A >= 1°C BMS allows max 60A <= 0°C BMS allows max 40A - */ +*/ #include #include @@ -20,8 +20,8 @@ #define commandQueueLoopFromKiaENiro 8 /** - * activateCommandQueue - */ + activateCommandQueue +*/ void CarKiaEniro::activateCommandQueue() { String commandQueueKiaENiro[commandQueueCountKiaENiro] = { @@ -102,11 +102,11 @@ void CarKiaEniro::activateCommandQueue() { } /** - * parseRowMerged - */ + parseRowMerged +*/ void CarKiaEniro::parseRowMerged() { - bool tempByte; + uint8_t tempByte; float tempFloat; String tmpStr; @@ -123,21 +123,31 @@ void CarKiaEniro::parseRowMerged() { // IGPM if (liveData->currentAtshRequest.equals("ATSH770")) { if (liveData->commandRequest.equals("22BC03")) { + // + tempByte = liveData->hexToDecFromResponse(14, 16, 1, false); + liveData->params.trunkDoorOpen = (bitRead(tempByte, 7) == 1); + liveData->params.leftFrontDoorOpen = (bitRead(tempByte, 5) == 1); + liveData->params.rightFrontDoorOpen = (bitRead(tempByte, 4) == 1); + liveData->params.rightRearDoorOpen = (bitRead(tempByte, 2) == 1); + liveData->params.leftRearDoorOpen = (bitRead(tempByte, 0) == 1); + // tempByte = liveData->hexToDecFromResponse(16, 18, 1, false); liveData->params.ignitionOn = (bitRead(tempByte, 5) == 1); + liveData->params.hoodOpen = (bitRead(tempByte, 0) == 1); if (liveData->params.ignitionOn) { liveData->params.lastIgnitionOnTime = liveData->params.currentTime; } + int32_t secDiff = liveData->params.currentTime - liveData->params.currentTime; if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn && !liveData->params.chargingOn) liveData->params.automaticShutdownTimer = liveData->params.currentTime; - liveData->params.lightInfo = liveData->hexToDecFromResponse(18, 20, 1, false); - liveData->params.headLights = (bitRead(liveData->params.lightInfo, 5) == 1); - liveData->params.dayLights = (bitRead(liveData->params.lightInfo, 3) == 1); + tempByte = liveData->hexToDecFromResponse(18, 20, 1, false); + liveData->params.headLights = (bitRead(tempByte, 5) == 1); + liveData->params.dayLights = (bitRead(tempByte, 3) == 1); } if (liveData->commandRequest.equals("22BC06")) { - liveData->params.brakeLightInfo = liveData->hexToDecFromResponse(14, 16, 1, false); - liveData->params.brakeLights = (bitRead(liveData->params.brakeLightInfo, 5) == 1); + tempByte = liveData->hexToDecFromResponse(14, 16, 1, false); + liveData->params.brakeLights = (bitRead(tempByte, 5) == 1); } } @@ -305,8 +315,8 @@ void CarKiaEniro::parseRowMerged() { } /** - * loadTestData - */ + loadTestData +*/ void CarKiaEniro::loadTestData() { // IGPM diff --git a/LiveData.cpp b/LiveData.cpp index 0ba42ef..8ec4580 100644 --- a/LiveData.cpp +++ b/LiveData.cpp @@ -28,15 +28,18 @@ void LiveData::initParams() { params.operationTimeSec = 0; params.chargingStartTime = params.currentTime = 0; params.chargingOn = false; - params.lightInfo = 0; params.headLights = false; params.dayLights = false; params.brakeLights = false; - params.brakeLightInfo = 0; + params.trunkDoorOpen = false; + params.leftFrontDoorOpen = false; + params.rightFrontDoorOpen = false; + params.leftRearDoorOpen = false; + params.rightRearDoorOpen = false; + params.hoodOpen = false; params.forwardDriveMode = false; params.reverseDriveMode = false; params.parkModeOrNeutral = false; - params.espState = 0; params.speedKmh = -1; params.motorRpm = -1; params.odoKm = -1; diff --git a/LiveData.h b/LiveData.h index a2930de..8162c2a 100644 --- a/LiveData.h +++ b/LiveData.h @@ -68,9 +68,15 @@ typedef struct { bool headLights; bool dayLights; bool brakeLights; - uint8_t lightInfo; + bool trunkDoorOpen; + bool leftFrontDoorOpen; + bool rightFrontDoorOpen; + bool leftRearDoorOpen; + bool rightRearDoorOpen; + bool hoodOpen; +/* uint8_t lightInfo; uint8_t brakeLightInfo; - uint8_t espState; + uint8_t espState;*/ float batteryTotalAvailableKWh; float speedKmh; float motorRpm; From bd938290262d98f0074ff95bcf254d1ad248d371 Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Thu, 24 Dec 2020 19:57:44 +0100 Subject: [PATCH 14/15] tempByte fix --- CarRenaultZoe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CarRenaultZoe.cpp b/CarRenaultZoe.cpp index f0bfca5..707620d 100644 --- a/CarRenaultZoe.cpp +++ b/CarRenaultZoe.cpp @@ -129,7 +129,7 @@ void CarRenaultZoe::activateCommandQueue() { */ void CarRenaultZoe::parseRowMerged() { - bool tempByte; + uint8_t tempByte; // LBC 79B if (liveData->currentAtshRequest.equals("ATSH79B")) { From fe6501fd6ae1a1032c047ecab08c88b4d9e8f764 Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Thu, 24 Dec 2020 20:20:01 +0100 Subject: [PATCH 15/15] eniro door status fixes --- Board320_240.cpp | 2 +- CarKiaEniro.cpp | 8 ++++---- LiveData.cpp | 2 +- LiveData.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Board320_240.cpp b/Board320_240.cpp index 0efce0b..5804dc3 100644 --- a/Board320_240.cpp +++ b/Board320_240.cpp @@ -1220,7 +1220,7 @@ void Board320_240::redrawScreen() { spr.fillRect(320 - 20, 20, 20, 98, TFT_YELLOW); if (liveData->params.rightRearDoorOpen) spr.fillRect(320 - 20, 122, 20, 98, TFT_YELLOW); - if (liveData->params.hoodOpen) + if (liveData->params.hoodDoorOpen) spr.fillRect(20, 240 - 20, 320 - 40, 20, TFT_YELLOW); // BLE not connected diff --git a/CarKiaEniro.cpp b/CarKiaEniro.cpp index 8f51af2..b557146 100644 --- a/CarKiaEniro.cpp +++ b/CarKiaEniro.cpp @@ -125,15 +125,15 @@ void CarKiaEniro::parseRowMerged() { if (liveData->commandRequest.equals("22BC03")) { // tempByte = liveData->hexToDecFromResponse(14, 16, 1, false); - liveData->params.trunkDoorOpen = (bitRead(tempByte, 7) == 1); + liveData->params.hoodDoorOpen = (bitRead(tempByte, 7) == 1); liveData->params.leftFrontDoorOpen = (bitRead(tempByte, 5) == 1); - liveData->params.rightFrontDoorOpen = (bitRead(tempByte, 4) == 1); + liveData->params.rightFrontDoorOpen = (bitRead(tempByte, 0) == 1); + liveData->params.leftRearDoorOpen = (bitRead(tempByte, 4) == 1); liveData->params.rightRearDoorOpen = (bitRead(tempByte, 2) == 1); - liveData->params.leftRearDoorOpen = (bitRead(tempByte, 0) == 1); // tempByte = liveData->hexToDecFromResponse(16, 18, 1, false); liveData->params.ignitionOn = (bitRead(tempByte, 5) == 1); - liveData->params.hoodOpen = (bitRead(tempByte, 0) == 1); + liveData->params.trunkDoorOpen = (bitRead(tempByte, 0) == 1); if (liveData->params.ignitionOn) { liveData->params.lastIgnitionOnTime = liveData->params.currentTime; } diff --git a/LiveData.cpp b/LiveData.cpp index 8ec4580..a30570e 100644 --- a/LiveData.cpp +++ b/LiveData.cpp @@ -36,7 +36,7 @@ void LiveData::initParams() { params.rightFrontDoorOpen = false; params.leftRearDoorOpen = false; params.rightRearDoorOpen = false; - params.hoodOpen = false; + params.hoodDoorOpen = false; params.forwardDriveMode = false; params.reverseDriveMode = false; params.parkModeOrNeutral = false; diff --git a/LiveData.h b/LiveData.h index 8162c2a..9b3fd57 100644 --- a/LiveData.h +++ b/LiveData.h @@ -73,7 +73,7 @@ typedef struct { bool rightFrontDoorOpen; bool leftRearDoorOpen; bool rightRearDoorOpen; - bool hoodOpen; + bool hoodDoorOpen; /* uint8_t lightInfo; uint8_t brakeLightInfo; uint8_t espState;*/