mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 19:42:08 +02:00
Merge pull request #1128 from dalathegreat/improvement/millis-reduction
Improvement: millis() reduction
This commit is contained in:
commit
c3838777cd
6 changed files with 10 additions and 15 deletions
|
@ -155,7 +155,7 @@ void setup_battery(void);
|
|||
void update_values_battery();
|
||||
|
||||
#ifdef RS485_BATTERY_SELECTED
|
||||
void transmit_rs485();
|
||||
void transmit_rs485(unsigned long currentMillis);
|
||||
void receive_RS485();
|
||||
#else
|
||||
void handle_incoming_can_frame_battery(CAN_frame rx_frame);
|
||||
|
|
|
@ -156,24 +156,22 @@ void decode_packet(uint8_t command, uint8_t data[8]) {
|
|||
}
|
||||
}
|
||||
|
||||
void DalyBms::transmit_rs485() {
|
||||
void DalyBms::transmit_rs485(unsigned long currentMillis) {
|
||||
|
||||
static uint8_t nextCommand = 0x90;
|
||||
|
||||
if (millis() - lastPacket > 60) {
|
||||
if (currentMillis - lastPacket > 60) {
|
||||
lastPacket = currentMillis;
|
||||
uint8_t tx_buff[13] = {0};
|
||||
tx_buff[0] = 0xA5;
|
||||
tx_buff[1] = 0x40;
|
||||
tx_buff[2] = nextCommand;
|
||||
tx_buff[3] = 8;
|
||||
tx_buff[12] = calculate_checksum(tx_buff);
|
||||
|
||||
#ifdef DEBUG_VIA_USB
|
||||
dump_buff("transmitting: ", tx_buff, 13);
|
||||
#endif
|
||||
|
||||
Serial2.write(tx_buff, 13);
|
||||
lastPacket = millis();
|
||||
|
||||
nextCommand++;
|
||||
if (nextCommand > 0x98)
|
||||
nextCommand = 0x90;
|
||||
|
|
|
@ -22,7 +22,7 @@ class DalyBms : public RS485Battery {
|
|||
public:
|
||||
void setup();
|
||||
void update_values();
|
||||
void transmit_rs485();
|
||||
void transmit_rs485(unsigned long currentMillis);
|
||||
void receive_RS485();
|
||||
|
||||
private:
|
||||
|
|
|
@ -161,7 +161,7 @@ uint16_t selectSOC(uint16_t SOC_low, uint16_t SOC_high) {
|
|||
}
|
||||
|
||||
/* These messages are needed for contactor closing */
|
||||
unsigned long startMillis;
|
||||
unsigned long startMillis = 0;
|
||||
uint8_t messageIndex = 0;
|
||||
uint8_t messageDelays[63] = {0, 0, 5, 10, 10, 15, 19, 19, 20, 20, 25, 30, 30, 35, 40, 40,
|
||||
45, 49, 49, 50, 50, 52, 53, 53, 54, 55, 60, 60, 65, 67, 67, 70,
|
||||
|
@ -1100,7 +1100,7 @@ void transmit_can_battery(unsigned long currentMillis) {
|
|||
}
|
||||
|
||||
if (messageIndex >= 63) {
|
||||
startMillis = millis(); // Start over!
|
||||
startMillis = currentMillis; // Start over!
|
||||
messageIndex = 0;
|
||||
}
|
||||
|
||||
|
@ -1131,9 +1131,6 @@ void transmit_can_battery(unsigned long currentMillis) {
|
|||
void setup_battery(void) { // Performs one time setup at startup
|
||||
strncpy(datalayer.system.info.battery_protocol, "Kia/Hyundai EGMP platform", 63);
|
||||
datalayer.system.info.battery_protocol[63] = '\0';
|
||||
|
||||
startMillis = millis(); // Record the starting time
|
||||
|
||||
datalayer.system.status.battery_allows_contactor_closing = true;
|
||||
datalayer.battery.info.number_of_cells = 192; // TODO: will vary depending on battery
|
||||
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_DV;
|
||||
|
|
|
@ -73,7 +73,7 @@ void wifi_monitor() {
|
|||
#endif
|
||||
// Try WiFi.reconnect() if it was successfully connected at least once
|
||||
if (hasConnectedBefore) {
|
||||
lastReconnectAttempt = millis(); // Reset reconnection attempt timer
|
||||
lastReconnectAttempt = currentMillis; // Reset reconnection attempt timer
|
||||
#ifdef DEBUG_LOG
|
||||
logging.println("Wi-Fi reconnect attempt...");
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue