CanSensor.c 2.43 KB
#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)
	{
	
	}
}