mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Remove all ifdefs from Tesla code
This commit is contained in:
parent
1ec6af8ea0
commit
e299b867c9
4 changed files with 94 additions and 81 deletions
|
@ -319,11 +319,11 @@ void setup_battery() {
|
||||||
|
|
||||||
/* User-selected Tesla settings */
|
/* User-selected Tesla settings */
|
||||||
bool user_selected_tesla_digital_HVIL = false;
|
bool user_selected_tesla_digital_HVIL = false;
|
||||||
uint16_t user_selected_tesla_GTW_country = 0;
|
uint16_t user_selected_tesla_GTW_country = 17477;
|
||||||
bool user_selected_tesla_GTW_rightHandDrive = false;
|
bool user_selected_tesla_GTW_rightHandDrive = true;
|
||||||
uint16_t user_selected_tesla_GTW_mapRegion = 0;
|
uint16_t user_selected_tesla_GTW_mapRegion = 2;
|
||||||
uint16_t user_selected_tesla_GTW_chassisType = 0;
|
uint16_t user_selected_tesla_GTW_chassisType = 2;
|
||||||
uint16_t user_selected_tesla_GTW_packEnergy = 0;
|
uint16_t user_selected_tesla_GTW_packEnergy = 1;
|
||||||
|
|
||||||
/* User-selected voltages used for custom-BMS batteries (RJXZS etc.) */
|
/* User-selected voltages used for custom-BMS batteries (RJXZS etc.) */
|
||||||
#if defined(MAX_CUSTOM_PACK_VOLTAGE_DV) && defined(MIN_CUSTOM_PACK_VOLTAGE_DV) && \
|
#if defined(MAX_CUSTOM_PACK_VOLTAGE_DV) && defined(MIN_CUSTOM_PACK_VOLTAGE_DV) && \
|
||||||
|
|
|
@ -676,39 +676,39 @@ void TeslaBattery::
|
||||||
clear_event(EVENT_BATTERY_FUSE);
|
clear_event(EVENT_BATTERY_FUSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TESLA_MODEL_3Y_BATTERY
|
if (user_selected_tesla_GTW_chassisType > 1) { //{{0, "Model S"}, {1, "Model X"}, {2, "Model 3"}, {3, "Model Y"}};
|
||||||
// Autodetect algoritm for chemistry on 3/Y packs.
|
// Autodetect algoritm for chemistry on 3/Y packs.
|
||||||
// NCM/A batteries have 96s, LFP has 102-108s
|
// NCM/A batteries have 96s, LFP has 102-108s
|
||||||
// Drawback with this check is that it takes 3-5minutes before all cells have been counted!
|
// Drawback with this check is that it takes 3-5minutes before all cells have been counted!
|
||||||
if (datalayer.battery.info.number_of_cells > 101) {
|
if (datalayer.battery.info.number_of_cells > 101) {
|
||||||
datalayer.battery.info.chemistry = battery_chemistry_enum::LFP;
|
datalayer.battery.info.chemistry = battery_chemistry_enum::LFP;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Once cell chemistry is determined, set maximum and minimum total pack voltage safety limits
|
//Once cell chemistry is determined, set maximum and minimum total pack voltage safety limits
|
||||||
if (datalayer.battery.info.chemistry == battery_chemistry_enum::LFP) {
|
if (datalayer.battery.info.chemistry == battery_chemistry_enum::LFP) {
|
||||||
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_3Y_LFP;
|
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_3Y_LFP;
|
||||||
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_3Y_LFP;
|
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_3Y_LFP;
|
||||||
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_LFP;
|
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_LFP;
|
||||||
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_LFP;
|
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_LFP;
|
||||||
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_LFP;
|
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_LFP;
|
||||||
} else { // NCM/A chemistry
|
} else { // NCM/A chemistry
|
||||||
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_3Y_NCMA;
|
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_3Y_NCMA;
|
||||||
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_3Y_NCMA;
|
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_3Y_NCMA;
|
||||||
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_NCA_NCM;
|
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_NCA_NCM;
|
||||||
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_NCA_NCM;
|
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_NCA_NCM;
|
||||||
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_NCA_NCM;
|
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_NCA_NCM;
|
||||||
}
|
}
|
||||||
|
|
||||||
// During forced balancing request via webserver, we allow the battery to exceed normal safety parameters
|
// During forced balancing request via webserver, we allow the battery to exceed normal safety parameters
|
||||||
if (datalayer.battery.settings.user_requests_balancing) {
|
if (datalayer.battery.settings.user_requests_balancing) {
|
||||||
datalayer.battery.status.real_soc = 9900; //Force battery to show up as 99% when balancing
|
datalayer.battery.status.real_soc = 9900; //Force battery to show up as 99% when balancing
|
||||||
datalayer.battery.info.max_design_voltage_dV = datalayer.battery.settings.balancing_max_pack_voltage_dV;
|
datalayer.battery.info.max_design_voltage_dV = datalayer.battery.settings.balancing_max_pack_voltage_dV;
|
||||||
datalayer.battery.info.max_cell_voltage_mV = datalayer.battery.settings.balancing_max_cell_voltage_mV;
|
datalayer.battery.info.max_cell_voltage_mV = datalayer.battery.settings.balancing_max_cell_voltage_mV;
|
||||||
datalayer.battery.info.max_cell_voltage_deviation_mV =
|
datalayer.battery.info.max_cell_voltage_deviation_mV =
|
||||||
datalayer.battery.settings.balancing_max_deviation_cell_voltage_mV;
|
datalayer.battery.settings.balancing_max_deviation_cell_voltage_mV;
|
||||||
datalayer.battery.status.max_charge_power_W = datalayer.battery.settings.balancing_float_power_W;
|
datalayer.battery.status.max_charge_power_W = datalayer.battery.settings.balancing_float_power_W;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif // TESLA_MODEL_3Y_BATTERY
|
|
||||||
|
|
||||||
// Check if user requests some action
|
// Check if user requests some action
|
||||||
if (datalayer.battery.settings.user_requests_tesla_isolation_clear) {
|
if (datalayer.battery.settings.user_requests_tesla_isolation_clear) {
|
||||||
|
@ -2015,7 +2015,7 @@ int index_118 = 0;
|
||||||
|
|
||||||
void TeslaBattery::transmit_can(unsigned long currentMillis) {
|
void TeslaBattery::transmit_can(unsigned long currentMillis) {
|
||||||
|
|
||||||
if (operate_contactors) { //Special S/X mode
|
if (user_selected_tesla_digital_HVIL) { //Special S/X? mode for 2024+ batteries
|
||||||
if ((datalayer.system.status.inverter_allows_contactor_closing) && (datalayer.battery.status.bms_status != FAULT)) {
|
if ((datalayer.system.status.inverter_allows_contactor_closing) && (datalayer.battery.status.bms_status != FAULT)) {
|
||||||
if (currentMillis - lastSend1CF >= 10) {
|
if (currentMillis - lastSend1CF >= 10) {
|
||||||
transmit_can_frame(&can_msg_1CF[index_1CF]);
|
transmit_can_frame(&can_msg_1CF[index_1CF]);
|
||||||
|
@ -2628,12 +2628,12 @@ void TeslaModel3YBattery::setup(void) { // Performs one time setup at startup
|
||||||
|
|
||||||
//0x7FF GTW CAN frame values
|
//0x7FF GTW CAN frame values
|
||||||
//Mux1
|
//Mux1
|
||||||
write_signal_value(&TESLA_7FF_Mux1, 16, 16, GTW_country, false);
|
write_signal_value(&TESLA_7FF_Mux1, 16, 16, user_selected_tesla_GTW_country, false);
|
||||||
write_signal_value(&TESLA_7FF_Mux1, 11, 1, GTW_rightHandDrive, false);
|
write_signal_value(&TESLA_7FF_Mux1, 11, 1, user_selected_tesla_GTW_country, false);
|
||||||
//Mux3
|
//Mux3
|
||||||
write_signal_value(&TESLA_7FF_Mux3, 8, 4, GTW_mapRegion, false);
|
write_signal_value(&TESLA_7FF_Mux3, 8, 4, user_selected_tesla_GTW_mapRegion, false);
|
||||||
write_signal_value(&TESLA_7FF_Mux3, 18, 3, GTW_chassisType, false);
|
write_signal_value(&TESLA_7FF_Mux3, 18, 3, user_selected_tesla_GTW_chassisType, false);
|
||||||
write_signal_value(&TESLA_7FF_Mux3, 32, 5, GTW_packEnergy, false);
|
write_signal_value(&TESLA_7FF_Mux3, 32, 5, user_selected_tesla_GTW_packEnergy, false);
|
||||||
|
|
||||||
strncpy(datalayer.system.info.battery_protocol, Name, 63);
|
strncpy(datalayer.system.info.battery_protocol, Name, 63);
|
||||||
datalayer.system.info.battery_protocol[63] = '\0';
|
datalayer.system.info.battery_protocol[63] = '\0';
|
||||||
|
|
|
@ -11,12 +11,14 @@
|
||||||
#define SELECTED_BATTERY_CLASS TeslaModelSXBattery
|
#define SELECTED_BATTERY_CLASS TeslaModelSXBattery
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*NOTE! IMPORTANT INFORMATION!
|
// 0x7FF gateway config, "Gen3" vehicles only, not applicable to Gen2 "classic" Model S and Model X
|
||||||
Be sure to scroll down in this file and configure all "GTW_" parameters to suit your battery.
|
// These are user configurable from the Webserver UI
|
||||||
Failure to configure these will result in VCFRONT and GTW MIA errors
|
extern bool user_selected_tesla_digital_HVIL;
|
||||||
*/
|
extern uint16_t user_selected_tesla_GTW_country;
|
||||||
|
extern bool user_selected_tesla_GTW_rightHandDrive;
|
||||||
//#define EXP_TESLA_BMS_DIGITAL_HVIL // Experimental parameter. Forces the transmission of additional CAN frames for experimental purposes, to test potential HVIL issues in 3/Y packs with newer firmware.
|
extern uint16_t user_selected_tesla_GTW_mapRegion;
|
||||||
|
extern uint16_t user_selected_tesla_GTW_chassisType;
|
||||||
|
extern uint16_t user_selected_tesla_GTW_packEnergy;
|
||||||
|
|
||||||
class TeslaBattery : public CanBattery {
|
class TeslaBattery : public CanBattery {
|
||||||
public:
|
public:
|
||||||
|
@ -53,21 +55,6 @@ class TeslaBattery : public CanBattery {
|
||||||
// Set this to true to try to close contactors/full startup even with no inverter defined/connected
|
// Set this to true to try to close contactors/full startup even with no inverter defined/connected
|
||||||
bool batteryTestOverride = false;
|
bool batteryTestOverride = false;
|
||||||
|
|
||||||
// 0x7FF gateway config, "Gen3" vehicles only, not applicable to Gen2 "classic" Model S and Model X
|
|
||||||
//
|
|
||||||
// ** MANUALLY SET FOR NOW **, TODO: change based on USER_SETTINGS.h or preset
|
|
||||||
//
|
|
||||||
static const uint16_t GTW_country =
|
|
||||||
18242; // "US" (USA): 21843, "CA" (Canada): 17217, "GB" (UK & N Ireland): 18242, "DK" (Denmark): 17483, "DE" (Germany): 17477, "AU" (Australia): 16725 [HVP shows errors if EU/US region mismatch for example]
|
|
||||||
// GTW_country is ISO 3166-1 Alpha-2 code, each letter converted to binary (8-bit chunks), those 8-bit chunks concatenated and then converted to decimal
|
|
||||||
static const uint8_t GTW_rightHandDrive =
|
|
||||||
1; // Left: 0, Right: 1 (not sure this matters but there for consistency in emulating the car - make sure correct for GTW_country, e.g. 0 for USA)
|
|
||||||
static const uint8_t GTW_mapRegion =
|
|
||||||
1; // "ME": 8, "NONE": 2, "CN": 3, "TW": 6, "JP": 5, "US": 0, "KR": 7, "AU": 4, "EU": 1 (not sure this matters but there for consistency)
|
|
||||||
static const uint8_t GTW_chassisType =
|
|
||||||
2; // "MODEL_3_CHASSIS": 2, "MODEL_Y_CHASSIS": 3 ("MODEL_S_CHASSIS": 0, "MODEL_X_CHASSIS": 1)
|
|
||||||
static const uint8_t GTW_packEnergy = 1; // "PACK_50_KWH": 0, "PACK_74_KWH": 1, "PACK_62_KWH": 2, "PACK_100_KWH": 3
|
|
||||||
|
|
||||||
/* Do not change anything below this line! */
|
/* Do not change anything below this line! */
|
||||||
static const int RAMPDOWN_SOC = 900; // 90.0 SOC% to start ramping down from max charge power towards 0 at 100.00%
|
static const int RAMPDOWN_SOC = 900; // 90.0 SOC% to start ramping down from max charge power towards 0 at 100.00%
|
||||||
static const int RAMPDOWNPOWERALLOWED = 10000; // What power we ramp down from towards top balancing
|
static const int RAMPDOWNPOWERALLOWED = 10000; // What power we ramp down from towards top balancing
|
||||||
|
@ -926,19 +913,14 @@ class TeslaBattery : public CanBattery {
|
||||||
|
|
||||||
class TeslaModel3YBattery : public TeslaBattery {
|
class TeslaModel3YBattery : public TeslaBattery {
|
||||||
public:
|
public:
|
||||||
TeslaModel3YBattery(battery_chemistry_enum chemistry) {
|
TeslaModel3YBattery(battery_chemistry_enum chemistry) { datalayer.battery.info.chemistry = chemistry; }
|
||||||
datalayer.battery.info.chemistry = chemistry;
|
|
||||||
#ifdef EXP_TESLA_BMS_DIGITAL_HVIL
|
|
||||||
operate_contactors = true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
static constexpr const char* Name = "Tesla Model 3/Y";
|
static constexpr const char* Name = "Tesla Model 3/Y";
|
||||||
virtual void setup(void);
|
virtual void setup(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TeslaModelSXBattery : public TeslaBattery {
|
class TeslaModelSXBattery : public TeslaBattery {
|
||||||
public:
|
public:
|
||||||
TeslaModelSXBattery() { operate_contactors = true; }
|
TeslaModelSXBattery() {}
|
||||||
static constexpr const char* Name = "Tesla Model S/X";
|
static constexpr const char* Name = "Tesla Model S/X";
|
||||||
virtual void setup(void);
|
virtual void setup(void);
|
||||||
};
|
};
|
||||||
|
|
|
@ -78,6 +78,33 @@ String options_for_enum(TEnum selected, Func name_for_type) {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename TMap>
|
||||||
|
String options_from_map(int selected, const TMap& value_name_map) {
|
||||||
|
String options;
|
||||||
|
for (const auto& [value, name] : value_name_map) {
|
||||||
|
options += "<option value=\"" + String(value) + "\"";
|
||||||
|
if (selected == value) {
|
||||||
|
options += " selected";
|
||||||
|
}
|
||||||
|
options += ">";
|
||||||
|
options += name;
|
||||||
|
options += "</option>";
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const std::map<int, String> tesla_countries = {
|
||||||
|
{21843, "US (USA)"}, {17217, "CA (Canada)"}, {18242, "GB (UK & N Ireland)"},
|
||||||
|
{17483, "DK (Denmark)"}, {17477, "DE (Germany)"}, {16725, "AU (Australia)"}};
|
||||||
|
|
||||||
|
static const std::map<int, String> tesla_mapregion = {
|
||||||
|
{8, "ME (Middle East)"}, {2, "NONE"}, {3, "CN (China)"}, {6, "TW (Taiwan)"}, {5, "JP (Japan)"},
|
||||||
|
{0, "US (USA)"}, {7, "KR (Korea)"}, {4, "AU (Australia)"}, {1, "EU (Europe)"}};
|
||||||
|
|
||||||
|
static const std::map<int, String> tesla_chassis = {{0, "Model S"}, {1, "Model X"}, {2, "Model 3"}, {3, "Model Y"}};
|
||||||
|
|
||||||
|
static const std::map<int, String> tesla_pack = {{0, "50 kWh"}, {2, "62 kWh"}, {1, "74 kWh"}, {3, "100 kWh"}};
|
||||||
|
|
||||||
const char* name_for_button_type(STOP_BUTTON_BEHAVIOR behavior) {
|
const char* name_for_button_type(STOP_BUTTON_BEHAVIOR behavior) {
|
||||||
switch (behavior) {
|
switch (behavior) {
|
||||||
case STOP_BUTTON_BEHAVIOR::LATCHING_SWITCH:
|
case STOP_BUTTON_BEHAVIOR::LATCHING_SWITCH:
|
||||||
|
@ -505,7 +532,7 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var == "GTWCOUNTRY") {
|
if (var == "GTWCOUNTRY") {
|
||||||
return String(settings.getUInt("GTWCOUNTRY", 0));
|
return options_from_map(settings.getUInt("GTWCOUNTRY", 0), tesla_countries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var == "GTWRHD") {
|
if (var == "GTWRHD") {
|
||||||
|
@ -513,15 +540,15 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var == "GTWMAPREG") {
|
if (var == "GTWMAPREG") {
|
||||||
return String(settings.getUInt("GTWMAPREG", 0));
|
return options_from_map(settings.getUInt("GTWMAPREG", 0), tesla_mapregion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var == "GTWCHASSIS") {
|
if (var == "GTWCHASSIS") {
|
||||||
return String(settings.getUInt("GTWCHASSIS", 0));
|
return options_from_map(settings.getUInt("GTWCHASSIS", 0), tesla_chassis);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var == "GTWPACK") {
|
if (var == "GTWPACK") {
|
||||||
return String(settings.getUInt("GTWPACK", 0));
|
return options_from_map(settings.getUInt("GTWPACK", 0), tesla_pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String();
|
return String();
|
||||||
|
@ -767,16 +794,20 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
||||||
<div class="if-tesla">
|
<div class="if-tesla">
|
||||||
<label>Digital HVIL (2024+): </label>
|
<label>Digital HVIL (2024+): </label>
|
||||||
<input type='checkbox' name='DIGITALHVIL' value='on' style='margin-left: 0;' %DIGITALHVIL% />
|
<input type='checkbox' name='DIGITALHVIL' value='on' style='margin-left: 0;' %DIGITALHVIL% />
|
||||||
<label>Country code: </label>
|
|
||||||
<input name='GTWCOUNTRY' type='text' value="%GTWCOUNTRY%" pattern="^[0-9]{1,2}$" />
|
|
||||||
<label>Right hand drive: </label>
|
<label>Right hand drive: </label>
|
||||||
<input type='checkbox' name='GTWRHD' value='on' style='margin-left: 0;' %GTWRHD% />
|
<input type='checkbox' name='GTWRHD' value='on' style='margin-left: 0;' %GTWRHD% />
|
||||||
<label>Map region: </label>
|
<label for='GTWCOUNTRY'>Country code: </label><select name='GTWCOUNTRY' id='GTWCOUNTRY'>
|
||||||
<input name='GTWMAPREG' type='text' value="%GTWMAPREG%" pattern="^[0-9]{1,2}$" />
|
%GTWCOUNTRY%
|
||||||
<label>Chassis type: </label>
|
</select>
|
||||||
<input name='GTWCHASSIS' type='text' value="%GTWCHASSIS%" pattern="^[0-9]{1,2}$" />
|
<label for='GTWMAPREG'>Map region: </label><select name='GTWMAPREG' id='GTWMAPREG'>
|
||||||
<label>Pack type: </label>
|
%GTWMAPREG%
|
||||||
<input name='GTWPACK' type='text' value="%GTWPACK%" pattern="^[0-9]{1,2}$" />
|
</select>
|
||||||
|
<label for='GTWCHASSIS'>Chassis type: </label><select name='GTWCHASSIS' id='GTWCHASSIS'>
|
||||||
|
%GTWCHASSIS%
|
||||||
|
</select>
|
||||||
|
<label for='GTWPACK'>Pack type: </label><select name='GTWPACK' id='GTWPACK'>
|
||||||
|
%GTWPACK%
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="if-battery">
|
<div class="if-battery">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue