mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
Merge pull request #1476 from dalathegreat/improvement/even-more-common-image-settings
Improvement: Remove old method to compile, all is now Common Image
This commit is contained in:
commit
955688fec0
102 changed files with 370 additions and 655 deletions
|
@ -3,10 +3,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "RS485Battery.h"
|
||||
|
||||
#if !defined(COMMON_IMAGE) && !defined(SELECTED_BATTERY_CLASS)
|
||||
#error No battery selected! Choose one from the USER_SETTINGS.h file or build COMMON_IMAGE.
|
||||
#endif
|
||||
|
||||
Battery* battery = nullptr;
|
||||
Battery* battery2 = nullptr;
|
||||
|
||||
|
@ -149,11 +145,6 @@ const battery_chemistry_enum battery_chemistry_default = battery_chemistry_enum:
|
|||
|
||||
battery_chemistry_enum user_selected_battery_chemistry = battery_chemistry_default;
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
#ifdef SELECTED_BATTERY_CLASS
|
||||
#error "Compile time SELECTED_BATTERY_CLASS should not be defined with COMMON_IMAGE"
|
||||
#endif
|
||||
|
||||
BatteryType user_selected_battery_type = BatteryType::NissanLeaf;
|
||||
bool user_selected_second_battery = false;
|
||||
|
||||
|
@ -287,39 +278,6 @@ void setup_battery() {
|
|||
}
|
||||
}
|
||||
}
|
||||
#else // Battery selection has been made at build-time
|
||||
|
||||
void setup_battery() {
|
||||
// Instantiate the battery only once just in case this function gets called multiple times.
|
||||
if (battery == nullptr) {
|
||||
#ifdef TESLA_MODEL_3Y_BATTERY
|
||||
battery = new SELECTED_BATTERY_CLASS(user_selected_battery_chemistry);
|
||||
#else
|
||||
battery = new SELECTED_BATTERY_CLASS();
|
||||
#endif
|
||||
}
|
||||
battery->setup();
|
||||
|
||||
#ifdef DOUBLE_BATTERY
|
||||
if (battery2 == nullptr) {
|
||||
#if defined(BMW_I3_BATTERY)
|
||||
battery2 =
|
||||
new SELECTED_BATTERY_CLASS(&datalayer.battery2, &datalayer.system.status.battery2_allowed_contactor_closing,
|
||||
can_config.battery_double, esp32hal->WUP_PIN2());
|
||||
#elif defined(KIA_HYUNDAI_64_BATTERY)
|
||||
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, &datalayer_extended.KiaHyundai64_2,
|
||||
&datalayer.system.status.battery2_allowed_contactor_closing,
|
||||
can_config.battery_double);
|
||||
#elif defined(SANTA_FE_PHEV_BATTERY) || defined(TEST_FAKE_BATTERY)
|
||||
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, can_config.battery_double);
|
||||
#else
|
||||
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, nullptr, can_config.battery_double);
|
||||
#endif
|
||||
}
|
||||
battery2->setup();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* User-selected Tesla settings */
|
||||
bool user_selected_tesla_digital_HVIL = false;
|
||||
|
@ -329,7 +287,7 @@ uint16_t user_selected_tesla_GTW_mapRegion = 2;
|
|||
uint16_t user_selected_tesla_GTW_chassisType = 2;
|
||||
uint16_t user_selected_tesla_GTW_packEnergy = 1;
|
||||
|
||||
// Use 0V for user selected cell/pack voltage defaults (COMMON_IMAGE will replace with saved values from NVM)
|
||||
// Use 0V for user selected cell/pack voltage defaults (On boot will be replaced with saved values from NVM)
|
||||
uint16_t user_selected_max_pack_voltage_dV = 0;
|
||||
uint16_t user_selected_min_pack_voltage_dV = 0;
|
||||
uint16_t user_selected_max_cell_voltage_mV = 0;
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include "BMW-I3-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef BMW_I3_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BmwI3Battery
|
||||
#endif
|
||||
|
||||
class BmwI3Battery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -37,7 +37,7 @@ uint8_t BmwIXBattery::increment_alive_counter(uint8_t counter) {
|
|||
return counter;
|
||||
}
|
||||
|
||||
static byte increment_C0_counter(byte counter) {
|
||||
static uint8_t increment_C0_counter(uint8_t counter) {
|
||||
counter++;
|
||||
// Reset to 0xF0 if it exceeds 0xFE
|
||||
if (counter > 0xFE) {
|
||||
|
@ -459,10 +459,12 @@ void BmwIXBattery::setup(void) { // Performs one time setup at startup
|
|||
|
||||
void BmwIXBattery::HandleIncomingUserRequest(void) {
|
||||
// Debug user request to open or close the contactors
|
||||
logging.print("User request: contactor close: ");
|
||||
logging.print(userRequestContactorClose);
|
||||
logging.print(" User request: contactor open: ");
|
||||
logging.println(userRequestContactorOpen);
|
||||
if (userRequestContactorClose) {
|
||||
logging.printf("User request: contactor close");
|
||||
}
|
||||
if (userRequestContactorOpen) {
|
||||
logging.printf("User request: contactor open");
|
||||
}
|
||||
if ((userRequestContactorClose == false) && (userRequestContactorOpen == false)) {
|
||||
// do nothing
|
||||
} else if ((userRequestContactorClose == true) && (userRequestContactorOpen == false)) {
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "BMW-IX-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef BMW_IX_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BmwIXBattery
|
||||
#endif
|
||||
|
||||
class BmwIXBattery : public CanBattery {
|
||||
public:
|
||||
BmwIXBattery() : renderer(*this) {}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "BMW-PHEV-BATTERY.h"
|
||||
#include <Arduino.h>
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
@ -149,15 +150,6 @@ uint8_t BmwPhevBattery::increment_alive_counter(uint8_t counter) {
|
|||
return counter;
|
||||
}
|
||||
|
||||
static byte increment_0C0_counter(byte counter) {
|
||||
counter++;
|
||||
// Reset to 0xF0 if it exceeds 0xFE
|
||||
if (counter > 0xFE) {
|
||||
counter = 0xF0;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
void BmwPhevBattery::processCellVoltages() {
|
||||
const int startByte = 3; // Start reading at byte 3
|
||||
const int numVoltages = 96; // Number of cell voltage values to process
|
||||
|
@ -469,7 +461,7 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
#endif // DEBUG_LOG && UDS_LOG
|
||||
transmit_can_frame(&BMW_6F1_REQUEST_CONTINUE_MULTIFRAME);
|
||||
gUDSContext.receivedInBatch = 0; // Reset batch count
|
||||
Serial.println("Sent FC for next batch of 3 frames.");
|
||||
logging.println("Sent FC for next batch of 3 frames.");
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -513,18 +505,18 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
battery_current = ((int32_t)((gUDSContext.UDS_buffer[3] << 24) | (gUDSContext.UDS_buffer[4] << 16) |
|
||||
(gUDSContext.UDS_buffer[5] << 8) | gUDSContext.UDS_buffer[6])) *
|
||||
0.1;
|
||||
logging.print("Received current/amps measurement data: ");
|
||||
logging.printf("Received current/amps measurement data: ");
|
||||
logging.print(battery_current);
|
||||
logging.print(" - ");
|
||||
logging.printf(" - ");
|
||||
for (uint16_t i = 0; i < gUDSContext.UDS_bytesReceived; i++) {
|
||||
// Optional leading zero for single-digit hex
|
||||
if (gUDSContext.UDS_buffer[i] < 0x10) {
|
||||
logging.print("0");
|
||||
logging.printf("0");
|
||||
}
|
||||
logging.print(gUDSContext.UDS_buffer[i], HEX);
|
||||
logging.print(" ");
|
||||
logging.printf(" ");
|
||||
}
|
||||
logging.println(); // new line at the end
|
||||
logging.println(""); // new line at the end
|
||||
}
|
||||
|
||||
//Cell Min/Max
|
||||
|
@ -540,14 +532,14 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
max_cell_voltage = (gUDSContext.UDS_buffer[11] << 8 | gUDSContext.UDS_buffer[12]) / 10;
|
||||
} else {
|
||||
logging.println("Cell Min Max Invalid 65535 or 0...");
|
||||
logging.print("Received data: ");
|
||||
logging.printf("Received data: ");
|
||||
for (uint16_t i = 0; i < gUDSContext.UDS_bytesReceived; i++) {
|
||||
// Optional leading zero for single-digit hex
|
||||
if (gUDSContext.UDS_buffer[i] < 0x10) {
|
||||
logging.print("0");
|
||||
logging.printf("0");
|
||||
}
|
||||
logging.print(gUDSContext.UDS_buffer[i], HEX);
|
||||
logging.print(" ");
|
||||
logging.printf(" ");
|
||||
}
|
||||
logging.println(); // new line at the end
|
||||
}
|
||||
|
@ -678,7 +670,7 @@ void BmwPhevBattery::transmit_can(unsigned long currentMillis) {
|
|||
}
|
||||
|
||||
void BmwPhevBattery::setup(void) { // Performs one time setup at startup
|
||||
strncpy(datalayer.system.info.battery_protocol, "BMW PHEV Battery", 63);
|
||||
strncpy(datalayer.system.info.battery_protocol, Name, 63);
|
||||
datalayer.system.info.battery_protocol[63] = '\0';
|
||||
//Wakeup the SME
|
||||
wake_battery_via_canbus();
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "BMW-PHEV-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef BMW_PHEV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BmwPhevBattery
|
||||
#endif
|
||||
|
||||
class BmwPhevBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
@ -14,6 +10,8 @@ class BmwPhevBattery : public CanBattery {
|
|||
virtual void update_values();
|
||||
virtual void transmit_can(unsigned long currentMillis);
|
||||
|
||||
static constexpr const char* Name = "BMW PHEV Battery";
|
||||
|
||||
BatteryHtmlRenderer& get_status_renderer() { return renderer; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "BOLT-AMPERA-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "BOLT-AMPERA-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef BOLT_AMPERA_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BoltAmperaBattery
|
||||
#endif
|
||||
|
||||
class BoltAmperaBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "BYD-ATTO-3-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -24,9 +24,6 @@ static const int RAMPDOWN_POWER_ALLOWED =
|
|||
10000; // Power to start ramp down from, set a lower value to limit the power even further as SOC decreases
|
||||
|
||||
/* Do not modify the rows below */
|
||||
#ifdef BYD_ATTO_3_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BydAttoBattery
|
||||
#endif
|
||||
|
||||
class BydAttoBattery : public CanBattery {
|
||||
public:
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "CELLPOWER-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef CELLPOWER_BMS
|
||||
#define SELECTED_BATTERY_CLASS CellPowerBms
|
||||
#endif
|
||||
|
||||
class CellPowerBms : public CanBattery {
|
||||
public:
|
||||
CellPowerBms() : CanBattery(CAN_Speed::CAN_SPEED_250KBPS) {}
|
||||
|
|
|
@ -120,7 +120,7 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) {
|
|||
uint8_t chargingrate = 0;
|
||||
if (x100_chg_lim.ConstantOfChargingRateIndication > 0) {
|
||||
chargingrate = x102_chg_session.StateOfCharge / x100_chg_lim.ConstantOfChargingRateIndication * 100;
|
||||
logging.print("Charge Rate (kW): ");
|
||||
logging.printf("Charge Rate (kW): ");
|
||||
logging.println(chargingrate);
|
||||
}
|
||||
|
||||
|
@ -220,9 +220,9 @@ void ChademoBattery::process_vehicle_charging_limits(CAN_frame rx_frame) {
|
|||
|
||||
if (get_measured_voltage() <= x200_discharge_limits.MinimumDischargeVoltage && CHADEMO_Status > CHADEMO_NEGOTIATE) {
|
||||
logging.println("x200 minimum discharge voltage met or exceeded, stopping.");
|
||||
logging.print("Measured: ");
|
||||
logging.printf("Measured: ");
|
||||
logging.print(get_measured_voltage());
|
||||
logging.print("Minimum voltage: ");
|
||||
logging.printf("Minimum voltage: ");
|
||||
logging.print(x200_discharge_limits.MinimumDischargeVoltage);
|
||||
CHADEMO_Status = CHADEMO_STOP;
|
||||
}
|
||||
|
@ -240,9 +240,9 @@ void ChademoBattery::process_vehicle_discharge_estimate(CAN_frame rx_frame) {
|
|||
|
||||
if (currentMillis - previousMillis5000 >= INTERVAL_5_S) {
|
||||
previousMillis5000 = currentMillis;
|
||||
logging.print("x201 availabile vehicle energy, completion time: ");
|
||||
logging.printf("x201 availabile vehicle energy, completion time: ");
|
||||
logging.println(x201_discharge_estimate.AvailableVehicleEnergy);
|
||||
logging.print("x201 approx vehicle completion time: ");
|
||||
logging.printf("x201 approx vehicle completion time: ");
|
||||
logging.println(x201_discharge_estimate.ApproxDischargeCompletionTime);
|
||||
}
|
||||
}
|
||||
|
@ -766,7 +766,7 @@ void ChademoBattery::handle_chademo_sequence() {
|
|||
/* check whether contactors ready, because externally dependent upon inverter allow during discharge */
|
||||
if (contactors_ready) {
|
||||
logging.println("Contactors ready");
|
||||
logging.print("Voltage: ");
|
||||
logging.printf("Voltage: ");
|
||||
logging.println(get_measured_voltage());
|
||||
/* transition to POWERFLOW state if discharge compatible on both sides */
|
||||
if (x109_evse_state.discharge_compatible && x102_chg_session.s.status.StatusVehicleDischargeCompatible &&
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
#include "CHADEMO-BATTERY-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef CHADEMO_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS ChademoBattery
|
||||
#endif
|
||||
|
||||
class ChademoBattery : public CanBattery {
|
||||
public:
|
||||
ChademoBattery() {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "CHADEMO-BATTERY.h"
|
||||
#include "src/devboard/utils/logging.h"
|
||||
|
||||
/* Initial frames received from ISA shunts provide invalid during initialization */
|
||||
static int framecount = 0;
|
||||
|
@ -87,17 +86,6 @@ void ISA_handleFrame(CAN_frame* frame) {
|
|||
|
||||
case 0x510:
|
||||
case 0x511:
|
||||
logging.print(millis()); // Example printout, time, ID, length, data: 7553 1DB 8 FF C0 B9 EA 0 0 2 5D
|
||||
logging.print(" ");
|
||||
logging.print(frame->ID, HEX);
|
||||
logging.print(" ");
|
||||
logging.print(frame->DLC);
|
||||
logging.print(" ");
|
||||
for (int i = 0; i < frame->DLC; ++i) {
|
||||
logging.print(frame->data.u8[i], HEX);
|
||||
logging.print(" ");
|
||||
}
|
||||
logging.println("");
|
||||
break;
|
||||
|
||||
case 0x521:
|
||||
|
@ -245,7 +233,7 @@ void ISA_initialize() {
|
|||
ISA_STOP();
|
||||
delay(500);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
logging.print("ISA Initialization ");
|
||||
logging.printf("ISA Initialization ");
|
||||
logging.println(i);
|
||||
|
||||
outframe.data.u8[0] = (0x20 + i);
|
||||
|
@ -382,7 +370,7 @@ void ISA_initCurrent() {
|
|||
}
|
||||
|
||||
void ISA_getCONFIG(uint8_t i) {
|
||||
logging.print("ISA Get Config ");
|
||||
logging.printf("ISA Get Config ");
|
||||
logging.println(i);
|
||||
|
||||
outframe.data.u8[0] = (0x60 + i);
|
||||
|
@ -398,7 +386,7 @@ void ISA_getCONFIG(uint8_t i) {
|
|||
}
|
||||
|
||||
void ISA_getCAN_ID(uint8_t i) {
|
||||
logging.print("ISA Get CAN ID ");
|
||||
logging.printf("ISA Get CAN ID ");
|
||||
logging.println(i);
|
||||
|
||||
outframe.data.u8[0] = (0x50 + i);
|
||||
|
@ -418,8 +406,8 @@ void ISA_getCAN_ID(uint8_t i) {
|
|||
}
|
||||
|
||||
void ISA_getINFO(uint8_t i) {
|
||||
logging.print("ISA Get INFO ");
|
||||
logging.println(i, HEX);
|
||||
logging.printf("ISA Get INFO ");
|
||||
logging.println(i);
|
||||
|
||||
outframe.data.u8[0] = (0x70 + i);
|
||||
outframe.data.u8[1] = 0x00;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "CMFA-EV-BATTERY.h"
|
||||
#include <cstring> //unit tests memcpy
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CMFA-EV-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef CMFA_EV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS CmfaEvBattery
|
||||
#endif
|
||||
|
||||
class CmfaEvBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -16,7 +16,7 @@ static uint16_t voltage_dV = 0;
|
|||
static uint32_t remaining_capacity_mAh = 0;
|
||||
static uint16_t cellvoltages_mV[48] = {0};
|
||||
static uint16_t cellvoltage_min_mV = 3700;
|
||||
static uint16_t cellvoltage_max_mV = 3700;
|
||||
static uint16_t cellvoltage_max_mV = 0;
|
||||
static uint16_t cell_count = 0;
|
||||
static uint16_t SOC = 0;
|
||||
static bool has_fault = false;
|
||||
|
@ -109,12 +109,12 @@ uint32_t decode_uint32be(uint8_t data[8], uint8_t offset) {
|
|||
}
|
||||
|
||||
void dump_buff(const char* msg, uint8_t* buff, uint8_t len) {
|
||||
logging.print("[DALY-BMS] ");
|
||||
logging.print(msg);
|
||||
logging.printf("[DALY-BMS] ");
|
||||
logging.printf(msg);
|
||||
for (int i = 0; i < len; i++) {
|
||||
logging.print(buff[i] >> 4, HEX);
|
||||
logging.print(buff[i] & 0xf, HEX);
|
||||
logging.print(" ");
|
||||
logging.printf(" ");
|
||||
}
|
||||
logging.println();
|
||||
}
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "RS485Battery.h"
|
||||
|
||||
#ifdef DALY_BMS
|
||||
#define SELECTED_BATTERY_CLASS DalyBms
|
||||
#endif
|
||||
|
||||
class DalyBms : public RS485Battery {
|
||||
public:
|
||||
void setup();
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "ECMP-HTML.h"
|
||||
|
||||
#ifdef STELLANTIS_ECMP_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS EcmpBattery
|
||||
#endif
|
||||
|
||||
class EcmpBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "FOXESS-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define FOXESS_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef FOXESS_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS FoxessBattery
|
||||
#endif
|
||||
|
||||
class FoxessBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "GEELY-GEOMETRY-C-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "GEELY-GEOMETRY-C-HTML.h"
|
||||
|
||||
#ifdef GEELY_GEOMETRY_C_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS GeelyGeometryCBattery
|
||||
#endif
|
||||
|
||||
class GeelyGeometryCBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _GEELY_GEOMETRY_C_HTML_H
|
||||
#define _GEELY_GEOMETRY_C_HTML_H
|
||||
|
||||
#include <cstring> //For unit test
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
#include "../devboard/webserver/BatteryHtmlRenderer.h"
|
||||
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "HYUNDAI-IONIQ-28-BATTERY-HTML.h"
|
||||
|
||||
#ifdef HYUNDAI_IONIQ_28_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS HyundaiIoniq28Battery
|
||||
#endif
|
||||
|
||||
class HyundaiIoniq28Battery : public CanBattery {
|
||||
public:
|
||||
// Use the default constructor to create the first or single battery.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "IMIEV-CZERO-ION-BATTERY.h"
|
||||
#include <cstring> //for unit tests
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
@ -76,17 +77,8 @@ void ImievCZeroIonBattery::
|
|||
|
||||
if (!BMU_Detected) {
|
||||
logging.println("BMU not detected, check wiring!");
|
||||
//TODO: Raise event
|
||||
}
|
||||
|
||||
logging.println("Battery Values");
|
||||
logging.print("BMU SOC: ");
|
||||
logging.print(BMU_SOC);
|
||||
logging.print(" BMU Current: ");
|
||||
logging.print(BMU_Current);
|
||||
logging.print(" BMU Battery Voltage: ");
|
||||
logging.print(BMU_PackVoltage);
|
||||
logging.print(" BMU_Power: ");
|
||||
logging.print(BMU_Power);
|
||||
}
|
||||
|
||||
void ImievCZeroIonBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define IMIEV_CZERO_ION_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef IMIEV_CZERO_ION_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS ImievCZeroIonBattery
|
||||
#endif
|
||||
|
||||
class ImievCZeroIonBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "JAGUAR-IPACE-BATTERY.h"
|
||||
#include <cstring> //for unit tests
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
@ -57,9 +58,9 @@ CAN_frame ipace_keep_alive = {.FD = false,
|
|||
.data = {0x9E, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};*/
|
||||
|
||||
static void print_units(const char* header, int value, const char* units) {
|
||||
logging.print(header);
|
||||
logging.print(value);
|
||||
logging.print(units);
|
||||
logging.printf(header);
|
||||
logging.printf("%d", value);
|
||||
logging.printf(units);
|
||||
}
|
||||
|
||||
void JaguarIpaceBattery::update_values() {
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef JAGUAR_IPACE_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS JaguarIpaceBattery
|
||||
#endif
|
||||
|
||||
class JaguarIpaceBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
|
||||
#define ESTIMATE_SOC_FROM_CELLVOLTAGE
|
||||
|
||||
#ifdef KIA_HYUNDAI_64_FD_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS Kia64FDBattery
|
||||
#endif
|
||||
|
||||
class Kia64FDBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -55,18 +55,6 @@ uint16_t KiaEGmpBattery::estimateSOC(uint16_t packVoltage, uint16_t cellCount, i
|
|||
// Calculate average cell voltage in millivolts
|
||||
uint16_t avgCellVoltage = compensatedPackVoltageMv / cellCount;
|
||||
|
||||
logging.print("Pack: ");
|
||||
logging.print(packVoltage / 10.0);
|
||||
logging.print("V, Current: ");
|
||||
logging.print(currentAmps / 10.0);
|
||||
logging.print("A, Drop: ");
|
||||
logging.print(voltageDrop / 1000.0);
|
||||
logging.print("V, Comp Pack: ");
|
||||
logging.print(compensatedPackVoltageMv / 1000.0);
|
||||
logging.print("V, Avg Cell: ");
|
||||
logging.print(avgCellVoltage);
|
||||
logging.println("mV");
|
||||
|
||||
// Use the cell voltage lookup table to estimate SOC
|
||||
return estimateSOCFromCell(avgCellVoltage);
|
||||
}
|
||||
|
@ -182,65 +170,6 @@ void KiaEGmpBattery::update_values() {
|
|||
if (leadAcidBatteryVoltage < 110) {
|
||||
set_event(EVENT_12V_LOW, leadAcidBatteryVoltage);
|
||||
}
|
||||
|
||||
/* Safeties verified. Perform USB serial printout if configured to do so */
|
||||
|
||||
logging.println(); //sepatator
|
||||
logging.println("Values from battery: ");
|
||||
logging.print("SOC BMS: ");
|
||||
logging.print((uint16_t)SOC_BMS / 10.0, 1);
|
||||
logging.print("% | SOC Display: ");
|
||||
logging.print((uint16_t)SOC_Display / 10.0, 1);
|
||||
logging.print("% | SOH ");
|
||||
logging.print((uint16_t)batterySOH / 10.0, 1);
|
||||
logging.println("%");
|
||||
logging.print((int16_t)batteryAmps / 10.0, 1);
|
||||
logging.print(" Amps | ");
|
||||
logging.print((uint16_t)batteryVoltage / 10.0, 1);
|
||||
logging.print(" Volts | ");
|
||||
logging.print((int16_t)datalayer.battery.status.active_power_W);
|
||||
logging.println(" Watts");
|
||||
logging.print("Allowed Charge ");
|
||||
logging.print((uint16_t)allowedChargePower * 10);
|
||||
logging.print(" W | Allowed Discharge ");
|
||||
logging.print((uint16_t)allowedDischargePower * 10);
|
||||
logging.println(" W");
|
||||
logging.print("MaxCellVolt ");
|
||||
logging.print(CellVoltMax_mV);
|
||||
logging.print(" mV No ");
|
||||
logging.print(CellVmaxNo);
|
||||
logging.print(" | MinCellVolt ");
|
||||
logging.print(CellVoltMin_mV);
|
||||
logging.print(" mV No ");
|
||||
logging.println(CellVminNo);
|
||||
logging.print("TempHi ");
|
||||
logging.print((int16_t)temperatureMax);
|
||||
logging.print("°C TempLo ");
|
||||
logging.print((int16_t)temperatureMin);
|
||||
logging.print("°C WaterInlet ");
|
||||
logging.print((int8_t)temperature_water_inlet);
|
||||
logging.print("°C PowerRelay ");
|
||||
logging.print((int8_t)powerRelayTemperature * 2);
|
||||
logging.println("°C");
|
||||
logging.print("Aux12volt: ");
|
||||
logging.print((int16_t)leadAcidBatteryVoltage / 10.0, 1);
|
||||
logging.println("V | ");
|
||||
logging.print("BmsManagementMode ");
|
||||
logging.print((uint8_t)batteryManagementMode, BIN);
|
||||
if (bitRead((uint8_t)BMS_ign, 2) == 1) {
|
||||
logging.print(" | BmsIgnition ON");
|
||||
} else {
|
||||
logging.print(" | BmsIgnition OFF");
|
||||
}
|
||||
|
||||
if (bitRead((uint8_t)batteryRelay, 0) == 1) {
|
||||
logging.print(" | PowerRelay ON");
|
||||
} else {
|
||||
logging.print(" | PowerRelay OFF");
|
||||
}
|
||||
logging.print(" | Inverter ");
|
||||
logging.print(inverterVoltage);
|
||||
logging.println(" Volts");
|
||||
}
|
||||
|
||||
// Getter implementations for HTML renderer
|
||||
|
@ -321,14 +250,10 @@ void KiaEGmpBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
break;
|
||||
case 0x7EC:
|
||||
// print_canfd_frame(frame);
|
||||
switch (rx_frame.data.u8[0]) {
|
||||
case 0x10: //"PID Header"
|
||||
// logging.println ("Send ack");
|
||||
poll_data_pid = rx_frame.data.u8[4];
|
||||
// if (rx_frame.data.u8[4] == poll_data_pid) {
|
||||
transmit_can_frame(&EGMP_7E4_ack); //Send ack to BMS if the same frame is sent as polled
|
||||
// }
|
||||
transmit_can_frame(&EGMP_7E4_ack); //Send ack to BMS
|
||||
break;
|
||||
case 0x21: //First frame in PID group
|
||||
if (poll_data_pid == 1) {
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
|
||||
#define ESTIMATE_SOC_FROM_CELLVOLTAGE
|
||||
|
||||
#ifdef KIA_E_GMP_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS KiaEGmpBattery
|
||||
#endif
|
||||
|
||||
class KiaEGmpBattery : public CanBattery {
|
||||
public:
|
||||
KiaEGmpBattery() : renderer(*this) {}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "KIA-HYUNDAI-64-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "KIA-HYUNDAI-64-HTML.h"
|
||||
|
||||
#ifdef KIA_HYUNDAI_64_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS KiaHyundai64Battery
|
||||
#endif
|
||||
|
||||
class KiaHyundai64Battery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _KIA_HYUNDAI_64_HTML_H
|
||||
#define _KIA_HYUNDAI_64_HTML_H
|
||||
|
||||
#include <cstring> //For unit test
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
#include "../devboard/webserver/BatteryHtmlRenderer.h"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "KIA-HYUNDAI-HYBRID-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define KIA_HYUNDAI_HYBRID_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef KIA_HYUNDAI_HYBRID_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS KiaHyundaiHybridBattery
|
||||
#endif
|
||||
|
||||
class KiaHyundaiHybridBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "MEB-BATTERY.h"
|
||||
#include <Arduino.h>
|
||||
#include <algorithm> // For std::min and std::max
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../communication/can/obd.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
|
@ -1262,8 +1263,6 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
handle_obd_frame(rx_frame);
|
||||
break;
|
||||
default:
|
||||
logging.printf("Unknown CAN frame received:\n");
|
||||
dump_can_frame(rx_frame, MSG_RX);
|
||||
break;
|
||||
}
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "MEB-HTML.h"
|
||||
|
||||
#ifdef MEB_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS MebBattery
|
||||
#endif
|
||||
|
||||
class MebBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "MG-5-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
@ -112,7 +113,7 @@ void Mg5Battery::transmit_can(unsigned long currentMillis) {
|
|||
}
|
||||
|
||||
void Mg5Battery::setup(void) { // Performs one time setup at startup
|
||||
strncpy(datalayer.system.info.battery_protocol, "MG 5 battery", 63);
|
||||
strncpy(datalayer.system.info.battery_protocol, Name, 63);
|
||||
datalayer.system.info.battery_protocol[63] = '\0';
|
||||
datalayer.system.status.battery_allows_contactor_closing = true;
|
||||
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_DV;
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define MG_5_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef MG_5_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS Mg5Battery
|
||||
#endif
|
||||
|
||||
class Mg5Battery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#include "MG-HS-PHEV-BATTERY.h"
|
||||
#include <cmath> //For unit test
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../communication/contactorcontrol/comm_contactorcontrol.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../devboard/utils/logging.h"
|
||||
|
||||
/*
|
||||
MG HS PHEV 16.6kWh battery integration
|
||||
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef MG_HS_PHEV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS MgHsPHEVBattery
|
||||
#endif
|
||||
|
||||
class MgHsPHEVBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "NISSAN-LEAF-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../charger/CHARGERS.h"
|
||||
#include "../charger/CanCharger.h"
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h" //For "More battery info" webpage
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../devboard/utils/logging.h"
|
||||
|
||||
#include "../charger/CHARGERS.h"
|
||||
#include "../charger/CanCharger.h"
|
||||
|
||||
uint16_t Temp_fromRAW_to_F(uint16_t temperature);
|
||||
//Cryptographic functions
|
||||
void decodeChallengeData(unsigned int SeedInput, unsigned char* Crypt_Output_Buffer);
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "NISSAN-LEAF-HTML.h"
|
||||
|
||||
#ifdef NISSAN_LEAF_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS NissanLeafBattery
|
||||
#endif
|
||||
|
||||
class NissanLeafBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../system_settings.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef ORION_BMS
|
||||
#define SELECTED_BATTERY_CLASS OrionBms
|
||||
#endif
|
||||
|
||||
class OrionBms : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef PYLON_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS PylonBattery
|
||||
#endif
|
||||
|
||||
class PylonBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "RANGE-ROVER-PHEV-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
/* TODO
|
||||
- LOG files from vehicle needed to determine CAN content needed to send towards battery!
|
||||
- BCCM_PMZ_A (0x18B 50ms)
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RANGE_ROVER_PHEV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RangeRoverPhevBattery
|
||||
#endif
|
||||
|
||||
class RangeRoverPhevBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../system_settings.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RELION_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RelionBattery
|
||||
#endif
|
||||
|
||||
class RelionBattery : public CanBattery {
|
||||
public:
|
||||
RelionBattery() : CanBattery(CAN_Speed::CAN_SPEED_250KBPS) {}
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RENAULT_KANGOO_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RenaultKangooBattery
|
||||
#endif
|
||||
|
||||
class RenaultKangooBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "RENAULT-TWIZY.h"
|
||||
#include <cstdint>
|
||||
#include <cstring> //For unit test
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define RENAULT_TWIZY_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RENAULT_TWIZY_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RenaultTwizyBattery
|
||||
#endif
|
||||
|
||||
class RenaultTwizyBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include "RENAULT-ZOE-GEN1-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
void transmit_can_frame(CAN_frame* tx_frame, int interface);
|
||||
|
||||
/* Information in this file is based of the OVMS V3 vehicle_renaultzoe.cpp component
|
||||
https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/blob/master/vehicle/OVMS.V3/components/vehicle_renaultzoe/src/vehicle_renaultzoe.cpp
|
||||
The Zoe BMS apparently does not send total pack voltage, so we use the polled 96x cellvoltages summed up as total voltage
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "RENAULT-ZOE-GEN1-HTML.h"
|
||||
|
||||
#ifdef RENAULT_ZOE_GEN1_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RenaultZoeGen1Battery
|
||||
#endif
|
||||
|
||||
class RenaultZoeGen1Battery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "RENAULT-ZOE-GEN2-HTML.h"
|
||||
|
||||
#ifdef RENAULT_ZOE_GEN2_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RenaultZoeGen2Battery
|
||||
#endif
|
||||
|
||||
class RenaultZoeGen2Battery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../system_settings.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RJXZS_BMS
|
||||
#define SELECTED_BATTERY_CLASS RjxzsBms
|
||||
#endif
|
||||
|
||||
class RjxzsBms : public CanBattery {
|
||||
public:
|
||||
RjxzsBms() : CanBattery(CAN_Speed::CAN_SPEED_250KBPS) {}
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef SAMSUNG_SDI_LV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS SamsungSdiLVBattery
|
||||
#endif
|
||||
|
||||
class SamsungSdiLVBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "SANTA-FE-PHEV-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
/* Credits go to maciek16c for these findings!
|
||||
https://github.com/maciek16c/hyundai-santa-fe-phev-battery
|
||||
https://openinverter.org/forum/viewtopic.php?p=62256
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef SANTA_FE_PHEV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS SantaFePhevBattery
|
||||
#endif
|
||||
|
||||
class SantaFePhevBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "SIMPBMS-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../battery/BATTERIES.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
void SimpBmsBattery::update_values() {
|
||||
|
||||
datalayer.battery.status.real_soc = (SOC * 100); //increase SOC range from 0-100 -> 100.00
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef SIMPBMS_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS SimpBmsBattery
|
||||
#endif
|
||||
|
||||
class SimpBmsBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "SONO-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef SONO_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS SonoBattery
|
||||
#endif
|
||||
|
||||
class SonoBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
CanShunt* shunt = nullptr;
|
||||
ShuntType user_selected_shunt_type = ShuntType::None;
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
#ifdef SELECTED_SHUNT_CLASS
|
||||
#error "Compile time SELECTED_SHUNT_CLASS should not be defined with COMMON_IMAGE"
|
||||
#endif
|
||||
|
||||
void setup_can_shunt() {
|
||||
if (shunt) {
|
||||
return;
|
||||
|
@ -30,21 +25,6 @@ void setup_can_shunt() {
|
|||
}
|
||||
}
|
||||
|
||||
#else
|
||||
void setup_can_shunt() {
|
||||
if (shunt) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(SELECTED_SHUNT_CLASS)
|
||||
shunt = new SELECTED_SHUNT_CLASS();
|
||||
if (shunt) {
|
||||
shunt->setup();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
extern std::vector<ShuntType> supported_shunt_types() {
|
||||
std::vector<ShuntType> types;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "TESLA-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h" //For Advanced Battery Insights webpage
|
||||
|
@ -995,52 +996,52 @@ void TeslaBattery::
|
|||
}
|
||||
|
||||
printFaultCodesIfActive();
|
||||
logging.print("BMS Contactors State: ");
|
||||
logging.print(getBMSContactorState(battery_contactor)); // Display what state the BMS thinks the contactors are in
|
||||
logging.print(", HVIL: ");
|
||||
logging.print(getHvilStatusState(battery_hvil_status));
|
||||
logging.print(", NegativeState: ");
|
||||
logging.print(getContactorState(battery_packContNegativeState));
|
||||
logging.print(", PositiveState: ");
|
||||
logging.printf("BMS Contactors State: ");
|
||||
logging.printf(getBMSContactorState(battery_contactor)); // Display what state the BMS thinks the contactors are in
|
||||
logging.printf(", HVIL: ");
|
||||
logging.printf(getHvilStatusState(battery_hvil_status));
|
||||
logging.printf(", NegativeState: ");
|
||||
logging.printf(getContactorState(battery_packContNegativeState));
|
||||
logging.printf(", PositiveState: ");
|
||||
logging.println(getContactorState(battery_packContPositiveState));
|
||||
logging.print("HVP Contactors setState: ");
|
||||
logging.print(
|
||||
logging.printf("HVP Contactors setState: ");
|
||||
logging.printf(
|
||||
getContactorText(battery_packContactorSetState)); // Display what state the HVP has set the contactors to be in
|
||||
logging.print(", Closing blocked: ");
|
||||
logging.print(getNoYes(battery_packCtrsClosingBlocked));
|
||||
logging.printf(", Closing blocked: ");
|
||||
logging.printf(getNoYes(battery_packCtrsClosingBlocked));
|
||||
if (battery_packContactorSetState == 5) {
|
||||
logging.print(" (already CLOSED)");
|
||||
logging.printf(" (already CLOSED)");
|
||||
}
|
||||
logging.print(", Pyrotest: ");
|
||||
logging.printf(", Pyrotest: ");
|
||||
logging.println(getNoYes(battery_pyroTestInProgress));
|
||||
|
||||
logging.print("Battery values: ");
|
||||
logging.print("Real SOC: ");
|
||||
logging.printf("Battery values: ");
|
||||
logging.printf("Real SOC: ");
|
||||
logging.print(battery_soc_ui / 10.0, 1);
|
||||
logging.print(", Battery voltage: ");
|
||||
logging.printf(", Battery voltage: ");
|
||||
logging.print(battery_volts / 10.0, 1);
|
||||
logging.print("V");
|
||||
logging.print(", Battery HV current: ");
|
||||
logging.printf("V");
|
||||
logging.printf(", Battery HV current: ");
|
||||
logging.print(battery_amps / 10.0, 1);
|
||||
logging.print("A");
|
||||
logging.print(", Fully charged?: ");
|
||||
logging.printf("A");
|
||||
logging.printf(", Fully charged?: ");
|
||||
if (battery_full_charge_complete)
|
||||
logging.print("YES, ");
|
||||
logging.printf("YES, ");
|
||||
else
|
||||
logging.print("NO, ");
|
||||
logging.printf("NO, ");
|
||||
if (datalayer.battery.info.chemistry == battery_chemistry_enum::LFP) {
|
||||
logging.print("LFP chemistry detected!");
|
||||
logging.printf("LFP chemistry detected!");
|
||||
}
|
||||
logging.println("");
|
||||
logging.print("Cellstats, Max: ");
|
||||
logging.printf("Cellstats, Max: ");
|
||||
logging.print(battery_cell_max_v);
|
||||
logging.print("mV (cell ");
|
||||
logging.printf("mV (cell ");
|
||||
logging.print(battery_BrickVoltageMaxNum);
|
||||
logging.print("), Min: ");
|
||||
logging.printf("), Min: ");
|
||||
logging.print(battery_cell_min_v);
|
||||
logging.print("mV (cell ");
|
||||
logging.printf("mV (cell ");
|
||||
logging.print(battery_BrickVoltageMinNum);
|
||||
logging.print("), Imbalance: ");
|
||||
logging.printf("), Imbalance: ");
|
||||
logging.print(battery_cell_deviation_mV);
|
||||
logging.println("mV.");
|
||||
|
||||
|
|
|
@ -4,13 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "TESLA-HTML.h"
|
||||
|
||||
#ifdef TESLA_MODEL_3Y_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS TeslaModel3YBattery
|
||||
#endif
|
||||
#ifdef TESLA_MODEL_SX_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS TeslaModelSXBattery
|
||||
#endif
|
||||
|
||||
// 0x7FF gateway config, "Gen3" vehicles only, not applicable to Gen2 "classic" Model S and Model X
|
||||
// These are user configurable from the Webserver UI
|
||||
extern bool user_selected_tesla_digital_HVIL;
|
||||
|
|
|
@ -3,12 +3,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/logging.h"
|
||||
|
||||
static void print_units(const char* header, int value, const char* units) {
|
||||
logging.print(header);
|
||||
logging.print(value);
|
||||
logging.print(units);
|
||||
}
|
||||
|
||||
void TestFakeBattery::
|
||||
update_values() { /* This function puts fake values onto the parameters sent towards the inverter */
|
||||
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef TEST_FAKE_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS TestFakeBattery
|
||||
#endif
|
||||
|
||||
class TestFakeBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "VOLVO-SPA-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h" //For "More battery info" webpage
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../devboard/utils/logging.h"
|
||||
|
||||
void VolvoSpaBattery::
|
||||
update_values() { //This function maps all the values fetched via CAN to the correct parameters used for the inverter
|
||||
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "VOLVO-SPA-HTML.h"
|
||||
|
||||
#ifdef VOLVO_SPA_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS VolvoSpaBattery
|
||||
#endif
|
||||
|
||||
class VolvoSpaBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "VOLVO-SPA-HYBRID-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h" //For "More battery info" webpage
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../devboard/utils/logging.h"
|
||||
|
||||
void VolvoSpaHybridBattery::
|
||||
update_values() { //This function maps all the values fetched via CAN to the correct parameters used for the inverter
|
||||
uint8_t cnt = 0;
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "VOLVO-SPA-HYBRID-HTML.h"
|
||||
|
||||
#ifdef VOLVO_SPA_HYBRID_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS VolvoSpaHybridBattery
|
||||
#endif
|
||||
|
||||
class VolvoSpaHybridBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -30,16 +30,11 @@ extern const char* name_for_charger_type(ChargerType type) {
|
|||
}
|
||||
|
||||
void setup_charger() {
|
||||
#ifdef COMMON_IMAGE
|
||||
|
||||
switch (user_selected_charger_type) {
|
||||
case ChargerType::ChevyVolt:
|
||||
charger = new ChevyVoltCharger();
|
||||
case ChargerType::NissanLeaf:
|
||||
charger = new NissanLeafCharger();
|
||||
}
|
||||
#else
|
||||
#ifdef SELECTED_CHARGER_CLASS
|
||||
charger = new SELECTED_CHARGER_CLASS();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ void init_stored_settings() {
|
|||
datalayer.battery.settings.user_set_bms_reset_duration_ms = temp;
|
||||
}
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
user_selected_battery_type = (BatteryType)settings.getUInt("BATTTYPE", (int)BatteryType::None);
|
||||
user_selected_battery_chemistry =
|
||||
(battery_chemistry_enum)settings.getUInt("BATTCHEM", (int)battery_chemistry_enum::NCA);
|
||||
|
@ -168,8 +167,6 @@ void init_stored_settings() {
|
|||
mqtt_user = settings.getString("MQTTUSER").c_str();
|
||||
mqtt_password = settings.getString("MQTTPASSWORD").c_str();
|
||||
|
||||
#endif
|
||||
|
||||
settings.end();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <freertos/FreeRTOS.h>
|
||||
#include <src/communication/nvm/comm_nvm.h>
|
||||
#include <list>
|
||||
#include "../../../USER_SECRETS.h"
|
||||
#include "../../../USER_SETTINGS.h"
|
||||
#include "../../battery/BATTERIES.h"
|
||||
#include "../../communication/contactorcontrol/comm_contactorcontrol.h"
|
||||
|
@ -15,29 +14,11 @@
|
|||
#include "mqtt.h"
|
||||
#include "mqtt_client.h"
|
||||
|
||||
#ifdef MQTT
|
||||
const bool mqtt_enabled_default = true;
|
||||
#else
|
||||
const bool mqtt_enabled_default = false;
|
||||
#endif
|
||||
bool mqtt_enabled = false;
|
||||
bool ha_autodiscovery_enabled = false;
|
||||
|
||||
bool mqtt_enabled = mqtt_enabled_default;
|
||||
|
||||
#ifdef HA_AUTODISCOVERY
|
||||
const bool ha_autodiscovery_enabled_default = true;
|
||||
#else
|
||||
const bool ha_autodiscovery_enabled_default = false;
|
||||
#endif
|
||||
|
||||
bool ha_autodiscovery_enabled = ha_autodiscovery_enabled_default;
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
const int mqtt_port_default = 0;
|
||||
const char* mqtt_server_default = "";
|
||||
#else
|
||||
const int mqtt_port_default = MQTT_PORT;
|
||||
const char* mqtt_server_default = MQTT_SERVER;
|
||||
#endif
|
||||
|
||||
int mqtt_port = mqtt_port_default;
|
||||
std::string mqtt_server = mqtt_server_default;
|
||||
|
@ -626,7 +607,7 @@ bool init_mqtt(void) {
|
|||
}
|
||||
|
||||
if (mqtt_manual_topic_object_name) {
|
||||
#ifdef COMMON_IMAGE
|
||||
|
||||
BatteryEmulatorSettingsStore settings;
|
||||
topic_name = settings.getString("MQTTTOPIC", mqtt_topic_name);
|
||||
object_id_prefix = settings.getString("MQTTOBJIDPREFIX", mqtt_object_id_prefix);
|
||||
|
@ -649,13 +630,6 @@ bool init_mqtt(void) {
|
|||
device_id = ha_device_id;
|
||||
}
|
||||
|
||||
#else
|
||||
// Use custom topic name, object ID prefix, and device name from user settings
|
||||
topic_name = mqtt_topic_name;
|
||||
object_id_prefix = mqtt_object_id_prefix;
|
||||
device_name = mqtt_device_name;
|
||||
device_id = ha_device_id;
|
||||
#endif
|
||||
} else {
|
||||
// Use default naming based on WiFi hostname for topic, object ID prefix, and device name
|
||||
topic_name = "battery-emulator_" + String(WiFi.getHostname());
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#ifndef UNIT_TEST
|
||||
// Real implementation for production
|
||||
#include <Print.h>
|
||||
|
||||
class Logging : public Print {
|
||||
void add_timestamp(size_t size);
|
||||
|
@ -51,12 +50,61 @@ class Logging {
|
|||
(void)fmt;
|
||||
}
|
||||
|
||||
// Overloaded print methods for different data types
|
||||
static void print(const char* str) { (void)str; }
|
||||
static void print(char c) { (void)c; }
|
||||
static void print(int8_t num) { (void)num; }
|
||||
static void print(uint8_t num) { (void)num; }
|
||||
static void print(int16_t num) { (void)num; }
|
||||
static void print(uint16_t num) { (void)num; }
|
||||
static void print(int32_t num) { (void)num; }
|
||||
static void print(uint32_t num) { (void)num; }
|
||||
static void print(int64_t num) { (void)num; }
|
||||
static void print(uint64_t num) { (void)num; }
|
||||
static void print(float num) { (void)num; }
|
||||
static void print(double num) { (void)num; }
|
||||
static void print(bool b) { (void)b; }
|
||||
|
||||
static void print(double num, int precision) {
|
||||
(void)num;
|
||||
(void)precision;
|
||||
}
|
||||
|
||||
static void print(float num, int precision) {
|
||||
(void)num;
|
||||
(void)precision;
|
||||
}
|
||||
|
||||
static void print(int32_t num, int base) {
|
||||
(void)num;
|
||||
(void)base;
|
||||
}
|
||||
|
||||
static void print(uint32_t num, int base) {
|
||||
(void)num;
|
||||
(void)base;
|
||||
}
|
||||
|
||||
static void println(const char* str) { (void)str; }
|
||||
static void println(char c) { (void)c; }
|
||||
static void println(int8_t num) { (void)num; }
|
||||
static void println(uint8_t num) { (void)num; }
|
||||
static void println(int16_t num) { (void)num; }
|
||||
static void println(uint16_t num) { (void)num; }
|
||||
static void println(int32_t num) { (void)num; }
|
||||
static void println(uint32_t num) { (void)num; }
|
||||
static void println(int64_t num) { (void)num; }
|
||||
static void println(uint64_t num) { (void)num; }
|
||||
static void println(float num) { (void)num; }
|
||||
static void println(double num) { (void)num; }
|
||||
static void println(bool b) { (void)b; }
|
||||
static void println() {} // Empty println
|
||||
|
||||
Logging() {}
|
||||
};
|
||||
|
||||
// Test macros - empty implementations
|
||||
#define DEBUG_PRINT(fmt, ...) ((void)0)
|
||||
#define DEBUG_PRINTF(fmt, ...) ((void)0)
|
||||
#define DEBUG_PRINTLN(str) ((void)0)
|
||||
|
||||
|
|
|
@ -135,12 +135,6 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
|
|||
return String(ssid.c_str());
|
||||
}
|
||||
|
||||
#ifndef COMMON_IMAGE
|
||||
if (var == "COMMONIMAGEDIVCLASS") {
|
||||
return "hidden";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (var == "SAVEDCLASS") {
|
||||
if (!settingsUpdated) {
|
||||
return "hidden";
|
||||
|
@ -839,7 +833,7 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
|||
<h4 style='color: white;'>SSID: <span id='SSID'>%SSID%</span><button onclick='editSSID()'>Edit</button></h4>
|
||||
<h4 style='color: white;'>Password: ######## <span id='Password'></span> <button onclick='editPassword()'>Edit</button></h4>
|
||||
|
||||
<div style='background-color: #404E47; padding: 10px; margin-bottom: 10px;border-radius: 50px; class="%COMMONIMAGEDIVCLASS%">
|
||||
<div style='background-color: #404E47; padding: 10px; margin-bottom: 10px;border-radius: 50px'>
|
||||
<div style='max-width: 500px;'>
|
||||
<form action='saveSettings' method='post' style='display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; align-items: center;'>
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <Preferences.h>
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
#include "../../../USER_SECRETS.h"
|
||||
#include "../../battery/BATTERIES.h"
|
||||
#include "../../battery/Battery.h"
|
||||
#include "../../charger/CHARGERS.h"
|
||||
|
@ -23,21 +22,10 @@
|
|||
extern std::string http_username;
|
||||
extern std::string http_password;
|
||||
|
||||
#ifdef WEBSERVER
|
||||
const bool webserver_enabled_default = true;
|
||||
#else
|
||||
const bool webserver_enabled_default = false;
|
||||
#endif
|
||||
bool webserver_enabled =
|
||||
true; // Global flag to enable or disable the webserver //Old method to disable was with #ifdef WEBSERVER
|
||||
|
||||
bool webserver_enabled = webserver_enabled_default; // Global flag to enable or disable the webserver
|
||||
|
||||
#ifndef COMMON_IMAGE
|
||||
const bool webserver_auth_default = WEBSERVER_AUTH_REQUIRED;
|
||||
#else
|
||||
const bool webserver_auth_default = false;
|
||||
#endif
|
||||
|
||||
bool webserver_auth = webserver_auth_default;
|
||||
bool webserver_auth = false;
|
||||
|
||||
// Create AsyncWebServer object on port 80
|
||||
AsyncWebServer server(80);
|
||||
|
@ -401,7 +389,6 @@ void init_webserver() {
|
|||
request->send(200, "text/html", "OK");
|
||||
});
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
struct BoolSetting {
|
||||
const char* name;
|
||||
bool existingValue;
|
||||
|
@ -557,7 +544,6 @@ void init_webserver() {
|
|||
settingsUpdated = settings.were_settings_updated();
|
||||
request->redirect("/settings");
|
||||
});
|
||||
#endif
|
||||
|
||||
// Route for editing SSID
|
||||
def_route_with_auth("/updateSSID", server, HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
|
@ -908,9 +894,6 @@ String processor(const String& var) {
|
|||
content += "<div style='background-color: #303E47; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||
content += "<h4>Software: " + String(version_number);
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
content += " (Common image) ";
|
||||
#endif
|
||||
// Show hardware used:
|
||||
#ifdef HW_LILYGO
|
||||
content += " Hardware: LilyGo T-CAN485";
|
||||
|
|
|
@ -12,17 +12,7 @@ const bool wifi_enabled_default = false;
|
|||
|
||||
bool wifi_enabled = wifi_enabled_default;
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
const bool wifiap_enabled_default = true;
|
||||
#else
|
||||
#ifdef WIFIAP
|
||||
const bool wifiap_enabled_default = true;
|
||||
#else
|
||||
const bool wifiap_enabled_default = false;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool wifiap_enabled = wifiap_enabled_default;
|
||||
bool wifiap_enabled = true; //Old method was with ifdef
|
||||
|
||||
#ifdef MDNSRESPONDER
|
||||
const bool mdns_enabled_default = true;
|
||||
|
|
|
@ -96,11 +96,6 @@ extern const char* name_for_inverter_type(InverterProtocolType type) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
#ifdef SELECTED_INVERTER_CLASS
|
||||
#error "Compile time SELECTED_INVERTER_CLASS should not be defined with COMMON_IMAGE"
|
||||
#endif
|
||||
|
||||
bool setup_inverter() {
|
||||
if (inverter) {
|
||||
return true;
|
||||
|
@ -205,24 +200,3 @@ bool setup_inverter() {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
bool setup_inverter() {
|
||||
if (inverter) {
|
||||
// The inverter is setup only once.
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef SELECTED_INVERTER_CLASS
|
||||
inverter = new SELECTED_INVERTER_CLASS();
|
||||
|
||||
if (inverter) {
|
||||
return inverter->setup();
|
||||
}
|
||||
|
||||
return false;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -7,11 +7,6 @@ extern InverterProtocol* inverter;
|
|||
#include "../../USER_SETTINGS.h"
|
||||
|
||||
#include "AFORE-CAN.h"
|
||||
|
||||
#ifdef BYD_CAN_DEYE
|
||||
#define BYD_CAN
|
||||
#endif
|
||||
|
||||
#include "BYD-CAN.h"
|
||||
#include "BYD-MODBUS.h"
|
||||
#include "FERROAMP-CAN.h"
|
||||
|
|
|
@ -14,18 +14,18 @@ void KostalInverterProtocol::float2frame(uint8_t* arr, float value, uint8_t fram
|
|||
}
|
||||
|
||||
static void dbg_timestamp(void) {
|
||||
logging.print("[");
|
||||
logging.printf("[");
|
||||
logging.print(millis());
|
||||
logging.print(" ms] ");
|
||||
logging.printf(" ms] ");
|
||||
}
|
||||
|
||||
static void dbg_frame(uint8_t* frame, int len, const char* prefix) {
|
||||
dbg_timestamp();
|
||||
logging.print(prefix);
|
||||
logging.print(": ");
|
||||
logging.printf(": ");
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
if (frame[i] < 0x10) {
|
||||
logging.print("0");
|
||||
logging.printf("0");
|
||||
}
|
||||
logging.print(frame[i], HEX);
|
||||
logging.print(" ");
|
||||
|
|
|
@ -20,7 +20,6 @@ class KostalInverterProtocol : public Rs485InverterProtocol {
|
|||
int baud_rate() { return 57600; }
|
||||
void float2frame(uint8_t* arr, float value, uint8_t framepointer);
|
||||
bool check_kostal_frame_crc(int len);
|
||||
|
||||
// How many value updates we can go without inverter gets reported as missing \
|
||||
// e.g. value set to 12, 12*5sec=60seconds without comm before event is raised
|
||||
const int RS485_HEALTHY = 12;
|
||||
|
|
|
@ -137,17 +137,6 @@ void SmaTripowerInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
|
|||
}
|
||||
}
|
||||
|
||||
void SmaTripowerInverter::pushFrame(CAN_frame* frame, std::function<void(void)> callback) {
|
||||
if (listLength >= 20) {
|
||||
return; //TODO: scream.
|
||||
}
|
||||
framesToSend[listLength] = {
|
||||
.frame = frame,
|
||||
.callback = callback,
|
||||
};
|
||||
listLength++;
|
||||
}
|
||||
|
||||
void SmaTripowerInverter::transmit_can(unsigned long currentMillis) {
|
||||
|
||||
// Send CAN Message only if we're enabled by inverter
|
||||
|
@ -155,18 +144,6 @@ void SmaTripowerInverter::transmit_can(unsigned long currentMillis) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (listLength > 0 && currentMillis - previousMillis250ms >= INTERVAL_250_MS) {
|
||||
previousMillis250ms = currentMillis;
|
||||
// Send next frame.
|
||||
Frame frame = framesToSend[0];
|
||||
transmit_can_frame(frame.frame);
|
||||
frame.callback();
|
||||
for (int i = 0; i < listLength - 1; i++) {
|
||||
framesToSend[i] = framesToSend[i + 1];
|
||||
}
|
||||
listLength--;
|
||||
}
|
||||
|
||||
if (!pairing_completed) {
|
||||
return;
|
||||
}
|
||||
|
@ -174,19 +151,19 @@ void SmaTripowerInverter::transmit_can(unsigned long currentMillis) {
|
|||
// Send CAN Message every 2s
|
||||
if (currentMillis - previousMillis2s >= INTERVAL_2_S) {
|
||||
previousMillis2s = currentMillis;
|
||||
pushFrame(&SMA_358);
|
||||
transmit_can_frame(&SMA_358);
|
||||
}
|
||||
// Send CAN Message every 10s
|
||||
if (currentMillis - previousMillis10s >= INTERVAL_10_S) {
|
||||
previousMillis10s = currentMillis;
|
||||
pushFrame(&SMA_518);
|
||||
pushFrame(&SMA_4D8);
|
||||
pushFrame(&SMA_3D8);
|
||||
transmit_can_frame(&SMA_518);
|
||||
transmit_can_frame(&SMA_4D8);
|
||||
transmit_can_frame(&SMA_3D8);
|
||||
}
|
||||
// Send CAN Message every 60s (potentially SMA_458 is not required for stable operation)
|
||||
if (currentMillis - previousMillis60s >= INTERVAL_60_S) {
|
||||
previousMillis60s = currentMillis;
|
||||
pushFrame(&SMA_458);
|
||||
transmit_can_frame(&SMA_458);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,18 +172,17 @@ void SmaTripowerInverter::completePairing() {
|
|||
}
|
||||
|
||||
void SmaTripowerInverter::transmit_can_init() {
|
||||
listLength = 0; // clear all frames
|
||||
|
||||
pushFrame(&SMA_558); //Pairing start - Vendor
|
||||
pushFrame(&SMA_598); //Serial
|
||||
pushFrame(&SMA_5D8); //BYD
|
||||
pushFrame(&SMA_618_0); //BATTERY
|
||||
pushFrame(&SMA_618_1); //-Box Pr
|
||||
pushFrame(&SMA_618_2); //emium H
|
||||
pushFrame(&SMA_618_3); //VS
|
||||
pushFrame(&SMA_358);
|
||||
pushFrame(&SMA_3D8);
|
||||
pushFrame(&SMA_458);
|
||||
pushFrame(&SMA_4D8);
|
||||
pushFrame(&SMA_518, [this]() { this->completePairing(); });
|
||||
transmit_can_frame(&SMA_558); //Pairing start - Vendor
|
||||
transmit_can_frame(&SMA_598); //Serial
|
||||
transmit_can_frame(&SMA_5D8); //BYD
|
||||
transmit_can_frame(&SMA_618_0); //BATTERY
|
||||
transmit_can_frame(&SMA_618_1); //-Box Pr
|
||||
transmit_can_frame(&SMA_618_2); //emium H
|
||||
transmit_can_frame(&SMA_618_3); //VS
|
||||
transmit_can_frame(&SMA_358);
|
||||
transmit_can_frame(&SMA_3D8);
|
||||
transmit_can_frame(&SMA_458);
|
||||
transmit_can_frame(&SMA_4D8);
|
||||
transmit_can_frame(&SMA_518);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ class SmaTripowerInverter : public SmaInverterBase {
|
|||
const int THIRTY_MINUTES = 1200;
|
||||
|
||||
void transmit_can_init();
|
||||
void pushFrame(CAN_frame* frame, std::function<void(void)> callback = []() {});
|
||||
void completePairing();
|
||||
|
||||
unsigned long previousMillis250ms = 0; // will store last time a 250ms CAN Message was send
|
||||
|
@ -33,14 +32,6 @@ class SmaTripowerInverter : public SmaInverterBase {
|
|||
unsigned long previousMillis10s = 0; // will store last time a 10s CAN Message was send
|
||||
unsigned long previousMillis60s = 0; // will store last time a 60s CAN Message was send
|
||||
|
||||
typedef struct {
|
||||
CAN_frame* frame;
|
||||
std::function<void(void)> callback;
|
||||
} Frame;
|
||||
|
||||
unsigned short listLength = 0;
|
||||
Frame framesToSend[20];
|
||||
|
||||
uint32_t inverter_time = 0;
|
||||
uint16_t inverter_voltage = 0;
|
||||
int16_t inverter_current = 0;
|
||||
|
|
|
@ -292,9 +292,8 @@ bool SofarInverter::setup() { // Performs one time setup at startup over CAN bu
|
|||
init_frame(SOFAR_783, 0x783);
|
||||
init_frame(SOFAR_784, 0x784);
|
||||
|
||||
String tempStr(datalayer.battery.settings.sofar_user_specified_battery_id);
|
||||
strncpy(datalayer.system.info.inverter_brand, tempStr.c_str(), 7);
|
||||
datalayer.system.info.inverter_brand[7] = '\0';
|
||||
snprintf(datalayer.system.info.inverter_brand, sizeof(datalayer.system.info.inverter_brand), "%s",
|
||||
datalayer.battery.settings.sofar_user_specified_battery_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue