#pragma once #include #include namespace Incart::DeviceComplexCommands { struct PolyCrc16Calculator { static uint16_t calculateCrc(std::vector buffer_, size_t offset_, size_t length_) { uint16_t totalCrc = 0; std::vector poly{ 5, 12, -4, 0 }; size_t polySize = poly.size(); for (size_t i = offset_; i < offset_ + length_; ++i) { uint16_t crc = 1; uint16_t bufferValue = buffer_[i]; for (size_t p = 0; p < polySize; ++p) { int32_t crcValue = (poly[p] > 0) ? (bufferValue << poly[p]) : (bufferValue >> -poly[p]); crc ^= static_cast(crcValue); } totalCrc ^= crc; } return totalCrc; } }; } // namespace Incart::DeviceComplexCommands