Modify sleep behavior for direct CAN access with free frames

This commit is contained in:
Carsten Schmiemann 2022-11-19 00:01:40 +01:00
parent 848429860c
commit 89d64b2211
2 changed files with 26 additions and 19 deletions

View File

@ -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

View File

@ -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