mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 02:51:29 +00:00
Move crc16 to helpers (#3780)
This commit is contained in:
@@ -35,22 +35,6 @@ void Modbus::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t crc16(const uint8_t *data, uint8_t len) {
|
||||
uint16_t crc = 0xFFFF;
|
||||
while (len--) {
|
||||
crc ^= *data++;
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
if ((crc & 0x01) != 0) {
|
||||
crc >>= 1;
|
||||
crc ^= 0xA001;
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
bool Modbus::parse_modbus_byte_(uint8_t byte) {
|
||||
size_t at = this->rx_buffer_.size();
|
||||
this->rx_buffer_.push_back(byte);
|
||||
|
||||
Reference in New Issue
Block a user