mirror of
https://github.com/esphome/esphome.git
synced 2026-05-27 20:53:46 +08:00
[bl0942] Fix millis overflow in packet timeout check (#14285)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -52,12 +52,12 @@ void BL0942::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (avail < sizeof(buffer)) {
|
if (avail < sizeof(buffer)) {
|
||||||
if (!this->rx_start_) {
|
if (!this->rx_start_.has_value()) {
|
||||||
this->rx_start_ = millis();
|
this->rx_start_ = millis();
|
||||||
} else if (millis() > this->rx_start_ + PKT_TIMEOUT_MS) {
|
} else if (millis() - *this->rx_start_ > PKT_TIMEOUT_MS) {
|
||||||
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message (%zu bytes)", avail);
|
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message (%zu bytes)", avail);
|
||||||
this->read_array((uint8_t *) &buffer, avail);
|
this->read_array((uint8_t *) &buffer, avail);
|
||||||
this->rx_start_ = 0;
|
this->rx_start_.reset();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ void BL0942::loop() {
|
|||||||
this->received_package_(&buffer);
|
this->received_package_(&buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->rx_start_ = 0;
|
this->rx_start_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BL0942::validate_checksum_(DataPacket *data) {
|
bool BL0942::validate_checksum_(DataPacket *data) {
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class BL0942 : public PollingComponent, public uart::UARTDevice {
|
|||||||
uint8_t address_ = 0;
|
uint8_t address_ = 0;
|
||||||
bool reset_ = false;
|
bool reset_ = false;
|
||||||
LineFrequency line_freq_ = LINE_FREQUENCY_50HZ;
|
LineFrequency line_freq_ = LINE_FREQUENCY_50HZ;
|
||||||
uint32_t rx_start_ = 0;
|
optional<uint32_t> rx_start_{};
|
||||||
uint32_t prev_cf_cnt_ = 0;
|
uint32_t prev_cf_cnt_ = 0;
|
||||||
|
|
||||||
bool validate_checksum_(DataPacket *data);
|
bool validate_checksum_(DataPacket *data);
|
||||||
|
|||||||
Reference in New Issue
Block a user