feat(can): 增加EEPROM状态码和系统配置保存功能
- 在CAN通信中增加EEPROM状态码字段,并通过CAN FD发送 - 实现Flash EEPROM对系统配置参数的CRC校验与保存 - 改进目标角度、速度等关键参数的读写逻辑,支持掉电保存 - 调整EEPROM地址映射,优化错误处理和状态反馈机制 - 修复CRC计算相关问题,增强数据可靠性
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
#ifndef __CRC_H
|
||||
#define __CRC_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "gd32c10x.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class CRC_Calculator {
|
||||
private:
|
||||
static bool table_initialized;
|
||||
static uint32_t crc_table[256];
|
||||
|
||||
/**
|
||||
* @brief 初始化CRC表
|
||||
*/
|
||||
static void init_crc_table();
|
||||
|
||||
/**
|
||||
* @brief 更新CRC值
|
||||
* @param crc 当前CRC值
|
||||
* @param data 要处理的数据
|
||||
* @return 更新后的CRC值
|
||||
*/
|
||||
static uint32_t update_crc(uint32_t crc, uint8_t data);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief 计算单个float值的CRC32
|
||||
* @param data float值
|
||||
* @return CRC32校验值
|
||||
*/
|
||||
static uint32_t calculate(const float& data);
|
||||
|
||||
/**
|
||||
* @brief 计算float数组的CRC32
|
||||
* @param data float数组指针
|
||||
* @param length 数组长度
|
||||
* @return CRC32校验值
|
||||
*/
|
||||
static uint32_t calculate(const float* data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief 验证单个float值的CRC32
|
||||
* @param data float值
|
||||
* @param expected_crc 期望的CRC值
|
||||
* @return true表示校验成功,false表示校验失败
|
||||
*/
|
||||
static bool verify(const float& data, uint32_t expected_crc);
|
||||
|
||||
/**
|
||||
* @brief 验证float数组的CRC32
|
||||
* @param data float数组指针
|
||||
* @param length 数组长度
|
||||
* @param expected_crc 期望的CRC值
|
||||
* @return true表示校验成功,false表示校验失败
|
||||
*/
|
||||
static bool verify(const float* data, size_t length, uint32_t expected_crc);
|
||||
|
||||
/**
|
||||
* @brief 获取CRC表初始化状态
|
||||
* @return true表示已初始化,false表示未初始化
|
||||
*/
|
||||
static bool isInitialized();
|
||||
|
||||
/**
|
||||
* @brief 强制重新初始化CRC表
|
||||
*/
|
||||
static void reinitialize();
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __CRC_H
|
||||
Reference in New Issue
Block a user