* @brief Computes a 16-bit CRC (CRC-CCITT) using polynomial 0x1021 and initial value 0x0000. */
| 218 | * @brief Computes a 16-bit CRC (CRC-CCITT) using polynomial 0x1021 and initial value 0x0000. |
| 219 | */ |
| 220 | static constexpr uint16_t crc16_ccitt(const char* data, const int length) noexcept |
| 221 | { |
| 222 | uint16_t crc = 0x0000; |
| 223 | |
| 224 | for (int i = 0; i < length; ++i) { |
| 225 | crc ^= static_cast<uint8_t>(data[i]) << 8; |
| 226 | for (int j = 0; j < 8; ++j) |
| 227 | if (crc & 0x8000) |
| 228 | crc = (crc << 1) ^ 0x1021; |
| 229 | else |
| 230 | crc <<= 1; |
| 231 | } |
| 232 | |
| 233 | return crc; |
| 234 | } |
| 235 | |
| 236 | //-------------------------------------------------------------------------------------------------- |
| 237 | // Checksum byte-packing helpers |