CodexPadFrameDecoder Arduino 库 1.0.0
载入中...
搜索中...
未找到
crc8.h
浏览该文件的文档.
1#pragma once
2
3#ifndef _CRC8_H_
4#define _CRC8_H_
5
6#include <stddef.h>
7#include <stdint.h>
8
9/**
10 * @file crc8.h
11 */
12
13namespace crc8 {
14/**
15 * @~Chinese
16 * @brief 计算数据的 CRC-8 校验值(SAE J1850 标准)。
17 * @param[in] data 待计算的数据指针。
18 * @param[in] size 数据长度(字节数)。
19 * @return uint8_t 计算得到的 CRC 值。
20 *
21 * @details 使用标准 CRC-8/SAE J1850 算法:
22 * - 多项式:0x1D (x^8 + x^4 + x^3 + x^2 + 1)
23 * - 初始值:0xFF
24 * - 最终异或:0xFF
25 * - 输入/输出不反转
26 * 内部使用 256 字节查表法运算,提高效率。
27 */
28/**
29 * @~English
30 * @brief Calculate the CRC-8 checksum of data (SAE J1850 standard).
31 * @param[in] data Pointer to the data to be calculated.
32 * @param[in] size Length of the data in bytes.
33 * @return uint8_t The calculated CRC value.
34 *
35 * @details Uses the standard CRC-8/SAE J1850 algorithm:
36 * - Polynomial: 0x1D (x^8 + x^4 + x^3 + x^2 + 1)
37 * - Initial value: 0xFF
38 * - Final XOR: 0xFF
39 * - No input/output reversal
40 * Internally uses a 256-byte lookup table for efficient computation.
41 */
42uint8_t Calculate(const uint8_t *data, const size_t size);
43} // namespace crc8
44
45#endif // _CRC8_H_
uint8_t Calculate(const uint8_t *data, const size_t size)
计算数据的 CRC-8 校验值(SAE J1850 标准)。