Skip to content

Commit

Permalink
Merge pull request #243 from Dimitrie78/master
Browse files Browse the repository at this point in the history
Add New Vehicle Smart ED/EQ 453 Gen.4
  • Loading branch information
dexterbg committed Jul 20, 2019
2 parents 3d34200 + ff0d46f commit 328c598
Show file tree
Hide file tree
Showing 10 changed files with 869 additions and 11 deletions.
2 changes: 1 addition & 1 deletion vehicle/OVMS.V3/components/vehicle_smarted/docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
========
Smart ED
Smart ED Gen.3
========

Vehicle Type: **SE**
Expand Down
35 changes: 25 additions & 10 deletions vehicle/OVMS.V3/components/vehicle_smarted/src/vehicle_smarted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ void OvmsVehicleSmartED::IncomingFrameCan1(CAN_frame_t* p_frame) {
0x518 01 4e 00 00 [f8 7f] c8 b4 // Charge duration?
*/
if (m_soc_rsoc) {
StandardMetrics.ms_v_bat_soh->SetValue((float) (d[7]/2));
StandardMetrics.ms_v_bat_soh->SetValue((float) (d[7]/2.0));
} else {
StandardMetrics.ms_v_bat_soc->SetValue((float) (d[7]/2));
StandardMetrics.ms_v_bat_soc->SetValue((float) (d[7]/2.0));
}
StandardMetrics.ms_v_charge_climit->SetValue(d[1]/2);
//HandleChargingStatus(d[1]!=0);
Expand All @@ -405,11 +405,13 @@ void OvmsVehicleSmartED::IncomingFrameCan1(CAN_frame_t* p_frame) {
= 340 (in HEX)
= 832 (in base10) and now by ten
= 83,2% */
float rsoc = ((d[4] & 0x03) * 256 + d[5]) / 10.0;
if (m_soc_rsoc) {
StandardMetrics.ms_v_bat_soc->SetValue(((float) ((d[4] & 0x03) * 256 + d[5])) / 10, Percentage);
StandardMetrics.ms_v_bat_soc->SetValue(rsoc, Percentage);
} else {
StandardMetrics.ms_v_bat_soh->SetValue(((float) ((d[4] & 0x03) * 256 + d[5])) / 10, Percentage);
StandardMetrics.ms_v_bat_soh->SetValue(rsoc, Percentage);
}
StandardMetrics.ms_v_bat_cac->SetValue((DEFAULT_BATTERY_AMPHOURS * rsoc) / 100, AmpHours);
break;
}
case 0x508: //HV ampere and charging yes/no
Expand Down Expand Up @@ -757,12 +759,21 @@ OvmsVehicle::vehicle_command_t OvmsVehicleSmartED::CommandSetChargeTimer(bool ti
0x512 00 00 12 1E 00 00 00 00
if one sets e.g. the time at 18:30. If you now mask byte 3 (0x12) with 0x40 (and set the second bit to high there), the A / C function is also activated.
*/
if(timerstart == 0) {
return Fail;
}
if(!StandardMetrics.ms_v_env_awake->AsBool()) {
return Fail;
if (!MyConfig.IsDefined("password","pin")) return Fail;

std::string vpin = MyConfig.GetParamValue("password","pin");
CommandUnlock(vpin.c_str());
vTaskDelay(600 / portTICK_PERIOD_MS);
CommandLock(vpin.c_str());
vTaskDelay(600 / portTICK_PERIOD_MS);
if(!StandardMetrics.ms_v_env_awake->AsBool()) return Fail;
}
if(timerstart == 0) {
timerstart = mt_vehicle_time->AsInt();
if(timerstart == 0) return Fail;
}

int t = timerstart + 600; // mt_vehicle_time + 10 min
//int days = (t / 86400);
//t = t - (days * 86400);
Expand Down Expand Up @@ -794,6 +805,11 @@ OvmsVehicle::vehicle_command_t OvmsVehicleSmartED::CommandSetChargeTimer(bool ti
frame.data.u8[6] = 0x00;
frame.data.u8[7] = 0x00;
m_can1->Write(&frame);
vTaskDelay(50 / portTICK_PERIOD_MS);
m_can1->Write(&frame);
vTaskDelay(50 / portTICK_PERIOD_MS);
m_can1->Write(&frame);

return Success;
}

Expand Down Expand Up @@ -958,6 +974,5 @@ class OvmsVehicleSmartEDInit {

OvmsVehicleSmartEDInit::OvmsVehicleSmartEDInit() {
ESP_LOGI(TAG, "Registering Vehicle: SMART ED (9000)");
MyVehicleFactory.RegisterVehicle<OvmsVehicleSmartED>("SE", "Smart ED");
MyVehicleFactory.RegisterVehicle<OvmsVehicleSmartED>("SE", "Smart ED 3.Gen");
}

Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class OvmsVehicleSmartED : public OvmsVehicle
OvmsMetricString *mt_nlg6_pn_hw; //!< Part number of base hardware (wo revisioning)

#define DEFAULT_BATTERY_CAPACITY 17600
#define DEFAULT_BATTERY_AMPHOURS 53
#define MAX_POLL_DATA_LEN 238
#define CELLCOUNT 93
#define SE_CANDATA_TIMEOUT 10
Expand Down
14 changes: 14 additions & 0 deletions vehicle/OVMS.V3/components/vehicle_smarteq/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Main component makefile.
#
# This Makefile can be left empty. By default, it will take the sources in the
# src/ directory, compile them and link them into lib(subdirectory_name).a
# in the build directory. This behaviour is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#

ifdef CONFIG_OVMS_VEHICLE_SMARTEQ
COMPONENT_ADD_INCLUDEDIRS:=src
COMPONENT_SRCDIRS:=src
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
endif
34 changes: 34 additions & 0 deletions vehicle/OVMS.V3/components/vehicle_smarteq/docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
========
Smart ED/EQ Gen.4 (453)
========

Vehicle Type: **SQ**

The Smart ED/EQ Gen.4 will be documented here.

----------------
Support Overview
----------------

=========================== ==============
Function Support Status
=========================== ==============
Hardware OVMS v3 (or later)
Vehicle Cable OBD-II to DB9 Data Cable for OVMS (1441200 right, or 1139300 left)
GSM Antenna 1000500 Open Vehicles OVMS GSM Antenna (or any compatible antenna)
GPS Antenna 1020200 Universal GPS Antenna (SMA Connector) (or any compatible antenna)
SOC Display Yes
Range Display Yes
GPS Location Yes (from modem module GPS)
Speed Display Yes
Temperature Display Yes (External Temp and Battery)
BMS v+t Display only Cell Volts atm.
TPMS Display No
Charge Status Display Yes
Charge Interruption Alerts No
Charge Control No
Cabin Pre-heat/cool Control No
Lock/Unlock Vehicle No
Valet Mode Control No
Others
=========================== ==============
164 changes: 164 additions & 0 deletions vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_can_poll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
; Project: Open Vehicle Monitor System
; Date: 1th October 2018
;
; Changes:
; 1.0 Initial release
;
; (C) 2018 Martin Graml
; (C) 2019 Thomas Heuer
;
; 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.
;
; Most of the CAN Messages are based on https://github.com/MyLab-odyssey/ED_BMSdiag
; http://ed.no-limit.de/wiki/index.php/Hauptseite
const PROGMEM uint32_t rqID_BMS = 0x79B;
const PROGMEM uint32_t respID_BMS = 0x7BB;
const PROGMEM byte rqPartNo[2] = {0x21, 0xEF};
const PROGMEM byte rqIDpart[2] = {0x21, 0x80};
const PROGMEM byte rqBattHealth[2] = {0x21, 0x61};
const PROGMEM byte rqBattLimits[2] = {0x21, 0x01};
const PROGMEM byte rqBattHVContactorCycles[2] = {0x21, 0x02};
const PROGMEM byte rqBattState[2] = {0x21, 0x07};
const PROGMEM byte rqBattSOC[2] = {0x21, 0x08};
const PROGMEM byte rqBattSOCrecal[2] = {0x21, 0x25};
const PROGMEM byte rqBattTemperatures[2] = {0x21, 0x04};
const PROGMEM byte rqBattVoltages_P1[2] = {0x21, 0x41};
const PROGMEM byte rqBattVoltages_P2[2] = {0x21, 0x42};
const PROGMEM byte rqBattOCV_Cal[2] = {0x21, 0x05};
const PROGMEM byte rqBattCellResistance_P1[2] = {0x21, 0x10};
const PROGMEM byte rqBattCellResistance_P2[2] = {0x21, 0x11};
const PROGMEM byte rqBattIsolation[2] = {0x21, 0x29};
const PROGMEM byte rqBattMeas_Capacity[2] = {0x21, 0x0B};
const PROGMEM byte rqBattSN[2] = {0x21, 0xA0};
const PROGMEM byte rqBattCapacity_dSOC_P1[2] = {0x21, 0x12};
const PROGMEM byte rqBattCapacity_dSOC_P2[2] = {0x21, 0x13};
const PROGMEM byte rqBattCapacity_P1[2] = {0x21, 0x14};
const PROGMEM byte rqBattCapacity_P2[2] = {0x21, 0x15};
const PROGMEM byte rqBattBalancing[2] = {0x21, 0x16};
const PROGMEM byte rqBattLogData_P1[2] = {0x21, 0x30};
const PROGMEM byte rqBattProdDate[3] = {0x22, 0x03, 0x04};
*/

#include "ovms_log.h"
static const char *TAG = "v-smarteq";

#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 "vehicle_smarteq.h"


/**
* Incoming poll reply messages
*/
void OvmsVehicleSmartEQ::IncomingPollReply(canbus* bus, uint16_t type, uint16_t pid, uint8_t* data, uint8_t length, uint16_t remain) {
static int last_pid = -1;
static int last_remain = -1;
static uint8_t buf[MAX_POLL_DATA_LEN];
static int bufpos = 0;

int i;

//if (pid == 0xF111) ESP_LOGD(TAG, "IncomingPollReply: pid=%#x len=%d remain=%d", pid, length, remain);

if ( pid != last_pid || remain >= last_remain ) {
// must be a new reply, so reset to the beginning
last_pid=pid;
last_remain=remain;
bufpos=0;
}

if (bufpos == MAX_POLL_DATA_LEN) {
remain=0;
m_poll_ml_remain=0;
} else {
for (i=0; i<length; i++) {
if ( bufpos < sizeof(buf) ) buf[bufpos++] = data[i];
}
}

if (remain==0) {
uint32_t id_pid = m_poll_moduleid_low<<16 | pid;
switch (m_poll_moduleid_low) {
case 0x7BB:
switch (pid) {
case 0x41: // rqBattVoltages_P1
PollReply_BMS_BattVolts(buf, bufpos, 0);
break;
case 0x42: // rqBattVoltages_P2
PollReply_BMS_BattVolts(buf, bufpos, 48);
break;
}
break;
case 0x793:
switch (pid) {
case 0x80: // rqIDpart OBL_7KW_Installed
//PollReply_BMS_BattVolts(buf, bufpos, 0);
break;
}
break;
default:
ESP_LOGI(TAG, "IncomingPollReply: unknown reply module|pid=%#x len=%d", id_pid, bufpos);
break;
}
last_pid=pid;
last_remain=remain;
bufpos=0;
memset(buf, 0, sizeof(buf));
}
}

void OvmsVehicleSmartEQ::PollReply_BMS_BattVolts(uint8_t* reply_data, uint16_t reply_len, uint16_t start) {
float CV;
static bool cellstat = false;

CV = (reply_data[0] * 256 + reply_data[1]);
if (CV == 5120 && start == 0) cellstat = false;
if (CV != 5120 && start == 0) cellstat = true;

if (cellstat) {
for(uint16_t n = 0; n < CELLCOUNT; n = n + 2){
CV = (reply_data[n] * 256 + reply_data[n + 1]);
CV = CV / 1024.0 * 1000;
BmsSetCellVoltage((n/2)+start, CV);
//ESP_LOGV(TAG, "CellVoltage: id=%d len=%F", (n/2)+start, CV);
}
}
}
/*
this->ReadCellVoltage(data, 3, CELLCOUNT / 2);
void canDiag::ReadCellVoltage(byte data_in[], uint16_t highOffset, uint16_t length) {
uint16_t CV;
for (uint16_t n = 0; n < (length * 2); n = n + 2) {
CV = (data_in[n + highOffset] * 256 + data_in[n + highOffset + 1]);
CV = CV / 1024.0 * 1000;
CellVoltage.push(CV);
}
}
*/

0 comments on commit 328c598

Please sign in to comment.