OVMS3/OVMS.V3/components/vehicle_renaultzoe_ph2/src/LBC_pids.cpp

135 lines
5.3 KiB
C++
Raw Normal View History

2022-04-15 14:17:12 +00:00
/*
; Project: Open Vehicle Monitor System
; Date: 15th Apr 2022
;
; (C) 2022 Carsten Schmiemann
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
; THE SOFTWARE.
*/
#include "vehicle_renaultzoe_ph2.h"
2022-04-14 22:35:23 +00:00
void OvmsVehicleRenaultZoePh2::IncomingLBC(uint16_t type, uint16_t pid, const char* data, uint16_t len) {
switch (pid) {
case 0x9005: { //Battery voltage
StandardMetrics.ms_v_bat_voltage->SetValue((float) (CAN_UINT(0) * 0.1), Volts);
ESP_LOGD(TAG, "9005 LBC ms_v_bat_voltage: %f", CAN_UINT(0) * 0.1);
break;
}
case 0x925D: { //Battery current
StandardMetrics.ms_v_bat_current->SetValue((float) ((CAN_UINT(4) - 1020) * 0.03125), Amps);
ESP_LOGD(TAG, "925D LBC ms_v_bat_current: %d", CAN_UINT(4));
ESP_LOGD(TAG, "925D LBC ms_v_bat_current: %f", ((CAN_UINT(4) - 1020) * 0.03125));
break;
}
case 0x9012: { //Battery average temperature
StandardMetrics.ms_v_bat_temp->SetValue((float) (CAN_UINT(0) - 40), Celcius);
ESP_LOGD(TAG, "9012 LBC ms_v_bat_temp: %d", (CAN_UINT(0) - 40));
break;
}
case 0x9002: { //Battery SOC
StandardMetrics.ms_v_bat_soc->SetValue((float) (CAN_UINT(0)) * 0.01, Percentage);
ESP_LOGD(TAG, "9002 LBC ms_v_bat_soc: %f", CAN_UINT(0) * 0.01);
break;
}
case 0x9003: { //Battery SOH
StandardMetrics.ms_v_bat_soh->SetValue((float) (CAN_UINT(0) * 0.01), Percentage);
ESP_LOGD(TAG, "9003 LBC ms_v_bat_soh: %f", CAN_UINT(0) * 0.01);
break;
}
case 0x9243: { //Battery energy charged kWh
StandardMetrics.ms_v_charge_kwh_grid_total->SetValue((float) (CAN_UINT32(0) * 0.001), kWh);
ESP_LOGD(TAG, "9243 LBC ms_v_charge_kwh_grid_total: %f", CAN_UINT32(0) * 0.001);
break;
}
case 0x9244: { //Battery energy discharged kWh
StandardMetrics.ms_v_bat_energy_used->SetValue((float) (CAN_UINT32(0) * 0.001), kWh);
ESP_LOGD(TAG, "9244 LBC ms_v_bat_energy_used: %f", CAN_UINT32(0) * 0.001);
break;
}
case 0x9246: { //Battery energy regenerated kWh
StandardMetrics.ms_v_bat_energy_recd->SetValue((float) (CAN_UINT32(0) * 0.001), kWh);
ESP_LOGD(TAG, "9246 LBC ms_v_bat_energy_recd: %f", CAN_UINT32(0) * 0.001);
break;
}
case 0x9007: { //Cell Max Voltage
StandardMetrics.ms_v_bat_pack_vmax->SetValue((float) (CAN_UINT(0) * 0.001), Volts);
ESP_LOGD(TAG, "9007 LBC ms_v_bat_pack_vmax: %f", CAN_UINT(0) * 0.001);
break;
}
case 0x9009: { //Cell Min Voltage
StandardMetrics.ms_v_bat_pack_vmin->SetValue((float) (CAN_UINT(0) * 0.001), Volts);
ESP_LOGD(TAG, "9009 LBC ms_v_bat_pack_vmin: %f", CAN_UINT(0) * 0.001);
break;
}
case 0x9014: { //Cell Max Temp
StandardMetrics.ms_v_bat_pack_tmax->SetValue((float) (CAN_UINT(0) - 40), Celcius);
ESP_LOGD(TAG, "9014 LBC ms_v_bat_pack_tmax: %d", CAN_UINT(0) - 40);
break;
}
case 0x9013: { //Cell Min Temp
StandardMetrics.ms_v_bat_pack_tmin->SetValue((float) (CAN_UINT(0) - 40), Celcius);
ESP_LOGD(TAG, "9013 LBC ms_v_bat_pack_tmin: %d", CAN_UINT(0) - 40);
break;
}
case 0x9018: { //Max charge power
mt_bat_max_charge_power->SetValue((float) (CAN_UINT(0) * 0.01), kW);
ESP_LOGD(TAG, "9018 LBC mt_bat_max_charge_power: %f", CAN_UINT(0) * 0.01);
break;
}
case 0x04: {
for(int i=2; i<36; i+=3){
BmsSetCellTemperature( (i-2)/3, (INT)CAN_BYTE(i)-40 );
//ESP_LOGD(TAG, "temp %d - %d", (i-2)/3, (INT)CAN_BYTE(i)-40);
}
break;
}
case 0x91C8: { //Available charge in kWh
StandardMetrics.ms_v_charge_kwh->SetValue(float(CAN_UINT24(0)), kWh);
ESP_LOGD(TAG, "91C8 LBC ms_v_charge_kwh: %d", CAN_UINT24(0));
break;
}
case 0x9021: {
for(int i=0; i<124; i+=2){
float cell = (float)CAN_UINT(i)/1000;
BmsSetCellVoltage(i/2, cell);
}
break;
}
case 0x9062: {
for(int i=0; i<68; i+=2){
float cell = (float)CAN_UINT(i)/1000;
BmsSetCellVoltage((i/2)+62, cell);
}
break;
}
default: {
char *buf = NULL;
size_t rlen = len, offset = 0;
do {
rlen = FormatHexDump(&buf, data + offset, rlen, 16);
offset += 16;
ESP_LOGW(TAG, "OBD2: unhandled reply [%02x %02x]: %s", type, pid, buf ? buf : "-");
} while (rlen);
if (buf)
free(buf);
break;
}
}
}