Files
half-steering-basic-framework/modules/super_cap/super_cap.md

56 lines
1.5 KiB
Markdown
Raw Permalink Normal View History

2026-03-10 03:05:49 +08:00
# super_cap (适配版)
2026-01-17 14:06:59 +08:00
## 代码结构
2026-03-10 03:05:49 +08:00
.h中放置的是数据和协议枚举定义、控制接口,.c中包含CAN接收中断的回调解析以及发送打包逻辑。当前版本已完全适配群星战队的超级电容协议。
2026-01-17 14:06:59 +08:00
## 外部接口
```c
SuperCapInstance *SuperCapInit(SuperCap_Init_Config_s* supercap_config);
2026-03-10 03:05:49 +08:00
void SuperCapSend(SuperCapInstance *instance, SuperCap_TxMsg_s *tx_data);
void SuperCapSetPowerOffset(SuperCapInstance *instance, uint8_t offset);
SuperCap_Msg_s SuperCapGet(SuperCapInstance *instance);
2026-01-17 14:06:59 +08:00
```
## 私有函数和变量
```c
static SuperCapInstance *super_cap_instance = NULL;
static uint8_t *rxbuff;
static void SuperCapRxCallback(can_instance *_instance)
```
2026-03-10 03:05:49 +08:00
SuperCapRxCallback()是super cap初始化can实例时的回调函数,用于CAN接收中断,进行协议解析(包含底盘功率右移量程的还原等处理)。
2026-01-17 14:06:59 +08:00
## 使用范例
初始化时设置如下:
```c
SuperCap_Init_Config_s capconfig = {
2026-03-10 03:05:49 +08:00
.can_config = {
.can_handle = &hcan1,
.rx_id = 0x100, // 超级电容发给C板的ID
.tx_id = 0x001 // C板发给超级电容的ID
}
};
SuperCapInstance *ins = SuperCapInit(&capconfig);
// 如果需要设置功率补偿
SuperCapSetPowerOffset(ins, 5);
2026-01-17 14:06:59 +08:00
```
发送通过`SuperCapSend()`,建议使用强制类型转换:
2026-03-10 03:05:49 +08:00
发送控制指令时,使用 SuperCap_TxMsg_s 结构体:
2026-01-17 14:06:59 +08:00
```c
2026-03-10 03:05:49 +08:00
SuperCap_TxMsg_s tx_cmd = {
.Enable = 1,
.Charge = 1,
.Powerlimit = 60,
.ChargePower = 40
};
SuperCapSend(ins, &tx_cmd);
2026-01-17 14:06:59 +08:00
```