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:
@@ -241,58 +241,58 @@ void CarKiaDebugObd2::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("220101")) {
|
||||
liveData->params.cumulativeEnergyChargedKWh = float(strtol(liveData->responseRowMerged.substring(82, 90).c_str(), 0, 16)) / 10.0;
|
||||
liveData->params.cumulativeEnergyChargedKWh = liveData->decFromResponse(82, 90) / 10.0;
|
||||
if (liveData->params.cumulativeEnergyChargedKWhStart == -1)
|
||||
liveData->params.cumulativeEnergyChargedKWhStart = liveData->params.cumulativeEnergyChargedKWh;
|
||||
liveData->params.cumulativeEnergyDischargedKWh = float(strtol(liveData->responseRowMerged.substring(90, 98).c_str(), 0, 16)) / 10.0;
|
||||
liveData->params.cumulativeEnergyDischargedKWh = liveData->decFromResponse(90, 98) / 10.0;
|
||||
if (liveData->params.cumulativeEnergyDischargedKWhStart == -1)
|
||||
liveData->params.cumulativeEnergyDischargedKWhStart = liveData->params.cumulativeEnergyDischargedKWh;
|
||||
liveData->params.auxVoltage = liveData->hexToDec(liveData->responseRowMerged.substring(64, 66).c_str(), 2, true) / 10.0;
|
||||
liveData->params.batPowerAmp = - liveData->hexToDec(liveData->responseRowMerged.substring(26, 30).c_str(), 2, true) / 10.0;
|
||||
liveData->params.batVoltage = liveData->hexToDec(liveData->responseRowMerged.substring(30, 34).c_str(), 2, false) / 10.0;
|
||||
liveData->params.auxVoltage = liveData->hexToDecFromResponse(64, 66, 2, true) / 10.0;
|
||||
liveData->params.batPowerAmp = - liveData->hexToDecFromResponse(26, 30, 2, true) / 10.0;
|
||||
liveData->params.batVoltage = liveData->hexToDecFromResponse(30, 34, 2, false) / 10.0;
|
||||
liveData->params.batPowerKw = (liveData->params.batPowerAmp * liveData->params.batVoltage) / 1000.0;
|
||||
liveData->params.batPowerKwh100 = liveData->params.batPowerKw / liveData->params.speedKmh * 100;
|
||||
liveData->params.batCellMaxV = liveData->hexToDec(liveData->responseRowMerged.substring(52, 54).c_str(), 1, false) / 50.0;
|
||||
liveData->params.batCellMinV = liveData->hexToDec(liveData->responseRowMerged.substring(56, 58).c_str(), 1, false) / 50.0;
|
||||
liveData->params.batModuleTempC[0] = liveData->hexToDec(liveData->responseRowMerged.substring(38, 40).c_str(), 1, true);
|
||||
liveData->params.batModuleTempC[1] = liveData->hexToDec(liveData->responseRowMerged.substring(40, 42).c_str(), 1, true);
|
||||
liveData->params.batModuleTempC[2] = liveData->hexToDec(liveData->responseRowMerged.substring(42, 44).c_str(), 1, true);
|
||||
liveData->params.batModuleTempC[3] = liveData->hexToDec(liveData->responseRowMerged.substring(44, 46).c_str(), 1, true);
|
||||
//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.batCellMaxV = liveData->hexToDecFromResponse(52, 54, 1, false) / 50.0;
|
||||
liveData->params.batCellMinV = liveData->hexToDecFromResponse(56, 58, 1, false) / 50.0;
|
||||
liveData->params.batModuleTempC[0] = liveData->hexToDecFromResponse(38, 40, 1, true);
|
||||
liveData->params.batModuleTempC[1] = liveData->hexToDecFromResponse(40, 42, 1, true);
|
||||
liveData->params.batModuleTempC[2] = liveData->hexToDecFromResponse(42, 44, 1, true);
|
||||
liveData->params.batModuleTempC[3] = liveData->hexToDecFromResponse(44, 46, 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.batModuleTempC[0];
|
||||
@@ -304,7 +304,7 @@ void CarKiaDebugObd2::parseRowMerged() {
|
||||
liveData->params.batMaxC = (liveData->params.batModuleTempC[3] > liveData->params.batMaxC) ? liveData->params.batModuleTempC[3] : liveData->params.batMaxC;
|
||||
liveData->params.batTempC = liveData->params.batMinC;
|
||||
|
||||
liveData->params.batInletC = liveData->hexToDec(liveData->responseRowMerged.substring(50, 52).c_str(), 1, true);
|
||||
liveData->params.batInletC = liveData->hexToDecFromResponse(50, 52, 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;
|
||||
@@ -318,26 +318,26 @@ void CarKiaDebugObd2::parseRowMerged() {
|
||||
// BMS 7e4
|
||||
if (liveData->commandRequest.equals("220102") && liveData->responseRowMerged.substring(12, 14) == "FF") {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
liveData->params.cellVoltage[i] = liveData->hexToDec(liveData->responseRowMerged.substring(14 + (i * 2), 14 + (i * 2) + 2).c_str(), 1, false) / 50;
|
||||
liveData->params.cellVoltage[i] = liveData->hexToDecFromResponse(14 + (i * 2), 14 + (i * 2) + 2, 1, false) / 50;
|
||||
}
|
||||
}
|
||||
// BMS 7e4
|
||||
if (liveData->commandRequest.equals("220103")) {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
liveData->params.cellVoltage[32 + i] = liveData->hexToDec(liveData->responseRowMerged.substring(14 + (i * 2), 14 + (i * 2) + 2).c_str(), 1, false) / 50;
|
||||
liveData->params.cellVoltage[32 + i] = liveData->hexToDecFromResponse(14 + (i * 2), 14 + (i * 2) + 2, 1, false) / 50;
|
||||
}
|
||||
}
|
||||
// BMS 7e4
|
||||
if (liveData->commandRequest.equals("220104")) {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
liveData->params.cellVoltage[64 + i] = liveData->hexToDec(liveData->responseRowMerged.substring(14 + (i * 2), 14 + (i * 2) + 2).c_str(), 1, false) / 50;
|
||||
liveData->params.cellVoltage[64 + i] = liveData->hexToDecFromResponse(14 + (i * 2), 14 + (i * 2) + 2, 1, false) / 50;
|
||||
}
|
||||
}
|
||||
// BMS 7e4
|
||||
if (liveData->commandRequest.equals("220105")) {
|
||||
liveData->params.socPercPrevious = liveData->params.socPerc;
|
||||
liveData->params.sohPerc = liveData->hexToDec(liveData->responseRowMerged.substring(56, 60).c_str(), 2, false) / 10.0;
|
||||
liveData->params.socPerc = liveData->hexToDec(liveData->responseRowMerged.substring(68, 70).c_str(), 1, false) / 2.0;
|
||||
liveData->params.sohPerc = liveData->hexToDecFromResponse(56, 60, 2, false) / 10.0;
|
||||
liveData->params.socPerc = liveData->hexToDecFromResponse(68, 70, 1, false) / 2.0;
|
||||
|
||||
// Soc10ced table, record x0% CEC/CED table (ex. 90%->89%, 80%->79%)
|
||||
if (liveData->params.socPercPrevious - liveData->params.socPerc > 0) {
|
||||
@@ -352,29 +352,29 @@ void CarKiaDebugObd2::parseRowMerged() {
|
||||
liveData->params.soc10time[index] = time_now_epoch;
|
||||
}
|
||||
}
|
||||
liveData->params.batHeaterC = liveData->hexToDec(liveData->responseRowMerged.substring(52, 54).c_str(), 1, true);
|
||||
liveData->params.batHeaterC = liveData->hexToDecFromResponse(52, 54, 1, true);
|
||||
//
|
||||
for (int i = 30; i < 32; i++) { // ai/aj position
|
||||
liveData->params.cellVoltage[96 - 30 + i] = liveData->hexToDec(liveData->responseRowMerged.substring(14 + (i * 2), 14 + (i * 2) + 2).c_str(), 1, false) / 50;
|
||||
liveData->params.cellVoltage[96 - 30 + i] = liveData->hexToDecFromResponse(14 + (i * 2), 14 + (i * 2) + 2, 1, false) / 50;
|
||||
}
|
||||
}
|
||||
// BMS 7e4
|
||||
if (liveData->commandRequest.equals("220106")) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user