daly bms: send rs485 packets more often, but also prevent broken reads when one packet generates multiple responses

This commit is contained in:
Jakob Löw 2025-02-13 00:31:17 +01:00
parent e4667656fd
commit 27d2333ad7
No known key found for this signature in database
GPG key ID: B77685F55C7C46C6

View file

@ -145,10 +145,9 @@ void decode_packet(uint8_t command, uint8_t data[8]) {
} }
void transmit_rs485() { void transmit_rs485() {
static uint32_t lastSend = 0;
static uint8_t nextCommand = 0x90; static uint8_t nextCommand = 0x90;
if (millis() - lastSend > 100) { if (millis() - lastPacket > 60) {
uint8_t tx_buff[13] = {0}; uint8_t tx_buff[13] = {0};
tx_buff[0] = 0xA5; tx_buff[0] = 0xA5;
tx_buff[1] = 0x40; tx_buff[1] = 0x40;
@ -161,7 +160,7 @@ void transmit_rs485() {
#endif #endif
Serial2.write(tx_buff, 13); Serial2.write(tx_buff, 13);
lastSend = millis(); lastPacket = millis();
nextCommand++; nextCommand++;
if (nextCommand > 0x98) if (nextCommand > 0x98)
@ -194,6 +193,7 @@ void receive_RS485() {
#endif #endif
decode_packet(recv_buff[2], &recv_buff[4]); decode_packet(recv_buff[2], &recv_buff[4]);
recv_len = 0; recv_len = 0;
lastPacket = millis();
} }
} }
} }