Allow ignoring of failed Modbus response CRC (#3930)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Jan Grewe
2022-12-22 20:14:11 +13:00
committed by GitHub
co-authored by Jesse Hills
parent ecbbf2d3f4
commit f2df542cb1
4 changed files with 14 additions and 4 deletions
+7 -2
View File
@@ -102,8 +102,12 @@ bool Modbus::parse_modbus_byte_(uint8_t byte) {
uint16_t computed_crc = crc16(raw, data_offset + data_len);
uint16_t remote_crc = uint16_t(raw[data_offset + data_len]) | (uint16_t(raw[data_offset + data_len + 1]) << 8);
if (computed_crc != remote_crc) {
ESP_LOGW(TAG, "Modbus CRC Check failed! %02X!=%02X", computed_crc, remote_crc);
return false;
if (this->disable_crc_) {
ESP_LOGD(TAG, "Modbus CRC Check failed, but ignored! %02X!=%02X", computed_crc, remote_crc);
} else {
ESP_LOGW(TAG, "Modbus CRC Check failed! %02X!=%02X", computed_crc, remote_crc);
return false;
}
}
}
std::vector<uint8_t> data(this->rx_buffer_.begin() + data_offset, this->rx_buffer_.begin() + data_offset + data_len);
@@ -139,6 +143,7 @@ void Modbus::dump_config() {
ESP_LOGCONFIG(TAG, "Modbus:");
LOG_PIN(" Flow Control Pin: ", this->flow_control_pin_);
ESP_LOGCONFIG(TAG, " Send Wait Time: %d ms", this->send_wait_time_);
ESP_LOGCONFIG(TAG, " CRC Disabled: %s", YESNO(this->disable_crc_));
}
float Modbus::get_setup_priority() const {
// After UART bus