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