OVMS3/OVMS.V3/components/vehicle_renaultzoe_ph2_obd/src/vehicle_renaultzoe_ph2_obd.h

137 lines
6.2 KiB
C
Raw Normal View History

2022-04-09 01:03:19 +02:00
/*
; Project: Open Vehicle Monitor System
2022-04-15 16:17:12 +02:00
; Date: 15th 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-05-27 23:25:17 +02:00
#ifndef __VEHICLE_RENAULTZOE_PH2_OBD_H__
#define __VEHICLE_RENAULTZOE_PH2_OBD_H__
2022-04-09 01:03:19 +02:00
2022-05-27 23:25:17 +02:00
static const char *TAG = "v-zoe-ph2-obd";
2022-04-15 16:17:12 +02:00
2022-04-09 01:03:19 +02:00
#include <atomic>
#include "can.h"
#include "vehicle.h"
#include "ovms_log.h"
#include "ovms_config.h"
#include "ovms_metrics.h"
#include "ovms_command.h"
#include "freertos/timers.h"
#ifdef CONFIG_OVMS_COMP_WEBSERVER
#include "ovms_webserver.h"
#endif
// CAN buffer access macros: b=byte# 0..7 / n=nibble# 0..15
#define CAN_BYTE(b) data[b]
#define CAN_UINT(b) (((UINT)CAN_BYTE(b) << 8) | CAN_BYTE(b+1))
#define CAN_UINT24(b) (((uint32_t)CAN_BYTE(b) << 16) | ((UINT)CAN_BYTE(b+1) << 8) | CAN_BYTE(b+2))
#define CAN_UINT32(b) (((uint32_t)CAN_BYTE(b) << 24) | ((uint32_t)CAN_BYTE(b+1) << 16) | ((UINT)CAN_BYTE(b+2) << 8) | CAN_BYTE(b+3))
#define CAN_NIBL(b) (data[b] & 0x0f)
#define CAN_NIBH(b) (data[b] >> 4)
#define CAN_NIB(n) (((n)&1) ? CAN_NIBL((n)>>1) : CAN_NIBH((n)>>1))
#define POLLSTATE_OFF PollSetState(0);
#define POLLSTATE_ON PollSetState(1);
2022-04-20 23:57:48 +02:00
#define POLLSTATE_DRIVING PollSetState(2);
2022-04-09 01:03:19 +02:00
#define POLLSTATE_CHARGING PollSetState(3);
using namespace std;
2022-05-27 23:25:17 +02:00
class OvmsVehicleRenaultZoePh2OBD : public OvmsVehicle {
2022-04-09 01:03:19 +02:00
public:
2022-05-27 23:25:17 +02:00
OvmsVehicleRenaultZoePh2OBD();
~OvmsVehicleRenaultZoePh2OBD();
2022-04-19 23:34:11 +02:00
static void WebCfgCommon(PageEntry_t& p, PageContext_t& c);
2022-04-20 00:39:20 +02:00
void ConfigChanged(OvmsConfigParam* param);
void ZoeWakeUp();
2022-04-09 01:03:19 +02:00
void IncomingFrameCan1(CAN_frame_t* p_frame);
void IncomingPollReply(canbus* bus, uint16_t type, uint16_t pid, uint8_t* data, uint8_t length, uint16_t remain);
void WebInit();
void WebDeInit();
2022-04-16 16:39:31 +02:00
bool CarIsCharging = false;
2022-04-17 08:25:32 +02:00
bool CarPluggedIn = false;
2022-04-17 13:48:30 +02:00
bool CarLastCharging = false;
2022-04-18 19:21:09 +02:00
bool CarIsDriving = false;
2022-04-19 02:19:55 +02:00
bool CarIsDrivingInit = false;
2022-04-20 23:45:03 +02:00
float ACInputPowerFactor = 0.0;
2022-04-23 16:59:43 +02:00
float Bat_cell_capacity = 0.0;
2022-04-09 01:03:19 +02:00
protected:
int m_range_ideal;
2022-04-17 11:17:54 +02:00
int m_battery_capacity;
2022-04-18 20:26:15 +02:00
bool m_UseCarTrip = false;
2022-04-20 22:56:03 +02:00
bool m_UseBMScalculation = false;
2022-04-21 00:15:39 +02:00
bool m_UseBMSsoc = false;
2022-05-08 23:52:03 +02:00
char zoe_vin[18] = "";
void IncomingINV(uint16_t type, uint16_t pid, const char* data, uint16_t len);
void IncomingEVC(uint16_t type, uint16_t pid, const char* data, uint16_t len);
2022-04-15 00:35:23 +02:00
void IncomingBCM(uint16_t type, uint16_t pid, const char* data, uint16_t len);
void IncomingLBC(uint16_t type, uint16_t pid, const char* data, uint16_t len);
2022-04-14 01:38:32 +02:00
void IncomingHVAC(uint16_t type, uint16_t pid, const char* data, uint16_t len);
2022-04-15 00:35:23 +02:00
void IncomingUCM(uint16_t type, uint16_t pid, const char* data, uint16_t len);
//void IncomingCLUSTER(uint16_t type, uint16_t pid, const char* data, uint16_t len);
2022-04-17 11:17:54 +02:00
int calcMinutesRemaining(float charge_voltage, float charge_current);
2022-04-18 19:21:09 +02:00
void ChargeStatistics();
2022-04-20 22:56:03 +02:00
void EnergyStatisticsOVMS();
void EnergyStatisticsBMS();
2022-04-18 19:21:09 +02:00
virtual void Ticker10(uint32_t ticker);//Handle charge, energy statistics
virtual void Ticker1(uint32_t ticker); //Handle trip counter
2022-04-15 16:17:12 +02:00
2022-04-09 01:03:19 +02:00
// Renault ZOE specific metrics
2022-04-20 21:36:52 +02:00
OvmsMetricBool *mt_bus_awake; //CAN bus awake status
OvmsMetricFloat *mt_pos_odometer_start; //ODOmeter at trip start
OvmsMetricFloat *mt_pos_car_trip; //Cluster tripcounter
OvmsMetricFloat *mt_bat_used_start; //Used battery kWh at trip start
OvmsMetricFloat *mt_bat_recd_start; //Recd battery kWh at trip start
OvmsMetricFloat *mt_bat_chg_start; //Charge battery kWh at charge start
2022-04-20 21:36:52 +02:00
OvmsMetricFloat *mt_bat_available_energy; //Available energy in battery
OvmsMetricFloat *mt_bat_aux_power_consumer; //Power usage by consumer
OvmsMetricFloat *mt_bat_aux_power_ptc; //Power usage by PTCs
OvmsMetricFloat *mt_bat_max_charge_power; //Battery max allowed charge, recd power
2022-04-21 23:00:52 +02:00
OvmsMetricFloat *mt_bat_cycles; //Battery full charge cycles
2022-04-21 00:15:39 +02:00
OvmsMetricFloat *mt_bat_lbc_soc; //Battery real SOC by BMS
OvmsMetricFloat *mt_bat_user_soc; //Battery user SOC by Cluster
2022-04-19 02:19:55 +02:00
OvmsMetricFloat *mt_main_power_available; //Mains power available
OvmsMetricString *mt_main_phases; //Mains phases used
OvmsMetricFloat *mt_main_phases_num; //Mains phases used
2022-04-14 01:11:37 +02:00
OvmsMetricString *mt_inv_status; //Inverter status string
2022-04-20 21:36:52 +02:00
OvmsMetricFloat *mt_inv_hv_voltage; //Inverter battery voltage sense, used for motor power calc
OvmsMetricFloat *mt_inv_hv_current; //Inverter battery current sense, used for motor power calc
2022-04-17 10:33:20 +02:00
OvmsMetricFloat *mt_mot_temp_stator1; //Temp of motor stator 1
OvmsMetricFloat *mt_mot_temp_stator2; //Temp of motor stator 2
2022-04-14 01:38:32 +02:00
OvmsMetricFloat *mt_hvac_compressor_speed; //Compressor speed
2022-04-20 21:36:52 +02:00
OvmsMetricFloat *mt_hvac_compressor_pressure;//Compressor high-side pressure in BAR
OvmsMetricFloat *mt_hvac_compressor_power; //Compressor power usage
2022-04-18 02:16:56 +02:00
OvmsMetricString *mt_hvac_compressor_mode; //Compressor mode
2022-04-20 23:26:00 +02:00
OvmsMetricFloat *mt_v_env_pressure; //Ambient air pressure
2022-04-20 21:36:52 +02:00
2022-04-14 01:38:32 +02:00
2022-04-09 01:03:19 +02:00
protected:
string zoe_obd_rxbuf;
};
2022-05-27 23:25:17 +02:00
#endif //#ifndef __VEHICLE_RENAULTZOE_PH2_OBD_H__