mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 19:42:08 +02:00
Add error handling write values to 0
This commit is contained in:
parent
44fa2ba3b0
commit
4f6aecfdb2
2 changed files with 9 additions and 15 deletions
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
// Interval settings
|
// Interval settings
|
||||||
int intervalUpdateValues = 4800; // Interval at which to update inverter values / Modbus registers
|
int intervalUpdateValues = 4800; // Interval at which to update inverter values / Modbus registers
|
||||||
|
const int interval1 = 1; // Interval for 1ms tasks
|
||||||
const int interval10 = 10; // Interval for 10ms tasks
|
const int interval10 = 10; // Interval for 10ms tasks
|
||||||
|
unsigned long previousMillis1ms = 0;
|
||||||
unsigned long previousMillis10ms = 50;
|
unsigned long previousMillis10ms = 50;
|
||||||
unsigned long previousMillisUpdateVal = 0;
|
unsigned long previousMillisUpdateVal = 0;
|
||||||
|
|
||||||
|
@ -128,12 +130,9 @@ void loop() {
|
||||||
#ifdef DUAL_CAN
|
#ifdef DUAL_CAN
|
||||||
receive_can2();
|
receive_can2();
|
||||||
#endif
|
#endif
|
||||||
<<<<<<< HEAD
|
|
||||||
#ifdef SERIAL_LINK_RECEIVER
|
#ifdef SERIAL_LINK_RECEIVER
|
||||||
receive_serial();
|
receive_serial();
|
||||||
#endif
|
#endif
|
||||||
=======
|
|
||||||
>>>>>>> main
|
|
||||||
|
|
||||||
// Process
|
// Process
|
||||||
if (millis() - previousMillis10ms >= interval10) // Every 10ms
|
if (millis() - previousMillis10ms >= interval10) // Every 10ms
|
||||||
|
@ -156,12 +155,9 @@ void loop() {
|
||||||
#ifdef DUAL_CAN
|
#ifdef DUAL_CAN
|
||||||
send_can2();
|
send_can2();
|
||||||
#endif
|
#endif
|
||||||
<<<<<<< HEAD
|
|
||||||
#ifdef SERIAL_LINK_TRANSMITTER
|
#ifdef SERIAL_LINK_TRANSMITTER
|
||||||
send_serial();
|
send_serial();
|
||||||
#endif
|
#endif
|
||||||
=======
|
|
||||||
>>>>>>> main
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialization functions
|
// Initialization functions
|
||||||
|
@ -229,7 +225,6 @@ void init_modbus() {
|
||||||
pinMode(PIN_5V_EN, OUTPUT);
|
pinMode(PIN_5V_EN, OUTPUT);
|
||||||
digitalWrite(PIN_5V_EN, HIGH);
|
digitalWrite(PIN_5V_EN, HIGH);
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
||||||
Serial2.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN); // If the Modbus RTU port will be used for serial link
|
Serial2.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN); // If the Modbus RTU port will be used for serial link
|
||||||
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS)
|
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS)
|
||||||
|
@ -237,8 +232,6 @@ void init_modbus() {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> main
|
|
||||||
#ifdef BYD_MODBUS
|
#ifdef BYD_MODBUS
|
||||||
// Init Static data to the RTU Modbus
|
// Init Static data to the RTU Modbus
|
||||||
handle_static_data_modbus_byd();
|
handle_static_data_modbus_byd();
|
||||||
|
@ -408,7 +401,6 @@ void send_can() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
#ifdef SERIAL_LINK_RECEIVER
|
#ifdef SERIAL_LINK_RECEIVER
|
||||||
//---- Receives serial data and transfers to the Inverter
|
//---- Receives serial data and transfers to the Inverter
|
||||||
void receive_serial() {
|
void receive_serial() {
|
||||||
|
@ -424,15 +416,15 @@ void receive_serial() {
|
||||||
//---- Gets data from Battery and serial Transmits the data to the Receiver
|
//---- Gets data from Battery and serial Transmits the data to the Receiver
|
||||||
void send_serial() {
|
void send_serial() {
|
||||||
static unsigned long currentMillis = millis();
|
static unsigned long currentMillis = millis();
|
||||||
if (currentMillis - previousMillis1ms > interval1) { //--- try 2 second
|
if (bms_status == ACTIVE) {
|
||||||
previousMillis1ms = currentMillis;
|
if (currentMillis - previousMillis1ms > interval1) { //--- try 2 second
|
||||||
manageSerialLinkTransmitter();
|
previousMillis1ms = currentMillis;
|
||||||
|
manageSerialLinkTransmitter();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> main
|
|
||||||
#ifdef DUAL_CAN
|
#ifdef DUAL_CAN
|
||||||
void receive_can2() { // This function is similar to receive_can, but just takes care of inverters in the 2nd bus.
|
void receive_can2() { // This function is similar to receive_can, but just takes care of inverters in the 2nd bus.
|
||||||
// Depending on which inverter is selected, we forward this to their respective CAN routines
|
// Depending on which inverter is selected, we forward this to their respective CAN routines
|
||||||
|
|
|
@ -82,6 +82,8 @@ void manageSerialLinkTransmitter() {
|
||||||
Serial.print(currentTime);
|
Serial.print(currentTime);
|
||||||
Serial.println(" - Transmit Failed : 60 seconds");
|
Serial.println(" - Transmit Failed : 60 seconds");
|
||||||
bms_status = 4; //FAULT
|
bms_status = 4; //FAULT
|
||||||
|
max_target_discharge_power = 0;
|
||||||
|
max_target_charge_power = 0;
|
||||||
LEDcolor = RED;
|
LEDcolor = RED;
|
||||||
// throw error
|
// throw error
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue