Move crc16 to helpers (#3780)

This commit is contained in:
Jesse Hills
2022-09-06 12:57:21 +12:00
committed by GitHub
parent 614eb81ad7
commit c317422ed7
7 changed files with 23 additions and 58 deletions
-16
View File
@@ -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);