CanSensor.c
2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "CanSensor.h"
CanBattery_Struct CanBatteryStruct; //电池数据结构体
u8 MusicSet[] = {0x23,0x00,0x01,0x00,0x00,0x00,0x00,0x00};
void Music_Select(u8 MusicS,u8 Vol)
{
static int LastTime = 0;
if(agv.Public.SystemTime - LastTime > 500)
{
LastTime = agv.Public.SystemTime;
if(agv.Command.Music_ONOFF)//屏幕输入参数,控制音乐开关
{
MusicSet[5] = MusicS;
MusicSet[6] = Vol;
CAN2_Send_Msg(0x60A,MusicSet, 8, 0);//给音乐模块发送指令
}
else
{
MusicSet[5] = MusicS;
MusicSet[6] = 0;
CAN2_Send_Msg(0x60A,MusicSet, 8, 0);//给音乐模块发送指令
}
}
}
u8 BatteryData[] = {0x00,0x55,0xFF,0x5A,0x00,0x00,0x00,0x00};//下发给电池指令,超过120S不发,电池会报异常
u8 SendBatteryData(void)
{
static int LastTime = 0;
if(agv.Public.SystemTime - LastTime > 20)
{
LastTime = agv.Public.SystemTime;
CAN_Send_Msg(BattaryID,BatteryData,8,0,2);
return 1;
}
return 0;
}
void ReceiveBatteryData(CanRxMsg *CanRxMsg)//接收电池数据
{
if(CanRxMsg->StdId == BattaryBackID_1)//0X53C电池反馈的第一帧数据
{
if(CanRxMsg->Data[0] == 0x03)
{
if ((CanRxMsg->Data[1] & 0x80) == 0x80) //放电 bit7=1
{
CanBatteryStruct.Current_out_int = 0;
CanRxMsg->Data[1] &= 0x7f;
}
else {
CanBatteryStruct.Current_out_int = 1; //电池充电
}
CanBatteryStruct.TotalCurrent = (CanRxMsg->Data[1] << 8) | CanRxMsg->Data[2];//总电流
CanBatteryStruct.SOC = (CanRxMsg->Data[3] << 8) | CanRxMsg->Data[4];//SOC 满电500
CanBatteryStruct.TotalVoltage = (CanRxMsg->Data[5] << 8) | CanRxMsg->Data[6];//总电压
CanBatteryStruct.StateTable = CanRxMsg->Data[7];//信息状态
if (CanBatteryStruct.StateTable & 0x01) //充电故障
{
CanBatteryStruct.StateTable0 = 1;
}
else
{
CanBatteryStruct.StateTable0 = 0;
}
if (CanBatteryStruct.StateTable & 0x02) //放电过流
{
CanBatteryStruct.StateTable1 = 1;
}
else
{
CanBatteryStruct.StateTable1 = 0;
}
if (CanBatteryStruct.StateTable & 0x04) //充电接触器闭合
{
CanBatteryStruct.StateTable2 = 1;
}
else
{
CanBatteryStruct.StateTable2 = 0; //断开
}
if (CanBatteryStruct.StateTable & 0x08) //电池容量标志位2
{
CanBatteryStruct.StateTable3 = 1;
}
else
{
CanBatteryStruct.StateTable3 = 0;
}
if (CanBatteryStruct.StateTable & 0x10) //电池容量标志位1
{
CanBatteryStruct.StateTable4 = 1;
}
else {
CanBatteryStruct.StateTable4 = 0;
}
}
}
else if(CanRxMsg->StdId == BattaryBackID_2)
{
}
}