refactoring - simplified usage of hexToDec (#10)

* refactoring - simplified usage of hexToDec - replaced by hexToDecFromResponse

* refactoring - simplified usage of hexToDec - replaced by hexToDecFromResponse (applied to CarHyundaiIoniq.cpp)

* refactoring - simplified usage of hexToDec - replaced by hexToDecFromResponse (applied to rest)

* refactoring - simplified usage of hexToDec - replaced by hexToDecFromResponse (fix)

* refactoring - simplified usage of float(strol(liveData->responseRowMerged.substring(...))) - as liveData->decFromResponse()
This commit is contained in:
Michal
2020-12-07 19:43:38 +01:00
committed by GitHub
parent fe6e4402c4
commit 71dc8e8555
8 changed files with 227 additions and 204 deletions

View File

@@ -86,69 +86,69 @@ void CarHyundaiIoniq::parseRowMerged() {
// VMCU 7E2
if (liveData->currentAtshRequest.equals("ATSH7E2")) {
if (liveData->commandRequest.equals("2101")) {
liveData->params.speedKmh = liveData->hexToDec(liveData->responseRowMerged.substring(32, 36).c_str(), 2, false) * 0.0155; // / 100.0 *1.609 = real to gps is 1.750
liveData->params.speedKmh = liveData->hexToDecFromResponse(32, 36, 2, false) * 0.0155; // / 100.0 *1.609 = real to gps is 1.750
if (liveData->params.speedKmh < -99 || liveData->params.speedKmh > 200)
liveData->params.speedKmh = 0;
}
if (liveData->commandRequest.equals("2102")) {
liveData->params.auxPerc = liveData->hexToDec(liveData->responseRowMerged.substring(50, 52).c_str(), 1, false);
liveData->params.auxCurrentAmp = - liveData->hexToDec(liveData->responseRowMerged.substring(46, 50).c_str(), 2, true) / 1000.0;
liveData->params.auxPerc = liveData->hexToDecFromResponse(50, 52, 1, false);
liveData->params.auxCurrentAmp = - liveData->hexToDecFromResponse(46, 50, 2, true) / 1000.0;
}
}
// Cluster module 7c6
if (liveData->currentAtshRequest.equals("ATSH7C6")) {
if (liveData->commandRequest.equals("22B002")) {
liveData->params.odoKm = float(strtol(liveData->responseRowMerged.substring(18, 24).c_str(), 0, 16));
liveData->params.odoKm = liveData->decFromResponse(18, 24);
}
}
// Aircon 7b3
if (liveData->currentAtshRequest.equals("ATSH7B3")) {
if (liveData->commandRequest.equals("220100")) {
liveData->params.indoorTemperature = (liveData->hexToDec(liveData->responseRowMerged.substring(16, 18).c_str(), 1, false) / 2) - 40;
liveData->params.outdoorTemperature = (liveData->hexToDec(liveData->responseRowMerged.substring(18, 20).c_str(), 1, false) / 2) - 40;
liveData->params.indoorTemperature = (liveData->hexToDecFromResponse(16, 18, 1, false) / 2) - 40;
liveData->params.outdoorTemperature = (liveData->hexToDecFromResponse(18, 20, 1, false) / 2) - 40;
}
if (liveData->commandRequest.equals("220102") && liveData->responseRowMerged.substring(12, 14) == "00") {
liveData->params.coolantTemp1C = (liveData->hexToDec(liveData->responseRowMerged.substring(14, 16).c_str(), 1, false) / 2) - 40;
liveData->params.coolantTemp2C = (liveData->hexToDec(liveData->responseRowMerged.substring(16, 18).c_str(), 1, false) / 2) - 40;
liveData->params.coolantTemp1C = (liveData->hexToDecFromResponse(14, 16, 1, false) / 2) - 40;
liveData->params.coolantTemp2C = (liveData->hexToDecFromResponse(16, 18, 1, false) / 2) - 40;
}
}
// BMS 7e4
if (liveData->currentAtshRequest.equals("ATSH7E4")) {
if (liveData->commandRequest.equals("2101")) {
liveData->params.cumulativeEnergyChargedKWh = float(strtol(liveData->responseRowMerged.substring(80, 88).c_str(), 0, 16)) / 10.0;
liveData->params.cumulativeEnergyChargedKWh = liveData->decFromResponse(80, 88) / 10.0;
if (liveData->params.cumulativeEnergyChargedKWhStart == -1)
liveData->params.cumulativeEnergyChargedKWhStart = liveData->params.cumulativeEnergyChargedKWh;
liveData->params.cumulativeEnergyDischargedKWh = float(strtol(liveData->responseRowMerged.substring(88, 96).c_str(), 0, 16)) / 10.0;
liveData->params.cumulativeEnergyDischargedKWh = liveData->decFromResponse(88, 96) / 10.0;
if (liveData->params.cumulativeEnergyDischargedKWhStart == -1)
liveData->params.cumulativeEnergyDischargedKWhStart = liveData->params.cumulativeEnergyDischargedKWh;
liveData->params.availableChargePower = float(strtol(liveData->responseRowMerged.substring(16, 20).c_str(), 0, 16)) / 100.0;
liveData->params.availableDischargePower = float(strtol(liveData->responseRowMerged.substring(20, 24).c_str(), 0, 16)) / 100.0;
liveData->params.isolationResistanceKOhm = liveData->hexToDec(liveData->responseRowMerged.substring(118, 122).c_str(), 2, true);
liveData->params.batFanStatus = liveData->hexToDec(liveData->responseRowMerged.substring(58, 60).c_str(), 2, true);
liveData->params.batFanFeedbackHz = liveData->hexToDec(liveData->responseRowMerged.substring(60, 62).c_str(), 2, true);
liveData->params.auxVoltage = liveData->hexToDec(liveData->responseRowMerged.substring(62, 64).c_str(), 2, true) / 10.0;
liveData->params.batPowerAmp = - liveData->hexToDec(liveData->responseRowMerged.substring(24, 28).c_str(), 2, true) / 10.0;
liveData->params.batVoltage = liveData->hexToDec(liveData->responseRowMerged.substring(28, 32).c_str(), 2, false) / 10.0;
liveData->params.availableChargePower = liveData->decFromResponse(16, 20) / 100.0;
liveData->params.availableDischargePower = liveData->decFromResponse(20, 24) / 100.0;
liveData->params.isolationResistanceKOhm = liveData->hexToDecFromResponse(118, 122, 2, true);
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;
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;
if (liveData->params.batPowerKw < 1) // Reset charging start time
liveData->params.chargingStartTime = liveData->params.currentTime;
liveData->params.batPowerKwh100 = liveData->params.batPowerKw / liveData->params.speedKmh * 100;
liveData->params.batCellMaxV = liveData->hexToDec(liveData->responseRowMerged.substring(50, 52).c_str(), 1, false) / 50.0;
liveData->params.batCellMinV = liveData->hexToDec(liveData->responseRowMerged.substring(54, 56).c_str(), 1, false) / 50.0;
liveData->params.batModuleTempC[0] = liveData->hexToDec(liveData->responseRowMerged.substring(36, 38).c_str(), 1, true);
liveData->params.batModuleTempC[1] = liveData->hexToDec(liveData->responseRowMerged.substring(38, 40).c_str(), 1, true);
liveData->params.batModuleTempC[2] = liveData->hexToDec(liveData->responseRowMerged.substring(40, 42).c_str(), 1, true);
liveData->params.batModuleTempC[3] = liveData->hexToDec(liveData->responseRowMerged.substring(42, 44).c_str(), 1, true);
liveData->params.batModuleTempC[4] = liveData->hexToDec(liveData->responseRowMerged.substring(44, 46).c_str(), 1, true);
//liveData->params.batTempC = liveData->hexToDec(liveData->responseRowMerged.substring(34, 36).c_str(), 1, true);
//liveData->params.batMaxC = liveData->hexToDec(liveData->responseRowMerged.substring(32, 34).c_str(), 1, true);
//liveData->params.batMinC = liveData->hexToDec(liveData->responseRowMerged.substring(34, 36).c_str(), 1, true);
liveData->params.batCellMaxV = liveData->hexToDecFromResponse(50, 52, 1, false) / 50.0;
liveData->params.batCellMinV = liveData->hexToDecFromResponse(54, 56, 1, false) / 50.0;
liveData->params.batModuleTempC[0] = liveData->hexToDecFromResponse(36, 38, 1, true);
liveData->params.batModuleTempC[1] = liveData->hexToDecFromResponse(38, 40, 1, true);
liveData->params.batModuleTempC[2] = liveData->hexToDecFromResponse(40, 42, 1, true);
liveData->params.batModuleTempC[3] = liveData->hexToDecFromResponse(42, 44, 1, true);
liveData->params.batModuleTempC[4] = liveData->hexToDecFromResponse(44, 46, 1, true);
//liveData->params.batTempC = liveData->hexToDecFromResponse(34, 36, 1, true);
//liveData->params.batMaxC = liveData->hexToDecFromResponse(32, 34, 1, true);
//liveData->params.batMinC = liveData->hexToDecFromResponse(34, 36, 1, true);
// 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->hexToDec(liveData->responseRowMerged.substring(48, 50).c_str(), 1, true);
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) {
if ( liveData->params.chargingGraphMinKw[int(liveData->params.socPerc)] == -100 || liveData->params.batPowerKw < liveData->params.chargingGraphMinKw[int(liveData->params.socPerc)])
liveData->params.chargingGraphMinKw[int(liveData->params.socPerc)] = liveData->params.batPowerKw;
@@ -162,35 +162,35 @@ void CarHyundaiIoniq::parseRowMerged() {
// BMS 7e4
if (liveData->commandRequest.equals("2102") && liveData->responseRowMerged.substring(10, 12) == "FF") {
for (int i = 0; i < 32; i++) {
liveData->params.cellVoltage[i] = liveData->hexToDec(liveData->responseRowMerged.substring(12 + (i * 2), 12 + (i * 2) + 2).c_str(), 1, false) / 50;
liveData->params.cellVoltage[i] = liveData->hexToDecFromResponse(12 + (i * 2), 12 + (i * 2) + 2, 1, false) / 50;
}
}
// BMS 7e4
if (liveData->commandRequest.equals("2103")) {
for (int i = 0; i < 32; i++) {
liveData->params.cellVoltage[32 + i] = liveData->hexToDec(liveData->responseRowMerged.substring(12 + (i * 2), 12 + (i * 2) + 2).c_str(), 1, false) / 50;
liveData->params.cellVoltage[32 + i] = liveData->hexToDecFromResponse(12 + (i * 2), 12 + (i * 2) + 2, 1, false) / 50;
}
}
// BMS 7e4
if (liveData->commandRequest.equals("2104")) {
for (int i = 0; i < 32; i++) {
liveData->params.cellVoltage[64 + i] = liveData->hexToDec(liveData->responseRowMerged.substring(12 + (i * 2), 12 + (i * 2) + 2).c_str(), 1, false) / 50;
liveData->params.cellVoltage[64 + i] = liveData->hexToDecFromResponse(12 + (i * 2), 12 + (i * 2) + 2, 1, false) / 50;
}
}
// BMS 7e4
if (liveData->commandRequest.equals("2105")) {
liveData->params.socPercPrevious = liveData->params.socPerc;
liveData->params.sohPerc = liveData->hexToDec(liveData->responseRowMerged.substring(54, 58).c_str(), 2, false) / 10.0;
liveData->params.socPerc = liveData->hexToDec(liveData->responseRowMerged.substring(66, 68).c_str(), 1, false) / 2.0;
liveData->params.sohPerc = liveData->hexToDecFromResponse(54, 58, 2, false) / 10.0;
liveData->params.socPerc = liveData->hexToDecFromResponse(66, 68, 1, false) / 2.0;
// Remaining battery modules (tempC)
liveData->params.batModuleTempC[5] = liveData->hexToDec(liveData->responseRowMerged.substring(22, 24).c_str(), 1, true);
liveData->params.batModuleTempC[6] = liveData->hexToDec(liveData->responseRowMerged.substring(24, 26).c_str(), 1, true);
liveData->params.batModuleTempC[7] = liveData->hexToDec(liveData->responseRowMerged.substring(26, 28).c_str(), 1, true);
liveData->params.batModuleTempC[8] = liveData->hexToDec(liveData->responseRowMerged.substring(28, 30).c_str(), 1, true);
liveData->params.batModuleTempC[9] = liveData->hexToDec(liveData->responseRowMerged.substring(30, 32).c_str(), 1, true);
liveData->params.batModuleTempC[10] = liveData->hexToDec(liveData->responseRowMerged.substring(32, 34).c_str(), 1, true);
liveData->params.batModuleTempC[11] = liveData->hexToDec(liveData->responseRowMerged.substring(34, 36).c_str(), 1, true);
liveData->params.batModuleTempC[5] = liveData->hexToDecFromResponse(22, 24, 1, true);
liveData->params.batModuleTempC[6] = liveData->hexToDecFromResponse(24, 26, 1, true);
liveData->params.batModuleTempC[7] = liveData->hexToDecFromResponse(26, 28, 1, true);
liveData->params.batModuleTempC[8] = liveData->hexToDecFromResponse(28, 30, 1, true);
liveData->params.batModuleTempC[9] = liveData->hexToDecFromResponse(30, 32, 1, true);
liveData->params.batModuleTempC[10] = liveData->hexToDecFromResponse(32, 34, 1, true);
liveData->params.batModuleTempC[11] = liveData->hexToDecFromResponse(34, 36, 1, true);
liveData->params.batMinC = liveData->params.batMaxC = liveData->params.batModuleTempC[0];
for (uint16_t i = 1; i < liveData->params.batModuleTempCount; i++) {
@@ -211,7 +211,7 @@ void CarHyundaiIoniq::parseRowMerged() {
liveData->params.soc10time[index] = liveData->params.currentTime;
}
}
liveData->params.batHeaterC = liveData->hexToDec(liveData->responseRowMerged.substring(50, 52).c_str(), 1, true);
liveData->params.batHeaterC = liveData->hexToDecFromResponse(50, 52, 1, true);
//
for (int i = 30; i < 32; i++) { // ai/aj position
liveData->params.cellVoltage[96 - 30 + i] = -1;
@@ -220,21 +220,21 @@ void CarHyundaiIoniq::parseRowMerged() {
// BMS 7e4
// IONIQ FAILED
if (liveData->commandRequest.equals("2106")) {
liveData->params.coolingWaterTempC = liveData->hexToDec(liveData->responseRowMerged.substring(14, 16).c_str(), 1, false);
liveData->params.coolingWaterTempC = liveData->hexToDecFromResponse(14, 16, 1, false);
}
}
// TPMS 7a0
if (liveData->currentAtshRequest.equals("ATSH7A0")) {
if (liveData->commandRequest.equals("22c00b")) {
liveData->params.tireFrontLeftPressureBar = liveData->hexToDec(liveData->responseRowMerged.substring(14, 16).c_str(), 2, false) / 72.51886900361; // === OK Valid *0.2 / 14.503773800722
liveData->params.tireFrontRightPressureBar = liveData->hexToDec(liveData->responseRowMerged.substring(22, 24).c_str(), 2, false) / 72.51886900361; // === OK Valid *0.2 / 14.503773800722
liveData->params.tireRearRightPressureBar = liveData->hexToDec(liveData->responseRowMerged.substring(30, 32).c_str(), 2, false) / 72.51886900361; // === OK Valid *0.2 / 14.503773800722
liveData->params.tireRearLeftPressureBar = liveData->hexToDec(liveData->responseRowMerged.substring(38, 40).c_str(), 2, false) / 72.51886900361; // === OK Valid *0.2 / 14.503773800722
liveData->params.tireFrontLeftTempC = liveData->hexToDec(liveData->responseRowMerged.substring(16, 18).c_str(), 2, false) - 50; // === OK Valid
liveData->params.tireFrontRightTempC = liveData->hexToDec(liveData->responseRowMerged.substring(24, 26).c_str(), 2, false) - 50; // === OK Valid
liveData->params.tireRearRightTempC = liveData->hexToDec(liveData->responseRowMerged.substring(32, 34).c_str(), 2, false) - 50; // === OK Valid
liveData->params.tireRearLeftTempC = liveData->hexToDec(liveData->responseRowMerged.substring(40, 42).c_str(), 2, false) - 50; // === OK Valid
liveData->params.tireFrontLeftPressureBar = liveData->hexToDecFromResponse(14, 16, 2, false) / 72.51886900361; // === OK Valid *0.2 / 14.503773800722
liveData->params.tireFrontRightPressureBar = liveData->hexToDecFromResponse(22, 24, 2, false) / 72.51886900361; // === OK Valid *0.2 / 14.503773800722
liveData->params.tireRearRightPressureBar = liveData->hexToDecFromResponse(30, 32, 2, false) / 72.51886900361; // === OK Valid *0.2 / 14.503773800722
liveData->params.tireRearLeftPressureBar = liveData->hexToDecFromResponse(38, 40, 2, false) / 72.51886900361; // === OK Valid *0.2 / 14.503773800722
liveData->params.tireFrontLeftTempC = liveData->hexToDecFromResponse(16, 18, 2, false) - 50; // === OK Valid
liveData->params.tireFrontRightTempC = liveData->hexToDecFromResponse(24, 26, 2, false) - 50; // === OK Valid
liveData->params.tireRearRightTempC = liveData->hexToDecFromResponse(32, 34, 2, false) - 50; // === OK Valid
liveData->params.tireRearLeftTempC = liveData->hexToDecFromResponse(40, 42, 2, false) - 50; // === OK Valid
}
}
@@ -315,9 +315,9 @@ void CarHyundaiIoniq::loadTestData() {
liveData->params.batModule02TempC = 29;
liveData->params.batModule03TempC = 28;
liveData->params.batModule04TempC = 30;
//liveData->params.batTempC = liveData->hexToDec(liveData->responseRowMerged.substring(36, 38).c_str(), 1, true);
//liveData->params.batMaxC = liveData->hexToDec(liveData->responseRowMerged.substring(34, 36).c_str(), 1, true);
//liveData->params.batMinC = liveData->hexToDec(liveData->responseRowMerged.substring(36, 38).c_str(), 1, true);
//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);
// 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.batModule01TempC;