Skip to content

Commit 6153b99

Browse files
authored
Merge pull request #1440 from zorgms/bms_part_info
smartEQ: Restructure BMS metrics and adjust polling
2 parents 8667c11 + 87ec17e commit 6153b99

11 files changed

Lines changed: 140 additions & 177 deletions

File tree

vehicle/OVMS.V3/components/vehicle_smarteq/docs/index.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ xsq.v.reset.speed Average trip speed (reset) [km/h]
180180
xsq.v.start.time Time since start [hh:mm]
181181
xsq.v.start.distance Trip distance since start [km]
182182
xsq.adc.factor Current ADC factor for 12V calculation [float]
183-
xsq.adc.factor.history Last calculated ADC factors (ring buffer) - persistent
183+
xsq.adc.factor.history Last calculated ADC factors (ring buffer)
184184
xsq.poll.state Current poll state (OFF/ON/RUNNING/CHARGING)
185185
xsq.ed4.values ED4scan: number of cells to show
186186
xsq.ddt4all.canbyte DDT4all CAN response bytes [hex string]
@@ -210,7 +210,7 @@ xsq.obl.misc OBL miscellaneous data vector: [0]=freq(H
210210
xsq.obl.leakdiag OBL leakage diagnostic status
211211
xsq.bms.prod.data BMS production data formatted (serial, MM/YYYY)
212212
xsq.bms.temps BMS temperature sensors vector [°C]
213-
xsq.bms.voltages BMS voltage values vector: [0]=cell_min(V), [1]=cell_max(V), [2]=cell_mean(V), [3]=link_volt(V), [4]=pack_volt(V), [5]=ocv_volt(V), [6]=12v_system(V)
213+
xsq.bms.voltages BMS voltage values vector: [0]=cell_min(V), [1]=cell_max(V), [2]=cell_mean(V), [3]=cell_sum(V), [4]=pack_volt(V), [5]=traction_link_volt(V), [6]=12v_bms_clamp30(V), [7]=Open Circuit 12V(V)
214214
xsq.bms.contactor.cycles HV contactor cycles vector: [0]=max, [1]=now, [2]=consumed, [3]=diff, [4]=1h_count - persistent
215215
xsq.bms.soc.values SOC values vector [0]=kernel, [1]=real, [2]=min, [3]=max, [4]=display [%]
216216
xsq.bms.soc.recal.state SOC recalibration state
@@ -234,8 +234,7 @@ xsq.bms.id.sw.version BMS Software Version (SoftwareNumber hex)
234234
xsq.bms.id.basic.parts BMS BasicPartList (PN/HW/Approval hex)
235235
xsq.bms.id.mfr BMS Manufacturer Identification Code
236236
xsq.12v.trickle.count 12V trickle charge counted in 24h, reset to 0 after 24h. Alert if count == 3 in 24h [count] - persistent
237-
xsq.12v.undervolt.history 12V undervoltage history [<timestamp>=<12V>]
238-
xsq.12v.undervolt.history.vec 12V undervoltage history vector (<12V>) - persistent
237+
xsq.12v.undervolt.history 12V undervoltage history vector (<12V>)
239238
=========================== ==============
240239

241240
-------------------------

vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_can_poll.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void OvmsVehicleSmartEQ::PollReply_BMS_SOC(const char* data, uint16_t reply_len)
449449
ocv = 0.0f;
450450
if(cap_loss < 0.0f || cap_loss > 100.0f)
451451
cap_loss = 0.0f;
452-
mt_bms_voltages->SetElemValue(5, ocv); // ocv_voltage
452+
mt_bms_voltages->SetElemValue(7, ocv); // ocv_voltage
453453
mt_bms_soc_values->SetElemValue(0, soc); // kernel SOC
454454
mt_bms_soc_values->SetElemValue(1, (real_soc_min + real_soc_max) / 2.0f); // real SOC
455455
mt_bms_soc_values->SetElemValue(2, real_soc_min); // SOC min
@@ -692,11 +692,10 @@ void OvmsVehicleSmartEQ::PollReply_BMS_BattState(const char* data, uint16_t repl
692692

693693
mt_bms_voltages->SetElemValue(0, v_cell_min); // cv_min
694694
mt_bms_voltages->SetElemValue(1, v_cell_max); // cv_max
695-
mt_bms_voltages->SetElemValue(2, (v_cell_min + v_cell_max) / 2.0f); // cv_mean
696-
697-
mt_bms_voltages->SetElemValue(3, v_link); // link
695+
mt_bms_voltages->SetElemValue(2, (v_cell_min + v_cell_max) / 2.0f); // cv_mean
696+
mt_bms_voltages->SetElemValue(3, cv_sum_raw); // cv_sum (HV)
698697
mt_bms_voltages->SetElemValue(4, v_pack_term); // contactor
699-
mt_bms_voltages->SetElemValue(5, cv_sum_raw); // cv_sum (HV)
698+
mt_bms_voltages->SetElemValue(5, v_link); // traction link 12V
700699

701700
// P = V × I (in kW)
702701
float pack_power_kw = (v_pack_term * i_pack) / 1000.0f;
@@ -813,10 +812,12 @@ void OvmsVehicleSmartEQ::PollReply_BCM_TPMS_InputCapt(const char* data, uint16_t
813812
{
814813
// Pressure: big-endian 16 bit *0.75 kPa
815814
uint16_t praw = CAN_UINT(8 + (i*2));
816-
m_tpms_pressure[i] = (float)praw != 0xffff ? (float)praw * 0.75f : 0.0f;
815+
if (praw != 0xffff)
816+
m_tpms_pressure[i] = (float)praw * 0.75f; // only valid values, 0xffff = invalid
817817
// Temperature: raw byte + offset -30.0
818818
uint16_t traw = (uint16_t)(uint8_t)CAN_BYTE(16 + i);
819-
m_tpms_temperature[i] = traw != 0xffff ? (float)traw - 30.0f : 0.0f;
819+
if (traw != 0xffff)
820+
m_tpms_temperature[i] = (float)traw - 30.0f; // only valid values, 0xffff = invalid
820821
m_tpms_lowbatt[i] = static_cast<bool>((raw >> i) & 0x01);
821822
}
822823
}

vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_commands.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandPreset(int verbosity,
562562
"obdii_7e4",
563563
"obdii_7e4_modify",
564564
"basic_tpms",
565-
"calc.adcfactor.samples"
565+
"calc.adcfactor.samples",
566+
"cell_interval_drv",
567+
"cell_interval_chg",
566568
};
567569

568570
int removed_count = 0;

vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_features.cpp

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ void OvmsVehicleSmartEQ::ReCalcADCfactor(float can12V, OvmsWriter* writer) {
274274
MyConfig.SetParamValueBool("xsq", "calc.adcfactor", false);
275275
}
276276
if (writer) writer->printf("New ADC factor stored: %.3f (prev %.3f, history size %u)\n", adc_factor_new, adc_factor_prev, (unsigned)n);
277+
// Send data log XSQ-ADC-FactorLog
278+
// V1: <new factor>,<prev factor>
279+
MyNotify.NotifyStringf("data", "xsq.adc.log.factor", "XSQ-ADC-FactorLog,1,%d,%.3f,%.3f", 86400 * 30, adc_factor_new, adc_factor_prev);
277280
#else
278281
ESP_LOGD(TAG, "ADC support not enabled");
279282
if (writer) writer->puts("ADC support not enabled");
@@ -318,48 +321,21 @@ void OvmsVehicleSmartEQ::DoorOpenState() {
318321

319322
void OvmsVehicleSmartEQ::smart12VHistory()
320323
{
321-
// On first call after reboot: restore previous entries from persistent vec metric
322-
if (m_12v_undervolt_history.empty())
323-
{
324-
size_t vn = mt_12v_undervolt_history_vec->GetSize();
325-
for (size_t i = 0; i < vn && i < 10; ++i)
326-
{
327-
float v = mt_12v_undervolt_history_vec->GetElemValue(i);
328-
if (v > 0.0f)
329-
{
330-
char entry[16];
331-
snprintf(entry, sizeof(entry), "reboot=%.2fV", v);
332-
m_12v_undervolt_history.push_back(entry);
333-
}
334-
}
335-
}
336-
float volt = StdMetrics.ms_v_bat_12v_voltage->AsFloat(0.0f);
337-
time_t ts = (time_t)StdMetrics.ms_m_timeutc->AsInt();
338-
if (ts < 86400) // UTC not yet synced (still at/near 1970-01-01)
339-
{
340-
ESP_LOGD(TAG, "smart12VHistory: UTC time not synced, skipping entry");
341-
m_12v_alerted = false;
342-
return;
343-
}
344-
struct tm t;
345-
localtime_r(&ts, &t);
346-
char buf[32];
347-
strftime(buf, sizeof(buf)-8, "%Y-%m-%dT%H:%M:%S", &t);
348-
snprintf(buf + 19, sizeof(buf) - 19, "=%.2fV", volt);
349-
m_12v_undervolt_history.push_back(buf);
324+
float volt = StdMetrics.ms_v_bat_12v_voltage->AsFloat(0.0f);
325+
float bms12v = mt_bms_voltages->GetElemValue(6); // 12V BMS clamp 30
326+
float usm12v = mt_evc_dcdc->GetElemValue(3); // 12V USM voltage
327+
m_12v_undervolt_history.push_back(volt);
350328
if (m_12v_undervolt_history.size() > 10)
351329
m_12v_undervolt_history.pop_front();
352-
std::string hist_str;
353-
float hist_vec[10];
330+
float hist[10];
354331
size_t n = m_12v_undervolt_history.size();
355-
for (size_t i=0; i<n; ++i)
356-
{
357-
if (i > 0) hist_str += '|';
358-
hist_str += m_12v_undervolt_history[i];
359-
hist_vec[i] = atof(strchr(m_12v_undervolt_history[i].c_str(), '=') + 1);
360-
}
361-
mt_12v_undervolt_history->SetValue(hist_str);
362-
mt_12v_undervolt_history_vec->SetElemValues(0, n, hist_vec);
332+
for (size_t i = 0; i < n; ++i)
333+
hist[i] = m_12v_undervolt_history[i];
334+
if (n > 0)
335+
mt_12v_undervolt_history->SetElemValues(0, n, hist);
336+
// Send data log XSQ-12V-undervoltagelog
337+
// V1: <12Vvoltage>,<USM12V>,<BMS12V>
338+
MyNotify.NotifyStringf("data", "xsq.12v.log.undervoltage", "XSQ-12V-undervoltagelog,1,%d,%.2f,%.2f,%.2f", 86400 * 30, volt, usm12v, bms12v);
363339
}
364340

365341
void OvmsVehicleSmartEQ::smartOn()
@@ -416,7 +392,7 @@ void OvmsVehicleSmartEQ::smartSleep()
416392

417393
void OvmsVehicleSmartEQ::smartChargeStart()
418394
{
419-
smartCoolDownPolling(20);
395+
smartCoolDownPolling(15);
420396
if (m_charge_finished)
421397
{
422398
ResetChargingValues();

vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_handle.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,8 @@ void OvmsVehicleSmartEQ::HandleOBDpolling() {
125125
if (m_obdii_745_tpms && IsOnEQ()) // full TPMS mode with individual pressure/temp/alert status for each wheel
126126
m_poll_vector.insert(m_poll_vector.end(), obdii_745_tpms_polls, endof_array(obdii_745_tpms_polls));
127127

128-
if (m_obdii_79b_cell) // 79b PIDs cell V/R/T values with configurable intervals
129-
{
130-
for (const auto& p79bcell : obdii_79b_cell_vrt_polls)
131-
{
132-
OvmsPoller::poll_pid_t p79bcell_mod = p79bcell;
133-
p79bcell_mod.polltime[2] = m_cfg_cell_interval_drv;
134-
p79bcell_mod.polltime[3] = m_cfg_cell_interval_chg;
135-
m_poll_vector.push_back(p79bcell_mod);
136-
}
137-
}
128+
if (m_obdii_79b_cell) // 79b PIDs cell V/R/T values
129+
m_poll_vector.insert(m_poll_vector.end(), obdii_79b_cell_vrt_polls, endof_array(obdii_79b_cell_vrt_polls));
138130

139131
if (m_obdii_7e4_dcdc) // 7e4 PIDs DCDC
140132
m_poll_vector.insert(m_poll_vector.end(), obdii_7e4_dcdc_polls, endof_array(obdii_7e4_dcdc_polls));

vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_notify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandED4scan(int verbosity,
253253
writer->printf(" Manufacturer ID: %s\n", mt_bms_mfr_id->AsString().c_str());
254254

255255
writer->puts("\n--- SOC Kernel Data (PID 0x08) ---");
256-
writer->printf(" Open Circuit Voltage: %.2f V\n", mt_bms_voltages->GetElemValue(5));
257256
writer->printf(" Real SOC (Min): %.2f%%\n", mt_bms_soc_values->GetElemValue(2));
258257
writer->printf(" Real SOC (Max): %.2f%%\n", mt_bms_soc_values->GetElemValue(3));
259258
writer->printf(" Kernel SOC: %.2f%%\n", mt_bms_soc_values->GetElemValue(0));
260259
writer->printf(" Capacity Loss: %.2f%%\n", mt_bms_cap->GetElemValue(3));
261260
writer->printf(" Initial Capacity: %.2f Ah\n", mt_bms_cap->GetElemValue(1));
262261
writer->printf(" Estimated Capacity: %.2f Ah\n", mt_bms_cap->GetElemValue(2));
263262
writer->printf(" Voltage State: %s\n", mt_bms_voltage_state->AsString().c_str());
263+
writer->printf(" Open Circuit 12V: %.2f V\n", mt_bms_voltages->GetElemValue(7));
264264

265265
writer->puts("\n--- SOC Recalibration (PID 0x25) ---");
266266
writer->printf(" Recalibration State: %s\n", mt_bms_soc_recal_state->AsString().c_str());
@@ -270,13 +270,14 @@ OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandED4scan(int verbosity,
270270
writer->puts("\n--- Battery State (PID 0x07) ---");
271271
writer->printf(" Cell Voltage Min: %.3f V\n", mt_bms_voltages->GetElemValue(0));
272272
writer->printf(" Cell Voltage Max: %.3f V\n", mt_bms_voltages->GetElemValue(1));
273-
writer->printf(" Cell Voltage Mean: %.3f V\n", mt_bms_voltages->GetElemValue(2));
274-
writer->printf(" Link Voltage: %.2f V\n", mt_bms_voltages->GetElemValue(3));
273+
writer->printf(" Cell Voltage Mean: %.3f V\n", mt_bms_voltages->GetElemValue(2));
274+
writer->printf(" Cell Voltage sum: %.2f V\n", mt_bms_voltages->GetElemValue(3));
275275
writer->printf(" Pack Voltage: %.2f V\n", mt_bms_voltages->GetElemValue(4));
276276
writer->printf(" Pack Current: %.2f A\n", StdMetrics.ms_v_bat_current->AsFloat());
277277
writer->printf(" Pack Power: %.2f kW\n", StdMetrics.ms_v_bat_power->AsFloat());
278278
writer->printf(" Contactor State: %s\n", mt_bms_HVcontactStateTXT->AsString().c_str());
279279
writer->printf(" Vehicle Mode: %s\n", mt_bms_EVmode_txt->AsString().c_str());
280+
writer->printf(" Traction Link Voltage: %.2f V\n", mt_bms_voltages->GetElemValue(5));
280281
writer->printf(" BMS 12V Voltage: %.2f V\n", mt_bms_voltages->GetElemValue(6));
281282

282283
writer->puts("\n--- EVC Data (0x7EC) ---");

0 commit comments

Comments
 (0)