mirror of
https://gitee.com/dlmu-cone/half-steering-basic-framework
synced 2026-10-24 01:52:20 +08:00
supercap&PowerCtrl
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "super_cap.h"
|
||||
#include "memory.h"
|
||||
#include "stdlib.h"
|
||||
#include "bsp_dwt.h" // 【新增】引入获取时间的头文件,或者是 "main.h" 用 HAL_GetTick()
|
||||
|
||||
static SuperCapInstance *super_cap_instance = NULL;
|
||||
|
||||
@@ -15,6 +16,9 @@ static void SuperCapRxCallback(CANInstance *_instance)
|
||||
rxbuff = _instance->rx_buff;
|
||||
Msg = &super_cap_instance->cap_msg;
|
||||
|
||||
// 【新增】更新最后一次收到消息的时间戳
|
||||
super_cap_instance->last_update_tick = DWT_GetTimeline_ms(); // 如果没有DWT,用 HAL_GetTick() 替换
|
||||
|
||||
// 按照新协议解析接收数据
|
||||
Msg->ready = (SuperCapReadyEnum)rxbuff[0];
|
||||
Msg->state = (SuperCapStateEnum)rxbuff[1];
|
||||
@@ -24,6 +28,18 @@ static void SuperCapRxCallback(CANInstance *_instance)
|
||||
Msg->bat_power = rxbuff[5];
|
||||
}
|
||||
|
||||
// 【新增】在线判断函数
|
||||
uint8_t SuperCapIsOnline(SuperCapInstance *instance)
|
||||
{
|
||||
if (instance == NULL) return 0;
|
||||
|
||||
// 如果当前时间减去上次接收时间超过 1000ms (1秒),则认为离线
|
||||
if (DWT_GetTimeline_ms() - instance->last_update_tick > 2000) {
|
||||
return 0; // 离线
|
||||
}
|
||||
return 1; // 在线
|
||||
}
|
||||
|
||||
SuperCapInstance *SuperCapInit(SuperCap_Init_Config_s *supercap_config)
|
||||
{
|
||||
super_cap_instance = (SuperCapInstance *)malloc(sizeof(SuperCapInstance));
|
||||
@@ -40,9 +56,9 @@ void SuperCapSend(SuperCapInstance *instance, SuperCap_TxMsg_s *tx_data)
|
||||
|
||||
// 按照新协议装载发送数据
|
||||
txbuff[0] = tx_data->Enable;
|
||||
txbuff[1] = tx_data->Charge;
|
||||
txbuff[1] = tx_data->Reserved1;
|
||||
txbuff[2] = tx_data->Powerlimit - instance->power_offset; // 计算功率补偿
|
||||
txbuff[3] = tx_data->ChargePower;
|
||||
txbuff[3] = tx_data->Reserved2;
|
||||
|
||||
CANTransmit(instance->can_ins, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user