#include "ProtoFecBusCRT.h"
#include "MainCtl.h"
#include "CnCpp.h"

#define FecBusMasterAddr 	1

extern "C"{
	#include "uart_fecbus_drv.h"
	#include "uart_key_drv.h"
}

unsigned short FecBusCRTStateCode;
unsigned char MsgFrmIndex = 1;

void TFecBusCRT::Init()
{
	unsigned int i;
	unsigned int x;
	unsigned int aAddr;
	
	RxGetFlag = 0;
	TxSetFlag = 0;
	
	InTxIndex = 0;
	OutTxIndex = 0;
	
	OnlineTick = 0;
	
	for(i=0; i<dFecCRT_BufCount_Tx; i++){
		aAddr = dAddrSdram_CrtTxBuf + (i * dFecCRT_BufEntrySize_Tx);
		for(x = 0;x<(dFecCRT_BufEntrySize_Tx/4);x++)
			*(volatile unsigned int *)(aAddr + (x*4)) = 0;
	}
	
	ErrState.Body.OffLine = 0;
	ErrState.Body.OffLineTick = 0;
	ErrReport.Body.OffLine = 0;
			
	OnTransmite.AckOk = 1;
	OnTransmite.RetryTimes = 0;
	OnTransmite.OnGoing = 0;
	OnTransmite.TimeOutTick = 0;
	
	Upload.Active = 0;
	
	MsgFrmIndex = 1;
	
	SendMaskFlag = 0;
}

void TFecBusCRT::ResetCallBack()
{
	Init();
	
	SendMaskFlag = 1;
}

void TFecBusCRT::MsgFrmIndexInc()
{
	MsgFrmIndex++;
	if(MsgFrmIndex > 63)MsgFrmIndex = 1;
}

unsigned short TFecBusCRT::Crc16Data(unsigned char* pdata,unsigned int len)
{
	unsigned int x = 0,y = 0;
	unsigned short crc = 0xFFFF;
	unsigned char data = 0;
	
	for(x=0;x<len;x++){
		data = (* pdata);
		crc ^= data;
		for(y=0;y<8;y++){
			if(crc & 0x01){
				crc>>=1;
				crc ^= 0xA001;
			}else{
				crc>>=1;
			}
		}
		pdata++;
	}
	return crc;
}

unsigned int TFecBusCRT::CheckCrc16(unsigned char* pdata,unsigned int len)
{
	unsigned short CrcData = 0;
	
	CrcData = *(pdata + len - 1);
	CrcData<<=8;
	CrcData |= *(pdata + len - 2);
	
	if(CrcData == Crc16Data(pdata,(len - 2))){
		return 0;
	}
	return 1;
}

void TFecBusCRT::iBufInsert()
{
	;
}

void TFecBusCRT::iBufProcess()
{
	unsigned char aYear, aMon, aDay, aHour, aMin, aSec;
	
	if(RxGetFlag){
		RxGetFlag = 0;
		
		if(ackRecDataCorrect == RxMsgState){
			
			OnlineTick = 0;
			ErrState.Body.OffLine = 0;
			ErrState.Body.OffLineTick = 0;
			
			if((2 == RxMsg.Prm.Section[0].body.Dlen)&&(FecFunStateAck == RxMsg.Prm.Section[0].body.DPFC[0])&&\
				(ackAddrNotExist != RxMsg.Prm.Section[0].body.DPFC[1])&&(RxMsg.Prm.Section[0].body.DPFC[1] <= ackRecDataCorrect)){
			
				OnTransmite.AckOk = 1;
				OnTransmite.RetryTimes = 0;
				OnTransmite.OnGoing = 0;
				OnTransmite.TimeOutTick = 0;
			
				if(ErrReport.Body.OffLine){
					//Remove Err Here
					ErrReport.Body.OffLine = 0;
					CtlCenter.ieAddBrdFaultCancel(9, 9);
				}
			}else
			if((4 == RxMsg.Prm.Section[0].body.Dlen)&&(FecQueryCurrentEvent == RxMsg.Prm.Section[0].body.DPFC[0])){
				//------------------------------------------------------------------------------------------------------------->>>>>
				Upload.Active = 1;
				Upload.InxFire = 0;
				Upload.InxStart = 0;
				Upload.InxSv = 0;
				Upload.InxFault = 0;
				Upload.InxMask = 0;
			}else
			if((8 == RxMsg.Prm.Section[0].body.Dlen)&&(FecFunSyncTime == RxMsg.Prm.Section[0].body.DPFC[0])){
				aYear = (RxMsg.Prm.Section[0].body.DPFC[2]/10*16) + (RxMsg.Prm.Section[0].body.DPFC[2]%10);
				aMon = (RxMsg.Prm.Section[0].body.DPFC[3]/10*16) + (RxMsg.Prm.Section[0].body.DPFC[3]%10);
				aDay = (RxMsg.Prm.Section[0].body.DPFC[4]/10*16) + (RxMsg.Prm.Section[0].body.DPFC[4]%10);
				aHour = (RxMsg.Prm.Section[0].body.DPFC[5]/10*16) + (RxMsg.Prm.Section[0].body.DPFC[5]%10);
				aMin = (RxMsg.Prm.Section[0].body.DPFC[6]/10*16) + (RxMsg.Prm.Section[0].body.DPFC[6]%10);
				aSec = (RxMsg.Prm.Section[0].body.DPFC[7]/10*16) + (RxMsg.Prm.Section[0].body.DPFC[7]%10);
				DataTimeSet(aYear, aMon, aDay, aHour, aMin, aSec, 1);	//aWk 1..7			
				Record.OperateAdd_CfgDateTime(aYear, aMon, aDay, aHour, aMin ,aSec);
			}else
			if((1 == RxMsg.Prm.Section[0].body.Dlen)&&(FecFunInformedHeartbeat == RxMsg.Prm.Section[0].body.DPFC[0])){
				rpyFecBusCRTMsg15();//应答状态
			}
		}else
		if(ackCrcError == RxMsgState){
			OnlineTick = 0;
			ErrState.Body.OffLine = 0;
			ErrState.Body.OffLineTick = 0;
		}
	}
}

void TFecBusCRT::oBufInsert()//10ms
{
	unsigned int i,x,y;
	unsigned int aAddr;
	
	if(!OnTransmite.OnGoing){
		
		if(InTxIndex != OutTxIndex){
			OutTxIndex++;
			if(OutTxIndex >= dFecCRT_BufCount_Tx)OutTxIndex = 0;
			
			aAddr = dAddrSdram_CrtTxBuf + (OutTxIndex * dFecCRT_BufEntrySize_Tx);
			for(i=0;i<(dFecCRT_BufEntrySize_Tx/4);i++)
				TxMsg.D32[i] = *(volatile unsigned int *)(aAddr + (i*4));
			/*
			TxMsg.avalibel = TxCRTMsg[OutTxIndex].avalibel;
			TxMsg.UsingMsgIndex = TxCRTMsg[OutTxIndex].UsingMsgIndex;
			TxMsg.FrameNum = TxCRTMsg[OutTxIndex].FrameNum;
			
			for(y = 0;y < TxMsg.FrameNum;y++){
				if(y > 3)break;
				for(x = 0;x < 5;x++){
					TxMsg.Section[y].D32[x] = TxCRTMsg[OutTxIndex].Section[y].D32[x];
				}
			}
			*/
			TxSetFlag = 1;
		}
	}
}

void TFecBusCRT::oBufProcess()//10ms
{
	unsigned int retry_time = 0;
	
	if(OnTransmite.OnGoing){
		OnTransmite.TimeOutTick++;
		
		retry_time = 99;//1000ms retry
			
		if(OnTransmite.TimeOutTick > retry_time){
			OnTransmite.TimeOutTick = 0;
			
			if(OnTransmite.RetryTimes < 3){
				OnTransmite.RetryFLAG = 1;
			}else{
				OnTransmite.RetryTimes = 0;
				OnTransmite.OnGoing = 0;
				//ErrState |= exErrCom;
			}
		}
	}
	
	if(!fecbus_tx_is_busy()){
		if(TxSetFlag){
			if(TxMsg.Prm.UsingMsgIndex){
				TxMsg.Prm.FrameTick++;
				if(TxMsg.Prm.FrameTick >= TxMsg.Prm.FrameNum){
					TxMsg.Prm.FrameTick = 0;
					TxSetFlag = 0;
				}
				set_fecbus_tx_data(TxMsg.Prm.Section[TxMsg.Prm.FrameTick].da8);
			}else{
				set_fecbus_tx_data(TxMsg.Prm.Section[0].da8);
				TxSetFlag = 0;
			}
			OnTransmite.TimeOutTick = 0;
			OnTransmite.AckOk = 0;
			OnTransmite.OnGoing = 1;
		}else
		if(OnTransmite.RetryFLAG){
			if(TxMsg.Prm.UsingMsgIndex){
				TxMsg.Prm.FrameTick++;
				if(TxMsg.Prm.FrameTick >= TxMsg.Prm.FrameNum){
					TxMsg.Prm.FrameTick = 0;
					OnTransmite.RetryFLAG = 0;
					OnTransmite.RetryTimes++;
				}
				set_fecbus_tx_data(TxMsg.Prm.Section[TxMsg.Prm.FrameTick].da8);
			}else{
				set_fecbus_tx_data(TxMsg.Prm.Section[0].da8);
				OnTransmite.RetryFLAG = 0;
				OnTransmite.RetryTimes++;
			}
			
			OnTransmite.TimeOutTick = 0;
			OnTransmite.AckOk = 0;
			OnTransmite.OnGoing = 1; 
		}
	}
}

void TFecBusCRT::iFecBusMsgInsert(TFecBusMsgUart * pMsg)
{
	unsigned int i = 0;
	unsigned int aSection = 0;
	unsigned int aAddr;
	
	InTxIndex++;
	if(InTxIndex >= dFecCRT_BufCount_Tx)InTxIndex = 0;
	
	//----------------load to full-----------------------
	if(InTxIndex == OutTxIndex){
		if(0 == InTxIndex)InTxIndex = dFecCRT_BufCount_Tx;
		else InTxIndex--;
		return;
	}
	//----------------------------------------------------
	
	aAddr = dAddrSdram_CrtTxBuf + (InTxIndex * dFecCRT_BufEntrySize_Tx);
	for(i=0;i<(dFecCRT_BufEntrySize_Tx/4);i++)
		*(volatile unsigned int *)(aAddr + (i*4)) = pMsg->D32[i];
	/*
	TxCRTMsg[InTxIndex].avalibel = pMsg->avalibel;
	TxCRTMsg[InTxIndex].UsingMsgIndex = pMsg->UsingMsgIndex;
	TxCRTMsg[InTxIndex].FrameNum = pMsg->FrameNum;
	
	for(aSection = 0;aSection < (pMsg->FrameNum);aSection++){
		for(i=0;i<5;i++){
			TxCRTMsg[InTxIndex].Section[aSection].D32[i] = pMsg->Section[aSection].D32[i];
		}
	}
	*/
}

void TFecBusCRT::iSetFecBusBufEnd(TFecBusMsgUart * pMsg,unsigned char Priority)
{
	TCrcValue CrcValue;
	
	pMsg->Prm.Section[0].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[0].body.FrmType = 0;
	pMsg->Prm.Section[0].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[0].body.Priority = Priority;
	pMsg->Prm.Section[0].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[0].body.MsgIndex = 0x01;//-------------
	pMsg->Prm.Section[0].body.FrmIndex = 0x00;
	pMsg->Prm.Section[0].body.Dlen = 0x02;
	pMsg->Prm.Section[0].body.DPFC[0] = 0x0F;
	pMsg->Prm.Section[0].body.DPFC[1] = 0x00;
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[0].da8, (pMsg->Prm.Section[0].body.Dlen + 8));
	
	pMsg->Prm.Section[0].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[0].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[0].body.Eop = FECBUS_END;
}

void TFecBusCRT::iSetFecBusMsg00(TFecBusMsgUart * pMsg)
{
	TCrcValue CrcValue;
	
	pMsg->Prm.avalibel = 1;
	pMsg->Prm.UsingMsgIndex = 0;
	pMsg->Prm.FrameNum = 1;
	
	pMsg->Prm.Section[0].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[0].body.FrmType = 0;
	pMsg->Prm.Section[0].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[0].body.Priority = 0x00;
	pMsg->Prm.Section[0].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[0].body.MsgIndex = 0x00;
	pMsg->Prm.Section[0].body.FrmIndex = 0x00;
	pMsg->Prm.Section[0].body.Dlen = 0x01;
	pMsg->Prm.Section[0].body.DPFC[0] = FecFunSyncSysTick;
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[0].da8, (pMsg->Prm.Section[0].body.Dlen + 8));
	
	pMsg->Prm.Section[0].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[0].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[0].body.Eop = FECBUS_END;
}

void TFecBusCRT::iSetFecBusMsg01(TFecBusMsgUart * pMsg, unsigned char aCtlNum)
{
	TCrcValue CrcValue;
	
	pMsg->Prm.avalibel = 1;
	pMsg->Prm.UsingMsgIndex = 0;
	pMsg->Prm.FrameNum = 1;
	
	pMsg->Prm.Section[0].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[0].body.FrmType = 0;
	pMsg->Prm.Section[0].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[0].body.Priority = 0x01;
	pMsg->Prm.Section[0].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[0].body.MsgIndex = 0x01;
	pMsg->Prm.Section[0].body.FrmIndex = 0x00;
	pMsg->Prm.Section[0].body.Dlen = 0x02;
	pMsg->Prm.Section[0].body.DPFC[0] = FecFunSysReset;
	pMsg->Prm.Section[0].body.DPFC[1] = aCtlNum;
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[0].da8, (pMsg->Prm.Section[0].body.Dlen + 8));
	
	pMsg->Prm.Section[0].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[0].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[0].body.Eop = FECBUS_END;
}

void TFecBusCRT::iSetFecBusMsg02(TFecBusMsgUart * pMsg, unsigned char aCtlNum)
{
	TCrcValue CrcValue;
	
	pMsg->Prm.avalibel = 1;
	pMsg->Prm.UsingMsgIndex = 0;
	pMsg->Prm.FrameNum = 1;
	
	pMsg->Prm.Section[0].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[0].body.FrmType = 0;
	pMsg->Prm.Section[0].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[0].body.Priority = 0x01;
	pMsg->Prm.Section[0].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[0].body.MsgIndex = 0x01;
	pMsg->Prm.Section[0].body.FrmIndex = 0x00;
	pMsg->Prm.Section[0].body.Dlen = 0x02;
	pMsg->Prm.Section[0].body.DPFC[0] = FecFunSysMute;
	pMsg->Prm.Section[0].body.DPFC[1] = aCtlNum;
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[0].da8, (pMsg->Prm.Section[0].body.Dlen + 8));
	
	pMsg->Prm.Section[0].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[0].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[0].body.Eop = FECBUS_END;
}

void TFecBusCRT::iSetFecBusMsg03(TFecBusMsgUart * pMsg, unsigned char aCtlNum)
{
	TCrcValue CrcValue;
	
	pMsg->Prm.avalibel = 1;
	pMsg->Prm.UsingMsgIndex = 0;
	pMsg->Prm.FrameNum = 1;
	
	pMsg->Prm.Section[0].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[0].body.FrmType = 0;
	pMsg->Prm.Section[0].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[0].body.Priority = 0x03;
	pMsg->Prm.Section[0].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[0].body.MsgIndex = 0x01;
	pMsg->Prm.Section[0].body.FrmIndex = 0x00;
	pMsg->Prm.Section[0].body.Dlen = 0x02;
	pMsg->Prm.Section[0].body.DPFC[0] = FecFunSysSlefCheck;
	pMsg->Prm.Section[0].body.DPFC[1] = aCtlNum;
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[0].da8, (pMsg->Prm.Section[0].body.Dlen + 8));
	
	pMsg->Prm.Section[0].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[0].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[0].body.Eop = FECBUS_END;
}

void TFecBusCRT::iSetFecBusMsg05(TFecBusMsgUart * pMsg, TFecEventBufBody * pEvent)
{
	TCrcValue CrcValue;
	
	pMsg->Prm.avalibel = 1;
	pMsg->Prm.UsingMsgIndex = 1;
	pMsg->Prm.FrameNum = 4;
	
	//-------------------------------------1-------------------------------------------------
	pMsg->Prm.Section[1].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[1].body.FrmType = 0;
	pMsg->Prm.Section[1].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[1].body.Priority = 0x01;
	pMsg->Prm.Section[1].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[1].body.MsgIndex = 0x01;
	pMsg->Prm.Section[1].body.FrmIndex = 0x01;
	pMsg->Prm.Section[1].body.Dlen = 0x08;
	pMsg->Prm.Section[1].body.DPFC[0] = FecFunPublishEmergencyEvent;
	pMsg->Prm.Section[1].body.DPFC[1] = pEvent->D8[0];
	pMsg->Prm.Section[1].body.DPFC[2] = pEvent->D8[1];
	pMsg->Prm.Section[1].body.DPFC[3] = pEvent->D8[2];
	pMsg->Prm.Section[1].body.DPFC[4] = pEvent->D8[3];
	pMsg->Prm.Section[1].body.DPFC[5] = pEvent->D8[4];
	pMsg->Prm.Section[1].body.DPFC[6] = pEvent->D8[5];
	pMsg->Prm.Section[1].body.DPFC[7] = pEvent->D8[6];
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[1].da8, (pMsg->Prm.Section[1].body.Dlen + 8));
	
	pMsg->Prm.Section[1].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[1].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[1].body.Eop = FECBUS_END;
	//-------------------------------------2-------------------------------------------------
	pMsg->Prm.Section[2].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[2].body.FrmType = 0;
	pMsg->Prm.Section[2].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[2].body.Priority = 0x01;
	pMsg->Prm.Section[2].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[2].body.MsgIndex = 0x01;
	pMsg->Prm.Section[2].body.FrmIndex = 0x02;
	pMsg->Prm.Section[2].body.Dlen = 0x08;
	pMsg->Prm.Section[2].body.DPFC[0] = pEvent->D8[7];
	pMsg->Prm.Section[2].body.DPFC[1] = pEvent->D8[8];
	pMsg->Prm.Section[2].body.DPFC[2] = pEvent->D8[9];
	pMsg->Prm.Section[2].body.DPFC[3] = pEvent->D8[10];
	pMsg->Prm.Section[2].body.DPFC[4] = pEvent->D8[11];
	pMsg->Prm.Section[2].body.DPFC[5] = pEvent->D8[12];
	pMsg->Prm.Section[2].body.DPFC[6] = pEvent->D8[13];
	pMsg->Prm.Section[2].body.DPFC[7] = pEvent->D8[14];
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[2].da8, (pMsg->Prm.Section[2].body.Dlen + 8));
	
	pMsg->Prm.Section[2].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[2].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[2].body.Eop = FECBUS_END;
	//-------------------------------------3-------------------------------------------------
	pMsg->Prm.Section[3].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[3].body.FrmType = 0;
	pMsg->Prm.Section[3].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[3].body.Priority = 0x01;
	pMsg->Prm.Section[3].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[3].body.MsgIndex = 0x01;
	pMsg->Prm.Section[3].body.FrmIndex = 0x03;
	pMsg->Prm.Section[3].body.Dlen = 0x01;
	pMsg->Prm.Section[3].body.DPFC[0] = pEvent->D8[15];
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[3].da8, (pMsg->Prm.Section[3].body.Dlen + 8));
	
	pMsg->Prm.Section[3].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[3].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[3].body.Eop = FECBUS_END;
	
	iSetFecBusBufEnd(pMsg,0x01);
}

void TFecBusCRT::iSetFecBusMsg06(TFecBusMsgUart * pMsg, TFecEventBufBody * pEvent)
{
	TCrcValue CrcValue;
	
	pMsg->Prm.avalibel = 1;
	pMsg->Prm.UsingMsgIndex = 1;
	pMsg->Prm.FrameNum = 4;
	
	//-------------------------------------1-------------------------------------------------
	pMsg->Prm.Section[1].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[1].body.FrmType = 0;
	pMsg->Prm.Section[1].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[1].body.Priority = 0x03;
	pMsg->Prm.Section[1].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[1].body.MsgIndex = 0x01;
	pMsg->Prm.Section[1].body.FrmIndex = 0x01;
	pMsg->Prm.Section[1].body.Dlen = 0x08;
	pMsg->Prm.Section[1].body.DPFC[0] = FecFunPublishGeneralEvent;
	pMsg->Prm.Section[1].body.DPFC[1] = pEvent->D8[0];
	pMsg->Prm.Section[1].body.DPFC[2] = pEvent->D8[1];
	pMsg->Prm.Section[1].body.DPFC[3] = pEvent->D8[2];
	pMsg->Prm.Section[1].body.DPFC[4] = pEvent->D8[3];
	pMsg->Prm.Section[1].body.DPFC[5] = pEvent->D8[4];
	pMsg->Prm.Section[1].body.DPFC[6] = pEvent->D8[5];
	pMsg->Prm.Section[1].body.DPFC[7] = pEvent->D8[6];
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[1].da8, (pMsg->Prm.Section[1].body.Dlen + 8));
	
	pMsg->Prm.Section[1].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[1].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[1].body.Eop = FECBUS_END;
	//-------------------------------------2-------------------------------------------------
	pMsg->Prm.Section[2].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[2].body.FrmType = 0;
	pMsg->Prm.Section[2].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[2].body.Priority = 0x03;
	pMsg->Prm.Section[2].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[2].body.MsgIndex = 0x01;
	pMsg->Prm.Section[2].body.FrmIndex = 0x02;
	pMsg->Prm.Section[2].body.Dlen = 0x08;
	pMsg->Prm.Section[2].body.DPFC[0] = pEvent->D8[7];
	pMsg->Prm.Section[2].body.DPFC[1] = pEvent->D8[8];
	pMsg->Prm.Section[2].body.DPFC[2] = pEvent->D8[9];
	pMsg->Prm.Section[2].body.DPFC[3] = pEvent->D8[10];
	pMsg->Prm.Section[2].body.DPFC[4] = pEvent->D8[11];
	pMsg->Prm.Section[2].body.DPFC[5] = pEvent->D8[12];
	pMsg->Prm.Section[2].body.DPFC[6] = pEvent->D8[13];
	pMsg->Prm.Section[2].body.DPFC[7] = pEvent->D8[14];
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[2].da8, (pMsg->Prm.Section[2].body.Dlen + 8));
	
	pMsg->Prm.Section[2].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[2].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[2].body.Eop = FECBUS_END;
	//-------------------------------------3-------------------------------------------------
	pMsg->Prm.Section[3].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[3].body.FrmType = 0;
	pMsg->Prm.Section[3].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[3].body.Priority = 0x03;
	pMsg->Prm.Section[3].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[3].body.MsgIndex = 0x01;
	pMsg->Prm.Section[3].body.FrmIndex = 0x03;
	pMsg->Prm.Section[3].body.Dlen = 0x01;
	pMsg->Prm.Section[3].body.DPFC[0] = pEvent->D8[15];
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[3].da8, (pMsg->Prm.Section[3].body.Dlen + 8));
	
	pMsg->Prm.Section[3].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[3].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[3].body.Eop = FECBUS_END;
	
	iSetFecBusBufEnd(pMsg,0x03);
}

void TFecBusCRT::iSetFecBusMsg15(TFecBusMsgUart * pMsg)
{
	TCrcValue CrcValue;
	
	pMsg->Prm.avalibel = 1;
	pMsg->Prm.UsingMsgIndex = 0;
	pMsg->Prm.FrameNum = 1;
	
	pMsg->Prm.Section[0].body.Header = FECBUS_HEAD;
	pMsg->Prm.Section[0].body.FrmType = 1;
	pMsg->Prm.Section[0].body.DestAddr = GraphAddr;//CRT addr
	pMsg->Prm.Section[0].body.Priority = 0x03;
	pMsg->Prm.Section[0].body.SrcAddr = FecBusMasterAddr;//fix 0x01;  MainCtl.fData.Split.MyNum;
	pMsg->Prm.Section[0].body.MsgIndex = 0x01;
	pMsg->Prm.Section[0].body.FrmIndex = 0x00;
	pMsg->Prm.Section[0].body.Dlen = 0x02;
	pMsg->Prm.Section[0].body.DPFC[0] = FecFunStateAck;
	pMsg->Prm.Section[0].body.DPFC[1] = ackRecDataCorrect;
	
	CrcValue.D16 = Crc16Data(pMsg->Prm.Section[0].da8, (pMsg->Prm.Section[0].body.Dlen + 8));
	
	pMsg->Prm.Section[0].body.CrcLoByte = CrcValue.body.LoByte;
	pMsg->Prm.Section[0].body.CrcHiByte = CrcValue.body.HiByte;
	pMsg->Prm.Section[0].body.Eop = FECBUS_END;
}

void TFecBusCRT::setFecBusCRTMsg01(unsigned char aCtlNum)
{
	iSetFecBusMsg01(&FecBusMsgUartTemp, aCtlNum);
	iFecBusMsgInsert(&FecBusMsgUartTemp);
}

void TFecBusCRT::setFecBusCRTMsg02(unsigned char aCtlNum)
{
	iSetFecBusMsg02(&FecBusMsgUartTemp, aCtlNum);
	iFecBusMsgInsert(&FecBusMsgUartTemp);
}

void TFecBusCRT::setFecBusCRTMsg03(unsigned char aCtlNum)
{
	iSetFecBusMsg03(&FecBusMsgUartTemp, aCtlNum);
	iFecBusMsgInsert(&FecBusMsgUartTemp);
}

void TFecBusCRT::rpyFecBusCRTMsg15(void)
{
	iSetFecBusMsg15(&FecBusMsgUartTemp);
	iFecBusMsgInsert(&FecBusMsgUartTemp);
}

void TFecBusCRT::getFecBusCRTTime(TRecordCommon aRC)
{
	FecBusCRTBufTemp.Data.Year = (aRC.Splite.Year/16*10) + (aRC.Splite.Year & 0x0F);
	FecBusCRTBufTemp.Data.Mon  = (aRC.Splite.Month/16*10) + (aRC.Splite.Month & 0x0F);
	FecBusCRTBufTemp.Data.Day  = (aRC.Splite.Day/16*10) + (aRC.Splite.Day & 0x0F);
	FecBusCRTBufTemp.Data.Hour = (aRC.Splite.Hour/16*10) + (aRC.Splite.Hour & 0x0F);
	FecBusCRTBufTemp.Data.Min  = (aRC.Splite.Minute/16*10) + (aRC.Splite.Minute & 0x0F);
	FecBusCRTBufTemp.Data.Sec  = (aRC.Splite.Second/16*10) + (aRC.Splite.Second & 0x0F);
}

void TFecBusCRT::getFecBusCRTStateCode(unsigned short StateCode)
{
	FecBusCRTBufTemp.Data.StateCode.D16 = StateCode;
}

void TFecBusCRT::setFecBusCRTStateCode(unsigned short StateCode)
{
	FecBusCRTStateCode = StateCode;
}

void TFecBusCRT::SetStateCodeAll()
{
	unsigned int aC;
	aC = 0;
	
	//AllowAuto, AllowManual, 
	if(AllowAuto)		aC |= 1;
	if(PowerSuplyState)	aC |= 2;
	if(PowerSuplyComm | PowerBkState | 	BatState)	aC |= 4;
	if(CtlCenter.ieMsgFire.Count >0)			aC |= 8;
	if(CtlCenter.ieMsgLinkage.StartCount >0)		aC |= 0x0000'0010;
	if(CtlCenter.ieMsgLinkage.FbCount >0)		aC |= 0x0000'0020;
	if(CtlCenter.ieMsgSv.Count >0)			aC |= 0x0000'0040;
	if(CtlCenter.ieMsgFault.Count >0)			aC |= 0x0000'0080;
	if(CtlCenter.ieMsgMask.Count >0)			aC |= 0x0000'0100;
	
	setFecBusCRTStateCode(static_cast<unsigned short>(aC));
}

void TFecBusCRT::SetStateCodeAutoManual()
{
	if(AllowAuto)FecBusCRTStateCode |= 0x0001;
	else FecBusCRTStateCode &= ~0x0001;
}

void TFecBusCRT::SetStateCodePsOnActive()
{
	if(PowerSuplyState)FecBusCRTStateCode |= 0x0002;
	else FecBusCRTStateCode &= ~0x0002;	
}

void TFecBusCRT::SetStateCodePsError()
{
	if(PowerSuplyComm | PowerBkState | 	BatState)FecBusCRTStateCode |= 0x0004;
	else FecBusCRTStateCode &= ~0x0004;	
}

void TFecBusCRT::SetStateCodeFire()
{
	if(CtlCenter.ieMsgFire.Count >0)FecBusCRTStateCode |= 0x0008;
	else FecBusCRTStateCode &= ~0x0008;
}

void TFecBusCRT::SetStateCodeStart()
{
	if(CtlCenter.ieMsgLinkage.StartCount >0)FecBusCRTStateCode |= 0x0010;
	else FecBusCRTStateCode &= ~0x0010;	
}

void TFecBusCRT::SetStateCodeFeedBack()
{
	if(CtlCenter.ieMsgLinkage.FbCount >0)FecBusCRTStateCode |= 0x0020;
	else FecBusCRTStateCode &= ~0x0020;	
}

void TFecBusCRT::SetStateCodeSv()	
{
	if(CtlCenter.ieMsgSv.Count >0)FecBusCRTStateCode |= 0x0040;
	else FecBusCRTStateCode &= ~0x0040;	
}

void TFecBusCRT::SetStateCodeFault()	
{
	if(CtlCenter.ieMsgFault.Count >0)FecBusCRTStateCode |= 0x0080;
	else FecBusCRTStateCode &= ~0x0080;	
}

void TFecBusCRT::SetStateCodeMask()
{
	if(CtlCenter.ieMsgMask.Count >0)FecBusCRTStateCode |= 0x0100;
	else FecBusCRTStateCode &= ~0x0100;	
}

void TFecBusCRT::getFecBusCRTDeviceCode(unsigned char dType)
{
	if(GBDeviceCodePrm[dType]){
		FecBusCRTBufTemp.Data.DeviceCode = dType;
	}else{
		FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
	}
}

void TFecBusCRT::getFecBusCRTEpFaultEvent(unsigned char aType, unsigned char State)
{
	if(1 == State){
		switch(aType){
			case 0: 
				FecBusCRTBufTemp.Data.EventCode = evFault;
				break;
			
			case 1: 
			case 2: 
			case 3:
				FecBusCRTBufTemp.Data.EventCode = evFaultComponent;
				break;
			
			case 4: 
			case 5:
				FecBusCRTBufTemp.Data.EventCode = evFaultCircuit;
				break;
			
			case 6:
				FecBusCRTBufTemp.Data.EventCode = evFaultMainPower;
				break;
			
			case 7:
			case 8:
				FecBusCRTBufTemp.Data.EventCode = evFaultSparePower;
				break;
			
			default: 
				FecBusCRTBufTemp.Data.EventCode = evUndefine;
				break;
		}
	}else{
		switch(aType){
			case 0: 
				FecBusCRTBufTemp.Data.EventCode = evFaultRecover;
				break;
			
			case 1: 
			case 2: 
			case 3:
				FecBusCRTBufTemp.Data.EventCode = evFaultComponentRecover;
				break;
			
			case 4: 
			case 5:
				FecBusCRTBufTemp.Data.EventCode = evFaultCircuitRecover;
				break;
			
			case 6:
				FecBusCRTBufTemp.Data.EventCode = evFaultMainPowerRecover;
				break;
			
			case 7:
			case 8:
				FecBusCRTBufTemp.Data.EventCode = evFaultSparePowerRecover;
				break;
			
			default: 
				FecBusCRTBufTemp.Data.EventCode = evUndefine;
				break;
		}
	}
}

void TFecBusCRT::getFecBusCRTFaultBrdDeviceCode(unsigned char aType)
{
	switch(aType){
		case 0: 
		case 7: 
		case 11:
			FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
			break;
		
		case 1: 
		case 10:
			FecBusCRTBufTemp.Data.DeviceCode = ftCtlCircuit;
			break;
		
		case 2: 
			FecBusCRTBufTemp.Data.DeviceCode = ftBusCtlPanel;
			break;
		
		case 3: 
			FecBusCRTBufTemp.Data.DeviceCode = ftDirCtlPanel;
			break;
		
		case 4: 
			FecBusCRTBufTemp.Data.DeviceCode = ftCanNetworkComm;
			break;
		
		case 5: 
			FecBusCRTBufTemp.Data.DeviceCode = ftMainPower;
			break;
		
		case 6: 
			FecBusCRTBufTemp.Data.DeviceCode = ftStandbyPower;
			break;
		
		case 8: 
			FecBusCRTBufTemp.Data.DeviceCode = ftBatChargeCircuit;
			break;
		
		case 9: 
			FecBusCRTBufTemp.Data.DeviceCode = ftGraphShow;
			break;
		
		default: 
			FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
			break;
	}
}

void TFecBusCRT::getFecBusCRTFaultBrdEventCode(unsigned char aType, unsigned char State)
{
	if(1 == State){
		switch(aType){
			case 0: 
			case 2: 
			case 3:
				FecBusCRTBufTemp.Data.EventCode = evFault;
				break;
			
			case 1: 
				FecBusCRTBufTemp.Data.EventCode = evFaultLoopTank;
				break;
			
			case 4: 
				FecBusCRTBufTemp.Data.EventCode = evFaultCommunications;
				break;
			
			case 5:
				FecBusCRTBufTemp.Data.EventCode = evFaultMainPower;
				break;
			
			case 6:
				FecBusCRTBufTemp.Data.EventCode = evFaultSparePower;
				break;
			
			case 7:
				FecBusCRTBufTemp.Data.EventCode = evFaultCircuit;
				break;
			
			case 8:
				FecBusCRTBufTemp.Data.EventCode = evFaultCharge;
				break;
			
			case 9:
			case 10:
				FecBusCRTBufTemp.Data.EventCode = evFaultCommunications;
				break;
			
			default: 
				FecBusCRTBufTemp.Data.EventCode = evFault;
				break;
		}
	}else{
		switch(aType){
			case 0: 
			case 2: 
			case 3:
				FecBusCRTBufTemp.Data.EventCode = evFaultRecover;
				break;
			
			case 1: 
				FecBusCRTBufTemp.Data.EventCode = evFaultLoopTankRecover;
				break;
			
			case 4: 
				FecBusCRTBufTemp.Data.EventCode = evFaultCommunicationsRecover;
				break;
			
			case 5:
				FecBusCRTBufTemp.Data.EventCode = evFaultMainPowerRecover;
				break;
			
			case 6:
				FecBusCRTBufTemp.Data.EventCode = evFaultSparePowerRecover;
				break;
			
			case 7:
				FecBusCRTBufTemp.Data.EventCode = evFaultCircuitRecover;
				break;
			
			case 8:
				FecBusCRTBufTemp.Data.EventCode = evFaultChargeRecover;
				break;
			
			case 9:
			case 10:
				FecBusCRTBufTemp.Data.EventCode = evFaultCommunicationsRecover;
				break;
			
			default: 
				FecBusCRTBufTemp.Data.EventCode = evFaultRecover;
				break;
		}
	}
}

void TFecBusCRT::getFecBusCRTFaultDevDeviceCode(unsigned char aType)
{
	switch(aType){
		case 0: 
		case 1:
		case 5: 
		case 14:
		case 17:
		case 18:
			FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
			break;
		
		case 2: 
			FecBusCRTBufTemp.Data.DeviceCode = ftCtlCircuit;
			break;
		
		case 3: 
			FecBusCRTBufTemp.Data.DeviceCode = ftBusCtlPanel;
			break;
		
		case 4: 
			FecBusCRTBufTemp.Data.DeviceCode = ftDirCtlPanel;
			break;
		
		case 6: 
			FecBusCRTBufTemp.Data.DeviceCode = ftDataMemCard;
			break;
		
		case 7: 
		case 8: 
		case 19:
		case 21:
		case 22:
		case 23:
			FecBusCRTBufTemp.Data.DeviceCode = ftMainPower;
			break;
		
		case 9:
		case 10:
		case 20:
		case 24:
		case 25:
		case 26:
		case 27:
			FecBusCRTBufTemp.Data.DeviceCode = ftStandbyPower;
			break;
		
		case 11: 
		case 12: 
		case 15: 
		case 16: 
			FecBusCRTBufTemp.Data.DeviceCode = ftCanNetworkComm;
			break;
		
		case 13: 
			FecBusCRTBufTemp.Data.DeviceCode = ftGraphShow;
			break;
		
		default: 
			FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
			break;
	}
}

void TFecBusCRT::getFecBusCRTFaultDevEventCode(unsigned char aType, unsigned char State)
{
	if(1 == State){
		switch(aType){
			case 0: 
			case 1: 
			case 2: 
			case 3:
			case 4: 
			case 5:
			case 6:
			case 14:
				FecBusCRTBufTemp.Data.EventCode = evFault;
				break;
			
			case 7:
			case 19:
				FecBusCRTBufTemp.Data.EventCode = evFaultMainPower;
				break;
			
			case 8:
			case 11:
			case 12:
			case 13:
			case 15:
			case 16:
			case 21:
				FecBusCRTBufTemp.Data.EventCode = evFaultCommunications;
				break;
			
			case 9:
			case 10:
			case 20:
			case 24:
			case 25:
			case 26:
			case 27:
				FecBusCRTBufTemp.Data.EventCode = evFaultSparePower;
				break;
			
			case 22: 
			case 23:
				FecBusCRTBufTemp.Data.EventCode = evFaultCircuit;
				break;
			
			default: 
				FecBusCRTBufTemp.Data.EventCode = evUndefine;
				break;
		}
	}else{
		switch(aType){
			case 0: 
			case 1: 
			case 2: 
			case 3:
			case 4: 
			case 5:
			case 6:
			case 14:
				FecBusCRTBufTemp.Data.EventCode = evFaultRecover;
				break;
			
			case 7:
			case 19:
				FecBusCRTBufTemp.Data.EventCode = evFaultMainPowerRecover;
				break;
			
			case 8:
			case 11:
			case 12:
			case 13:
			case 15:
			case 16:
			case 21:
				FecBusCRTBufTemp.Data.EventCode = evFaultCommunicationsRecover;
				break;
			
			case 9:
			case 10:			
			case 20:
			case 24:
			case 25:
			case 26:
			case 27:
				FecBusCRTBufTemp.Data.EventCode = evFaultSparePowerRecover;
				break;
			
			case 22: 
			case 23:
				FecBusCRTBufTemp.Data.EventCode = evFaultCircuitRecover;
				break;
			
			default: 
				FecBusCRTBufTemp.Data.EventCode = evUndefine;
				break;
		}
	}
}

void TFecBusCRT::iFecBusCRTFaultInsert(TRecordCommon aRC)
{
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char aData0;
	unsigned char aData1;
	
	if(MainCtl.fData.Split.NetworkMode == 2)return;
	if(GraphUsing == 0)return;
	
	FecBusCRTBufTemp.Data.CtlNum = aRC.Splite.PCtlNum;

	aP0	= aRC.Splite.P0;
	aP1 = aRC.Splite.P1;
	dType = aRC.Splite.dType;
	aData0 = aRC.Splite.Data0;
	aData1 = aRC.Splite.Data1 & 0x01;
	
	if((aRC.Splite.Data1 & 0xF0) == 0xC0){
		if((aRC.Splite.P1 >= dADDR_HANDPAD_START) && (aRC.Splite.P1 <= dADDR_HANDPAD_END)){
			FecBusCRTBufTemp.Data.UnitNum = aRC.Splite.P1;
			FecBusCRTBufTemp.Data.DeviceNum = 0;
			FecBusCRTBufTemp.Data.ChannelNum = 0;
			
			FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
			if(aData1)FecBusCRTBufTemp.Data.EventCode = evFaultCommunications;
			else FecBusCRTBufTemp.Data.EventCode = evFaultCommunicationsRecover;
		}else
		if((aRC.Splite.P1 >= dADDR_DIRECTPAD_START) && (aRC.Splite.P1 <= dADDR_DIRECTPAD_END)){
			FecBusCRTBufTemp.Data.UnitNum = aRC.Splite.P1;
			FecBusCRTBufTemp.Data.DeviceNum = 0;
			FecBusCRTBufTemp.Data.ChannelNum = 0;
			
			FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
			if(aData1)FecBusCRTBufTemp.Data.EventCode = evFaultCommunications;
			else FecBusCRTBufTemp.Data.EventCode = evFaultCommunicationsRecover;
		}
	}else
	if((aRC.Splite.Data1 & 0xF0) == 0xD0){
		FecBusCRTBufTemp.Data.UnitNum = aP0;
		FecBusCRTBufTemp.Data.DeviceNum = 0;
		FecBusCRTBufTemp.Data.ChannelNum = 0;
		
		getFecBusCRTFaultDevDeviceCode(aData0);
		getFecBusCRTFaultDevEventCode(aData0, aData1);
	}else
	if((aRC.Splite.Data1 & 0xF0) == 0xE0){
		FecBusCRTBufTemp.Data.UnitNum = aP0;
		FecBusCRTBufTemp.Data.DeviceNum = 0;
		FecBusCRTBufTemp.Data.ChannelNum = 0;
		
		FecBusCRTBufTemp.Data.DeviceCode = ftCtlCircuit;
		if(aData1)FecBusCRTBufTemp.Data.EventCode = evFault;
		else FecBusCRTBufTemp.Data.EventCode = evFaultRecover;
	}else
	if((aRC.Splite.Data1 & 0xF0) == 0xF0){
		FecBusCRTBufTemp.Data.UnitNum = aP0;
		FecBusCRTBufTemp.Data.DeviceNum = 0;
		FecBusCRTBufTemp.Data.ChannelNum = 0;
		
		getFecBusCRTFaultBrdDeviceCode(aData0);
		getFecBusCRTFaultBrdEventCode(aData0, aData1);
	}else{
		FecBusCRTBufTemp.Data.UnitNum = aP0;
		FecBusCRTBufTemp.Data.DeviceNum = aP1;
		FecBusCRTBufTemp.Data.ChannelNum = 0;
		
		if((aP0 > 0)&&(aP0 < 40)){
			getFecBusCRTDeviceCode(dType);
		}else
		if((aP0 >= dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_START)){
			FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
		}
		
		getFecBusCRTEpFaultEvent(aData0, aData1);
	}
	
	getFecBusCRTTime(aRC);
	getFecBusCRTStateCode(FecBusCRTStateCode);
	
	if(FecBusCRTBufTemp.Data.EventCode > 131)return;
	if(1 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg06(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}else
	if(2 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg05(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}
}

void TFecBusCRT::iFecBusCRTFireInsert(TRecordCommon aRC)
{
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char aData0;
	unsigned char aData1;
	unsigned char IsFirst;
	
	if(MainCtl.fData.Split.NetworkMode == 2)return;
	if(GraphUsing == 0)return;
	
	FecBusCRTBufTemp.Data.CtlNum = aRC.Splite.PCtlNum;

	aP0	= aRC.Splite.P0;
	aP1 = aRC.Splite.P1;
	dType = aRC.Splite.dType;
	aData0 = aRC.Splite.Data0;
	aData1 = aRC.Splite.Data1 & 0x01;
	IsFirst = aRC.Splite.Data1;
	
	FecBusCRTBufTemp.Data.UnitNum = aP0;
	FecBusCRTBufTemp.Data.DeviceNum = aP1;
	FecBusCRTBufTemp.Data.ChannelNum = 0;
	
	if((aP0)&&(aP0 <= 40)){
		getFecBusCRTDeviceCode(dType);
	}else
	if((aP0 >= dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_END)){
		FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
	}else{
		FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
	}
	
	if(1 == IsFirst){
		FecBusCRTBufTemp.Data.EventCode = evFirstFireAlarm;
	}else{
		FecBusCRTBufTemp.Data.EventCode = evFireAlarm;
	}
	
	getFecBusCRTTime(aRC);
	getFecBusCRTStateCode(FecBusCRTStateCode);
	
	if(FecBusCRTBufTemp.Data.EventCode > 131)return;
	if(1 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg06(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}else
	if(2 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg05(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}
}

void TFecBusCRT::iFecBusCRTOperateInsert(TRecordCommon aRC)
{
	static unsigned int setHandAuto = 0x00;
	
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char mType;
	unsigned char aData0;
	unsigned char aData1;
	
	if(MainCtl.fData.Split.NetworkMode == 2)return;
	if(GraphUsing == 0)return;

	aP0	= aRC.Splite.P0;
	aP1 = aRC.Splite.P1;
	dType = aRC.Splite.dType;
	mType = aRC.Splite.mType;
	aData0 = aRC.Splite.Data0;
	aData1 = aRC.Splite.Data1;
	
	FecBusCRTBufTemp.Data.CtlNum = aRC.Splite.PCtlNum;
	
	if(mType == etOperate){
		switch(aData0){
			case otPowerOff:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evSystemPowerOff;
				break;
			
			case otPowerOn:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evSystemPowerOn;
				break;
			
			case otReset:
				if((MainCtl.fData.Split.NetworkMode != 2)&&(FecBusCRTBufTemp.Data.CtlNum == 1)){
				}else return;
			
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evReset;
			
				//if((MainCtl.fData.Split.NetworkMode == 1)&&(FecBusCRTBufTemp.Data.CtlNum != 1))SendMaskFlag = 1;
				break;
			
			case otMute:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evMuteBell;
				break;
			
			case otMask:
				FecBusCRTBufTemp.Data.UnitNum = aRC.Splite.P0;
				FecBusCRTBufTemp.Data.DeviceNum = aRC.Splite.P1;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evMask;
				break;
			
			case otUnMask:
				FecBusCRTBufTemp.Data.UnitNum = aRC.Splite.P0;
				FecBusCRTBufTemp.Data.DeviceNum = aRC.Splite.P1;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evMaskRelieve;
				break;
			
			case otRegiste:
				return;
				break;
			
			case otUnRegiste:
				return;
				break;
			
			case otSetCanNetwork:
				return;
				break;
			
			case otCfgBoard:
				return;
				break;
			
			case otCfgCrt:
				return;
				break;
			
			case otCfgPriter:
				return;
				break;
			
			case otCfgDevice:
				return;
				break;
			
			case otCfgDateTime:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evAdjustClock;
				break;
				
			case otCfgPermissionAllow:
				return;
				break;
			
			case otAllowSet:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
			
				if(setHandAuto != (aData1 & 0x01)){
					setHandAuto &=~0x01;
					setHandAuto |=(aData1 & 0x01);
					FecBusCRTBufTemp.Data.EventCode = evAutomatic;
				}else
				if(setHandAuto != (aData1 & 0x02)){
					setHandAuto &=~0x02;
					setHandAuto |=(aData1 & 0x02);
					FecBusCRTBufTemp.Data.EventCode = evManual;
				}
				break;
			
			case otAlramSetOnOff:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftAlramVaCircuit;
				if(aData1){
					FecBusCRTBufTemp.Data.EventCode = evLaunch;
				}else{
					FecBusCRTBufTemp.Data.EventCode = evShutoff;
				}
				break;
				
			case otBusPadOn:
				FecBusCRTBufTemp.Data.UnitNum = aP0;
				FecBusCRTBufTemp.Data.DeviceNum = aP1;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evLaunch;
				break;
			
			case otBusPadOff:
				FecBusCRTBufTemp.Data.UnitNum = aP0;
				FecBusCRTBufTemp.Data.DeviceNum = aP1;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evShutoff;
				break;
			
			case otDirectPadManualAllowOn:
				return;
				//---------------------------------------------------------------------------------
				//FillText4DirectPadManualAllowOn();
				break;
			
			case otDirectPadManualAllowOff:
				return;
				//---------------------------------------------------------------------------------
				//FillText4DirectPadManualAllowOff();
				break;
			
			case otDirectPadNodeOn:
				FecBusCRTBufTemp.Data.UnitNum = aP0;
				FecBusCRTBufTemp.Data.DeviceNum = aP1;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evLaunch;
				break;
			
			case otDirectPadNodeOff:
				FecBusCRTBufTemp.Data.UnitNum = aP0;
				FecBusCRTBufTemp.Data.DeviceNum = aP1;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evShutoff;
				break;
			
			case otUserCheck:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evKeyPressFunctionCheck;
				break;
			
			case otLinkageGo:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evLaunchInrerLink;
				break;
			
			case otSetNwTime:
			case otReqNwTime:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evAdjustClock;
				break;
			
			case otSelfCheck:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evSelfCheck;
				break;
			
			case otSetManualAllowState:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evManual;
				break;
			
			case otSetAutoAllowState:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evAutomatic;
				break;
			
			case otRemoteSetManualAllowState:
				return;
				break;
			
			case otRemoteSetAutoAllowState:
				return;
				break;
			
			case otReportManualAllowState:
				return;
				break;
			
			case otReportAutoAllowState:
				return;
				break;
			
			case otFireConfirm:
			case otFireRemoteConfirm:
			case otFaultConfirm:
			case otFaultRemoteConfirm:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				FecBusCRTBufTemp.Data.EventCode = evFaultOrFireAlarmExactly;
				break;
			
			case otSetSmokeSensViaCircuit:
				return;
				break;
				
			case otSetSmokeSensViaAddr:
				return;
				break;
				
			case otCleanUp:
				return;
				break;
				
			case otLinkageExpsSaveRemove:
				return;
				break;
				
			case otBusPadModify:
				return;
				break;
			
			case otDirectPadModify:
				return;
				break;
			
			case otDescpModify:
				return;
				break;
				
			case otPassWdModify:
				return;
				break;
				
			case otRegisterByManual:
				return;
				break;
				
			case otAddRemoveNwCtl:
				return;
				break;
				
			case otRegCanNetwork:
				return;
				break;
				
			case  otClearNetworkCfg:
				return;
				break;
				
			case  otBroadcastVa:
				return;
				break;
				
			case otSetAllowState:
				FecBusCRTBufTemp.Data.UnitNum = 0;
				FecBusCRTBufTemp.Data.DeviceNum = 0;
				FecBusCRTBufTemp.Data.ChannelNum = 0;
				FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
				if(aData1 == 3)FecBusCRTBufTemp.Data.EventCode = evManual;
				else if(aData1 == 1)FecBusCRTBufTemp.Data.EventCode = evAutomatic;
				else if(aData1 == 2)FecBusCRTBufTemp.Data.EventCode = evManual;
				else if(aData1 == 2)FecBusCRTBufTemp.Data.EventCode = evManual;
				break;
		}
	}
	
	getFecBusCRTTime(aRC);
	getFecBusCRTStateCode(FecBusCRTStateCode);
	
	if(FecBusCRTBufTemp.Data.EventCode > 131)return;
	if(1 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg06(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}else
	if(2 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg05(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}
}

void TFecBusCRT::iFecBusCRTLinkageInsert(TRecordCommon aRC)
{
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char aData0;
	unsigned char aData1;
	unsigned char data;
	
	if(MainCtl.fData.Split.NetworkMode == 2)return;
	if(GraphUsing == 0)return;
	
	FecBusCRTBufTemp.Data.CtlNum = aRC.Splite.PCtlNum;

	aP0 = aRC.Splite.P0;
	aP1 = aRC.Splite.P1;
	dType = aRC.Splite.dType;
	aData0 = aRC.Splite.Data0;
	aData1 = aRC.Splite.Data1 & 0x01;
	data = aRC.Splite.iByte0;
	
	FecBusCRTBufTemp.Data.UnitNum = aP0;
	FecBusCRTBufTemp.Data.DeviceNum = aP1;
	FecBusCRTBufTemp.Data.ChannelNum = 0;
	
	if( (aP0 >0) && (aP0 <=40) ){
		getFecBusCRTDeviceCode(dType);
	}else
	if(  (aP0 >=dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_END)  ){
		FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
	}else{
		FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
	}
	
	if(data == 0x01){
		FecBusCRTBufTemp.Data.EventCode = evLaunchInrerLink;
	}else
	if(data == 0x02){
		FecBusCRTBufTemp.Data.EventCode = evLaunchInrerLink;
	}else
	if(data == 0x03){
		FecBusCRTBufTemp.Data.EventCode = evFeedBack;
	}else
	if(data == 0x04){
		FecBusCRTBufTemp.Data.EventCode = evFeedBack;
	}else
	if(data == 0x05){
		FecBusCRTBufTemp.Data.EventCode = evLaunchInrerLink;
	}else
	if(data == 0x06){
		FecBusCRTBufTemp.Data.EventCode = evLaunchInrerLink;
	}else
	if(data == 0x07){
		return;
	}else
	if(data == 0xB1){
		FecBusCRTBufTemp.Data.EventCode = evShutoff;
	}else
	if(data == 0xB3){
		FecBusCRTBufTemp.Data.EventCode = evFeedBackRevoke;
	}else
	if(data == 0xB5){
		FecBusCRTBufTemp.Data.EventCode = evShutoff;
	}else
	if(data == 0xB6){
		FecBusCRTBufTemp.Data.EventCode = evShutoff;
	}else
	if(data == 0xB7){
		return;
	}
	
	getFecBusCRTTime(aRC);
	getFecBusCRTStateCode(FecBusCRTStateCode);
	
	if(FecBusCRTBufTemp.Data.EventCode > 131)return;
	if(1 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg06(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}else
	if(2 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg05(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}
}

void TFecBusCRT::iFecBusCRTSvInsert(TRecordCommon aRC)
{
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char aData0;
	unsigned char aData1;
	
	if(MainCtl.fData.Split.NetworkMode == 2)return;
	if(GraphUsing == 0)return;
	
	FecBusCRTBufTemp.Data.CtlNum = aRC.Splite.PCtlNum;

	aP0	= aRC.Splite.P0;
	aP1 = aRC.Splite.P1;
	dType = aRC.Splite.dType;
	aData0 = aRC.Splite.Data0;
	aData1 = aRC.Splite.Data1 & 0x01;
	
	FecBusCRTBufTemp.Data.UnitNum = aP0;
	FecBusCRTBufTemp.Data.DeviceNum = aP1;
	FecBusCRTBufTemp.Data.ChannelNum = 0;
	
	if( (aP0 >0) && (aP0 <=40) ){
		getFecBusCRTDeviceCode(dType);
	}else
	if(  (aP0 >=dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_END)  ){
		FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
	}else{
		FecBusCRTBufTemp.Data.DeviceCode = ftMainCtl;
	}
	
	FecBusCRTBufTemp.Data.EventCode = evSuperVisory;
	
	getFecBusCRTTime(aRC);
	getFecBusCRTStateCode(FecBusCRTStateCode);
	
	if(FecBusCRTBufTemp.Data.EventCode > 131)return;
	if(1 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg06(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}else
	if(2 == EventCodePrm[FecBusCRTBufTemp.Data.EventCode]){
		iSetFecBusMsg05(&FecBusMsgUartTemp, &FecBusCRTBufTemp);
		iFecBusMsgInsert(&FecBusMsgUartTemp);
	}
}

void TFecBusCRT::Task10Ms()
{
	static unsigned int TaskTick = 0;
	TaskTick++;
	if(TaskTick > 29){//300ms
		TaskTick = 0;
		oBufInsert();
	}
	oBufProcess();
}

void TFecBusCRT::Task1000Ms()
{
	static TFecBusMsgUart ipMsg;
	static TFecEventBufBody ipEvent;
	static unsigned int send_tick;
	
	static unsigned int tick = 1;
	
	if(MainCtl.fData.Split.NetworkMode == 2)return;
	if(GraphUsing == 0)return;
	
	ipEvent.Data.CtlNum = 1;
	ipEvent.Data.UnitNum = 1;//单元编号（1字节）
	ipEvent.Data.DeviceNum = tick; //设备编号（1字节）
	ipEvent.Data.ChannelNum = 1; //通道编号（1字节）
		
	ipEvent.Data.DeviceCode = ftMainCtlFireLinkkage; //设备类型代码（2字节）
	ipEvent.Data.EventCode = evFaultCommunications;//evFireAlarm; //事件代码（2字节）
		
	ipEvent.Data.StateCode.D16 = 1; //状态代码（2字节）
	ipEvent.Data.Year = 24;//年（1字节）
	ipEvent.Data.Mon = 8;//月（1字节）
		
	ipEvent.Data.Day = 3;//日（1字节）
	ipEvent.Data.Hour = 12;//时（1字节）
	ipEvent.Data.Min = 1;//分（1字节）
	ipEvent.Data.Sec = 1;//秒（1字节）
	
	
	send_tick++;
	if(4 == send_tick){
		if(InTxIndex == OutTxIndex){
			iSetFecBusMsg00(&ipMsg);//sync heart
		
			iFecBusMsgInsert(&ipMsg);
		}
	}else
	if(send_tick > 15){
		send_tick = 0;
		/*
		tick++;if(tick>2)tick=1;
		iSetFecBusMsg06(&ipMsg,&ipEvent);
		
		iFecBusMsgInsert(&ipMsg);
		*/
	}
	
	ErrState.Body.OffLineTick++;
	if(ErrState.Body.OffLineTick > 75){
		ErrState.Body.OffLineTick = 100;
		ErrState.Body.OffLine = 1;
		if(ErrReport.Body.OffLine == 0){
			//Report Here
			ErrReport.Body.OffLine = 1;
			CtlCenter.ieAddBrdFault(9, 9);
		}
	}
	
	UploadMask2CrtTask();
}

void TFecBusCRT::Upload2CrtTask(void)
{
	unsigned int PrcCount;
	if(Upload.Active != 1)return;
	if(MainCtl.fData.Split.NetworkMode == 2)return;
	PrcCount = 0;
	while(Upload.InxFire < CtlCenter.ieMsgFire.Count){
		TControlCenter::sFireGetViaIndex(Upload.InxFire, &EvMsg);
		ShipMsg();
		iFecBusCRTFireInsert(Upload.aRc);
		Upload.InxFire++;
		if(PrcCount++ > 1000){ PrcCount =0; sys_error_led_task();}
	}
	while(Upload.InxStart < CtlCenter.ieMsgLinkage.Count){
		TControlCenter::sLinkageGetViaIndex(Upload.InxStart, &EvMsg);
		ShipMsg();
		
		if(Upload.aRc.Splite.mType == etLinkageStart){
			Upload.aRc.Splite.iByte0 = 0x01;//启动
			if(0x09 == Upload.aRc.Splite.Data0){
				Upload.aRc.Splite.iByte0 = 0xB1;//停止
			}
		}else
		if(Upload.aRc.Splite.mType == etLinkageFeedBack){
			Upload.aRc.Splite.iByte0 = 0x03;
		}
		
		iFecBusCRTLinkageInsert(Upload.aRc);
		Upload.InxStart++;
		if(PrcCount++ > 1000){ PrcCount =0; sys_error_led_task();}
		
	}
	while(Upload.InxSv < CtlCenter.ieMsgSv.Count){
		TControlCenter::sSvGetViaIndex(Upload.InxSv, &EvMsg);
		ShipMsg();
		iFecBusCRTSvInsert(Upload.aRc);
		Upload.InxSv++;
		if(PrcCount++ > 1000){ PrcCount =0; sys_error_led_task();}
	}
	while(Upload.InxFault < CtlCenter.ieMsgFault.Count){
		TControlCenter::sFaultGetViaIndex(Upload.InxFault, &EvMsg);
		ShipMsg();
		iFecBusCRTFaultInsert(Upload.aRc);
		Upload.InxFault++;
		if(PrcCount++ > 1000){ PrcCount =0; sys_error_led_task();}
	}
	while(Upload.InxMask < CtlCenter.ieMsgMask.Count){	
		TControlCenter::sMaskGetViaIndex(Upload.InxMask, &EvMsg);
		ShipMsg();
		Upload.aRc.Splite.mType = etOperate;
		Upload.aRc.Splite.Data0 = otMask;
		iFecBusCRTOperateInsert(Upload.aRc);
		Upload.InxMask++;
		if(PrcCount++ > 1000){ PrcCount =0; sys_error_led_task();}
	}
	Upload.Active = 0;
	sys_error_led_task();
}

void TFecBusCRT::UploadMask2CrtTask(void)
{
	static unsigned int UploadTick = 0;
	unsigned int PrcCount=0,Index=0;
	
	if(SendMaskFlag){
		UploadTick++;
		if(UploadTick > 19){
			UploadTick = 0;
			SendMaskFlag = 0;
			if(1 == MainCtl.fData.Split.NetworkMode){
				while(Index < CtlCenter.ieMsgMask.Count){	
					TControlCenter::sMaskGetViaIndex(Index, &EvMsg);
					ShipMsg();
					Upload.aRc.Splite.mType = etOperate;
					Upload.aRc.Splite.Data0 = otMask;
					iFecBusCRTOperateInsert(Upload.aRc);
					Index++;
					if(PrcCount++ > 1000){ PrcCount =0; sys_error_led_task();}
				}
			}
		}
	}else{
		UploadTick = 0;
	}
}

void TFecBusCRT::ShipMsg()
{
	Upload.aRc.D32[0] = EvMsg.D32[0];
	Upload.aRc.D32[1] = EvMsg.D32[1];
	Upload.aRc.D32[2] = EvMsg.D32[2];
	Upload.aRc.D32[3] = EvMsg.D32[3];
}





















