Setting voltage for battery is always fake

This commit is contained in:
Jaakko Haakana 2025-06-01 13:43:57 +03:00
parent 6bd0865195
commit 0eb852997c
4 changed files with 8 additions and 8 deletions

View file

@ -26,7 +26,7 @@ class Battery {
virtual bool supports_reset_SOH() { return false; } virtual bool supports_reset_SOH() { return false; }
virtual bool supports_reset_BECM() { return false; } virtual bool supports_reset_BECM() { return false; }
virtual bool supports_contactor_close() { return false; } virtual bool supports_contactor_close() { return false; }
virtual bool supports_set_voltage() { return false; } virtual bool supports_set_fake_voltage() { return false; }
virtual bool supports_manual_balancing() { return false; } virtual bool supports_manual_balancing() { return false; }
virtual bool supports_real_BMS_status() { return false; } virtual bool supports_real_BMS_status() { return false; }
@ -41,7 +41,7 @@ class Battery {
virtual void request_open_contactors() {} virtual void request_open_contactors() {}
virtual void request_close_contactors() {} virtual void request_close_contactors() {}
virtual void set_voltage(float v) {} virtual void set_fake_voltage(float v) {}
virtual float get_voltage() { static_cast<float>(datalayer.battery.status.voltage_dV) / 10.0; } virtual float get_voltage() { static_cast<float>(datalayer.battery.status.voltage_dV) / 10.0; }
// This allows for battery specific SOC plausibility calculations to be performed. // This allows for battery specific SOC plausibility calculations to be performed.

View file

@ -26,8 +26,8 @@ class TestFakeBattery : public CanBattery {
virtual void update_values(); virtual void update_values();
virtual void transmit_can(unsigned long currentMillis); virtual void transmit_can(unsigned long currentMillis);
bool supports_set_voltage() { return true; } bool supports_set_fake_voltage() { return true; }
void set_voltage(float val) { datalayer.battery.status.voltage_dV = val * 10; } void set_fake_voltage(float val) { datalayer.battery.status.voltage_dV = val * 10; }
private: private:
DATALAYER_BATTERY_TYPE* datalayer_battery; DATALAYER_BATTERY_TYPE* datalayer_battery;

View file

@ -89,7 +89,7 @@ String settings_processor(const String& var) {
// Close the block // Close the block
content += "</div>"; content += "</div>";
if (battery->supports_set_voltage()) { if (battery->supports_set_fake_voltage()) {
content += "<div style='background-color: #2E37AD; padding: 10px; margin-bottom: 10px;border-radius: 50px'>"; content += "<div style='background-color: #2E37AD; padding: 10px; margin-bottom: 10px;border-radius: 50px'>";
content += "<h4 style='color: white;'>Fake battery voltage: " + String(battery->get_voltage(), 1) + content += "<h4 style='color: white;'>Fake battery voltage: " + String(battery->get_voltage(), 1) +
" V </span> <button onclick='editFakeBatteryVoltage()'>Edit</button></h4>"; " V </span> <button onclick='editFakeBatteryVoltage()'>Edit</button></h4>";
@ -281,7 +281,7 @@ String settings_processor(const String& var) {
"BalMaxDevCellV?value='+value,true);xhr.send();}else{alert('Invalid value. Please enter a value " "BalMaxDevCellV?value='+value,true);xhr.send();}else{alert('Invalid value. Please enter a value "
"between 300 and 600');}}}"; "between 300 and 600');}}}";
if (battery->supports_set_voltage()) { if (battery->supports_set_fake_voltage()) {
content += content +=
"function editFakeBatteryVoltage(){var value=prompt('Enter new fake battery " "function editFakeBatteryVoltage(){var value=prompt('Enter new fake battery "
"voltage');if(value!==null){if(value>=0&&value<=5000){var xhr=new " "voltage');if(value!==null){if(value>=0&&value<=5000){var xhr=new "

View file

@ -601,7 +601,7 @@ void init_webserver() {
}); });
// Route for editing FakeBatteryVoltage // Route for editing FakeBatteryVoltage
server.on("/updateBatteryVoltage", HTTP_GET, [](AsyncWebServerRequest* request) { server.on("/updateFakeBatteryVoltage", HTTP_GET, [](AsyncWebServerRequest* request) {
if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password)) if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password))
return request->requestAuthentication(); return request->requestAuthentication();
if (!request->hasParam("value")) { if (!request->hasParam("value")) {
@ -611,7 +611,7 @@ void init_webserver() {
String value = request->getParam("value")->value(); String value = request->getParam("value")->value();
float val = value.toFloat(); float val = value.toFloat();
battery->set_voltage(val); battery->set_fake_voltage(val);
request->send(200, "text/plain", "Updated successfully"); request->send(200, "text/plain", "Updated successfully");
}); });