2022-04-09 01:03:19 +02:00
/*
; Project : Open Vehicle Monitor System
2022-04-15 16:17:12 +02:00
; Date : 15 th Apr 2022
2022-04-09 01:03:19 +02:00
;
2022-04-15 16:17:12 +02:00
; ( C ) 2022 Carsten Schmiemann
2022-04-09 01:03:19 +02:00
;
; 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 .
*/
2022-04-15 16:17:12 +02:00
2022-04-09 01:03:19 +02:00
# include "ovms_log.h"
# include <stdio.h>
# include <string>
# include <iomanip>
# include "pcp.h"
# include "ovms_metrics.h"
# include "ovms_events.h"
# include "ovms_config.h"
# include "ovms_command.h"
# include "metrics_standard.h"
# include "ovms_notify.h"
# include "ovms_peripherals.h"
# include "ovms_netmanager.h"
2022-05-27 23:25:17 +02:00
# include "vehicle_renaultzoe_ph2_obd.h"
2022-04-15 00:35:23 +02:00
# include "ph2_poller.h"
2022-04-12 01:26:13 +02:00
2022-05-27 23:25:17 +02:00
OvmsVehicleRenaultZoePh2OBD : : OvmsVehicleRenaultZoePh2OBD ( ) {
ESP_LOGI ( TAG , " Start Renault Zoe Ph2 (OBD) vehicle module " ) ;
2022-04-09 01:03:19 +02:00
2022-04-19 23:14:39 +02:00
//Init variables supressing push on boot up
2022-04-10 20:30:54 +02:00
StandardMetrics . ms_v_type - > SetValue ( " RZ2 " ) ;
2022-04-09 01:03:19 +02:00
StandardMetrics . ms_v_charge_inprogress - > SetValue ( false ) ;
2022-04-19 23:14:39 +02:00
StandardMetrics . ms_v_charge_pilot - > SetValue ( false ) ;
StandardMetrics . ms_v_charge_state - > SetValue ( " stopped " ) ;
StandardMetrics . ms_v_charge_substate - > SetValue ( " stopped " ) ;
StandardMetrics . ms_v_env_on - > SetValue ( false ) ;
2022-04-09 01:03:19 +02:00
2022-05-27 23:25:17 +02:00
MyConfig . RegisterParam ( " xrz2o " , " Renault Zoe Ph2 (OBD) configuration " , true , true ) ;
2022-04-20 00:39:20 +02:00
ConfigChanged ( NULL ) ;
2022-04-19 23:34:11 +02:00
2022-04-19 23:14:39 +02:00
// Init Zoe Ph2 OBD Connection (CAN Gateway)
2022-04-09 01:03:19 +02:00
RegisterCanBus ( 1 , CAN_MODE_ACTIVE , CAN_SPEED_500KBPS ) ;
2022-04-17 00:02:50 +02:00
POLLSTATE_OFF ;
2022-04-19 02:19:55 +02:00
ESP_LOGI ( TAG , " Pollstate switched to OFF " ) ;
2022-04-16 04:51:35 +02:00
2022-04-10 20:30:54 +02:00
PollSetPidList ( m_can1 , renault_zoe_polls ) ;
2022-04-18 20:26:15 +02:00
PollSetThrottling ( 10 ) ;
2022-04-09 01:03:19 +02:00
PollSetResponseSeparationTime ( 20 ) ;
2022-04-20 21:46:05 +02:00
// Renault ZOE specific metrics
2022-04-19 02:19:55 +02:00
mt_bus_awake = MyMetrics . InitBool ( " zph2.v.bus.awake " , SM_STALE_NONE , false ) ;
2022-05-07 01:02:15 +02:00
mt_pos_odometer_start = MyMetrics . InitFloat ( " zph2.v.pos.odometer.start " , SM_STALE_MID , 0 , Kilometers , true ) ;
mt_pos_car_trip = MyMetrics . InitFloat ( " zph2.v.pos.car.trip " , SM_STALE_NONE , 0 , Kilometers , true ) ;
mt_bat_used_start = MyMetrics . InitFloat ( " zph2.b.used.start " , SM_STALE_MID , 0 , kWh , true ) ;
mt_bat_recd_start = MyMetrics . InitFloat ( " zph2.b.recd.start " , SM_STALE_MID , 0 , kWh , true ) ;
mt_bat_chg_start = MyMetrics . InitFloat ( " zph2.b.chg.start " , SM_STALE_MID , 0 , kWh , true ) ;
mt_bat_available_energy = MyMetrics . InitFloat ( " zph2.b.avail.energy " , SM_STALE_NONE , 0 , kWh , true ) ;
2022-04-20 21:36:52 +02:00
mt_bat_aux_power_consumer = MyMetrics . InitFloat ( " zph2.b.aux.power.consumer " , SM_STALE_MID , 0 , Watts ) ;
mt_bat_aux_power_ptc = MyMetrics . InitFloat ( " zph2.b.aux.power.ptc " , SM_STALE_MID , 0 , Watts ) ;
2022-05-07 01:02:15 +02:00
mt_bat_max_charge_power = MyMetrics . InitFloat ( " zph2.b.max.charge.power " , SM_STALE_MID , 0 , kW , true ) ;
2022-04-21 23:00:52 +02:00
mt_bat_cycles = MyMetrics . InitFloat ( " zph2.b.cycles " , SM_STALE_MID , 0 , Other , true ) ;
2022-04-19 02:19:55 +02:00
mt_main_power_available = MyMetrics . InitFloat ( " zph2.c.main.power.available " , SM_STALE_MIN , 0 , kW ) ;
mt_main_phases = MyMetrics . InitString ( " zph2.c.main.phases " , SM_STALE_MIN , 0 ) ;
mt_main_phases_num = MyMetrics . InitFloat ( " zph2.c.main.phases.num " , SM_STALE_MIN , 0 ) ;
mt_inv_status = MyMetrics . InitString ( " zph2.m.inverter.status " , SM_STALE_NONE , 0 ) ;
2022-05-07 01:02:15 +02:00
mt_inv_hv_voltage = MyMetrics . InitFloat ( " zph2.i.voltage " , SM_STALE_MID , 0 , Volts , true ) ;
2022-04-20 21:36:52 +02:00
mt_inv_hv_current = MyMetrics . InitFloat ( " zph2.i.current " , SM_STALE_MID , 0 , Amps ) ;
2022-04-18 02:16:56 +02:00
mt_mot_temp_stator1 = MyMetrics . InitFloat ( " zph2.m.temp.stator1 " , SM_STALE_MID , 0 , Celcius ) ;
mt_mot_temp_stator2 = MyMetrics . InitFloat ( " zph2.m.temp.stator2 " , SM_STALE_MID , 0 , Celcius ) ;
2022-04-21 20:55:17 +02:00
mt_hvac_compressor_speed = MyMetrics . InitFloat ( " zph2.h.compressor.speed " , SM_STALE_MID , 0 , rpm ) ;
mt_hvac_compressor_pressure = MyMetrics . InitFloat ( " zph2.h.compressor.pressure " , SM_STALE_MID , 0 , Bar ) ;
2022-04-18 02:16:56 +02:00
mt_hvac_compressor_power = MyMetrics . InitFloat ( " zph2.h.compressor.power " , SM_STALE_MID , 0 , Watts ) ;
2022-04-21 20:55:17 +02:00
mt_hvac_compressor_mode = MyMetrics . InitString ( " zph2.h.compressor.mode " , SM_STALE_MID , 0 , Other ) ;
2022-04-21 20:48:18 +02:00
mt_bat_lbc_soc = MyMetrics . InitFloat ( " zph2.b.lbc.soc " , SM_STALE_MAX , 0 , Percentage , true ) ;
mt_bat_user_soc = MyMetrics . InitFloat ( " zph2.b.user.soc " , SM_STALE_MAX , 0 , Percentage , true ) ;
2022-04-20 23:49:17 +02:00
2022-04-09 01:03:19 +02:00
// BMS configuration:
2022-04-16 23:11:29 +02:00
BmsSetCellArrangementVoltage ( 96 , 1 ) ;
2022-04-10 20:30:54 +02:00
BmsSetCellArrangementTemperature ( 12 , 1 ) ;
2022-04-09 01:03:19 +02:00
BmsSetCellLimitsVoltage ( 2.0 , 5.0 ) ;
BmsSetCellLimitsTemperature ( - 39 , 200 ) ;
BmsSetCellDefaultThresholdsVoltage ( 0.030 , 0.050 ) ;
2022-04-16 04:51:35 +02:00
BmsSetCellDefaultThresholdsTemperature ( 4.0 , 5.0 ) ;
2022-04-16 06:00:59 +02:00
# ifdef CONFIG_OVMS_COMP_WEBSERVER
WebInit ( ) ;
# endif
2022-04-09 01:03:19 +02:00
}
2022-05-27 23:25:17 +02:00
OvmsVehicleRenaultZoePh2OBD : : ~ OvmsVehicleRenaultZoePh2OBD ( ) {
ESP_LOGI ( TAG , " Stop Renault Zoe Ph2 (OBD) vehicle module " ) ;
2022-04-09 01:03:19 +02:00
}
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : ConfigChanged ( OvmsConfigParam * param ) {
if ( param & & param - > GetName ( ) ! = " xrz2o " )
2022-04-19 23:34:11 +02:00
return ;
// get values from config store
2022-05-27 23:25:17 +02:00
m_range_ideal = MyConfig . GetParamValueInt ( " xrz2o " , " rangeideal " , 350 ) ;
m_battery_capacity = MyConfig . GetParamValueInt ( " xrz2o " , " battcapacity " , 52000 ) ;
m_UseCarTrip = MyConfig . GetParamValueBool ( " xrz2o " , " UseCarTrip " , false ) ;
m_UseBMScalculation = MyConfig . GetParamValueBool ( " xrz2o " , " UseBMScalculation " , false ) ;
m_UseBMSsoc = MyConfig . GetParamValueBool ( " xrz2o " , " UseBMSsoc " , false ) ;
2022-04-19 23:34:11 +02:00
StandardMetrics . ms_v_bat_range_ideal - > SetValue ( m_range_ideal , Kilometers ) ;
2022-04-23 16:59:43 +02:00
if ( m_battery_capacity = = 52000 ) {
Bat_cell_capacity = 78.0 * 2 * ( StandardMetrics . ms_v_bat_soh - > AsFloat ( ) / 100.0 ) ;
}
if ( m_battery_capacity = = 41000 ) {
Bat_cell_capacity = 65.6 * 2 * ( StandardMetrics . ms_v_bat_soh - > AsFloat ( ) / 100.0 ) ;
}
if ( m_battery_capacity = = 22000 ) {
Bat_cell_capacity = 36.0 * 2 * ( StandardMetrics . ms_v_bat_soh - > AsFloat ( ) / 100.0 ) ;
}
2022-05-27 23:25:17 +02:00
ESP_LOGI ( TAG , " Renault Zoe Ph2 (OBD) reload configuration: Range ideal: %d, Battery capacity: %d, Use Car trip counter: %s, Use BMS as energy counter: %s, Use BMS for SOC: %s " , m_range_ideal , m_battery_capacity , m_UseCarTrip ? " Yes " : " No " , m_UseBMScalculation ? " yes " : " no " , m_UseBMSsoc ? " yes " : " no " ) ;
2022-04-19 23:34:11 +02:00
}
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : ZoeWakeUp ( ) {
2022-04-21 21:03:59 +02:00
ESP_LOGI ( TAG , " Zoe woke up (CAN Bus activity detected) " ) ;
mt_bus_awake - > SetValue ( true ) ; ;
StandardMetrics . ms_v_env_charging12v - > SetValue ( true ) ;
POLLSTATE_ON ;
ESP_LOGI ( TAG , " Pollstate switched to ON " ) ;
}
2022-04-09 01:03:19 +02:00
/**
* Handles incoming CAN - frames on bus 1
*/
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : IncomingFrameCan1 ( CAN_frame_t * p_frame ) {
2022-04-09 01:03:19 +02:00
uint8_t * data = p_frame - > data . u8 ;
2022-04-23 15:24:49 +02:00
//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]);
2022-04-16 21:22:38 +02:00
//ESP_LOGD(TAG, "Status CAN Bus: %s", mt_bus_awake->AsBool() ? "true" : "false");
2022-04-16 19:55:43 +02:00
2022-04-16 14:41:36 +02:00
// Poll reply gives 0x83 0xc0 that means zoe is sleeping and CAN gateway does not respond to anything
2022-04-16 20:40:40 +02:00
if ( mt_bus_awake - > AsBool ( ) & & data [ 0 ] = = 0x83 & & data [ 1 ] = = 0xc0 ) {
2022-04-13 22:16:04 +02:00
ESP_LOGI ( TAG , " Zoe has gone to sleep (CAN Gateway NAK response) " ) ;
mt_bus_awake - > SetValue ( false ) ;
2022-04-16 14:41:36 +02:00
StandardMetrics . ms_v_env_awake - > SetValue ( false ) ;
StandardMetrics . ms_v_env_charging12v - > SetValue ( false ) ;
StandardMetrics . ms_v_pos_speed - > SetValue ( 0 ) ;
2022-04-18 01:11:40 +02:00
StandardMetrics . ms_v_bat_12v_current - > SetValue ( 0 ) ;
StandardMetrics . ms_v_charge_12v_current - > SetValue ( 0 ) ;
2022-04-18 13:25:47 +02:00
StandardMetrics . ms_v_bat_current - > SetValue ( 0 ) ;
2022-04-13 22:16:04 +02:00
POLLSTATE_OFF ;
2022-04-19 02:19:55 +02:00
ESP_LOGI ( TAG , " Pollstate switched to OFF " ) ;
2022-05-18 00:43:20 +02:00
//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 " ) ;
}
2022-04-23 11:50:11 +02:00
} else if ( ! mt_bus_awake - > AsBool ( ) ) {
ZoeWakeUp ( ) ;
2022-04-16 14:41:36 +02:00
}
//There are some free frames on wakeup and start and stop charging.... I try to use them to see if Car is awake and charging, see /Reference/ZOE_Ph2_xxx text files
2022-04-23 11:50:11 +02:00
//if (!mt_bus_awake->AsBool() && (data[0] == 0x05 || data[0] == 0x06 || data[0] == 0x07)) { //listen for SingleFrames (0x0) with length of 5-7
// ZoeWakeUp();
//}
2022-04-09 01:03:19 +02:00
}
/**
* Handles incoming poll results
*/
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : IncomingPollReply ( canbus * bus , uint16_t type , uint16_t pid , uint8_t * data , uint8_t length , uint16_t remain ) {
2022-04-09 01:03:19 +02:00
string & rxbuf = zoe_obd_rxbuf ;
2022-04-16 21:22:38 +02:00
//ESP_LOGV(TAG, "pid: %04x length: %d m_poll_ml_remain: %d m_poll_ml_frame: %d", pid, length, m_poll_ml_remain, m_poll_ml_frame);
2022-04-12 19:57:30 +02:00
2022-04-09 01:03:19 +02:00
// init / fill rx buffer:
if ( m_poll_ml_frame = = 0 ) {
rxbuf . clear ( ) ;
rxbuf . reserve ( length + remain ) ;
}
rxbuf . append ( ( char * ) data , length ) ;
if ( remain )
return ;
switch ( m_poll_moduleid_low ) {
2022-04-12 00:09:57 +02:00
// ****** INV *****
case 0x18daf1df :
IncomingINV ( type , pid , rxbuf . data ( ) , rxbuf . size ( ) ) ;
2022-04-09 01:03:19 +02:00
break ;
// ****** EVC *****
2022-04-12 00:09:57 +02:00
case 0x18daf1da :
2022-04-09 01:03:19 +02:00
IncomingEVC ( type , pid , rxbuf . data ( ) , rxbuf . size ( ) ) ;
break ;
2022-04-15 00:35:23 +02:00
// ****** BCM *****
2022-04-17 13:15:50 +02:00
case 0x765 :
2022-04-15 00:35:23 +02:00
IncomingBCM ( type , pid , rxbuf . data ( ) , rxbuf . size ( ) ) ;
2022-04-09 01:03:19 +02:00
break ;
// ****** LBC *****
2022-04-12 00:09:57 +02:00
case 0x18daf1db :
2022-04-09 01:03:19 +02:00
IncomingLBC ( type , pid , rxbuf . data ( ) , rxbuf . size ( ) ) ;
break ;
2022-04-14 01:38:32 +02:00
// ****** HVAC *****
2022-04-17 13:15:50 +02:00
case 0x764 :
2022-04-14 01:38:32 +02:00
IncomingHVAC ( type , pid , rxbuf . data ( ) , rxbuf . size ( ) ) ;
2022-04-09 01:03:19 +02:00
break ;
2022-04-15 00:35:23 +02:00
// ****** UCM *****
2022-04-17 13:15:50 +02:00
case 0x76D :
2022-04-15 00:35:23 +02:00
IncomingUCM ( type , pid , rxbuf . data ( ) , rxbuf . size ( ) ) ;
2022-04-18 20:26:15 +02:00
break ;
// ****** CLUSTER *****
2022-05-07 01:02:15 +02:00
//case 0x763:
// IncomingCLUSTER(type, pid, rxbuf.data(), rxbuf.size());
// break;
2022-04-09 01:03:19 +02:00
}
}
2022-05-27 23:25:17 +02:00
int OvmsVehicleRenaultZoePh2OBD : : calcMinutesRemaining ( float charge_voltage , float charge_current ) {
2022-04-23 16:06:43 +02:00
float bat_soc = mt_bat_lbc_soc - > AsFloat ( 100 ) ;
2022-04-17 11:17:54 +02:00
2022-04-23 17:51:46 +02:00
float remaining_wh = m_battery_capacity - ( m_battery_capacity * bat_soc / 100.0 ) ;
2022-04-17 11:17:54 +02:00
float remaining_hours = remaining_wh / ( charge_current * charge_voltage ) ;
float remaining_mins = remaining_hours * 60.0 ;
2022-04-23 16:03:40 +02:00
//ESP_LOGD(TAG, "SOC: %f, BattCap:%d, Current: %f, Voltage: %f, RemainWH: %f, RemainHour: %f, RemainMin: %f", bat_soc, m_battery_capacity, charge_current, charge_voltage, remaining_wh, remaining_hours, remaining_mins);
2022-04-17 11:17:54 +02:00
return MIN ( 1440 , ( int ) remaining_mins ) ;
}
2022-04-17 13:48:30 +02:00
//Handle Charging values
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : ChargeStatistics ( ) {
2022-04-18 23:31:52 +02:00
float charge_current = fabs ( StandardMetrics . ms_v_bat_current - > AsFloat ( 0 , Amps ) ) ;
2022-04-17 11:17:54 +02:00
float charge_voltage = StandardMetrics . ms_v_bat_voltage - > AsFloat ( 0 , Volts ) ;
2022-04-18 23:31:52 +02:00
float battery_power = fabs ( StandardMetrics . ms_v_bat_power - > AsFloat ( 0 , kW ) ) ;
2022-04-17 11:17:54 +02:00
float charger_power = StandardMetrics . ms_v_charge_power - > AsFloat ( 0 , kW ) ;
2022-04-18 01:07:32 +02:00
float ac_current = StandardMetrics . ms_v_charge_current - > AsFloat ( 0 , Amps ) ;
string ac_phases = mt_main_phases - > AsString ( ) ;
2022-04-17 11:17:54 +02:00
2022-04-17 13:48:30 +02:00
if ( CarIsCharging ! = CarLastCharging ) {
if ( CarIsCharging ) {
StandardMetrics . ms_v_charge_kwh - > SetValue ( 0 ) ;
StandardMetrics . ms_v_charge_inprogress - > SetValue ( CarIsCharging ) ;
2022-04-23 12:35:02 +02:00
if ( m_UseBMScalculation ) {
mt_bat_chg_start - > SetValue ( StandardMetrics . ms_v_charge_kwh_grid_total - > AsFloat ( ) ) ;
}
2022-04-17 13:48:30 +02:00
} else {
StandardMetrics . ms_v_charge_inprogress - > SetValue ( CarIsCharging ) ;
}
}
2022-04-23 12:35:02 +02:00
CarLastCharging = CarIsCharging ;
2022-04-17 13:48:30 +02:00
2022-04-18 23:31:52 +02:00
if ( ! StandardMetrics . ms_v_charge_pilot - > AsBool ( ) | | ! StandardMetrics . ms_v_charge_inprogress - > AsBool ( ) | | ( charge_current < = 0.0 ) ) {
2022-04-17 11:17:54 +02:00
return ;
}
2022-04-18 23:31:52 +02:00
if ( charge_voltage > 0 & & charge_current > 0 ) {
float power = charge_voltage * charge_current / 1000.0 ;
2022-04-17 11:17:54 +02:00
float energy = power / 3600.0 * 10.0 ;
2022-05-07 01:26:48 +02:00
float c_efficiency ;
2022-04-23 12:35:02 +02:00
if ( m_UseBMScalculation ) {
2022-04-23 14:33:17 +02:00
StandardMetrics . ms_v_charge_kwh - > SetValue ( StandardMetrics . ms_v_charge_kwh_grid_total - > AsFloat ( ) - mt_bat_chg_start - > AsFloat ( ) ) ;
2022-04-23 12:35:02 +02:00
} else {
StandardMetrics . ms_v_charge_kwh - > SetValue ( StandardMetrics . ms_v_charge_kwh - > AsFloat ( ) + energy ) ;
}
2022-04-17 11:17:54 +02:00
int minsremaining = calcMinutesRemaining ( charge_voltage , charge_current ) ;
2022-04-23 16:03:40 +02:00
StandardMetrics . ms_v_charge_duration_full - > SetValue ( minsremaining , Minutes ) ;
2022-04-17 11:17:54 +02:00
2022-04-23 12:35:02 +02:00
if ( StandardMetrics . ms_v_charge_type - > AsString ( ) = = " type2 " ) {
2022-05-07 01:26:48 +02:00
c_efficiency = ( battery_power / charger_power ) * 100.0 ;
if ( c_efficiency < 100.0 ) {
StandardMetrics . ms_v_charge_efficiency - > SetValue ( c_efficiency ) ;
}
2022-04-23 16:21:37 +02:00
ESP_LOGI ( TAG , " Charge time remaining: %d mins, AC Charge at %.2f kW with %.1f amps, %s at %.1f efficiency, %.2f powerfactor " , minsremaining , charger_power , ac_current , ac_phases . c_str ( ) , StandardMetrics . ms_v_charge_efficiency - > AsFloat ( 100 ) , ACInputPowerFactor ) ;
2022-04-23 12:35:02 +02:00
} else if ( StandardMetrics . ms_v_charge_type - > AsString ( ) = = " ccs " | | StandardMetrics . ms_v_charge_type - > AsString ( ) = = " chademo " ) {
StandardMetrics . ms_v_charge_power - > SetValue ( battery_power ) ;
2022-04-23 16:21:37 +02:00
ESP_LOGI ( TAG , " Charge time remaining: %d mins, DC Charge at %.2f kW " , minsremaining , battery_power ) ;
2022-04-17 11:17:54 +02:00
}
2022-04-23 12:35:02 +02:00
}
2022-04-17 11:17:54 +02:00
}
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : EnergyStatisticsOVMS ( ) {
2022-04-18 19:21:09 +02:00
float voltage = StandardMetrics . ms_v_bat_voltage - > AsFloat ( 0 , Volts ) ;
float current = StandardMetrics . ms_v_bat_current - > AsFloat ( 0 , Amps ) ;
float power = voltage * current / 1000.0 ;
if ( power ! = 0.0 & & StandardMetrics . ms_v_env_on - > AsBool ( ) ) {
2022-04-19 22:43:20 +02:00
float energy = power / 3600.0 * 10.0 ;
2022-04-19 02:19:55 +02:00
if ( energy > 0.0f )
2022-04-20 09:55:28 +02:00
StandardMetrics . ms_v_bat_energy_used - > SetValue ( StandardMetrics . ms_v_bat_energy_used - > AsFloat ( ) + energy ) ;
2022-04-18 19:21:09 +02:00
else
2022-04-20 09:55:28 +02:00
StandardMetrics . ms_v_bat_energy_recd - > SetValue ( StandardMetrics . ms_v_bat_energy_recd - > AsFloat ( ) - energy ) ;
2022-04-18 19:21:09 +02:00
}
}
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : EnergyStatisticsBMS ( ) {
2022-04-20 22:56:03 +02:00
StandardMetrics . ms_v_bat_energy_used - > SetValue ( StandardMetrics . ms_v_bat_energy_used_total - > AsFloat ( ) - mt_bat_used_start - > AsFloat ( ) ) ;
StandardMetrics . ms_v_bat_energy_recd - > SetValue ( StandardMetrics . ms_v_bat_energy_recd_total - > AsFloat ( ) - mt_bat_recd_start - > AsFloat ( ) ) ;
}
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : Ticker10 ( uint32_t ticker ) {
2022-04-18 19:21:09 +02:00
if ( StandardMetrics . ms_v_charge_pilot - > AsBool ( ) & & ! StandardMetrics . ms_v_env_on - > AsBool ( ) ) {
ChargeStatistics ( ) ;
} else {
2022-04-20 22:56:03 +02:00
if ( m_UseBMScalculation ) {
EnergyStatisticsBMS ( ) ;
} else {
EnergyStatisticsOVMS ( ) ;
}
2022-04-18 19:21:09 +02:00
}
}
2022-05-27 23:25:17 +02:00
void OvmsVehicleRenaultZoePh2OBD : : Ticker1 ( uint32_t ticker ) {
2022-04-18 20:26:15 +02:00
if ( StandardMetrics . ms_v_env_on - > AsBool ( ) & & ! CarIsDriving & & ! m_UseCarTrip ) {
2022-04-18 19:21:09 +02:00
CarIsDriving = true ;
//Start trip after power on
StandardMetrics . ms_v_pos_trip - > SetValue ( 0 ) ;
mt_pos_odometer_start - > SetValue ( StandardMetrics . ms_v_pos_odometer - > AsFloat ( 0 ) ) ;
StandardMetrics . ms_v_bat_energy_used - > SetValue ( 0 ) ;
StandardMetrics . ms_v_bat_energy_recd - > SetValue ( 0 ) ;
2022-04-20 22:56:03 +02:00
if ( m_UseBMScalculation ) {
mt_bat_used_start - > SetValue ( StandardMetrics . ms_v_bat_energy_used_total - > AsFloat ( ) ) ;
mt_bat_recd_start - > SetValue ( StandardMetrics . ms_v_bat_energy_recd_total - > AsFloat ( ) ) ;
}
2022-04-18 19:21:09 +02:00
}
2022-04-19 02:19:55 +02:00
if ( CarIsDriving & & ! CarIsDrivingInit ) {
CarIsDrivingInit = true ;
2022-04-20 23:57:48 +02:00
ESP_LOGI ( TAG , " Pollstate switched to DRIVING " ) ;
POLLSTATE_DRIVING ;
2022-04-19 02:19:55 +02:00
}
if ( ! StandardMetrics . ms_v_env_on - > AsBool ( ) & & CarIsDriving ) {
CarIsDriving = false ;
CarIsDrivingInit = false ;
ESP_LOGI ( TAG , " Pollstate switched to ON " ) ;
POLLSTATE_ON ;
}
2022-04-23 13:52:10 +02:00
if ( StandardMetrics . ms_v_charge_pilot - > AsBool ( ) & & StandardMetrics . ms_v_charge_inprogress - > AsBool ( ) & & ! CarIsCharging ) {
2022-04-19 02:19:55 +02:00
CarIsCharging = true ;
ESP_LOGI ( TAG , " Pollstate switched to CHARGING " ) ;
POLLSTATE_CHARGING ;
} else if ( ! StandardMetrics . ms_v_charge_pilot - > AsBool ( ) & & CarIsCharging ) {
CarIsCharging = false ;
2022-04-23 14:31:15 +02:00
StandardMetrics . ms_v_charge_duration_full - > SetValue ( 0 ) ;
2022-04-19 02:19:55 +02:00
ESP_LOGI ( TAG , " Pollstate switched to ON " ) ;
POLLSTATE_ON ;
2022-04-23 14:10:02 +02:00
} else if ( StandardMetrics . ms_v_charge_pilot - > AsBool ( ) & & CarIsCharging & & StandardMetrics . ms_v_charge_substate - > AsString ( ) = = " powerwait " ) {
CarIsCharging = false ;
2022-04-23 14:31:15 +02:00
StandardMetrics . ms_v_charge_duration_full - > SetValue ( 0 ) ;
2022-04-23 14:10:02 +02:00
ESP_LOGI ( TAG , " Pollstate switched to OFF, Wait for power... " ) ;
POLLSTATE_OFF ;
2022-05-07 12:22:59 +02:00
} else if ( StandardMetrics . ms_v_charge_pilot - > AsBool ( ) & & CarIsCharging & & StandardMetrics . ms_v_charge_state - > AsString ( ) = = " done " ) {
CarIsCharging = false ;
StandardMetrics . ms_v_charge_duration_full - > SetValue ( 0 ) ;
ESP_LOGI ( TAG , " Pollstate switched to OFF, done charging... " ) ;
POLLSTATE_OFF ;
2022-04-19 02:19:55 +02:00
}
2022-04-18 20:26:15 +02:00
if ( StandardMetrics . ms_v_env_on - > AsBool ( ) & & ! m_UseCarTrip ) {
2022-04-18 03:13:01 +02:00
StandardMetrics . ms_v_pos_trip - > SetValue ( StandardMetrics . ms_v_pos_odometer - > AsFloat ( 0 ) - mt_pos_odometer_start - > AsFloat ( 0 ) ) ;
}
2022-04-18 20:48:43 +02:00
if ( m_UseCarTrip ) {
StandardMetrics . ms_v_pos_trip - > SetValue ( mt_pos_car_trip - > AsFloat ( ) ) ;
}
2022-04-20 00:46:24 +02:00
StandardMetrics . ms_v_bat_range_est - > SetValue ( ( m_range_ideal * ( StandardMetrics . ms_v_bat_soc - > AsFloat ( 1 ) * 0.01 ) ) , Kilometers ) ;
2022-04-21 00:15:39 +02:00
if ( m_UseBMSsoc ) {
StandardMetrics . ms_v_bat_soc - > SetValue ( mt_bat_lbc_soc - > AsFloat ( 0 ) ) ;
} else {
StandardMetrics . ms_v_bat_soc - > SetValue ( mt_bat_user_soc - > AsFloat ( 0 ) ) ;
}
2022-04-18 03:13:01 +02:00
}
2022-05-27 23:25:17 +02:00
class OvmsVehicleRenaultZoePh2OBDInit {
public : OvmsVehicleRenaultZoePh2OBDInit ( ) ;
} MyOvmsVehicleRenaultZoePh2OBDInit __attribute__ ( ( init_priority ( 9000 ) ) ) ;
2022-04-09 01:03:19 +02:00
2022-05-27 23:25:17 +02:00
OvmsVehicleRenaultZoePh2OBDInit : : OvmsVehicleRenaultZoePh2OBDInit ( )
2022-04-15 16:17:12 +02:00
{
2022-05-27 23:25:17 +02:00
ESP_LOGI ( TAG , " Registering Vehicle: Renault Zoe Ph2 (OBD) (9000) " ) ;
MyVehicleFactory . RegisterVehicle < OvmsVehicleRenaultZoePh2OBD > ( " RZ2 " , " Renault Zoe Ph2 (OBD) " ) ;
2022-04-15 16:17:12 +02:00
}