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

198 lines
7.9 KiB
C++
Raw Normal View History

2022-04-08 23:03:19 +00:00
/*
; Project: Open Vehicle Monitor System
2022-04-15 14:17:12 +00:00
; Date: 15th Apr 2022
2022-04-08 23:03:19 +00:00
;
2022-04-15 14:17:12 +00:00
; (C) 2022 Carsten Schmiemann
2022-04-08 23:03:19 +00: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 14:17:12 +00:00
2022-04-08 23:03:19 +00: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-04-10 18:30:54 +00:00
#include "vehicle_renaultzoe_ph2.h"
2022-04-14 22:35:23 +00:00
#include "ph2_poller.h"
2022-04-08 23:03:19 +00:00
OvmsVehicleRenaultZoePh2::OvmsVehicleRenaultZoePh2() {
2022-04-10 18:30:54 +00:00
ESP_LOGI(TAG, "Start Renault Zoe Ph2 vehicle module");
2022-04-08 23:03:19 +00:00
2022-04-10 18:30:54 +00:00
StandardMetrics.ms_v_type->SetValue("RZ2");
2022-04-08 23:03:19 +00:00
StandardMetrics.ms_v_charge_inprogress->SetValue(false);
// Zoe CAN bus runs at 500 kbps
RegisterCanBus(1, CAN_MODE_ACTIVE, CAN_SPEED_500KBPS);
// Poll Specific PIDs
2022-04-11 22:09:57 +00:00
POLLSTATE_ON;
2022-04-10 18:30:54 +00:00
PollSetPidList(m_can1, renault_zoe_polls);
2022-04-14 22:35:23 +00:00
PollSetThrottling(5);
2022-04-08 23:03:19 +00:00
PollSetResponseSeparationTime(20);
// init metrics:
2022-04-10 18:30:54 +00:00
mt_pos_odometer_start = MyMetrics.InitFloat("zph2.v.pos.odometer.start", SM_STALE_MID, 0, Kilometers);
2022-04-13 20:16:04 +00:00
mt_bus_awake = MyMetrics.InitBool("zph2.v.bus.awake", SM_STALE_MIN, false);
2022-04-10 18:30:54 +00:00
mt_available_energy = MyMetrics.InitFloat("zph2.v.avail.energy", SM_STALE_MID, 0, kWh);
mt_main_power_consumed = MyMetrics.InitFloat("zph2.c.main.power.consumed", SM_STALE_MID, 0, kWh);
2022-04-14 00:06:36 +00:00
mt_inv_status = MyMetrics.InitString("zph2.m.inverter.status", SM_STALE_MID, 0);
2022-04-13 20:16:04 +00: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-13 23:11:37 +00:00
mt_aux_power_consumer = MyMetrics.InitFloat("zph2.c.aux.power.consumer", SM_STALE_MID, 0, Watts);
mt_aux_power_ptc = MyMetrics.InitFloat("zph2.c.aux.power.ptc", SM_STALE_MID, 0, Watts);
mt_inv_hv_voltage = MyMetrics.InitFloat("zph2.m.inverter.voltage", SM_STALE_MID, 0, Volts);
mt_inv_hv_current = MyMetrics.InitFloat("zph2.m.inverter.current", SM_STALE_MID, 0, Amps);
mt_bat_max_charge_power = MyMetrics.InitFloat("zph2.b.max.charge.power", SM_STALE_MID, 0, kW);
2022-04-13 23:38:32 +00:00
mt_hvac_compressor_speed = MyMetrics.InitFloat("zph2.h.compressor.speed", SM_STALE_MID, 0);
2022-04-08 23:03:19 +00:00
// BMS configuration:
BmsSetCellArrangementVoltage(96, 8);
2022-04-10 18:30:54 +00:00
BmsSetCellArrangementTemperature(12, 1);
2022-04-08 23:03:19 +00:00
BmsSetCellLimitsVoltage(2.0, 5.0);
BmsSetCellLimitsTemperature(-39, 200);
BmsSetCellDefaultThresholdsVoltage(0.030, 0.050);
BmsSetCellDefaultThresholdsTemperature(4.0, 5.0);
2022-04-16 04:00:59 +00:00
#ifdef CONFIG_OVMS_COMP_WEBSERVER
WebInit();
#endif
2022-04-08 23:03:19 +00:00
}
OvmsVehicleRenaultZoePh2::~OvmsVehicleRenaultZoePh2() {
2022-04-10 18:30:54 +00:00
ESP_LOGI(TAG, "Stop Renault Zoe Ph2 vehicle module");
2022-04-08 23:03:19 +00:00
}
/**
* Handles incoming CAN-frames on bus 1
*/
void OvmsVehicleRenaultZoePh2::IncomingFrameCan1(CAN_frame_t* p_frame) {
uint8_t *data = p_frame->data.u8;
2022-04-10 18:30:54 +00: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-08 23:03:19 +00:00
// Poll reply gives 0x83 0xc0 that means zoe is sleeping and CAN gateway does not respond to anything
if (mt_bus_awake && data[0] == 0x83 && data[1] == 0xc0) {
2022-04-13 20:16:04 +00:00
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_on->SetValue(false);
StandardMetrics.ms_v_env_awake->SetValue(false);
StandardMetrics.ms_v_env_charging12v->SetValue(false);
StandardMetrics.ms_v_pos_speed->SetValue( 0 );
2022-04-13 20:16:04 +00:00
POLLSTATE_OFF;
}
//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
if (!mt_bus_awake && (data[0] == 0x05 || data[0] == 0x06 || data[0] == 0x07)) { //listen for SingleFrames (0x0) with length of 5-7
ESP_LOGI(TAG,"Zoe woke up (CAN Bus activity detected)");
mt_bus_awake->SetValue(true);
StandardMetrics.ms_v_env_awake->SetValue(true);
StandardMetrics.ms_v_env_on->SetValue(true);
StandardMetrics.ms_v_env_awake->SetValue(true);
StandardMetrics.ms_v_env_charging12v->SetValue(true);
POLLSTATE_ON;
}
2022-04-16 14:39:31 +00:00
if (mt_bus_awake && !CarIsCharging && data[2] == 0x92 && data[3] == 0x10) { //received 0x9210 from LBC, only sent freely on starting charge so far
ESP_LOGI(TAG,"Zoe stared charging");
StandardMetrics.ms_v_env_on->SetValue(false);
StandardMetrics.ms_v_charge_state->SetValue("charging");
POLLSTATE_CHARGING;
2022-04-08 23:03:19 +00:00
}
2022-04-16 14:39:31 +00:00
if (mt_bus_awake && CarIsCharging && data[2] == 0x92 && data[3] == 0x43) { //received 0x9243 from LBC, only sent freely on stopping charge so far
ESP_LOGI(TAG,"Zoe stopped charging");
StandardMetrics.ms_v_charge_state->SetValue("stopped");
POLLSTATE_ON;
}
if (mt_bus_awake && !CarIsDriving && StandardMetrics.ms_v_pos_gpsspeed->AsFloat() > 5) { //If GPS speed bigger than 5km/h then assume Vehicle driving, later I used OBD speed for that
ESP_LOGI(TAG,"Zoe is driving");
StandardMetrics.ms_v_env_on->SetValue(false);
POLLSTATE_RUNNING;
CarIsDriving = true;
} else if (mt_bus_awake && CarIsDriving && StandardMetrics.ms_v_pos_gpsspeed->AsFloat() < 5) {
ESP_LOGI(TAG,"Zoe stopped driving");
POLLSTATE_ON;
}
2022-04-08 23:03:19 +00:00
}
/**
* Handles incoming poll results
*/
void OvmsVehicleRenaultZoePh2::IncomingPollReply(canbus* bus, uint16_t type, uint16_t pid, uint8_t* data, uint8_t length, uint16_t remain) {
2022-04-08 23:03:19 +00:00
string& rxbuf = zoe_obd_rxbuf;
2022-04-12 17:57:30 +00: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-08 23:03:19 +00: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-11 22:09:57 +00:00
// ****** INV *****
case 0x18daf1df:
IncomingINV(type, pid, rxbuf.data(), rxbuf.size());
2022-04-08 23:03:19 +00:00
break;
// ****** EVC *****
2022-04-11 22:09:57 +00:00
case 0x18daf1da:
2022-04-08 23:03:19 +00:00
IncomingEVC(type, pid, rxbuf.data(), rxbuf.size());
break;
2022-04-14 22:35:23 +00:00
// ****** BCM *****
case 0x1893:
IncomingBCM(type, pid, rxbuf.data(), rxbuf.size());
2022-04-08 23:03:19 +00:00
break;
// ****** LBC *****
2022-04-11 22:09:57 +00:00
case 0x18daf1db:
2022-04-08 23:03:19 +00:00
IncomingLBC(type, pid, rxbuf.data(), rxbuf.size());
break;
2022-04-13 23:38:32 +00:00
// ****** HVAC *****
2022-04-14 22:35:23 +00:00
case 0x1892:
2022-04-13 23:38:32 +00:00
IncomingHVAC(type, pid, rxbuf.data(), rxbuf.size());
2022-04-08 23:03:19 +00:00
break;
2022-04-14 22:35:23 +00:00
// ****** UCM *****
case 0x1901:
IncomingUCM(type, pid, rxbuf.data(), rxbuf.size());
2022-04-08 23:03:19 +00:00
break;
}
}
class OvmsVehicleRenaultZoePh2Init {
public: OvmsVehicleRenaultZoePh2Init();
} MyOvmsVehicleRenaultZoePh2Init __attribute__ ((init_priority (9000)));
2022-04-15 14:17:12 +00:00
OvmsVehicleRenaultZoePh2Init::OvmsVehicleRenaultZoePh2Init()
{
ESP_LOGI(TAG, "Registering Vehicle: Renault Zoe Ph2 (9000)");
2022-04-10 18:30:54 +00:00
MyVehicleFactory.RegisterVehicle<OvmsVehicleRenaultZoePh2>("RZ2","Renault Zoe Ph2");
2022-04-15 14:17:12 +00:00
}