diff --git a/Software/src/battery/Shunt.h b/Software/src/battery/Shunt.h index 6ed3f1f4..20e7f1eb 100644 --- a/Software/src/battery/Shunt.h +++ b/Software/src/battery/Shunt.h @@ -6,6 +6,8 @@ #include "src/communication/can/comm_can.h" #include "src/devboard/utils/types.h" +enum class ShuntType { None = 0, BmwSbox = 1, Highest }; + class CanShunt : public Transmitter, CanReceiver { public: virtual void setup() = 0; @@ -35,4 +37,8 @@ class CanShunt : public Transmitter, CanReceiver { extern CanShunt* shunt; +extern std::vector supported_shunt_types(); +extern const char* name_for_shunt_type(ShuntType type); +extern ShuntType user_selected_shunt_type; + #endif diff --git a/Software/src/battery/Shunts.cpp b/Software/src/battery/Shunts.cpp index 35a0b98c..1e0349b1 100644 --- a/Software/src/battery/Shunts.cpp +++ b/Software/src/battery/Shunts.cpp @@ -2,7 +2,35 @@ #include "Shunt.h" 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; + } + + switch (user_selected_shunt_type) { + case ShuntType::None: + shunt = nullptr; + return; + case ShuntType::BmwSbox: + shunt = new BmwSbox(); + break; + default: + return; + } + + if (shunt) { + shunt->setup(); + } +} + +#else void setup_can_shunt() { if (shunt) { return; @@ -15,3 +43,25 @@ void setup_can_shunt() { } #endif } +#endif + +extern std::vector supported_shunt_types() { + std::vector types; + + for (int i = 0; i < (int)ShuntType::Highest; i++) { + types.push_back((ShuntType)i); + } + + return types; +} + +extern const char* name_for_shunt_type(ShuntType type) { + switch (type) { + case ShuntType::None: + return "None"; + case ShuntType::BmwSbox: + return BmwSbox::Name; + default: + return nullptr; + } +} diff --git a/Software/src/communication/nvm/comm_nvm.cpp b/Software/src/communication/nvm/comm_nvm.cpp index 97eddbb3..23d47a72 100644 --- a/Software/src/communication/nvm/comm_nvm.cpp +++ b/Software/src/communication/nvm/comm_nvm.cpp @@ -79,6 +79,7 @@ void init_stored_settings() { (battery_chemistry_enum)settings.getUInt("BATTCHEM", (int)battery_chemistry_enum::NCA); user_selected_inverter_protocol = (InverterProtocolType)settings.getUInt("INVTYPE", (int)InverterProtocolType::None); user_selected_charger_type = (ChargerType)settings.getUInt("CHGTYPE", (int)ChargerType::None); + user_selected_shunt_type = (ShuntType)settings.getUInt("SHUNTTYPE", (int)ShuntType::None); auto readIf = [](const char* settingName) { auto batt1If = (comm_interface)settings.getUInt(settingName, (int)comm_interface::CanNative); diff --git a/Software/src/devboard/webserver/settings_html.cpp b/Software/src/devboard/webserver/settings_html.cpp index 63e23afe..a240991a 100644 --- a/Software/src/devboard/webserver/settings_html.cpp +++ b/Software/src/devboard/webserver/settings_html.cpp @@ -187,6 +187,17 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti return options_for_enum((comm_interface)settings.getUInt("CHGCOMM", (int)comm_interface::CanNative), name_for_comm_interface); } + + if (var == "SHUNTTYPE") { + return options_for_enum_with_none((ShuntType)settings.getUInt("SHUNTTYPE", (int)ShuntType::None), + name_for_shunt_type, ShuntType::None); + } + + if (var == "SHUNTCOMM") { + return options_for_enum((comm_interface)settings.getUInt("SHUNTCOMM", (int)comm_interface::CanNative), + name_for_comm_interface); + } + if (var == "EQSTOP") { return options_for_enum_with_none( (STOP_BUTTON_BEHAVIOR)settings.getUInt("EQSTOP", (int)STOP_BUTTON_BEHAVIOR::NOT_CONNECTED), @@ -650,6 +661,14 @@ const char* getCANInterfaceName(CAN_Interface interface) { %CHGCOMM% + + + + diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index b4194064..84630d4d 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -432,30 +432,33 @@ void init_webserver() { if (p->name() == "inverter") { auto type = static_cast(atoi(p->value().c_str())); settings.saveUInt("INVTYPE", (int)type); + } else if (p->name() == "INVCOMM") { + auto type = static_cast(atoi(p->value().c_str())); + settings.saveUInt("INVCOMM", (int)type); } else if (p->name() == "battery") { auto type = static_cast(atoi(p->value().c_str())); settings.saveUInt("BATTTYPE", (int)type); } else if (p->name() == "BATTCHEM") { auto type = static_cast(atoi(p->value().c_str())); settings.saveUInt("BATTCHEM", (int)type); - } else if (p->name() == "charger") { - auto type = static_cast(atoi(p->value().c_str())); - settings.saveUInt("CHGTYPE", (int)type); - } else if (p->name() == "EQSTOP") { - auto type = static_cast(atoi(p->value().c_str())); - settings.saveUInt("EQSTOP", (int)type); } else if (p->name() == "BATTCOMM") { auto type = static_cast(atoi(p->value().c_str())); settings.saveUInt("BATTCOMM", (int)type); - } else if (p->name() == "BATT2COMM") { - auto type = static_cast(atoi(p->value().c_str())); - settings.saveUInt("BATT2COMM", (int)type); - } else if (p->name() == "INVCOMM") { - auto type = static_cast(atoi(p->value().c_str())); - settings.saveUInt("INVCOMM", (int)type); + } else if (p->name() == "charger") { + auto type = static_cast(atoi(p->value().c_str())); + settings.saveUInt("CHGTYPE", (int)type); } else if (p->name() == "CHGCOMM") { auto type = static_cast(atoi(p->value().c_str())); settings.saveUInt("CHGCOMM", (int)type); + } else if (p->name() == "EQSTOP") { + auto type = static_cast(atoi(p->value().c_str())); + settings.saveUInt("EQSTOP", (int)type); + } else if (p->name() == "BATT2COMM") { + auto type = static_cast(atoi(p->value().c_str())); + settings.saveUInt("BATT2COMM", (int)type); + } else if (p->name() == "shunt") { + auto type = static_cast(atoi(p->value().c_str())); + settings.saveUInt("SHUNTTYPE", (int)type); } else if (p->name() == "SHUNTCOMM") { auto type = static_cast(atoi(p->value().c_str())); settings.saveUInt("SHUNTCOMM", (int)type);