mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
Pre-commit fix
This commit is contained in:
parent
055c933ee0
commit
30d37480be
9 changed files with 128 additions and 131 deletions
|
@ -844,10 +844,10 @@ void send_can_leaf_battery() {
|
|||
break;
|
||||
}
|
||||
|
||||
//Only send this message when NISSANLEAF_CHARGER is not defined (otherwise it will collide!)
|
||||
#ifndef NISSANLEAF_CHARGER
|
||||
//Only send this message when NISSANLEAF_CHARGER is not defined (otherwise it will collide!)
|
||||
#ifndef NISSANLEAF_CHARGER
|
||||
ESP32Can.CANWriteFrame(&LEAF_1F2); //Contains (CHG_STA_RQ == 1 == Normal Charge)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mprun10r++;
|
||||
if (mprun10r > 19) { // 0x1F2 patter repeats after 20 messages,
|
||||
|
|
|
@ -48,7 +48,7 @@ void update_values_test_battery() { /* This function puts fake values onto the p
|
|||
max_target_charge_power = 5000; // 5kW
|
||||
|
||||
for (int i = 0; i < 97; ++i) {
|
||||
cellvoltages[i] = 3500+i;
|
||||
cellvoltages[i] = 3500 + i;
|
||||
}
|
||||
|
||||
/*Finally print out values to serial if configured to do so*/
|
||||
|
|
|
@ -26,7 +26,14 @@ static unsigned long previousMillis10ms = 0;
|
|||
static unsigned long previousMillis100ms = 0;
|
||||
|
||||
/* LEAF charger/battery parameters */
|
||||
enum OBC_MODES : uint8_t { IDLE_OR_QC = 1, FINISHED = 2, CHARGING_OR_INTERRUPTED = 4, IDLE1 = 8, IDLE2 = 9, PLUGGED_IN_WAITING_ON_TIMER };
|
||||
enum OBC_MODES : uint8_t {
|
||||
IDLE_OR_QC = 1,
|
||||
FINISHED = 2,
|
||||
CHARGING_OR_INTERRUPTED = 4,
|
||||
IDLE1 = 8,
|
||||
IDLE2 = 9,
|
||||
PLUGGED_IN_WAITING_ON_TIMER
|
||||
};
|
||||
enum OBC_VOLTAGES : uint8_t { NO_SIGNAL = 0, AC110 = 1, AC230 = 2, ABNORMAL_WAVE = 3 };
|
||||
static uint16_t OBC_Charge_Power = 0; // Actual charger output
|
||||
static uint8_t mprun100 = 0; // Counter 0-3
|
||||
|
@ -118,7 +125,6 @@ static uint8_t crctable[256] = {
|
|||
196, 65, 75, 206, 76, 201, 195, 70, 215, 82, 88, 221, 255, 122, 112, 245, 100, 225, 235, 110, 175, 42,
|
||||
32, 165, 52, 177, 187, 62, 28, 153, 147, 22, 135, 2, 8, 141};
|
||||
|
||||
|
||||
void receive_can_nissanleaf_charger(CAN_frame_t rx_frame) {
|
||||
|
||||
switch (rx_frame.MsgID) {
|
||||
|
@ -132,20 +138,19 @@ void receive_can_nissanleaf_charger(CAN_frame_t rx_frame) {
|
|||
break;
|
||||
case 0x390:
|
||||
OBC_Charge_Status = ((rx_frame.data.u8[5] & 0x7E) >> 1);
|
||||
if(OBC_Charge_Status == PLUGGED_IN_WAITING_ON_TIMER || CHARGING_OR_INTERRUPTED) {
|
||||
if (OBC_Charge_Status == PLUGGED_IN_WAITING_ON_TIMER || CHARGING_OR_INTERRUPTED) {
|
||||
PPStatus = true; //plug inserted
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PPStatus = false; //plug not inserted
|
||||
}
|
||||
OBC_Status_AC_Voltage = ((rx_frame.data.u8[3] & 0x18) >> 3);
|
||||
if(OBC_Status_AC_Voltage == AC110){
|
||||
if (OBC_Status_AC_Voltage == AC110) {
|
||||
charger_stat_ACvol = 110;
|
||||
}
|
||||
if(OBC_Status_AC_Voltage == AC230){
|
||||
if (OBC_Status_AC_Voltage == AC230) {
|
||||
charger_stat_ACvol = 230;
|
||||
}
|
||||
if(OBC_Status_AC_Voltage == ABNORMAL_WAVE){
|
||||
if (OBC_Status_AC_Voltage == ABNORMAL_WAVE) {
|
||||
charger_stat_ACvol = 1;
|
||||
}
|
||||
|
||||
|
@ -168,9 +173,9 @@ void send_can_nissanleaf_charger() {
|
|||
if (mprun10 >= 4)
|
||||
mprun10 = 0;
|
||||
|
||||
/* 1DB is the main control message. If LEAF battery is used, the battery controls almost everything */
|
||||
// Only send these messages if Nissan LEAF battery is not used
|
||||
#ifndef NISSAN_LEAF_BATTERY
|
||||
/* 1DB is the main control message. If LEAF battery is used, the battery controls almost everything */
|
||||
// Only send these messages if Nissan LEAF battery is not used
|
||||
#ifndef NISSAN_LEAF_BATTERY
|
||||
|
||||
// VCM message, containing info if battery should sleep or stay awake
|
||||
ESP32Can.CANWriteFrame(&LEAF_50B); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1
|
||||
|
@ -180,7 +185,7 @@ void send_can_nissanleaf_charger() {
|
|||
|
||||
LEAF_1DC.data.u8[7] = calculate_CRC_Nissan(&LEAF_1DC);
|
||||
ESP32Can.CANWriteFrame(&LEAF_1DC);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
OBCpowerSetpoint = ((charger_setpoint_HV_IDC * 4) + 0x64);
|
||||
|
||||
|
@ -194,12 +199,12 @@ void send_can_nissanleaf_charger() {
|
|||
// so 0x64=100. 0xA0=160. so 60 decimal steps. 1 step=100W???
|
||||
|
||||
// This line controls if power should flow or not
|
||||
if (PPStatus && charger_HV_enabled) { //Charging starts when cable plugged in and User has requested charging to start via WebUI
|
||||
if (PPStatus &&
|
||||
charger_HV_enabled) { //Charging starts when cable plugged in and User has requested charging to start via WebUI
|
||||
// clamp min and max values
|
||||
if (OBCpowerSetpoint > 0xA0) { //15A TODO, raise once cofirmed how to map bits into frame0 and frame1
|
||||
OBCpowerSetpoint = 0xA0;
|
||||
}
|
||||
else if(OBCpowerSetpoint <= 0x64) {
|
||||
} else if (OBCpowerSetpoint <= 0x64) {
|
||||
OBCpowerSetpoint = 0x64; // 100W? stuck at 100 in drive mode (no charging)
|
||||
}
|
||||
|
||||
|
@ -210,13 +215,11 @@ void send_can_nissanleaf_charger() {
|
|||
|
||||
// decrement charger power if volt setpoint is reached
|
||||
if (battery_voltage >= (CHARGER_SET_HV * 10)) {
|
||||
if (OBCpower > 0x64){
|
||||
if (OBCpower > 0x64) {
|
||||
OBCpower--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// set power to 0 if charge control is set to off or not in charge mode
|
||||
OBCpower = 0x64;
|
||||
}
|
||||
|
@ -225,8 +228,8 @@ void send_can_nissanleaf_charger() {
|
|||
LEAF_1F2.data.u8[6] = mprun10;
|
||||
LEAF_1F2.data.u8[7] = calculate_checksum_nibble(&LEAF_1F2);
|
||||
|
||||
ESP32Can.CANWriteFrame(&LEAF_1F2); // Sending of 1F2 message is halted in LEAF-BATTERY function incase charger is used!
|
||||
|
||||
ESP32Can.CANWriteFrame(
|
||||
&LEAF_1F2); // Sending of 1F2 message is halted in LEAF-BATTERY function incase charger is used!
|
||||
}
|
||||
|
||||
/* Send messages every 100ms here */
|
||||
|
@ -238,8 +241,8 @@ void send_can_nissanleaf_charger() {
|
|||
mprun100 = 0;
|
||||
}
|
||||
|
||||
// Only send these messages if Nissan LEAF battery is not used
|
||||
#ifndef NISSAN_LEAF_BATTERY
|
||||
// Only send these messages if Nissan LEAF battery is not used
|
||||
#ifndef NISSAN_LEAF_BATTERY
|
||||
|
||||
LEAF_55B.data.u8[6] = ((0x1 << 4) | (mprun100));
|
||||
|
||||
|
@ -249,9 +252,8 @@ void send_can_nissanleaf_charger() {
|
|||
ESP32Can.CANWriteFrame(&LEAF_59E);
|
||||
|
||||
ESP32Can.CANWriteFrame(&LEAF_5BC);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t calculate_CRC_Nissan(CAN_frame_t* frame) {
|
||||
|
@ -262,9 +264,9 @@ uint8_t calculate_CRC_Nissan(CAN_frame_t* frame) {
|
|||
return crc;
|
||||
}
|
||||
|
||||
uint8_t calculate_checksum_nibble(CAN_frame_t *frame){
|
||||
uint8_t calculate_checksum_nibble(CAN_frame_t* frame) {
|
||||
uint8_t sum = 0;
|
||||
for(uint8_t i = 0; i < 7; i++){
|
||||
for (uint8_t i = 0; i < 7; i++) {
|
||||
sum += frame->data.u8[i] >> 4;
|
||||
sum += frame->data.u8[i] & 0xF;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,6 @@ void update_values_can_nissanleaf_charger();
|
|||
void send_can_nissanleaf_charger();
|
||||
void receive_can_nissanleaf_charger(CAN_frame_t rx_frame);
|
||||
uint8_t calculate_CRC_Nissan(CAN_frame_t* frame);
|
||||
uint8_t calculate_checksum_nibble(CAN_frame_t *frame);
|
||||
uint8_t calculate_checksum_nibble(CAN_frame_t* frame);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -61,8 +61,9 @@ void init_webserver() {
|
|||
[](AsyncWebServerRequest* request) { request->send_P(200, "text/html", index_html, settings_processor); });
|
||||
|
||||
// Route for going to cellmonitor web page
|
||||
server.on("/cellmonitor", HTTP_GET,
|
||||
[](AsyncWebServerRequest* request) { request->send_P(200, "text/html", index_html, cellmonitor_processor); });
|
||||
server.on("/cellmonitor", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
request->send_P(200, "text/html", index_html, cellmonitor_processor);
|
||||
});
|
||||
|
||||
// Route for editing Wh
|
||||
server.on("/updateBatterySize", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
|
@ -129,7 +130,7 @@ void init_webserver() {
|
|||
String value = request->getParam("value")->value();
|
||||
float val = value.toFloat();
|
||||
|
||||
battery_voltage = val*10;
|
||||
battery_voltage = val * 10;
|
||||
|
||||
request->send(200, "text/plain", "Updated successfully");
|
||||
});
|
||||
|
@ -524,7 +525,7 @@ String processor(const String& var) {
|
|||
content += "<span style='color: red;'>✕</span>";
|
||||
}
|
||||
content += "</h4>";
|
||||
#ifdef CHEVYVOLT_CHARGER
|
||||
#ifdef CHEVYVOLT_CHARGER
|
||||
float chgPwrDC = static_cast<float>(charger_stat_HVcur * charger_stat_HVvol);
|
||||
float chgPwrAC = static_cast<float>(charger_stat_ACcur * charger_stat_ACvol);
|
||||
float chgEff = chgPwrDC / chgPwrAC * 100;
|
||||
|
@ -543,11 +544,11 @@ String processor(const String& var) {
|
|||
content += "<h4 style='color: white;'>Charger LVDC Output V: " + String(LVvol, 2) + "</h4>";
|
||||
content += "<h4 style='color: white;'>Charger AC Input V: " + String(ACvol, 2) + " VAC</h4>";
|
||||
content += "<h4 style='color: white;'>Charger AC Input I: " + String(ACcur, 2) + " A</h4>";
|
||||
#endif
|
||||
#ifdef NISSANLEAF_CHARGER
|
||||
float chgPwrDC = static_cast<float>(charger_stat_HVcur*100);
|
||||
charger_stat_HVcur = chgPwrDC/(battery_voltage/10); // P/U=I
|
||||
charger_stat_HVvol = static_cast<float>(battery_voltage/10);
|
||||
#endif
|
||||
#ifdef NISSANLEAF_CHARGER
|
||||
float chgPwrDC = static_cast<float>(charger_stat_HVcur * 100);
|
||||
charger_stat_HVcur = chgPwrDC / (battery_voltage / 10); // P/U=I
|
||||
charger_stat_HVvol = static_cast<float>(battery_voltage / 10);
|
||||
float ACvol = charger_stat_ACvol;
|
||||
float HVvol = charger_stat_HVvol;
|
||||
float HVcur = charger_stat_HVcur;
|
||||
|
@ -556,13 +557,11 @@ String processor(const String& var) {
|
|||
content += "<h4 style='color: white;'>Charger HVDC Output V: " + String(HVvol, 2) + " V</h4>";
|
||||
content += "<h4 style='color: white;'>Charger HVDC Output I: " + String(HVcur, 2) + " A</h4>";
|
||||
content += "<h4 style='color: white;'>Charger AC Input V: " + String(ACvol, 2) + " VAC</h4>";
|
||||
#endif
|
||||
#endif
|
||||
// Close the block
|
||||
content += "</div>";
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
content += "<button onclick='goToUpdatePage()'>Perform OTA update</button>";
|
||||
content += " ";
|
||||
content += "<button onclick='goToSettingsPage()'>Change Settings</button>";
|
||||
|
@ -885,10 +884,6 @@ String cellmonitor_processor(const String& var) {
|
|||
return String();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void onOTAStart() {
|
||||
// Log when OTA has started
|
||||
Serial.println("OTA update started!");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue