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

168 lines
7 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::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);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2006 EVC ms_v_pos_odometer: %d", CAN_UINT24(0));
2022-04-14 22:35:23 +00:00
break;
}
2022-04-16 13:32:15 +00:00
//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;
//}
2022-04-16 11:41:45 +00:00
case 0x2005: { //12V Battery Voltage
2022-04-14 22:35:23 +00:00
StandardMetrics.ms_v_charge_12v_voltage->SetValue((float) (CAN_UINT(0) * 0.01), Volts);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2005 EVC ms_v_charge_12v_voltage: %f", CAN_UINT(0) * 0.01);
2022-04-14 22:35:23 +00:00
break;
}
2022-04-16 11:41:45 +00:00
case 0x21D0: { //12V Battery Charger/DCDC Temp
2022-04-16 20:34:58 +00:00
StandardMetrics.ms_v_charge_12v_temp->SetValue((float) ((CAN_UINT(0) - 40) * 0.001), Celcius);
2022-04-16 20:28:00 +00:00
ESP_LOGD(TAG, "21D0 EVC ms_v_charge_12v_temp: %f", (CAN_UINT(0) - 40) * 0.001);
2022-04-14 22:35:23 +00:00
break;
}
2022-04-16 11:41:45 +00:00
case 0x21CF: { //Inverter status
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "21CF EVC mt_inv_status: %d", CAN_NIBL(0));
2022-04-14 22:35:23 +00:00
if (CAN_NIBL(0) == 1) {
mt_inv_status->SetValue("Inverter off");
2022-04-16 23:22:14 +00:00
StandardMetrics.ms_v_env_on->SetValue(false);
2022-04-14 22:35:23 +00:00
} else if (CAN_NIBL(0) == 2) {
mt_inv_status->SetValue("Inverter on");
2022-04-16 23:22:14 +00:00
StandardMetrics.ms_v_env_on->SetValue(true);
2022-04-14 22:35:23 +00:00
} else if (CAN_NIBL(0) == 3) {
mt_inv_status->SetValue("Inverter decharging");
2022-04-16 23:22:14 +00:00
StandardMetrics.ms_v_env_on->SetValue(false);
2022-04-14 22:35:23 +00:00
} else if (CAN_NIBL(0) == 4) {
mt_inv_status->SetValue("Inverter alternator mode");
2022-04-16 23:22:14 +00:00
StandardMetrics.ms_v_env_on->SetValue(false);
2022-04-14 22:35:23 +00:00
} else if (CAN_NIBL(0) == 5) {
mt_inv_status->SetValue("Inverter ready to sleep");
2022-04-16 23:22:14 +00:00
StandardMetrics.ms_v_env_on->SetValue(false);
2022-04-14 22:35:23 +00:00
} else {
mt_inv_status->SetValue("Inverter state unknown");
}
break;
}
2022-04-16 13:32:15 +00:00
case 0x2218: { // Ambient temperature
StandardMetrics.ms_v_env_temp->SetValue((float) (CAN_UINT(0) * 0.1 - 273), Celcius);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2218 EVC ms_v_env_temp: %f", (CAN_UINT(0) * 0.1 - 273));
2022-04-14 22:35:23 +00:00
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);
2022-04-14 22:35:23 +00:00
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);
2022-04-14 22:35:23 +00:00
break;
}
case 0x2B85: { // Charge plug preset
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2B85 EVC Charge plug present: %d", CAN_NIBL(0));
2022-04-16 23:03:46 +00:00
if (CAN_NIBL(0) == 1) {
StandardMetrics.ms_v_charge_pilot->SetValue(true);
ESP_LOGD(TAG, "Charge cable plugged in");
}
2022-04-16 23:03:46 +00:00
if (CAN_NIBL(0) == 0) {
StandardMetrics.ms_v_charge_pilot->SetValue(false);
ESP_LOGD(TAG, "Charge cable plugged out");
}
break;
}
case 0x2B6D: { // Charge MMI States
2022-04-17 06:21:37 +00:00
//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");
2022-04-16 23:03:46 +00:00
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2B6D Charge MMI States : No Charge");
2022-04-16 23:03:46 +00:00
POLLSTATE_ON;
}
if (CAN_NIBL(0) == 1) {
StandardMetrics.ms_v_charge_state->SetValue("timerwait");
StandardMetrics.ms_v_charge_substate->SetValue("timerwait");
2022-04-17 06:21:37 +00:00
//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");
2022-04-16 23:03:46 +00:00
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2B6D Charge MMI States : Ended charge");
2022-04-16 23:03:46 +00:00
POLLSTATE_ON;
}
if (CAN_NIBL(0) == 3) {
StandardMetrics.ms_v_charge_state->SetValue("charging");
StandardMetrics.ms_v_charge_substate->SetValue("onrequest");
2022-04-16 23:03:46 +00:00
StandardMetrics.ms_v_charge_inprogress->SetValue(true);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2B6D Charge MMI States : Charge in progress");
2022-04-16 23:03:46 +00:00
POLLSTATE_CHARGING;
}
if (CAN_NIBL(0) == 4) {
StandardMetrics.ms_v_charge_state->SetValue("stopped");
StandardMetrics.ms_v_charge_substate->SetValue("interrupted");
2022-04-16 23:03:46 +00:00
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2B6D Charge MMI States : Charge failure");
2022-04-16 23:03:46 +00:00
POLLSTATE_ON;
}
if (CAN_NIBL(0) == 5) {
StandardMetrics.ms_v_charge_state->SetValue("stopped");
StandardMetrics.ms_v_charge_substate->SetValue("powerwait");
2022-04-16 23:03:46 +00:00
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2B6D Charge MMI States : Waiting for current charge");
2022-04-16 23:03:46 +00:00
POLLSTATE_ON;
}
if (CAN_NIBL(0) == 6) {
StandardMetrics.ms_v_door_chargeport->SetValue(true);
2022-04-17 06:21:37 +00:00
//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");
2022-04-16 23:03:46 +00:00
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
2022-04-17 06:21:37 +00:00
//ESP_LOGD(TAG, "2B6D Charge MMI States : Charge preparation");
2022-04-16 23:03:46 +00:00
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;
}
2022-04-14 22:35:23 +00:00
}
}