mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
Use base class for KIA Hyundai Hybrid battery
This commit is contained in:
parent
abf7fe3c26
commit
26f2a7943d
2 changed files with 68 additions and 56 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "../include.h"
|
#include "../include.h"
|
||||||
#ifdef KIA_HYUNDAI_HYBRID_BATTERY
|
#ifdef KIA_HYUNDAI_HYBRID_BATTERY
|
||||||
|
#include "../communication/can/comm_can.h"
|
||||||
#include "../datalayer/datalayer.h"
|
#include "../datalayer/datalayer.h"
|
||||||
#include "../devboard/utils/events.h"
|
#include "../devboard/utils/events.h"
|
||||||
#include "KIA-HYUNDAI-HYBRID-BATTERY.h"
|
#include "KIA-HYUNDAI-HYBRID-BATTERY.h"
|
||||||
|
@ -9,51 +10,8 @@
|
||||||
- We need to figure out how to keep the BMS alive. Most likely we need to send a specific CAN message
|
- We need to figure out how to keep the BMS alive. Most likely we need to send a specific CAN message
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do not change code below unless you are sure what you are doing */
|
void KiaHyundaiHybridBattery::
|
||||||
static unsigned long previousMillis1000 = 0; // will store last time a 100ms CAN Message was send
|
update_values() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
|
||||||
|
|
||||||
static uint16_t SOC = 0;
|
|
||||||
static uint16_t SOC_display = 0;
|
|
||||||
static bool interlock_missing = false;
|
|
||||||
static int16_t battery_current = 0;
|
|
||||||
static uint8_t battery_current_high_byte = 0;
|
|
||||||
static uint16_t battery_voltage = 0;
|
|
||||||
static uint32_t available_charge_power = 0;
|
|
||||||
static uint32_t available_discharge_power = 0;
|
|
||||||
static int8_t battery_module_max_temperature = 0;
|
|
||||||
static int8_t battery_module_min_temperature = 0;
|
|
||||||
static uint8_t poll_data_pid = 0;
|
|
||||||
static uint16_t cellvoltages_mv[98];
|
|
||||||
static uint16_t min_cell_voltage_mv = 3700;
|
|
||||||
static uint16_t max_cell_voltage_mv = 3700;
|
|
||||||
|
|
||||||
CAN_frame KIA_7E4_id1 = {.FD = false,
|
|
||||||
.ext_ID = false,
|
|
||||||
.DLC = 8,
|
|
||||||
.ID = 0x7E4,
|
|
||||||
.data = {0x02, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
|
||||||
CAN_frame KIA_7E4_id2 = {.FD = false,
|
|
||||||
.ext_ID = false,
|
|
||||||
.DLC = 8,
|
|
||||||
.ID = 0x7E4,
|
|
||||||
.data = {0x02, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
|
||||||
CAN_frame KIA_7E4_id3 = {.FD = false,
|
|
||||||
.ext_ID = false,
|
|
||||||
.DLC = 8,
|
|
||||||
.ID = 0x7E4,
|
|
||||||
.data = {0x02, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
|
||||||
CAN_frame KIA_7E4_id5 = {.FD = false,
|
|
||||||
.ext_ID = false,
|
|
||||||
.DLC = 8,
|
|
||||||
.ID = 0x7E4,
|
|
||||||
.data = {0x02, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00}};
|
|
||||||
CAN_frame KIA_7E4_ack = {.FD = false,
|
|
||||||
.ext_ID = false,
|
|
||||||
.DLC = 8,
|
|
||||||
.ID = 0x7E4, //Ack frame, correct PID is returned. Flow control message
|
|
||||||
.data = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
|
||||||
|
|
||||||
void update_values_battery() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
|
|
||||||
|
|
||||||
datalayer.battery.status.real_soc = SOC * 50;
|
datalayer.battery.status.real_soc = SOC * 50;
|
||||||
|
|
||||||
|
@ -86,7 +44,7 @@ void update_values_battery() { //This function maps all the values fetched via
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
|
void KiaHyundaiHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||||
switch (rx_frame.ID) {
|
switch (rx_frame.ID) {
|
||||||
case 0x5F1:
|
case 0x5F1:
|
||||||
|
@ -230,7 +188,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void transmit_can_battery(unsigned long currentMillis) {
|
|
||||||
|
void KiaHyundaiHybridBattery::transmit_can(unsigned long currentMillis) {
|
||||||
|
|
||||||
// Send 1000ms CAN Message
|
// Send 1000ms CAN Message
|
||||||
if (currentMillis - previousMillis1000 >= INTERVAL_1_S) {
|
if (currentMillis - previousMillis1000 >= INTERVAL_1_S) {
|
||||||
|
@ -255,7 +214,7 @@ void transmit_can_battery(unsigned long currentMillis) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_battery(void) { // Performs one time setup at startup
|
void KiaHyundaiHybridBattery::setup(void) { // Performs one time setup at startup
|
||||||
strncpy(datalayer.system.info.battery_protocol, "Kia/Hyundai Hybrid", 63);
|
strncpy(datalayer.system.info.battery_protocol, "Kia/Hyundai Hybrid", 63);
|
||||||
datalayer.system.info.battery_protocol[63] = '\0';
|
datalayer.system.info.battery_protocol[63] = '\0';
|
||||||
datalayer.system.status.battery_allows_contactor_closing = true;
|
datalayer.system.status.battery_allows_contactor_closing = true;
|
||||||
|
|
|
@ -3,14 +3,67 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "../include.h"
|
#include "../include.h"
|
||||||
|
|
||||||
#define BATTERY_SELECTED
|
#include "CanBattery.h"
|
||||||
#define MAX_PACK_VOLTAGE_DV 2550 //5000 = 500.0V
|
|
||||||
#define MIN_PACK_VOLTAGE_DV 1700
|
|
||||||
#define MAX_CELL_DEVIATION_MV 100
|
|
||||||
#define MAX_CELL_VOLTAGE_MV 4250 //Battery is put into emergency stop if one cell goes over this value
|
|
||||||
#define MIN_CELL_VOLTAGE_MV 2700 //Battery is put into emergency stop if one cell goes below this value
|
|
||||||
|
|
||||||
void setup_battery(void);
|
#define BATTERY_SELECTED
|
||||||
void transmit_can_frame(CAN_frame* tx_frame, int interface);
|
#define SELECTED_BATTERY_CLASS KiaHyundaiHybridBattery
|
||||||
|
|
||||||
|
class KiaHyundaiHybridBattery : public CanBattery {
|
||||||
|
public:
|
||||||
|
virtual void setup(void);
|
||||||
|
virtual void handle_incoming_can_frame(CAN_frame rx_frame);
|
||||||
|
virtual void update_values();
|
||||||
|
virtual void transmit_can(unsigned long currentMillis);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const int MAX_PACK_VOLTAGE_DV = 2550; //5000 = 500.0V
|
||||||
|
static const int MIN_PACK_VOLTAGE_DV = 1700;
|
||||||
|
static const int MAX_CELL_DEVIATION_MV = 100;
|
||||||
|
static const int MAX_CELL_VOLTAGE_MV = 4250; //Battery is put into emergency stop if one cell goes over this value
|
||||||
|
static const int MIN_CELL_VOLTAGE_MV = 2700; //Battery is put into emergency stop if one cell goes below this value
|
||||||
|
|
||||||
|
unsigned long previousMillis1000 = 0; // will store last time a 100ms CAN Message was send
|
||||||
|
|
||||||
|
uint16_t SOC = 0;
|
||||||
|
uint16_t SOC_display = 0;
|
||||||
|
bool interlock_missing = false;
|
||||||
|
int16_t battery_current = 0;
|
||||||
|
uint8_t battery_current_high_byte = 0;
|
||||||
|
uint16_t battery_voltage = 0;
|
||||||
|
uint32_t available_charge_power = 0;
|
||||||
|
uint32_t available_discharge_power = 0;
|
||||||
|
int8_t battery_module_max_temperature = 0;
|
||||||
|
int8_t battery_module_min_temperature = 0;
|
||||||
|
uint8_t poll_data_pid = 0;
|
||||||
|
uint16_t cellvoltages_mv[98];
|
||||||
|
uint16_t min_cell_voltage_mv = 3700;
|
||||||
|
uint16_t max_cell_voltage_mv = 3700;
|
||||||
|
|
||||||
|
CAN_frame KIA_7E4_id1 = {.FD = false,
|
||||||
|
.ext_ID = false,
|
||||||
|
.DLC = 8,
|
||||||
|
.ID = 0x7E4,
|
||||||
|
.data = {0x02, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||||
|
CAN_frame KIA_7E4_id2 = {.FD = false,
|
||||||
|
.ext_ID = false,
|
||||||
|
.DLC = 8,
|
||||||
|
.ID = 0x7E4,
|
||||||
|
.data = {0x02, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||||
|
CAN_frame KIA_7E4_id3 = {.FD = false,
|
||||||
|
.ext_ID = false,
|
||||||
|
.DLC = 8,
|
||||||
|
.ID = 0x7E4,
|
||||||
|
.data = {0x02, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||||
|
CAN_frame KIA_7E4_id5 = {.FD = false,
|
||||||
|
.ext_ID = false,
|
||||||
|
.DLC = 8,
|
||||||
|
.ID = 0x7E4,
|
||||||
|
.data = {0x02, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00}};
|
||||||
|
CAN_frame KIA_7E4_ack = {.FD = false,
|
||||||
|
.ext_ID = false,
|
||||||
|
.DLC = 8,
|
||||||
|
.ID = 0x7E4, //Ack frame, correct PID is returned. Flow control message
|
||||||
|
.data = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue