/******************************************************************************
* Copyright (c)
* Original Author	:
* Last rev by		:
* Last rev date		:
* Last change list	:
* Overview			:
* Description		:
* NOTE				:
*******************************************************************************/
#ifndef Protocol_C
#define Protocol_C
//-----------------------------------------------------------------------------
// Include
//-----------------------------------------------------------------------------
#include "Protocol.h"
#include "MonitorSci.h"

//-----------------------------------------------------------------------------
// Adding Constants and Macro Definitions

//-----------------------------------------------------------------------------
//Adding Public Variables Stuff
//-----------------------------------------------------------------------------
Uint16  uiAnalogDataBag[100+2];  //模拟量


float fceshisavenum1  ;  //模拟量
float fceshisavenum2  ;  //模拟量
float fceshisavenum3  ;  //模拟量
float fceshisavenum4  ;  //模拟量


Uint32 ceshisavenum1  ;  //模拟量
Uint32 ceshisavenum2  ;  //模拟量

Uint16  uiCommandDataBag[eSciCommdEndID+2];     //控制量
//Union_UserFault              unUserFault;       //用户故障量
//Union_AdminFault	         unAdminFault;      //管理故障量



SumUserAdminFault  UserAdminFault     ;





volatile Union_ModState      unModState;        //模块各种运行状态
volatile Union_SysCommand    unSysCommand;      //系统控制指令

Union_CharWord1			unCharWord1;			//模块特征字1
Union_CharWord2			unCharWord2;			//模块特征字2
Union_IndicateLedCmd  	unIndicateLedCmd;		//指示灯控制
Union_FaultMask 		unFaultMask;         	//故障屏蔽

//-----------------------------------------------------------------------------
//Adding Private Variables (i.e. static)
//-----------------------------------------------------------------------------
//const Struct_CommCfgTbl strCommCfgTbl[eCommCfgEndID]=
//{
//    { GBMSStartAddr         , eGBMSAnlgStartID         ,eGBMSAnlgEndID         - eGBMSAnlgStartID         , &uiAnalogDataBag[eGBMSAnlgStartID        ] },  //   0   GBMS信息
//    { CBMSStartAddr         , eCBMSAnlgStartID         ,eCBMSAnlgEndID         - eCBMSAnlgStartID         , &uiAnalogDataBag[eCBMSAnlgStartID        ] },  //   1   CBMS信息
//    { DCDCStartAddr         , eDCDCAnlgStartID         ,eDCDCAnlgEndID         - eDCDCAnlgStartID         , &uiAnalogDataBag[eDCDCAnlgStartID        ] },  //   2   DCDC信息
//
//    { DCDCSetStartAddr      , eDCDCSetDataStartID      ,eDCDCSetDataEndID      - eDCDCSetDataStartID      , &uiSetDataBag[eDCDCSetDataStartID        ] },  //   3   DCDC设置量
//    { BMSSetStartAddr       , eBMSSetDataStartID       ,eBMSSetDataEndID       - eBMSSetDataStartID       , &uiSetDataBag[eBMSSetDataStartID         ] },  //   4   BMS设置量
//};

//-----------------------------------------------------------------------------
//Adding Private Function
//-----------------------------------------------------------------------------
void Protocol_AnologUpdate(void);
void Protocol_AlarmRenew(void);
/******************************************************************************
Function Name		:
-------------------------------------------------------------------------------
Function Descriptions:
Parameter Name list	:
ReturnTyp			:
Refer documents	:
******************************************************************************/
void Protocol_Task_RealTime(void)
{

}

/******************************************************************************
Function Name		:
-------------------------------------------------------------------------------
Function Descriptions:
Parameter Name list	:
ReturnType			:
Refer documents	:
******************************************************************************/
void Protocol_Task_1ms(void)
{

}

/******************************************************************************
Function Name		:
-------------------------------------------------------------------------------
Function Descriptions:
Parameter Name list	:
ReturnType			:
Refer documents	:
******************************************************************************/
void Protocol_Task_5ms(void)
{

}

/******************************************************************************
Function Name		:
-------------------------------------------------------------------------------
Function Descriptions:
Parameter Name list	:
ReturnType			:
Refer documents	:
******************************************************************************/
void Protocol_Task_20ms(void)
{
	Protocol_AnologUpdate();
	Protocol_AlarmRenew();

	UserAdminFault.uiDigital[0]=10;
//	UserAdminFault.uiDigital[1]=111;
//	UserAdminFault.uiDigital[2]=116;
//	UserAdminFault.uiDigital[3]=300;
	UserAdminFault.uiDigital[4]=1100;


	UserAdminFault.Fault.AdminFault.bit.b1msDCOverCurrFault=1;

    UserAdminFault.Fault.UserFault.bit.bGridCurrDCCompFault=1;
    UserAdminFault.Fault.UserFault.bit.bIslandFault=1;
    UserAdminFault.Fault.UserFault.bit.bSelfCheckFault=1;






	UserAdminFault.Fault.AdminFault.bit.bAdmin_Reserved61Fault=1;
	UserAdminFault.Fault.AdminFault.bit.bAdmin_Reserved62Fault=1;
	UserAdminFault.Fault.AdminFault.bit.bAdmin_Reserved63Fault=1;
	UserAdminFault.Fault.AdminFault.bit.bAdmin_Reserved64Fault=1;
	UserAdminFault.Fault.AdminFault.bit.bAdmin_Reserved65Fault=1;


}

/******************************************************************************
Function Name		:
-------------------------------------------------------------------------------
Function Descriptions:
Parameter Name list	:
ReturnType			:
Refer documents	:
******************************************************************************/
void Protocol_Task_100ms(void)
{
//    unCharWord1.uiDigital = uiSetDataBag[eModChar1SetID];			    //模块特征字1
//    unCharWord2.uiDigital = uiSetDataBag[eModChar2SetID];			    //模块特征字2

    unIndicateLedCmd.uiDigital = uiCommandDataBag[eIndicateLedCmdID];	//指示灯控制
    unFaultMask.uiDigital[0] = uiCommandDataBag[eMaskAlarm1CmdID]; 		//故障屏蔽1
    unFaultMask.uiDigital[1] = uiCommandDataBag[eMaskAlarm2CmdID]; 		//故障屏蔽2
    unFaultMask.uiDigital[2] = uiCommandDataBag[eMaskAlarm3CmdID];  	//故障屏蔽3
    unFaultMask.uiDigital[3] = uiCommandDataBag[eMaskAlarm4CmdID];  	//故障屏蔽4

	unSysCommand.uiDigital[0] = uiCommandDataBag[eSysControl2CmdID];    //  16  系统控制命令1
	unSysCommand.uiDigital[1] = uiCommandDataBag[eSysControl1CmdID];	//  17  系统控制命令2

}
/******************************************************************************
Function Name           : CanProtocol_AlarmRenew
------------------------------------------------------------------------------
Function Descriptions   :
Parameter Name list     :
ReturnType              :
Refer documents        :
******************************************************************************/
void Protocol_AlarmRenew(void)
{
    static Uint16   uiRenewStep = 0;

    uiRenewStep++;
    switch(uiRenewStep)
    {
        case 1:
        {
//        	unUserFault.bit.bOutVoltOverLockFault		=	0	;//0 bit0：输出过压锁死
//        	unUserFault.bit.bEnviTempOverFault			=	0;//(Fault_AnalogFaultFlagGet(e100msEnvirTemp2OverAdcID)||Fault_AnalogFaultFlagGet(e100msEnvirTemp1OverAdcID));	//1 bit1环温过温
//        	unUserFault.bit.bModuleFault				=	unFaultFlag.bit.bStopFault;	//	2	bit2：	模块故障
//        	unUserFault.bit.bModuleProtect              =   0;//3 bit3：模块保护
//        	unUserFault.bit.bFanFault					=	0;//Fault_DigitalFaultFlagGet(e100msFanFaultIoID);// 4 bit4： 风扇故障
//        	if(   Fault_AnalogFaultFlagGet(e1msBatCurrFastOverAdcID)
//        	   || Fault_AnalogFaultFlagGet(e20msBatCurrOverAdcID)
//			   || Fault_DigitalFaultFlagGet(eIntInputShortIoID)
//        	)
//        	{
//        		unUserFault.bit.bInOverCurr	= 1;	//5	输入过流
//        	}
//        	else
//        	{
//        		unUserFault.bit.bInOverCurr	= 0;
//        	}
//        	if(   Fault_AnalogFaultFlagGet(e1msDcCurrFastOverAdcID)
//			   || Fault_AnalogFaultFlagGet(e20msDcCurrOverAdcID)
//			   || Fault_DigitalFaultFlagGet(e1msL1CurrOverLimitFaultIoID)
//			   || Fault_DigitalFaultFlagGet(e1msL2CurrOverLimitFaultIoID)
//			   || Fault_DigitalFaultFlagGet(eIntOutputShortIoID)
//		    )
//        	{
//        		unUserFault.bit.bOutOverCurr	= 1;	//	6	输出过流
//        	}
//        	else
//        	{
//        		unUserFault.bit.bOutOverCurr = 0;	//	6	输出过流
//        	}
//        	unUserFault.bit.bReserved7Fault				=	0	;	//	7	bit7：	预留
//        	unUserFault.bit.bTempLowOffAlarm			=	0	;	//	8	bit8：	低温关机告警
//        	unUserFault.bit.bModuleOffState				=	0;//uiDCDCOnOffRx;//9 bit9：	模块关机状态
//        	unUserFault.bit.bReserved10Fault			=	0	;	//	10	bit10：	预留
//        	unUserFault.bit.bModWalkInEnState			=	0	;	//	11	bit11：	模块WALK-In功能使能
//        	unUserFault.bit.bInnerTempOverFault			=	Fault_AnalogFaultFlagGet(e100msSink2TempOverAdcID)	;	//	12	bit12：	内部过温
//        	unUserFault.bit.bReserved13Fault			=	0	;	//	13	bit13：	预留
//



            break;
        }

        case 2:
        {

            break;
        }

        default:
        {
            uiRenewStep = 0;
            break;
        }
    }

}

/******************************************************************************
Function Name           : CanProtocol_AnologUpdate
------------------------------------------------------------------------------
Function Descriptions   : 更新模拟量
Parameter Name list     :
ReturnType              :
Refer documents        : 100ms  
******************************************************************************/
void Protocol_AnologUpdate(void)
{
    static int16 uiRenewStep = 0;
//    int32 lModulePower;

//    extern Union_BmsPtl0Fault unBmsPtl0Fault;
//    extern Union_BmsPtl1Fault unBmsPtl1Fault;
    //-----------------------------------------------------------------------------------------

    uiRenewStep++;
    switch(uiRenewStep)
    {
        case 1:
        {


        	uiAnalogDataBag[1 ] = 12081;  //
        	uiAnalogDataBag[2 ] = 2;  //
        	uiAnalogDataBag[3 ] = 3;  //
        	uiAnalogDataBag[4 ] = 4;  //
        	uiAnalogDataBag[5 ] = 5;  //
        	uiAnalogDataBag[6 ] = 6;  //
        	uiAnalogDataBag[7 ] = 7;  //
        	uiAnalogDataBag[8 ] = 8;  //
        	uiAnalogDataBag[9 ] = 9;  //
        	uiAnalogDataBag[10 ] = 10 ;  //
        	uiAnalogDataBag[11 ] = 11 ;  //
        	uiAnalogDataBag[12 ] = 12 ;  //
        	uiAnalogDataBag[13 ] = 13 ;  //
        	uiAnalogDataBag[14 ] = 14 ;  //
        	uiAnalogDataBag[15 ] = 15 ;  //
        	uiAnalogDataBag[16 ] = 16 ;  //
        	uiAnalogDataBag[17 ] = 17 ;  //
        	uiAnalogDataBag[18 ] = 18 ;  //
        	uiAnalogDataBag[19 ] = 19 ;  //
        	uiAnalogDataBag[20 ] = 20 ;  //
        	uiAnalogDataBag[21 ] = 21 ;  //
        	uiAnalogDataBag[22 ] = 22 ;  //
        	uiAnalogDataBag[23 ] = 23 ;  //
        	uiAnalogDataBag[24 ] = 24 ;  //
        	uiAnalogDataBag[25 ] = 25 ;  //
        	uiAnalogDataBag[26 ] = 26 ;  //
        	uiAnalogDataBag[27 ] = 27 ;  //
        	uiAnalogDataBag[28 ] = 28 ;  //
            uiAnalogDataBag[50] = 50 ;  //
            uiAnalogDataBag[51] = 51 ;  //
        	uiAnalogDataBag[52] = 52 ;  //
        	uiAnalogDataBag[53] = 53 ;  //
        	uiAnalogDataBag[54] = 54 ;  //
        	uiAnalogDataBag[55] = 55 ;  //
        	uiAnalogDataBag[56] = 56 ;  //
        	uiAnalogDataBag[57] = 57 ;  //
        	uiAnalogDataBag[58] = 58 ;  //
        	uiAnalogDataBag[59] = 59 ;  //
        	uiAnalogDataBag[60] = 60 ;  //
        	uiAnalogDataBag[61] = 61 ;  //
        	uiAnalogDataBag[62] = 62 ;  //
        	uiAnalogDataBag[63] = 63 ;  //
        	uiAnalogDataBag[64] = 64 ;  //
        	uiAnalogDataBag[65] = 65 ;  //
        	uiAnalogDataBag[66] = 66 ;  //
        	uiAnalogDataBag[67] = 67 ;  //
        	uiAnalogDataBag[68] = 68 ;  //
        	uiAnalogDataBag[69] = 69 ;  //
        	uiAnalogDataBag[70] = 70 ;  //
        	uiAnalogDataBag[71] = 71 ;  //
        	uiAnalogDataBag[72] = 72 ;  //
        	uiAnalogDataBag[73] = 73 ;  //
        	uiAnalogDataBag[74] = 74 ;  //
        	uiAnalogDataBag[75] = 75 ;  //
        	uiAnalogDataBag[76] = 76 ;  //
        	uiAnalogDataBag[77] = 77 ;  //
        	uiAnalogDataBag[78] = 78 ;  //
        	uiAnalogDataBag[79] = 79 ;  //









            break;
        }

        default:
        {
            uiRenewStep = 0;
            break;
        }
    }

}

#endif //Protocol_C
//===========================================================================
// End of file.
//===========================================================================
