#include "exRecord.h"
#include "Runtime.h"
#include "MainCtl.h"

extern "C"{
	#include "uart_memory_drv.h"
	#include "internal_flash.h"
}

unsigned short ExrecordStateCode;

void TexRecord::Init()
{
	unsigned int i = 0;
	
	RxGetFlag = 0;
	TxSetFlag = 0;
	
	InRecordIndex = 0;
	OutRecordIndex = 0;
	
	OnlineTick = 0;
	ReadyFlag = 0;
	
	GetVerFlag = 0;
	GetModleFlag = 0;
	
	ExRecordBufTemp.Data.CtlAddr = MainCtl.fData.Split.MyNum;
	ExRecordBufTemp.Data.CtlType = factory_prm.ctl_type & 0xFF;
	for(i=0;i<8;i++){
		ExRecordBufTemp.Data.Pid[i] = factory_prm.pid[i];
	}
	for(i=0;i<4;i++){
		ExRecordBufTemp.Data.Pid[i+8] = 0;
	}
}

void TexRecord::iBufInsert()
{
	;
}

void TexRecord::iBufProcess()
{
	if(RxGetFlag){
		RxGetFlag = 0;
		if(RxMsg.DS.Cmd == TxMsg.DS.Cmd){
			
			OnlineTick = 0;
			ErrState.Body.OffLine = 0;
			ReadyFlag = 1;
			
			if(exWriteRecord != TxMsg.DS.Cmd){
				TxMsg.DS.Cmd = exNoCmd;
				OnTransmite.AckOk = 1;
				OnTransmite.RetryTimes = 0;
				OnTransmite.OnGoing = 0;
				OnTransmite.TimeOutTick = 0;
			}
			
			switch(RxMsg.DS.Cmd){
				case exHeartBeat : 
					//ErrState &=~exErrCom;
					break;
		
				case exGetModle:
					HwInf.ExtMemUartPushData(cmQueryBoardModel, &RxMsg.DS.Data[0]);
					break;
				
				case exGetVer:
					HwInf.ExtMemUartPushData(cmQueryVer, &RxMsg.DS.Data[0]);
					break;
				
				case exSetCtlMsg:
					break;
				
				case exGetCtlMsg:
					break;
				
				case exGetErrState:
					if(1 == RxMsg.DS.Data[0]){
						ErrState.Body.ReadWriteFail = 66;
					}else 
					if(0 == RxMsg.DS.Data[0]){
						ErrState.Body.ReadWriteFail = 0;
					}
					
					if(ErrState.D32){
						if(ErrReport.D32 == 0){
							CtlCenter.ieAddDevFault(dDevFaultExStroge,0);
							ErrReport.D32 = 0x6601;
						}
					}else{
						if(ErrReport.D32 != 0){
							CtlCenter.ieAddDevFaultCancel(dDevFaultExStroge,0);
							ErrReport.D32 = 0;
						}
					}
					
					break;
			
				case exGetTotalRecordNum:
					break;
				
				case exWriteRecord:
					if(1 == RxMsg.DS.Data[0]){
						OnTransmite.OnGoing = 1;
						OnTransmite.AckOk = 0;
						
						if(OnTransmite.RetryTimes > 2){
							OnTransmite.AckOk = 1;
							OnTransmite.RetryTimes = 0;
							OnTransmite.OnGoing = 0;
							OnTransmite.TimeOutTick = 0;
								
							ErrState.Body.ReadWriteFail = 66;
							if(ErrReport.D32 == 0){
								CtlCenter.ieAddDevFault(dDevFaultExStroge,0);
								ErrReport.D32 = 0x6601;
							}
						}
					}else{
						TxMsg.DS.Cmd = exNoCmd;
						OnTransmite.AckOk = 1;
						OnTransmite.RetryTimes = 0;
						OnTransmite.OnGoing = 0;
						OnTransmite.TimeOutTick = 0;
					}
					break;
				
				case exReadRecordOrder:
					break;
				
				case exClearRecord:
					break;
					
				default : break;
			}
		}
	}
		/*
	if(RxGetFlag){
		RxGetFlag = 0;
		if(RxMsg.DS.Cmd == dExRecordCmdIdf){
			
			OnTransmite.AckOk = 1;
			OnTransmite.RetryTimes = 0;
			OnTransmite.OnGoing = 0;
			OnTransmite.TimeOutTick = 0;
			
			if(RxMsg.DS.Data[0] == dExRecordReport){
				OnlineTick = 0;
				ErrState.Body.OffLine = 0;
				
				if(RxMsg.DS.Data[1] == 0x66){
					ErrState.Body.ReadWriteFail = 66;
				}else{
					ErrState.Body.ReadWriteFail = 0;
				}
				
				if(ErrState.D32){
					if(ErrReport.D32 == 0){
						CtlCenter.ieAddDevFault(dDevFaultExStroge,0);
						ErrReport.D32 = 0x6601;
					}
				}else{
					if(ErrReport.D32 != 0){
						CtlCenter.ieAddDevFaultCancel(dDevFaultExStroge,0);
						ErrReport.D32 = 0;
					}
				}
			}
		}
	}
	*/
}

void TexRecord::oBufInsert()
{
	;
}

void TexRecord::oBufInsert(TMemComBufBody aNsBuf)
{
	;
}

void TexRecord::oBufProcess()//10ms
{
	unsigned int retry_time = 0;
	
	if(OnTransmite.OnGoing){
		OnTransmite.TimeOutTick++;
		
		if(exWriteRecord == TxMsg.DS.Cmd){
			retry_time = 49;//500ms retry
		}else{
			retry_time = 1;//1ms 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(!memory_is_busy()){
		if(TxSetFlag){
			TxSetFlag = 0;
			
			set_memory_tx_data(TxMsg.DS.Cmd, TxMsg.DS.Data, TxMsg.DS.Len);
			OnTransmite.TimeOutTick = 0;
			OnTransmite.AckOk = 0;
			OnTransmite.OnGoing = 1; 
		}else
		if(OnTransmite.RetryFLAG){
			OnTransmite.RetryFLAG = 0;
			
			OnTransmite.RetryTimes++;
			set_memory_tx_data(TxMsg.DS.Cmd, TxMsg.DS.Data, TxMsg.DS.Len);
			OnTransmite.TimeOutTick = 0;
			OnTransmite.AckOk = 0;
			OnTransmite.OnGoing = 1; 
		}
	}
	/*
			TxMsg.DS.Cmd = exWriteRecord;
			TxMsg.DS.Len = 18;
			TxMsg.DS.Data[0] = ExRecordBuf[OutRecordIndex].Data.Memtype;
			TxMsg.DS.Data[1] = (ExRecordBuf[OutRecordIndex].Data.CtlNum & 0xFF);
			TxMsg.DS.Data[2] = ((ExRecordBuf[OutRecordIndex].Data.CtlNum>>8) & 0xFF);
			TxMsg.DS.Data[3] = ExRecordBuf[OutRecordIndex].Data.UnitNum;
			TxMsg.DS.Data[4] = ExRecordBuf[OutRecordIndex].Data.DeviceNum;
			TxMsg.DS.Data[5] = ExRecordBuf[OutRecordIndex].Data.ChannelNum;
			TxMsg.DS.Data[6] = (ExRecordBuf[OutRecordIndex].Data.DeviceCode & 0xFF);
			TxMsg.DS.Data[7] = ((ExRecordBuf[OutRecordIndex].Data.DeviceCode>>8) & 0xFF);
			TxMsg.DS.Data[8] = (ExRecordBuf[OutRecordIndex].Data.EventCode & 0xFF);
			TxMsg.DS.Data[9] = ((ExRecordBuf[OutRecordIndex].Data.EventCode>>8) & 0xFF);
			TxMsg.DS.Data[10] = (ExRecordBuf[OutRecordIndex].Data.StateCode.D16 & 0xFF);
			TxMsg.DS.Data[11] = ((ExRecordBuf[OutRecordIndex].Data.StateCode.D16>>8) & 0xFF);
			TxMsg.DS.Data[12] = ExRecordBuf[OutRecordIndex].Data.Year;
			TxMsg.DS.Data[13] = ExRecordBuf[OutRecordIndex].Data.Mon;
			TxMsg.DS.Data[14] = ExRecordBuf[OutRecordIndex].Data.Day;
			TxMsg.DS.Data[15] = ExRecordBuf[OutRecordIndex].Data.Hour;
			TxMsg.DS.Data[16] = ExRecordBuf[OutRecordIndex].Data.Min;
			TxMsg.DS.Data[17] = ExRecordBuf[OutRecordIndex].Data.Sec;
	
		if(!memory_is_busy()){
			
			set_memory_tx_data(TxMsg.DS.Cmd, TxMsg.DS.Data, TxMsg.DS.Len);
	}
	*/
}

void TexRecord::iRecordBufInsert(unsigned char * pdata)
{
	unsigned int i = 0;
	
	InRecordIndex++;
	if(InRecordIndex >= EXRECORDBUFDEEP)InRecordIndex = 0;
	
	for(i=0;i<32;i++){
		ExRecordBuf[InRecordIndex].D8[i] = (*pdata);
		pdata++;
	}
}
/*
void TexRecord::iRecordSetMsgType(unsigned char MsgType)
{
	ExRecordBufTemp.Data.MsgType	= MsgType;
}

void TexRecord::iRecordSetCtlNum(unsigned short CtlNum)
{
	ExRecordBufTemp.Data.CtlNum	= CtlNum;
}

void TexRecord::iRecordSetUnitNum(unsigned char UnitNum)
{
	ExRecordBufTemp.Data.UnitNum	= UnitNum;
}

void TexRecord::iRecordSetEventCode(unsigned short EventCode)
{
	ExRecordBufTemp.Data.EventCode	= EventCode;
}
*/
void TexRecord::getExRecordTime(TRecordCommon aRC)
{
	ExRecordBufTemp.Data.Year = (aRC.Splite.Year/16*10) + (aRC.Splite.Year & 0x0F);
	ExRecordBufTemp.Data.Mon  = (aRC.Splite.Month/16*10) + (aRC.Splite.Month & 0x0F);
	ExRecordBufTemp.Data.Day  = (aRC.Splite.Day/16*10) + (aRC.Splite.Day & 0x0F);
	ExRecordBufTemp.Data.Hour = (aRC.Splite.Hour/16*10) + (aRC.Splite.Hour & 0x0F);
	ExRecordBufTemp.Data.Min  = (aRC.Splite.Minute/16*10) + (aRC.Splite.Minute & 0x0F);
	ExRecordBufTemp.Data.Sec  = (aRC.Splite.Second/16*10) + (aRC.Splite.Second & 0x0F);
}

void TexRecord::getExRecordStateCode(unsigned short StateCode)
{
	ExRecordBufTemp.Data.StateCode.D16 = StateCode;
}

void TexRecord::setExRecordStateCode(unsigned short StateCode)
{
	ExrecordStateCode = StateCode;

}

void TexRecord::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;
	
	setExRecordStateCode(static_cast<unsigned short>(aC));
}

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

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

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

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

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

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

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

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

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

void TexRecord::getExRecordDeviceCode(unsigned char dType)
{	
	if(GBDeviceCodePrm[dType]){
		ExRecordBufTemp.Data.DeviceCode = dType;
	}else{
		ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
	}
}

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

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

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

void TexRecord::getExRecordFaultDevDeviceCode(unsigned char aType)
{
	switch(aType){
		case 0: 
		case 1:
		case 5: 
		case 14:
		case 17:
		case 18:
			ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
			break;
		
		case 2: 
			ExRecordBufTemp.Data.DeviceCode = ftCtlCircuit;
			break;
		
		case 3: 
			ExRecordBufTemp.Data.DeviceCode = ftBusCtlPanel;
			break;
		
		case 4: 
			ExRecordBufTemp.Data.DeviceCode = ftDirCtlPanel;
			break;
		
		case 6: 
			ExRecordBufTemp.Data.DeviceCode = ftDataMemCard;
			break;
		
		case 7:
		case 8: 
		case 19:
		case 21:
		case 22:
		case 23:
			ExRecordBufTemp.Data.DeviceCode = ftMainPower;
			break;
		
		case 9:
		case 10:
		case 20:
		case 24:
		case 25:
		case 26:
		case 27:
			ExRecordBufTemp.Data.DeviceCode = ftStandbyPower;
			break;

		case 11: 
		case 12: 
		case 15: 
		case 16: 
			ExRecordBufTemp.Data.DeviceCode = ftCanNetworkComm;
			break;
		
		case 13: 
			ExRecordBufTemp.Data.DeviceCode = ftGraphShow;
			break;
		
		default: 
			ExRecordBufTemp.Data.DeviceCode = ftUndefineFecDevType;
			break;
	}
}

void TexRecord::getExRecordFaultDevEventCode(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:
				ExRecordBufTemp.Data.EventCode = evFault;
				break;
			
			case 7:
			case 19:
				ExRecordBufTemp.Data.EventCode = evFaultMainPower;
				break;
			
			case 8:
			case 11:
			case 12:
			case 13:
			case 15:
			case 16:
			case 21:
				ExRecordBufTemp.Data.EventCode = evFaultCommunications;
				break;
			
			case 9:
			case 10:
			case 20:
			case 24:
			case 25:
			case 26:
			case 27:
				ExRecordBufTemp.Data.EventCode = evFaultSparePower;
				break;
			
			case 22: 
			case 23:
				ExRecordBufTemp.Data.EventCode = evFaultCircuit;
				break;

			default: 
				ExRecordBufTemp.Data.EventCode = evUndefine;
				break;
		}
	}else{
		switch(aType){
			case 0: 
			case 1: 
			case 2: 
			case 3:
			case 4: 
			case 5:
			case 6:
			case 14:
				ExRecordBufTemp.Data.EventCode = evFaultRecover;
				break;
			
			case 7:
			case 19:
				ExRecordBufTemp.Data.EventCode = evFaultMainPowerRecover;
				break;
			
			case 8:
			case 11:
			case 12:
			case 13:
			case 15:
			case 16:
			case 21:
				ExRecordBufTemp.Data.EventCode = evFaultCommunicationsRecover;
				break;
			
			case 9:
			case 10:			
			case 20:
			case 24:
			case 25:
			case 26:
			case 27:
				ExRecordBufTemp.Data.EventCode = evFaultSparePowerRecover;
				break;

			case 22: 
			case 23:
				ExRecordBufTemp.Data.EventCode = evFaultCircuitRecover;
				break;
			
			default: 
				ExRecordBufTemp.Data.EventCode = evUndefine;
				break;
		}
	}
}

void TexRecord::iExRecordFaultInsert(TRecordCommon aRC)
{
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char aData0;
	unsigned char aData1;
	
	ExRecordBufTemp.Data.MsgType = 3;
	ExRecordBufTemp.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)){
			ExRecordBufTemp.Data.UnitNum = aRC.Splite.P1;
			ExRecordBufTemp.Data.DeviceNum = 0;
			ExRecordBufTemp.Data.ChannelNum = 0;
			
			ExRecordBufTemp.Data.DeviceCode = ftBusCtlPanel;
			if(aData1)ExRecordBufTemp.Data.EventCode = evFaultCommunications;
			else ExRecordBufTemp.Data.EventCode = evFaultCommunicationsRecover;
		}else
		if((aRC.Splite.P1 >= dADDR_DIRECTPAD_START) && (aRC.Splite.P1 <= dADDR_DIRECTPAD_END)){
			ExRecordBufTemp.Data.UnitNum = aRC.Splite.P1;
			ExRecordBufTemp.Data.DeviceNum = 0;
			ExRecordBufTemp.Data.ChannelNum = 0;
			
			ExRecordBufTemp.Data.DeviceCode = ftDirCtlPanel;
			if(aData1)ExRecordBufTemp.Data.EventCode = evFaultCommunications;
			else ExRecordBufTemp.Data.EventCode = evFaultCommunicationsRecover;
		}
	}else
	if((aRC.Splite.Data1 & 0xF0) == 0xD0){
		ExRecordBufTemp.Data.UnitNum = aP0;
		ExRecordBufTemp.Data.DeviceNum = 0;
		ExRecordBufTemp.Data.ChannelNum = 0;
		
		getExRecordFaultDevDeviceCode(aData0);
		getExRecordFaultDevEventCode(aData0, aData1);
	}else
	if((aRC.Splite.Data1 & 0xF0) == 0xE0){
		ExRecordBufTemp.Data.UnitNum = aP0;
		ExRecordBufTemp.Data.DeviceNum = 0;
		ExRecordBufTemp.Data.ChannelNum = 0;
		
		ExRecordBufTemp.Data.DeviceCode = ftCtlCircuit;
		if(aData1)ExRecordBufTemp.Data.EventCode = evFault;
		else ExRecordBufTemp.Data.EventCode = evFaultRecover;
	}else
	if((aRC.Splite.Data1 & 0xF0) == 0xF0){
		ExRecordBufTemp.Data.UnitNum = aP0;
		ExRecordBufTemp.Data.DeviceNum = 0;
		ExRecordBufTemp.Data.ChannelNum = 0;
		
		getExRecordFaultBrdDeviceCode(aData0);
		getExRecordFaultBrdEventCode(aData0, aData1);
	}else{
		ExRecordBufTemp.Data.UnitNum = aP0;
		ExRecordBufTemp.Data.DeviceNum = aP1;
		ExRecordBufTemp.Data.ChannelNum = 0;
		
		if((aP0 > 0)&&(aP0 < 40)){
			getExRecordDeviceCode(dType);
		}else
		if((aP0 >= dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_START)){
			ExRecordBufTemp.Data.DeviceCode = ftDirCtlPanel;
		}
		
		getExRecordEpFaultEvent(aData0, aData1);
	}
	
	/*
	ExRecordBufTemp.Data.UnitNum = 
	ExRecordBufTemp.Data.DeviceNum =
	ExRecordBufTemp.Data.ChannelNum =
	ExRecordBufTemp.Data.DeviceCode =
	ExRecordBufTemp.Data.EventCode =
	
	ExRecordBufTemp.Data.StateCode.D16 =
	*/
	getExRecordTime(aRC);
	getExRecordStateCode(ExrecordStateCode);
	iRecordBufInsert(ExRecordBufTemp.D8);
}

void TexRecord::iExRecordFireInsert(TRecordCommon aRC)
{
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char aData0;
	unsigned char aData1;
	unsigned char IsFirst;
	
	ExRecordBufTemp.Data.MsgType = 2;
	ExRecordBufTemp.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;
	
	ExRecordBufTemp.Data.UnitNum = aP0;
	ExRecordBufTemp.Data.DeviceNum = aP1;
	ExRecordBufTemp.Data.ChannelNum = 0;
	
	if((aP0)&&(aP0 <= 40)){
		getExRecordDeviceCode(dType);
	}else
	if((aP0 >= dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_END)){
		ExRecordBufTemp.Data.DeviceCode = ftDirCtlPanel;
	}else{
		ExRecordBufTemp.Data.DeviceCode = ftUndefineFecDevType;
	}
	
	if(1 == IsFirst){
		ExRecordBufTemp.Data.EventCode = evFirstFireAlarm;
	}else{
		ExRecordBufTemp.Data.EventCode = evFireAlarm;
	}
	
	getExRecordTime(aRC);
	getExRecordStateCode(ExrecordStateCode);
	iRecordBufInsert(ExRecordBufTemp.D8);
	
	if(1 == IsFirst){
		ExRecordBufTemp.Data.MsgType = 1;
		iRecordBufInsert(ExRecordBufTemp.D8);
	}
}

void TexRecord::iExRecordOperateInsert(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;

	aP0	= aRC.Splite.P0;
	aP1 = aRC.Splite.P1;
	dType = aRC.Splite.dType;
	mType = aRC.Splite.mType;
	aData0 = aRC.Splite.Data0;
	aData1 = aRC.Splite.Data1;
	
	ExRecordBufTemp.Data.MsgType = 4;
	ExRecordBufTemp.Data.CtlNum = aRC.Splite.PCtlNum;
	
	if(mType == etOperate){
		switch(aData0){
			case otPowerOff:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evSystemPowerOff;
				break;
			
			case otPowerOn:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evSystemPowerOn;
				break;
			
			case otReset:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evReset;
				break;
			
			case otMute:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evMuteBell;
				break;
			
			case otMask:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evMask;
				break;
			
			case otUnMask:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.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:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evAdjustClock;
				break;
				
			case otCfgPermissionAllow:
				return;
				break;
			
			case otAllowSet:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
			
				if(setHandAuto != (aData1 & 0x01)){
					setHandAuto &=~0x01;
					setHandAuto |=(aData1 & 0x01);
					ExRecordBufTemp.Data.EventCode = evAutomatic;
				}else
				if(setHandAuto != (aData1 & 0x02)){
					setHandAuto &=~0x02;
					setHandAuto |=(aData1 & 0x02);
					ExRecordBufTemp.Data.EventCode = evManual;
				}
				break;
			
			case otAlramSetOnOff:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftAlramVaCircuit;
				if(aData1){
					ExRecordBufTemp.Data.EventCode = evLaunch;
				}else{
					ExRecordBufTemp.Data.EventCode = evShutoff;
				}
				break;
				
			case otBusPadOn:
				ExRecordBufTemp.Data.UnitNum = aP0;
				ExRecordBufTemp.Data.DeviceNum = aP1;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftBusCtlPanel;
				ExRecordBufTemp.Data.EventCode = evLaunch;
				break;
			
			case otBusPadOff:
				ExRecordBufTemp.Data.UnitNum = aP0;
				ExRecordBufTemp.Data.DeviceNum = aP1;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftBusCtlPanel;
				ExRecordBufTemp.Data.EventCode = evShutoff;
				break;
			
			case otDirectPadManualAllowOn:
				return;
				//---------------------------------------------------------------------------------
				//FillText4DirectPadManualAllowOn();
				break;
			
			case otDirectPadManualAllowOff:
				return;
				//---------------------------------------------------------------------------------
				//FillText4DirectPadManualAllowOff();
				break;
			
			case otDirectPadNodeOn:
				ExRecordBufTemp.Data.UnitNum = aP0;
				ExRecordBufTemp.Data.DeviceNum = aP1;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftDirCtlPanel;
				ExRecordBufTemp.Data.EventCode = evLaunch;
				break;
			
			case otDirectPadNodeOff:
				ExRecordBufTemp.Data.UnitNum = aP0;
				ExRecordBufTemp.Data.DeviceNum = aP1;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftDirCtlPanel;
				ExRecordBufTemp.Data.EventCode = evShutoff;
				break;
			
			case otUserCheck:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evKeyPressFunctionCheck;
				break;
			
			case otLinkageGo:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evLaunchInrerLink;
				break;
			
			case otSetNwTime:
			case otReqNwTime:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evAdjustClock;
				break;
			
			case otSelfCheck:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evSelfCheck;
				break;
			
			case otSetManualAllowState:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.Data.EventCode = evManual;
				break;
			
			case otSetAutoAllowState:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.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:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				ExRecordBufTemp.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:
				ExRecordBufTemp.Data.UnitNum = 0;
				ExRecordBufTemp.Data.DeviceNum = 0;
				ExRecordBufTemp.Data.ChannelNum = 0;
				ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
				if(aData1 == 3)ExRecordBufTemp.Data.EventCode = evManual;
				else if(aData1 == 1)ExRecordBufTemp.Data.EventCode = evAutomatic;
				else if(aData1 == 2)ExRecordBufTemp.Data.EventCode = evManual;
				else if(aData1 == 2)ExRecordBufTemp.Data.EventCode = evManual;
				break;
		}
	}
	
	getExRecordTime(aRC);
	getExRecordStateCode(ExrecordStateCode);
	iRecordBufInsert(ExRecordBufTemp.D8);
}

void TexRecord::iExRecordLinkageInsert(TRecordCommon aRC)
{
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char aData0;
	unsigned char aData1;
	unsigned char data;
	
	ExRecordBufTemp.Data.MsgType = 4;
	ExRecordBufTemp.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;
	
	ExRecordBufTemp.Data.UnitNum = aP0;
	ExRecordBufTemp.Data.DeviceNum = aP1;
	ExRecordBufTemp.Data.ChannelNum = 0;
	
	if( (aP0 >0) && (aP0 <=40) ){
		getExRecordDeviceCode(dType);
	}else
	if(  (aP0 >=dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_END)  ){
		ExRecordBufTemp.Data.DeviceCode = ftDirCtlPanel;
	}else{
		ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
	}
	
	if(data == 0x01){
		ExRecordBufTemp.Data.EventCode = evLaunchInrerLink;
	}else
	if(data == 0x02){
		ExRecordBufTemp.Data.EventCode = evLaunchInrerLink;
	}else
	if(data == 0x03){
		ExRecordBufTemp.Data.EventCode = evFeedBack;
	}else
	if(data == 0x04){
		ExRecordBufTemp.Data.EventCode = evFeedBack;
	}else
	if(data == 0x05){
		ExRecordBufTemp.Data.EventCode = evLaunchInrerLink;
	}else
	if(data == 0x06){
		ExRecordBufTemp.Data.EventCode = evLaunchInrerLink;
	}else
	if(data == 0x07){
		return;
	}else
	if(data == 0xB1){
		ExRecordBufTemp.Data.EventCode = evShutoff;
	}else
	if(data == 0xB3){
		ExRecordBufTemp.Data.EventCode = evFeedBackRevoke;
	}else
	if(data == 0xB5){
		ExRecordBufTemp.Data.EventCode = evShutoff;
	}else
	if(data == 0xB6){
		ExRecordBufTemp.Data.EventCode = evShutoff;
	}else
	if(data == 0xB7){
		return;
	}
	
	getExRecordTime(aRC);
	getExRecordStateCode(ExrecordStateCode);
	iRecordBufInsert(ExRecordBufTemp.D8);
}

void TexRecord::iExRecordSvInsert(TRecordCommon aRC)
{
	unsigned char aP0;
	unsigned char aP1;
	unsigned char dType;
	unsigned char aData0;
	unsigned char aData1;
	
	ExRecordBufTemp.Data.MsgType = 4;
	ExRecordBufTemp.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;
	
	ExRecordBufTemp.Data.UnitNum = aP0;
	ExRecordBufTemp.Data.DeviceNum = aP1;
	ExRecordBufTemp.Data.ChannelNum = 0;
	
	if( (aP0 >0) && (aP0 <=40) ){
		getExRecordDeviceCode(dType);
	}else
	if(  (aP0 >=dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_END)  ){
		ExRecordBufTemp.Data.DeviceCode = ftDirCtlPanel;
	}else{
		ExRecordBufTemp.Data.DeviceCode = ftMainCtl;
	}
	
	ExRecordBufTemp.Data.EventCode = evSuperVisory;
	
	getExRecordTime(aRC);
	getExRecordStateCode(ExrecordStateCode);
	iRecordBufInsert(ExRecordBufTemp.D8);
}

void TexRecord::oCmdInsert()//10ms
{
	static unsigned int send_tick = 0;
	
	if(!OnTransmite.OnGoing){
		send_tick++;
		if(send_tick > (1000 - 1)){//10s
			send_tick = 0;
		}
		
		if(GetVerFlag){
			GetVerFlag = 0;
			
			TxMsg.DS.Cmd = exGetVer;
			TxMsg.DS.Len = 0;
			
			TxSetFlag = 1;
		}else
		if(GetModleFlag){
			GetModleFlag = 0;
			
			TxMsg.DS.Cmd = exGetModle;
			TxMsg.DS.Len = 0;
			
			TxSetFlag = 1;
		}else
		if((ReadyFlag)&&(InRecordIndex != OutRecordIndex)){
			OutRecordIndex++;
			if(OutRecordIndex >= EXRECORDBUFDEEP)OutRecordIndex = 0;
			
			TxMsg.DS.Cmd = exWriteRecord;
			TxMsg.DS.Len = 32;
			TxMsg.DS.Data[0]  = ExRecordBuf[OutRecordIndex].Data.MsgType;
			TxMsg.DS.Data[1]  = ExRecordBuf[OutRecordIndex].Data.CtlAddr;
			TxMsg.DS.Data[2]  = (ExRecordBuf[OutRecordIndex].Data.CtlType & 0xFF);
			TxMsg.DS.Data[3]  = ((ExRecordBuf[OutRecordIndex].Data.CtlType>>8) & 0xFF);
			TxMsg.DS.Data[4]  = ExRecordBuf[OutRecordIndex].Data.Pid[0];
			TxMsg.DS.Data[5]  = ExRecordBuf[OutRecordIndex].Data.Pid[1];
			TxMsg.DS.Data[6]  = ExRecordBuf[OutRecordIndex].Data.Pid[2];
			TxMsg.DS.Data[7]  = ExRecordBuf[OutRecordIndex].Data.Pid[3];
			TxMsg.DS.Data[8]  = ExRecordBuf[OutRecordIndex].Data.Pid[4];
			TxMsg.DS.Data[9]  = ExRecordBuf[OutRecordIndex].Data.Pid[5];
			TxMsg.DS.Data[10] = ExRecordBuf[OutRecordIndex].Data.Pid[6];
			TxMsg.DS.Data[11] = ExRecordBuf[OutRecordIndex].Data.Pid[7];
			TxMsg.DS.Data[12] = ExRecordBuf[OutRecordIndex].Data.Pid[8];
			TxMsg.DS.Data[13] = ExRecordBuf[OutRecordIndex].Data.Pid[9];
			TxMsg.DS.Data[14] = ExRecordBuf[OutRecordIndex].Data.Pid[10];
			TxMsg.DS.Data[15] = ExRecordBuf[OutRecordIndex].Data.Pid[11];
			TxMsg.DS.Data[16] = ExRecordBuf[OutRecordIndex].Data.CtlNum;
			TxMsg.DS.Data[17] = ExRecordBuf[OutRecordIndex].Data.UnitNum;
			TxMsg.DS.Data[18] = ExRecordBuf[OutRecordIndex].Data.DeviceNum;
			TxMsg.DS.Data[19] = ExRecordBuf[OutRecordIndex].Data.ChannelNum;
			TxMsg.DS.Data[20] = (ExRecordBuf[OutRecordIndex].Data.DeviceCode & 0xFF);
			TxMsg.DS.Data[21] = ((ExRecordBuf[OutRecordIndex].Data.DeviceCode>>8) & 0xFF);
			TxMsg.DS.Data[22] = (ExRecordBuf[OutRecordIndex].Data.EventCode & 0xFF);
			TxMsg.DS.Data[23] = ((ExRecordBuf[OutRecordIndex].Data.EventCode>>8) & 0xFF);
			TxMsg.DS.Data[24] = (ExRecordBuf[OutRecordIndex].Data.StateCode.D16 & 0xFF);
			TxMsg.DS.Data[25] = ((ExRecordBuf[OutRecordIndex].Data.StateCode.D16>>8) & 0xFF);
			TxMsg.DS.Data[26] = ExRecordBuf[OutRecordIndex].Data.Year;
			TxMsg.DS.Data[27] = ExRecordBuf[OutRecordIndex].Data.Mon;
			TxMsg.DS.Data[28] = ExRecordBuf[OutRecordIndex].Data.Day;
			TxMsg.DS.Data[29] = ExRecordBuf[OutRecordIndex].Data.Hour;
			TxMsg.DS.Data[30] = ExRecordBuf[OutRecordIndex].Data.Min;
			TxMsg.DS.Data[31] = ExRecordBuf[OutRecordIndex].Data.Sec;
			
			TxSetFlag = 1;
		}else
		/*
		if(10 == send_tick){
			TxMsg.DS.Cmd = exHeartBeat;
			TxMsg.DS.Len = 0;
			
			TxSetFlag = 1;
		}else
		*/
		if(200 == send_tick){
			TxMsg.DS.Cmd = exGetErrState;
			TxMsg.DS.Len = 0;
			
			TxSetFlag = 1;
		}
	}
}

void TexRecord::Task10Ms()
{
	oCmdInsert();
	
	oBufProcess();
}

void TexRecord::Task1000Ms()
{
	if(OnlineTick < 30){
		OnlineTick++;
	}else{
		ErrState.Body.OffLine = 1;
		ReadyFlag = 0;
	}
	
	if(ErrState.D32){
		if(ErrReport.D32 == 0){
			CtlCenter.ieAddDevFault(dDevFaultExStroge,0);
			ErrReport.D32 = 0x6601;
		}
	}else{
		if(ErrReport.D32 != 0){
			CtlCenter.ieAddDevFaultCancel(dDevFaultExStroge,0);
			ErrReport.D32 = 0;
		}
	}
}
			
