📄 canuser.c
字号:
/****************************************Copyright (c)**************************************************
** 哈 尔 滨 光 宇 国 际 集 团
** 电力电子研究所
** 研发部
**
** http://www.coslight.com.cn
** 联系电话:0451-86677970-6738
**
**--------------文件信息--------------------------------------------------------------------------------
**文 件 名: CanUser.C
**创 建 人: 刘宝贵
**最后修改日期: 2007年8月6日
**描 述: 用于处理CAN通信
**
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 刘宝贵
** 版 本: v1.0
** 日 期: 2007年8月6日
** 描 述: 原始版本
**
***--------------当前版本修订------------------------------------------------------------------------------
** 修改人:
** 日 期:
** 描 述:
** 说 明:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#include "config.h"
#include "stdlib.h"
stcTxBUF CTBuf; //
stcRxBUF CRBuf; //
#define CAN_R_CONFIG 0 //读配置
#define CAN_W_CONFIG 1 //写配置
#define CAN_R_FIXED_VALUE 2 //读定值
#define CAN_W_FIXED_VALUE 3 //写定值
#define CAN_R_ANALOG 4 //读模拟量
#define CAN_R_DIGITAL 5 //读数字量
#define CAN_W_CONTROL 6 //写控制量
/*********************************************************************************************************
** 函数名称: uint32 CanSendAnalog(uint8 CanIndex)
** 功能描述: 读模拟量:(包1 )电池环境温度、1、2节电池单只电压,(包2 )3、4、5节电池单只电压。
(包3)6、7、8节电池单只电压,(包4)-----(包37)108节电池单只电压
** 输 入: CanIndex Can口的选择 CAN0 或CAN1
** 输 出: 0;成功发送;1;发送失败
** 作 者: 刘宝贵
** 日 期: 2007年8月6日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint32 CanSendAnalog(uint8 CanIndex)
{
uint8 err;
uint32 status=0;
uint8 i;
for(i=0;i<36;i++)
{
OSSemPend(CanSendSem[CanIndex],0,&err); //申请发送数据信号量
CTBuf.TxFrameInfo.Bits.PRIO_BIT = 0; //缓冲区数据发送优先级的值
CTBuf.TxFrameInfo.Bits.FF_BIT = 0; //帧格式 =0标准帧; =1扩展帧;
CTBuf.TxFrameInfo.Bits.RTR_BIT = 0; //帧类型 =0数据帧; =1远程帧;
CTBuf.TxFrameInfo.Bits.DLC_BIT = 8; //数据长度
CTBuf.TxCANID.Word = (CAN_R_ANALOG<<7) + BoardAddress + 0x400;//CAN ID的最高位置 1
CTBuf.CANTDA.DataType.Bits8.Data1_BIT = i+1; //数据包号
CTBuf.CANTDA.DataType.Bits8.Data2_BIT = 37; //总包数
CTBuf.CANTDA.DataType.Bits16.Data2_BIT = CellU[i*3]; //电池电压数据
CTBuf.CANTDB.DataType.Bits16.Data1_BIT = CellU[i*3+1]; //电池电压数据
CTBuf.CANTDB.DataType.Bits16.Data2_BIT = CellU[i*3+2]; //电池电压数据
status = CANSendData(CanIndex,0,&CTBuf); //CAN通道号:通道0 ;发送命令字:正常发送 要发送的数据:CTBuf
}
OSSemPend(CanSendSem[CanIndex],0,&err); //申请发送数据信号量
CTBuf.TxFrameInfo.Bits.PRIO_BIT = 0; //缓冲区数据发送优先级的值
CTBuf.TxFrameInfo.Bits.FF_BIT = 0; //帧格式 =0标准帧; =1扩展帧;
CTBuf.TxFrameInfo.Bits.RTR_BIT = 0; //帧类型 =0数据帧; =1远程帧;
CTBuf.TxFrameInfo.Bits.DLC_BIT = 8; //数据长度
CTBuf.TxCANID.Word = (CAN_R_ANALOG<<7) + BoardAddress + 0x400; //CAN ID的最高位置 1
CTBuf.CANTDA.DataType.Bits8.Data1_BIT = 37; //数据包号
CTBuf.CANTDA.DataType.Bits8.Data2_BIT = 37; //总包数
CTBuf.CANTDA.DataType.Bits16.Data2_BIT = Temperature; //电池环境温度
CTBuf.CANTDB.DataType.Bits16.Data1_BIT = 0; //无数据
CTBuf.CANTDB.DataType.Bits16.Data2_BIT = 0; //无数据
status = CANSendData(CanIndex,0,&CTBuf); //CAN通道号:通道0 ;发送命令字:正常发送 要发送的数据:CTBuf
return status;
}
/*********************************************************************************************************
** 函数名称: uint32 CanSendDigital(uint8 CanIndex)
** 功能描述: 读状态量:(包1 R)1-48只状态(包2 R)49-96只状态(包3R) 97-108只状态,温度状态
** 输 入: CanIndex Can口的选择 CAN0 或CAN1
** 输 出: 0;成功发送;1;发送失败
** 作 者: 刘宝贵
** 日 期: 2007年8月6日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint32 CanSendDigital(uint8 CanIndex)
{
uint8 i;
uint8 err;
uint32 status=0;
//判定每只电池的告警状态
for(i=0;i<14;i++)
{
CellAlarm[i].Byte = 0;
if(CellU[i*8 + 0] > CellUHigh || CellU[i*8 + 0] < CellULow){ CellAlarm[i].Bits.Bit0 = 1;}
if(CellU[i*8 + 1] > CellUHigh || CellU[i*8 + 1] < CellULow){ CellAlarm[i].Bits.Bit1 = 1;}
if(CellU[i*8 + 2] > CellUHigh || CellU[i*8 + 2] < CellULow){ CellAlarm[i].Bits.Bit2 = 1;}
if(CellU[i*8 + 3] > CellUHigh || CellU[i*8 + 3] < CellULow){ CellAlarm[i].Bits.Bit3 = 1;}
if(CellU[i*8 + 4] > CellUHigh || CellU[i*8 + 4] < CellULow){ CellAlarm[i].Bits.Bit4 = 1;}
if(CellU[i*8 + 5] > CellUHigh || CellU[i*8 + 5] < CellULow){ CellAlarm[i].Bits.Bit5 = 1;}
if(CellU[i*8 + 6] > CellUHigh || CellU[i*8 + 6] < CellULow){ CellAlarm[i].Bits.Bit6 = 1;}
if(CellU[i*8 + 7] > CellUHigh || CellU[i*8 + 7] < CellULow){ CellAlarm[i].Bits.Bit7 = 1;}
}
//将无效数据清成0
CellAlarm[13].Bits.Bit5 = 0;
CellAlarm[13].Bits.Bit6 = 0;
CellAlarm[13].Bits.Bit7 = 0;
CellAlarm[14].Byte = 0;
CellAlarm[15].Byte = 0;
CellAlarm[16].Byte = 0;
CellAlarm[17].Byte = 0;
//判定温度的告警状态
if(Temperature > TempHigh ){ CellAlarm[13].Bits.Bit4 = 1;}
//将告警信息发出
for(i=0;i<3;i++)
{
OSSemPend(CanSendSem[CanIndex],0,&err); //申请发送数据信号量
CTBuf.TxFrameInfo.Bits.PRIO_BIT = 0; //缓冲区数据发送优先级的值
CTBuf.TxFrameInfo.Bits.FF_BIT = 0; //帧格式 =0标准帧; =1扩展帧;
CTBuf.TxFrameInfo.Bits.RTR_BIT = 0; //帧类型 =0数据帧; =1远程帧;
CTBuf.TxFrameInfo.Bits.DLC_BIT = 8; //数据长度
CTBuf.TxCANID.Word = (CAN_R_DIGITAL<<7) + BoardAddress + 0x400; //CAN ID的最高位置 1
CTBuf.CANTDA.DataType.Bits8.Data1_BIT = i+1; //数据包号
CTBuf.CANTDA.DataType.Bits8.Data2_BIT = 3; //总包数
CTBuf.CANTDA.DataType.Bits8.Data3_BIT = CellAlarm[i*6 + 0].Byte; //电池告警数据
CTBuf.CANTDA.DataType.Bits8.Data4_BIT = CellAlarm[i*6 + 1].Byte; //电池告警数据
CTBuf.CANTDB.DataType.Bits8.Data1_BIT = CellAlarm[i*6 + 2].Byte; //电池告警数据
CTBuf.CANTDB.DataType.Bits8.Data2_BIT = CellAlarm[i*6 + 3].Byte; //电池告警数据
CTBuf.CANTDB.DataType.Bits8.Data3_BIT = CellAlarm[i*6 + 4].Byte; //电池告警数据
CTBuf.CANTDB.DataType.Bits8.Data4_BIT = CellAlarm[i*6 + 5].Byte; //电池告警数据
status = CANSendData(CanIndex,0,&CTBuf); //CAN通道号:通道0 ;发送命令字:正常发送 要发送的数据:CTBuf
}
return status;
}
/*********************************************************************************************************
** 函数名称: uint32 CanSendFixedValue(CanIndex)
** 功能描述: 发送定值数据(包1 W)电池过压点、电池欠压点、过温点(包2 W)校准K值
** 输 入: CanIndex Can口的选择 CAN0 或CAN1
** 输 出: 0;成功发送;1;发送失败
** 作 者: 刘宝贵
** 日 期: 2007年8月6日
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -