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

174 lines
No EOL
7.1 KiB
C++

/*
; 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"
void OvmsVehicleRenaultZoePh2::IncomingEVC(uint16_t type, uint16_t pid, const char* data, uint16_t len) {
switch (pid) {
case 0x2006: { // Odometer (Total Vehicle Distance)
StandardMetrics.ms_v_pos_odometer->SetValue((float) CAN_UINT24(0), Kilometers);
//ESP_LOGD(TAG, "2006 EVC ms_v_pos_odometer: %d", CAN_UINT24(0));
break;
}
//case 0x2A8C: { //12V Battery Current
// StandardMetrics.ms_v_charge_12v_current->SetValue((float) (CAN_UINT(0)), Amps);
// ESP_LOGD(TAG, "2A8C EVC ms_v_charge_12v_current: %d", CAN_UINT(0));
// break;
//}
case 0x2005: { //12V Battery Voltage
StandardMetrics.ms_v_charge_12v_voltage->SetValue((float) (CAN_UINT(0) * 0.01), Volts);
//ESP_LOGD(TAG, "2005 EVC ms_v_charge_12v_voltage: %f", CAN_UINT(0) * 0.01);
break;
}
case 0x21D0: { //12V Battery Charger/DCDC Temp
StandardMetrics.ms_v_charge_12v_temp->SetValue((float) ((CAN_UINT(0) - 40) * 0.001), Celcius);
ESP_LOGD(TAG, "21D0 EVC ms_v_charge_12v_temp: %f", (CAN_UINT(0) - 40) * 0.001);
break;
}
case 0x21CF: { //Inverter status
//ESP_LOGD(TAG, "21CF EVC mt_inv_status: %d", CAN_NIBL(0));
if (CAN_NIBL(0) == 1) {
mt_inv_status->SetValue("Inverter off");
StandardMetrics.ms_v_env_on->SetValue(false);
} else if (CAN_NIBL(0) == 2) {
mt_inv_status->SetValue("Inverter on");
StandardMetrics.ms_v_env_on->SetValue(true);
} else if (CAN_NIBL(0) == 3) {
mt_inv_status->SetValue("Inverter decharging");
StandardMetrics.ms_v_env_on->SetValue(false);
} else if (CAN_NIBL(0) == 4) {
mt_inv_status->SetValue("Inverter alternator mode");
StandardMetrics.ms_v_env_on->SetValue(false);
} else if (CAN_NIBL(0) == 5) {
mt_inv_status->SetValue("Inverter ready to sleep");
StandardMetrics.ms_v_env_on->SetValue(false);
} else {
mt_inv_status->SetValue("Inverter state unknown");
}
break;
}
case 0x2218: { // Ambient temperature
StandardMetrics.ms_v_env_temp->SetValue((float) (CAN_UINT(0) * 0.1 - 273), Celcius);
//ESP_LOGD(TAG, "2218 EVC ms_v_env_temp: %f", (CAN_UINT(0) * 0.1 - 273));
break;
}
case 0x2A09: { // Power consumption by consumer
mt_aux_power_consumer->SetValue((float) CAN_UINT(0) * 10, Watts);
ESP_LOGD(TAG, "2A09 EVC mt_aux_power_consumer: %d", CAN_UINT(0) * 10);
break;
}
case 0x2191: { // Power consumption by ptc
mt_aux_power_ptc->SetValue((float) CAN_UINT(0) * 10, Watts);
ESP_LOGD(TAG, "2191 EVC mt_aux_power_ptc: %d", CAN_UINT(0) * 10);
break;
}
case 0x2B85: { // Charge plug preset
//ESP_LOGD(TAG, "2B85 EVC Charge plug present: %d", CAN_NIBL(0));
if (CAN_NIBL(0) == 1) {
StandardMetrics.ms_v_charge_pilot->SetValue(true);
if (!CarPluggedIn) {
ESP_LOGI(TAG, "Charge cable plugged in");
CarPluggedIn = true;
}
}
if (CAN_NIBL(0) == 0) {
StandardMetrics.ms_v_charge_pilot->SetValue(false);
if (CarPluggedIn) {
ESP_LOGI(TAG, "Charge cable plugged out");
CarPluggedIn = false;
}
}
break;
}
case 0x2B6D: { // Charge MMI States
//ESP_LOGD(TAG, "2B6D Charge MMI States RAW: %d", CAN_NIBL(0));
if (CAN_NIBL(0) == 0) {
StandardMetrics.ms_v_charge_state->SetValue("stopped");
StandardMetrics.ms_v_charge_substate->SetValue("stopped");
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
//ESP_LOGD(TAG, "2B6D Charge MMI States : No Charge");
POLLSTATE_ON;
}
if (CAN_NIBL(0) == 1) {
StandardMetrics.ms_v_charge_state->SetValue("timerwait");
StandardMetrics.ms_v_charge_substate->SetValue("timerwait");
//ESP_LOGD(TAG, "2B6D Charge MMI States : Waiting for a planned charge");
}
if (CAN_NIBL(0) == 2) {
StandardMetrics.ms_v_charge_state->SetValue("done");
StandardMetrics.ms_v_charge_substate->SetValue("stopped");
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
//ESP_LOGD(TAG, "2B6D Charge MMI States : Ended charge");
POLLSTATE_ON;
}
if (CAN_NIBL(0) == 3) {
StandardMetrics.ms_v_charge_state->SetValue("charging");
StandardMetrics.ms_v_charge_substate->SetValue("onrequest");
StandardMetrics.ms_v_charge_inprogress->SetValue(true);
//ESP_LOGD(TAG, "2B6D Charge MMI States : Charge in progress");
POLLSTATE_CHARGING;
}
if (CAN_NIBL(0) == 4) {
StandardMetrics.ms_v_charge_state->SetValue("stopped");
StandardMetrics.ms_v_charge_substate->SetValue("interrupted");
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
//ESP_LOGD(TAG, "2B6D Charge MMI States : Charge failure");
POLLSTATE_ON;
}
if (CAN_NIBL(0) == 5) {
StandardMetrics.ms_v_charge_state->SetValue("stopped");
StandardMetrics.ms_v_charge_substate->SetValue("powerwait");
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
//ESP_LOGD(TAG, "2B6D Charge MMI States : Waiting for current charge");
POLLSTATE_ON;
}
if (CAN_NIBL(0) == 6) {
StandardMetrics.ms_v_door_chargeport->SetValue(true);
//ESP_LOGD(TAG, "2B6D Charge MMI States : Chargeport opened");
}
if (CAN_NIBL(0) == 8) {
StandardMetrics.ms_v_charge_state->SetValue("prepare");
StandardMetrics.ms_v_charge_substate->SetValue("powerwait");
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
//ESP_LOGD(TAG, "2B6D Charge MMI States : Charge preparation");
POLLSTATE_CHARGING;
}
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 from EVC [%02x %02x]: %s", type, pid, buf ? buf : "-");
} while (rlen);
if (buf)
free(buf);
break;
}
}
}