From 89d64b221113a4b1b209939160ad6133dca10578 Mon Sep 17 00:00:00 2001 From: Carsten Schmiemann Date: Sat, 19 Nov 2022 00:01:40 +0100 Subject: [PATCH] Modify sleep behavior for direct CAN access with free frames --- .../src/vehicle_renaultzoe_ph2_can.cpp | 41 +++++++++++-------- .../src/vehicle_renaultzoe_ph2_can.h | 4 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/OVMS.V3/components/vehicle_renaultzoe_ph2_can/src/vehicle_renaultzoe_ph2_can.cpp b/OVMS.V3/components/vehicle_renaultzoe_ph2_can/src/vehicle_renaultzoe_ph2_can.cpp index 411a795..a0060da 100644 --- a/OVMS.V3/components/vehicle_renaultzoe_ph2_can/src/vehicle_renaultzoe_ph2_can.cpp +++ b/OVMS.V3/components/vehicle_renaultzoe_ph2_can/src/vehicle_renaultzoe_ph2_can.cpp @@ -144,27 +144,13 @@ void OvmsVehicleRenaultZoePh2CAN::ZoeWakeUp() { void OvmsVehicleRenaultZoePh2CAN::IncomingFrameCan1(CAN_frame_t* p_frame) { uint8_t *data = p_frame->data.u8; ESP_LOGI(TAG, "PID:%x DATA: %02x %02x %02x %02x %02x %02x %02x %02x", p_frame->MsgID, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); - //ESP_LOGD(TAG, "Status CAN Bus: %s", mt_bus_awake->AsBool() ? "true" : "false"); - // Poll reply gives 0x83 0xc0 that means zoe is sleeping and CAN gateway does not respond to anything - if (mt_bus_awake->AsBool() && data[0] == 0x83 && data[1] == 0xc0) { - ESP_LOGI(TAG,"Zoe has gone to sleep (CAN Gateway NAK response)"); - mt_bus_awake->SetValue(false); - StandardMetrics.ms_v_env_awake->SetValue(false); - StandardMetrics.ms_v_env_charging12v->SetValue(false); - StandardMetrics.ms_v_pos_speed->SetValue( 0 ); - StandardMetrics.ms_v_bat_12v_current->SetValue( 0 ); - StandardMetrics.ms_v_charge_12v_current->SetValue( 0 ); - StandardMetrics.ms_v_bat_current->SetValue( 0 ); - POLLSTATE_OFF; - ESP_LOGI(TAG, "Pollstate switched to OFF"); - //Check if car is locked, if not send notify - if (!StandardMetrics.ms_v_env_locked->AsBool()) { - MyNotify.NotifyString("alert", "vehicle.lock", "Vehicle is not locked"); - } - } else if (!mt_bus_awake->AsBool()) { + //If a CAN message comes in, start polling + if (!mt_bus_awake->AsBool()) { ZoeWakeUp(); } + //Reset CAN1 inactivity timer, inactivity after 5 sec detected to stop polling + m_can1_activity_timer = 5; } /** @@ -313,6 +299,25 @@ void OvmsVehicleRenaultZoePh2CAN::Ticker10(uint32_t ticker) { } void OvmsVehicleRenaultZoePh2CAN::Ticker1(uint32_t ticker) { + //Stop polling after 5 seconds of inactivity on CAN1 (M-CAN) + if (m_can1_activity_timer > 0) { + if (--m_can1_activity_timer == 0) { + ESP_LOGI(TAG,"Zoe has gone to sleep (No messages on M-CAN for 10 seconds)"); + mt_bus_awake->SetValue(false); + StandardMetrics.ms_v_env_awake->SetValue(false); + StandardMetrics.ms_v_env_charging12v->SetValue(false); + StandardMetrics.ms_v_pos_speed->SetValue( 0 ); + StandardMetrics.ms_v_bat_12v_current->SetValue( 0 ); + StandardMetrics.ms_v_charge_12v_current->SetValue( 0 ); + StandardMetrics.ms_v_bat_current->SetValue( 0 ); + POLLSTATE_OFF; + ESP_LOGI(TAG, "Pollstate switched to OFF"); + //Check if car is locked, if not send notify + if (!StandardMetrics.ms_v_env_locked->AsBool()) { + MyNotify.NotifyString("alert", "vehicle.lock", "Vehicle is not locked"); + } + + if (StandardMetrics.ms_v_env_on->AsBool() && !CarIsDriving) { CarIsDriving = true; //Start trip after power on diff --git a/OVMS.V3/components/vehicle_renaultzoe_ph2_can/src/vehicle_renaultzoe_ph2_can.h b/OVMS.V3/components/vehicle_renaultzoe_ph2_can/src/vehicle_renaultzoe_ph2_can.h index 46d733d..1047fe3 100644 --- a/OVMS.V3/components/vehicle_renaultzoe_ph2_can/src/vehicle_renaultzoe_ph2_can.h +++ b/OVMS.V3/components/vehicle_renaultzoe_ph2_can/src/vehicle_renaultzoe_ph2_can.h @@ -99,8 +99,10 @@ class OvmsVehicleRenaultZoePh2CAN : public OvmsVehicle { void EnergyStatisticsBMS(); virtual void Ticker10(uint32_t ticker);//Handle charge, energy statistics virtual void Ticker1(uint32_t ticker); //Handle trip counter + + private: + unsigned int m_can1_activity_timer; - // Renault ZOE specific metrics OvmsMetricBool *mt_bus_awake; //CAN bus awake status OvmsMetricFloat *mt_pos_odometer_start; //ODOmeter at trip start