// 解析总电流 (0.1A)
g_bms.data.total_current_p1a = le16s_to_host(data + 6);
+ printf( "can recv frame 1: max_charge_current_p1a:%d, max_discharge_current_p1a:%d, total_voltage_p1v:%d, total_current_p1a:%d\n",
+ g_bms.data.max_charge_current_p1a,
+ g_bms.data.max_discharge_current_p1a,
+ g_bms.data.total_voltage_p1v,
+ g_bms.data.total_current_p1a );
}
void user_bms_parse_frame2(const uint8_t *data) {
// 第7-8字节为预留,不处理
g_bms.data.reserve_2 = le16_to_host(data + 6);
+ printf( "can recv frame 2: total_soc_p1:%d, total_soh_p1:%d, max_charge_voltage_p1v:%d, reserve_2:%d\n",
+ g_bms.data.total_soc_p1,
+ g_bms.data.total_soh_p1,
+ g_bms.data.max_charge_voltage_p1v,
+ g_bms.data.reserve_2 );
}
void user_bms_parse_frame3(const uint8_t *data) {
perror("read");
return;
}
-
+ printf( "can read msg, size:%d\n", nbytes );
if (nbytes != sizeof(struct can_frame)) return;
+ printf( "read frame: id:%08X, dlc:%d, data:", frame.can_id, frame.can_dlc );
+ for( int i=0; i<frame.can_dlc; i++ ){
+ printf( "%02x ", frame.data[i] );
+ }
+ printf( "\n" );
+
// 更新最后接收时间
g_bms.data.last_update_time = time(NULL);
g_bms.data.is_connected = true;
-
+ frame.can_id &= 0x1FFFFFFF;
// 根据CAN ID解析不同的数据帧
switch (frame.can_id) {
case BMS_FRAME1_ID:
+printf( "FRAME1_ID\n" );
if (frame.can_dlc == 8) {
user_bms_parse_frame1(frame.data);
}
static void* bms_task_thread(void* arg)
{
// 初始化BMS模块 (使用vcan0接口)
- if (!user_bms_init("vcan0")) {
+ if (!user_bms_init("can0")) {
printf("Failed to initialize BMS module\n");
return NULL;
}
// 主循环
while (1) {
// 发送心跳包 (每2秒一次)
+ heartbeat++;
if (heartbeat % 4 == 0) { // 因为主循环是500ms,4*500ms=2s
user_bms_send_heartbeat(heartbeat);
- heartbeat++;
if (heartbeat > 65535) heartbeat = 0;
}