* @brief Computes an 8-bit CRC (CRC-8) using polynomial 0x31. */
| 102 | * @brief Computes an 8-bit CRC (CRC-8) using polynomial 0x31. |
| 103 | */ |
| 104 | static constexpr uint8_t crc8(const char* data, const int length) noexcept |
| 105 | { |
| 106 | uint8_t crc = 0xFF; |
| 107 | for (int i = 0; i < length; ++i) { |
| 108 | crc ^= static_cast<uint8_t>(data[i]); |
| 109 | for (int j = 0; j < 8; ++j) |
| 110 | if (crc & 0x80) |
| 111 | crc = (crc << 1) ^ 0x31; |
| 112 | else |
| 113 | crc <<= 1; |
| 114 | } |
| 115 | return crc; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @brief Computes an additive modulo-256 checksum. |