diff --git a/Software/src/battery/RENAULT-TWIZY.cpp b/Software/src/battery/RENAULT-TWIZY.cpp index 487973c9..1dffca86 100644 --- a/Software/src/battery/RENAULT-TWIZY.cpp +++ b/Software/src/battery/RENAULT-TWIZY.cpp @@ -5,19 +5,6 @@ #include "../devboard/utils/events.h" #include "RENAULT-TWIZY.h" -/* Do not change code below unless you are sure what you are doing */ - -static int16_t cell_temperatures_dC[7] = {0}; -static int16_t current_dA = 0; -static uint16_t voltage_dV = 0; -static int16_t cellvoltages_mV[14] = {0}; -static int16_t max_discharge_power = 0; -static int16_t max_recup_power = 0; -static int16_t max_charge_power = 0; -static uint16_t SOC = 0; -static uint16_t SOH = 0; -static uint16_t remaining_capacity_Wh = 0; - int16_t max_value(int16_t* entries, size_t len) { int result = INT16_MIN; for (int i = 0; i < len; i++) { @@ -38,7 +25,7 @@ int16_t min_value(int16_t* entries, size_t len) { return result; } -void update_values_battery() { +void RenaultTwizyBattery::update_values() { datalayer.battery.status.real_soc = SOC; datalayer.battery.status.soh_pptt = SOH; @@ -65,7 +52,7 @@ void update_values_battery() { max_value(cell_temperatures_dC, sizeof(cell_temperatures_dC) / sizeof(*cell_temperatures_dC)); } -void handle_incoming_can_frame_battery(CAN_frame rx_frame) { +void RenaultTwizyBattery::handle_incoming_can_frame(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x155: @@ -127,11 +114,11 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) { } } -void transmit_can_battery(unsigned long currentMillis) { +void RenaultTwizyBattery::transmit_can(unsigned long currentMillis) { // we do not need to send anything to the battery for now } -void setup_battery(void) { // Performs one time setup at startup +void RenaultTwizyBattery::setup(void) { // Performs one time setup at startup strncpy(datalayer.system.info.battery_protocol, "Renault Twizy", 63); datalayer.system.info.battery_protocol[63] = '\0'; datalayer.battery.info.number_of_cells = 14; diff --git a/Software/src/battery/RENAULT-TWIZY.h b/Software/src/battery/RENAULT-TWIZY.h index 36105a98..f4ab501c 100644 --- a/Software/src/battery/RENAULT-TWIZY.h +++ b/Software/src/battery/RENAULT-TWIZY.h @@ -1,15 +1,35 @@ #ifndef RENAULT_TWIZY_BATTERY_H #define RENAULT_TWIZY_BATTERY_H #include "../include.h" +#include "CanBattery.h" #define BATTERY_SELECTED -#define MAX_PACK_VOLTAGE_DV 579 // 57.9V at 100% SOC (with 70% SOH, new one might be higher) -#define MIN_PACK_VOLTAGE_DV 480 // 48.4V at 13.76% SOC -#define MAX_CELL_DEVIATION_MV 150 -#define MAX_CELL_VOLTAGE_MV 4200 //Battery is put into emergency stop if one cell goes over this value -#define MIN_CELL_VOLTAGE_MV 3400 //Battery is put into emergency stop if one cell goes below this value +#define SELECTED_BATTERY_CLASS RenaultTwizyBattery -void setup_battery(void); -void transmit_can_frame(CAN_frame* tx_frame, int interface); +class RenaultTwizyBattery : 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 = 579; // 57.9V at 100% SOC (with 70% SOH, new one might be higher) + static const int MIN_PACK_VOLTAGE_DV = 480; // 48.4V at 13.76% SOC + static const int MAX_CELL_DEVIATION_MV = 150; + static const int MAX_CELL_VOLTAGE_MV = 4200; //Battery is put into emergency stop if one cell goes over this value + static const int MIN_CELL_VOLTAGE_MV = 3400; //Battery is put into emergency stop if one cell goes below this value + + int16_t cell_temperatures_dC[7] = {0}; + int16_t current_dA = 0; + uint16_t voltage_dV = 0; + int16_t cellvoltages_mV[14] = {0}; + int16_t max_discharge_power = 0; + int16_t max_recup_power = 0; + int16_t max_charge_power = 0; + uint16_t SOC = 0; + uint16_t SOH = 0; + uint16_t remaining_capacity_Wh = 0; +}; #endif