#include "ControlCenter.h"
#include "RuntimeData.h"
#include "Runtime.h"
#include "Gui.h"

extern "C"{
	#include "user_norflash.h"
	#include "user_eeprom.h"
	#include "fdcan_task.h"
	#include "task.h"
	#include "HW_config.h"
}

enum{
	ieStateNull = 0,
	ieStateActive = 0xAA,
};

void TControlCenter::Init()
{
	ieMsgFire.WriteIndex = 0;
	ieMsgFire.ReflashIndex = 0;
	ieMsgLinkage.ReflashIndex = 0;
	ieMsgSv.ReflashIndex = 0;
	ieMsgFault.ReflashIndex = 0;
	
	SysFreeTick1Ms =0;
	
	MsgReset();
	
	IsSendResetToPad =0;
	IsSendSelfCheckToPad = 0;
	
	PassWordII.Ava = 0;
	PassWordIII.Ava = 0;
	
	PsBatUpDateTick = 0;
}

void TControlCenter::MsgReset()
{
	unsigned int i;
	unsigned int AddrSd;
	
	hydrantKpFbHasSend = 0;
	
	ieGot = 0;
	ieIndexMsgFault =0;
	ieIndexMsgStart =0;
	ieIndexMsgFeedBack =0;
	
	ieMsgFire.WriteIndex = 0;
	
	ieMsgFire.Count = 0;
	ieMsgFire.ActualCount =0;
	ieMsgFault.Count = 0;
	ieMsgFault.VaCount = 0;
	ieMsgSv.Count = 0;
	ieMsgLinkage.SatrtHasBennActive = 0;
	ieMsgLinkage.Count = 0;
	ieMsgLinkage.FbCount = 0;
	ieMsgLinkage.PumpFbCount =0;
	ieMsgLinkage.PumpFbLocalCount =0;
	ieMsgLinkage.MissingCount = 0;
	ieMsgLinkage.StartCount = 0;
	ieMsgLinkage.VaCount = 0;
	ieMsgLinkage.VaCountOld = 0;
	ieMsgLinkage.BroadcastCount =0;
	ieMsgLinkage.BroadcastCountOld =0;
	ieMsgLinkage.IsBroadcastAndVa =0;
	ieMsgLinkage.HydrantPadCount =0;
	ieMsgLinkage.HydrantPadCountOld =0;
	ieMsgLinkage.HydrantPadNewActive = 0;
	ieMsgLinkage.DelayCount = 0;
	ieMsgLinkage.DelayCountOld = 0;
	ieMsgLinkage.StopCount = 0;
	
	
	for(i=0; i<ieMSG_FIRE_MAX_COUNT; i++){
		AddrSd = dAddrSdRam_MsgFire + (i * 24);
		*(volatile unsigned int*)(AddrSd) 	= 0;
		*(volatile unsigned int*)(AddrSd + 4) 	= 0;
		*(volatile unsigned int*)(AddrSd + 8)	= 0;
		*(volatile unsigned int*)(AddrSd + 12)	= 0;
		*(volatile unsigned int*)(AddrSd + 16)	= 0;
		*(volatile unsigned int*)(AddrSd + 20)	= 0;
	}
	
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		AddrSd = dAddrSdRam_MsgLinkage + (i * 24);
		*(volatile unsigned int*)(AddrSd) 	= 0;
		*(volatile unsigned int*)(AddrSd + 4) 	= 0;
		*(volatile unsigned int*)(AddrSd + 8)	= 0;
		*(volatile unsigned int*)(AddrSd + 12)	= 0;	
		*(volatile unsigned int*)(AddrSd + 16)	= 0;	
		*(volatile unsigned int*)(AddrSd + 20)	= 0;	
	}
	
	for(i=0; i<ieMSG_SV_MAX_COUNT; i++){
		AddrSd = dAddrSdRam_MsgSv + (i * 24);
		*(volatile unsigned int*)(AddrSd) 	= 0;
		*(volatile unsigned int*)(AddrSd + 4) 	= 0;
		*(volatile unsigned int*)(AddrSd + 8)	= 0;
		*(volatile unsigned int*)(AddrSd + 12)	= 0;
		*(volatile unsigned int*)(AddrSd + 16)	= 0;
		*(volatile unsigned int*)(AddrSd + 20)	= 0;	
	}
	
	for(i=0; i<ieMSG_FAULT_MAX_COUNT; i++){
		AddrSd = dAddrSdRam_MsgFault + (i * 24);
		*(volatile unsigned int*)(AddrSd) 	= 0;
		*(volatile unsigned int*)(AddrSd + 4) 	= 0;
		*(volatile unsigned int*)(AddrSd + 8)	= 0;
		*(volatile unsigned int*)(AddrSd + 12)	= 0;
		*(volatile unsigned int*)(AddrSd + 16)	= 0;
		*(volatile unsigned int*)(AddrSd + 20)	= 0;	
	}
	if(MainCtl.fData.Split.NetworkMode == 1){
		ieMsgMask.Count = 0;
		for(i=0; i<ieMSG_MASK_MAX_COUNT; i++){
			AddrSd = dAddrSdRam_MsgMask + (i * 24);
			*(volatile unsigned int*)(AddrSd) 	= 0;
			*(volatile unsigned int*)(AddrSd + 4) 	= 0;
			*(volatile unsigned int*)(AddrSd + 8)	= 0;
			*(volatile unsigned int*)(AddrSd + 12)	= 0;
			*(volatile unsigned int*)(AddrSd + 16)	= 0;
			*(volatile unsigned int*)(AddrSd + 20)	= 0;
		}
	}
	
	IsSendResetToPad = 0;
	IsSendSelfCheckToPad = 0;
	
	DisplayPadPrcFireIndex = 0;
	DisplayPadBuf.Count = 0;
	DisplayPadBuf.ReadIndex = 0;
	DisplayPadBuf.WriteIndex = 0;
	for(i=0; i<dDiplayPadCtlBufMaxCount; i++){
		AddrSd = dAddrSdRam_DisplayPadBuf + i * 8;
		*(volatile unsigned int*)(AddrSd + 0) = 0;
		*(volatile unsigned int*)(AddrSd + 4) = 0;
	}
	
	InspecDataInit();
	
	FeedBackMissCount = 0;
	KeyPad.FbMissCountOld = 0;
	
	PsBatUpDateTick = 0;
	
	FiredUserCode.Count =0;
	for(i=0; i<dLINK_INPUT_MAX_COUNT; i++){
		FiredUserCode.uCode[i] = 0;
		FiredUserCode.AreaNum[i] = 0;
		FiredUserCode.AssignType[i] = 0;
		FiredUserCode.eType[i] = 0;
	}
}

void TControlCenter::WaitChipIdle(unsigned int ChipX)
{
	volatile unsigned int aWait, Sta;
	do{
		for(aWait=0; aWait<1000000;aWait++);
		Sta = nor_get_busy_state(ChipX);
	}while(Sta);
}

void TControlCenter::FireGetViaPath(unsigned int aIndex)
{
	unsigned int AddrSd = dAddrSdRam_MsgFire + (aIndex * 24);
	MsgReadTmp.D32[0] = *(volatile unsigned int*)(AddrSd);
	MsgReadTmp.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	MsgReadTmp.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	MsgReadTmp.D32[3] = *(volatile unsigned int*)(AddrSd + 12);
	MsgReadTmp.D32[4] = *(volatile unsigned int*)(AddrSd + 16);
	MsgReadTmp.D32[5] = *(volatile unsigned int*)(AddrSd + 20);
} 

void TControlCenter::FireGet4DisplayPadViaIndex(unsigned int aIndex)
{
	unsigned int AddrSd = dAddrSdRam_MsgFire + (aIndex * 24);
	DisplayPadMsg.D32[0] = *(volatile unsigned int*)(AddrSd);
	DisplayPadMsg.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	DisplayPadMsg.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	DisplayPadMsg.D32[3] = *(volatile unsigned int*)(AddrSd + 12);
} 

void TControlCenter::FireMsgClearOne(unsigned int aIndex)
{
	unsigned int AddrSd = dAddrSdRam_MsgFire + (aIndex * 24);
	*(volatile unsigned int*)(AddrSd + 4) = 0;
	*(volatile unsigned int*)(AddrSd + 8) = 0;
} 

void TControlCenter::FireMsgCopyOne(unsigned int aIndex)
{
	unsigned int AddrSd = dAddrSdRam_MsgFire + (aIndex * 24);
	*(volatile unsigned int*)(AddrSd + 0) = MsgReadTmp.D32[0];
	*(volatile unsigned int*)(AddrSd + 4) = MsgReadTmp.D32[1];
	*(volatile unsigned int*)(AddrSd + 8) = MsgReadTmp.D32[2];
	*(volatile unsigned int*)(AddrSd + 12) = MsgReadTmp.D32[3];
	*(volatile unsigned int*)(AddrSd + 16) = MsgReadTmp.D32[4];
	*(volatile unsigned int*)(AddrSd + 20) = MsgReadTmp.D32[5];
} 

void TControlCenter::FireMsgExtGet(unsigned int aIndex)
{
	unsigned int AddrSd = dAddrSdRam_MsgFire + (aIndex * 24);
	MsgExtGet.D32[0] = *(volatile unsigned int*)(AddrSd + 0);
	MsgExtGet.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	MsgExtGet.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	MsgExtGet.D32[3] = *(volatile unsigned int*)(AddrSd + 12);
	MsgExtGet.D32[4] = *(volatile unsigned int*)(AddrSd + 16);
	MsgExtGet.D32[5] = *(volatile unsigned int*)(AddrSd + 20);
}

void TControlCenter::FireTurnOnVa(void)
{
	TRecordCommon aIm;
	
	aIm.Splite.Year = DateTime.Date.Split.Year;
	aIm.Splite.Month = DateTime.Date.Split.Month;
	aIm.Splite.Day = DateTime.Date.Split.Day;
	aIm.Splite.Hour = DateTime.Time.Split.Hour;
	aIm.Splite.Minute = DateTime.Time.Split.Minute;
	aIm.Splite.Second = DateTime.Time.Split.Second;	
	aIm.Splite.mType = etLinkageStart;
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xF0;	//Board Index
	aIm.Splite.P1 = 0xF0;
	aIm.Splite.P2 = 0xF0;	
	aIm.Splite.dType = 0;			
	aIm.Splite.Data0 = 0x06;
	aIm.Splite.Data1 = 0;//Is Set=1  Recover=0
	aIm.Splite.iByte0	= CmdActiveDefaultSet[cmVAAlramStart][8];
	

	AlramVaOnOff = 1;
	aIm.Splite.Data0 = CmdActiveDefaultSet[cmVAAlramStart][8];
	aIm.Splite.iByte0	= CmdActiveDefaultSet[cmVAAlramStart][8];
	//Record.OperateAdd_AlramSoundOn(MainCtl.fData.Split.MyNum);
	tData[0] = 0;
	tData[1] = 0;
	tData[2] = 0;
	InnerCan.OBufInsert(1, cmVAAlramStart, tData, 3);

	//ProtoC2C.PublishEventAlramOnOff(AlramVaOnOff);
}

void TControlCenter::iePushOneMsgFire(TRecordCommon aIm, unsigned int auC)
{
	int i,z,y, isMore;
	int x, aWriteIndex;
	unsigned char aCn, aP0, aP1, aAssignType;
	TDMix	mVal;
	
	aCn = aIm.Splite.PCtlNum;
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	aAssignType = 0;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aCn == MainCtl.fData.Split.MyNum){
			aAssignType = Port[aP0].AssignType[aP1];
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return;
			}else{
				Port[aP0].StateTable[aP1] |= dEpStateBitFire;
			}
		}else{
			aCn--;
			if( (aCn < dNETWORK_MACHINE_COUNT) && (aP0 < dPORT_MAX_COUNT) ){
				mVal.D32 = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
				mVal.D8[0] |= dEpStateBitFire;
				mVal.D8[1] = aIm.Splite.dType;
				
				SetNetworkEpData(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, mVal.D16[0]);
			}
		}
	}
	ieMsgFire.RequestRead =0;
	ieMsgFire.Lock = 1;

	if(ieMsgFire.WriteIndex >= (ieMSG_FIRE_MAX_COUNT)){
		ieMsgFire.WriteIndex = ieMSG_FIRE_MAX_COUNT;
		aWriteIndex = ieMSG_FIRE_MAX_COUNT -1; 
		ieMsgFire.isMore = 1;
		for(i=1; i<(ieMSG_FIRE_MAX_COUNT-1); i++){
			z = i+1;	
			FireGetViaPath(i+1);
			FireMsgCopyOne(i);
		}	
	}else{
		ieMsgFire.isMore = 0;
		aWriteIndex = ieMsgFire.WriteIndex;
		ieMsgFire.WriteIndex++;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	MsgReadTmp.Splite.Data0 = LinkInputTypeFire;
	if(ieMsgFire.Count == 0)MsgReadTmp.Splite.Data1 = 1;
	else MsgReadTmp.Splite.Data1 = 0;
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.State = ieStateActive;
	MsgReadTmp.Splite.P2 =0;
	FireMsgCopyOne(aWriteIndex);
	
	const unsigned int tInx = FiredUserCode.Count;
	FiredUserCode.uCode[tInx] = aIm.Splite.UserCode;
	FiredUserCode.AreaNum[tInx] = aIm.Splite.AreaNum;
	FiredUserCode.dType[tInx] = aIm.Splite.dType;
	FiredUserCode.AssignType[tInx] = 0;
	FiredUserCode.eType[tInx] = LinkInputTypeFire;
	if( FiredUserCode.Count < (dLINK_INPUT_MAX_COUNT -2) )FiredUserCode.Count++;
	
	ieMsgFire.Count = ieMsgFire.WriteIndex;
	if(MsgReadTmp.Splite.Data0 != TControlCenter::LinkInputTypeFireSimulate){
		ieMsgFire.ActualCount++;
	}
	ieMsgFire.ReflashIndex++;
	ieMsgFire.Lock = 0;
	AlarmSoundWhat = 0;
	
	IsMuteFire = 0;
	IsMute = 0;
	
	
	/*if(FireVaTrenOned == 0){
		//Turn On Va
		FireVaTrenOned =1;
		FireTurnOnVa();
	}*/
	
	ieGot = 1;
}

int TControlCenter::iePushOneMsgFireSimulate(TRecordCommon aIm, unsigned int auC)
{
	int i,z,y, isMore;
	int x, aWriteIndex;
	unsigned char aCn, aP0, aP1, aAssignType;
	TDMix	mVal;
	
	aCn = aIm.Splite.PCtlNum;
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	aAssignType = 0;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aCn == MainCtl.fData.Split.MyNum){
			aAssignType = Port[aP0].AssignType[aP1];
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return 0;
			}else{
				//Port[aP0].StateTable[aP1] |= dEpStateBitFire;
			}
		}else{
			aCn--;
			if( (aCn < dNETWORK_MACHINE_COUNT) && (aP0 < dPORT_MAX_COUNT) ){
				if(aP1 >= dEP_MAX_COUNT_PER_PORT)return 0;
				//mVal.D32 = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
				//mVal.D8[0] |= dEpStateBitFire;
				//mVal.D8[1] = aIm.Splite.dType;
				
				//SetNetworkEpData(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, mVal.D16[0]);
			}
		}
	}else{
		return 0;
	}
	ieMsgFire.RequestRead =0;
	ieMsgFire.Lock = 1;

	if(ieMsgFire.WriteIndex >= (ieMSG_FIRE_MAX_COUNT)){
		ieMsgFire.WriteIndex = ieMSG_FIRE_MAX_COUNT;
		aWriteIndex = ieMSG_FIRE_MAX_COUNT -1; 
		ieMsgFire.isMore = 1;
		for(i=1; i<(ieMSG_FIRE_MAX_COUNT-1); i++){
			z = i+1;	
			FireGetViaPath(i+1);
			FireMsgCopyOne(i);
		}	
	}else{
		ieMsgFire.isMore = 0;
		aWriteIndex = ieMsgFire.WriteIndex;
		ieMsgFire.WriteIndex++;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	MsgReadTmp.Splite.Data0 = LinkInputTypeFireSimulate;
	if(ieMsgFire.Count == 0)MsgReadTmp.Splite.Data1 = 1;
	else MsgReadTmp.Splite.Data1 = 0;
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.State = ieStateActive;
	MsgReadTmp.Splite.P2 =0;
	FireMsgCopyOne(aWriteIndex);
	
	const unsigned int tInx = FiredUserCode.Count;
	FiredUserCode.uCode[tInx] = aIm.Splite.UserCode;
	FiredUserCode.AreaNum[tInx] = aIm.Splite.AreaNum;
	FiredUserCode.dType[tInx] = aIm.Splite.dType;
	FiredUserCode.AssignType[tInx] = 0;
	FiredUserCode.eType[tInx] = LinkInputTypeFireSimulate;
	if(FiredUserCode.Count < (dLINK_INPUT_MAX_COUNT -2))FiredUserCode.Count++;
	
	ieMsgFire.Count = ieMsgFire.WriteIndex;
	ieMsgFire.ReflashIndex++;
	ieMsgFire.Lock = 0;
	
	AlarmSoundWhat = 0;
	
	IsMuteFire = 0;
	IsMute = 0;
	
	
	/*if(FireVaTrenOned == 0){
		//Turn On Va
		FireVaTrenOned =1;
		FireTurnOnVa();
	}*/
	
	ieGot = 1;
	
	return 1;
}

void TControlCenter::LinkageGetViaPath(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgLinkage + (aIndex * 24);
	MsgReadTmp.D32[0] = *(volatile unsigned int*)(AddrSd);
	MsgReadTmp.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	MsgReadTmp.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	MsgReadTmp.D32[3] = *(volatile unsigned int*)(AddrSd + 12);
	MsgReadTmp.D32[4] = *(volatile unsigned int*)(AddrSd + 16);
	MsgReadTmp.D32[5] = *(volatile unsigned int*)(AddrSd + 20);
} 

void TControlCenter::LinkageMsgClearOne(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgLinkage + (aIndex * 24);
	*(volatile unsigned int*)(AddrSd + 0) = 0;
	*(volatile unsigned int*)(AddrSd + 4) = 0;
	*(volatile unsigned int*)(AddrSd + 8) = 0;
	*(volatile unsigned int*)(AddrSd + 12) = 0;
	*(volatile unsigned int*)(AddrSd + 16) = 0;
	*(volatile unsigned int*)(AddrSd + 20) = 0;
} 

void TControlCenter::LinkageMsgCopyOne(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgLinkage + (aIndex * 24);
	*(volatile unsigned int*)(AddrSd + 0) = MsgReadTmp.D32[0];
	*(volatile unsigned int*)(AddrSd + 4) = MsgReadTmp.D32[1];
	*(volatile unsigned int*)(AddrSd + 8) = MsgReadTmp.D32[2];
	*(volatile unsigned int*)(AddrSd + 12) = MsgReadTmp.D32[3];
	*(volatile unsigned int*)(AddrSd + 16) = MsgReadTmp.D32[4];
	*(volatile unsigned int*)(AddrSd + 20) = MsgReadTmp.D32[5];
} 

void TControlCenter::LinkageMsgExtGet(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgLinkage + (aIndex * 24);
	MsgExtGet.D32[0] = *(volatile unsigned int*)(AddrSd + 0);
	MsgExtGet.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	MsgExtGet.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	MsgExtGet.D32[3] = *(volatile unsigned int*)(AddrSd + 12);
	MsgExtGet.D32[4] = *(volatile unsigned int*)(AddrSd + 16);
	MsgExtGet.D32[5] = *(volatile unsigned int*)(AddrSd + 20);
}

void TControlCenter::SvGetViaPath(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgSv + (aIndex * 24);
	MsgReadTmp.D32[0] = *(volatile unsigned int*)(AddrSd);
	MsgReadTmp.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	MsgReadTmp.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	MsgReadTmp.D32[3] = *(volatile unsigned int*)(AddrSd + 12);	
	MsgReadTmp.D32[4] = *(volatile unsigned int*)(AddrSd + 16);	
	MsgReadTmp.D32[5] = *(volatile unsigned int*)(AddrSd + 20);	
}

void TControlCenter::SvMsgClearOne(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgSv + (aIndex * 24);
	*(volatile unsigned int*)(AddrSd + 0) = 0;
	*(volatile unsigned int*)(AddrSd + 4) = 0;
	*(volatile unsigned int*)(AddrSd + 8) = 0;
	*(volatile unsigned int*)(AddrSd + 12) = 0;
	*(volatile unsigned int*)(AddrSd + 16) = 0;
	*(volatile unsigned int*)(AddrSd + 20) = 0;
} 

void TControlCenter::SvMsgCopyOne(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgSv + (aIndex * 24);
	*(volatile unsigned int*)(AddrSd + 0) = MsgReadTmp.D32[0];
	*(volatile unsigned int*)(AddrSd + 4) = MsgReadTmp.D32[1];
	*(volatile unsigned int*)(AddrSd + 8) = MsgReadTmp.D32[2];
	*(volatile unsigned int*)(AddrSd + 12) = MsgReadTmp.D32[3];
	*(volatile unsigned int*)(AddrSd + 16) = MsgReadTmp.D32[4];
	*(volatile unsigned int*)(AddrSd + 20) = MsgReadTmp.D32[5];
} 

void TControlCenter::SvMsgExtGet(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgSv + (aIndex * 24);
	MsgExtGet.D32[0] = *(volatile unsigned int*)(AddrSd + 0);
	MsgExtGet.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	MsgExtGet.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	MsgExtGet.D32[3] = *(volatile unsigned int*)(AddrSd + 12);
	MsgExtGet.D32[4] = *(volatile unsigned int*)(AddrSd + 16);
	MsgExtGet.D32[5] = *(volatile unsigned int*)(AddrSd + 20);
}
	
void TControlCenter::FaultGetViaPath(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgFault + (aIndex * 24);
	MsgReadTmp.D32[0] = *(volatile unsigned int*)(AddrSd);
	MsgReadTmp.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	MsgReadTmp.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	MsgReadTmp.D32[3] = *(volatile unsigned int*)(AddrSd + 12);	
	MsgReadTmp.D32[4] = *(volatile unsigned int*)(AddrSd + 16);	
	MsgReadTmp.D32[5] = *(volatile unsigned int*)(AddrSd + 20);	
}

void TControlCenter::FaultMsgClearOne(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgFault + (aIndex * 24);
	*(volatile unsigned int*)(AddrSd + 0) = 0;
	*(volatile unsigned int*)(AddrSd + 4) = 0;
	*(volatile unsigned int*)(AddrSd + 8) = 0;
	*(volatile unsigned int*)(AddrSd + 12) = 0;
	*(volatile unsigned int*)(AddrSd + 16) = 0;
	*(volatile unsigned int*)(AddrSd + 20) = 0;
} 

void TControlCenter::FaultMsgCopyOne(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgFault + (aIndex * 24);
	*(volatile unsigned int*)(AddrSd + 0) = MsgReadTmp.D32[0];
	*(volatile unsigned int*)(AddrSd + 4) = MsgReadTmp.D32[1];
	*(volatile unsigned int*)(AddrSd + 8) = MsgReadTmp.D32[2];
	*(volatile unsigned int*)(AddrSd + 12) = MsgReadTmp.D32[3];
	*(volatile unsigned int*)(AddrSd + 16) = MsgReadTmp.D32[4];
	*(volatile unsigned int*)(AddrSd + 20) = MsgReadTmp.D32[5];
} 

void TControlCenter::FaultMsgExtGet(unsigned int aIndex)
{
	volatile unsigned int AddrSd = dAddrSdRam_MsgFault + (aIndex * 24);
	MsgExtGet.D32[0] = *(volatile unsigned int*)(AddrSd + 0);
	MsgExtGet.D32[1] = *(volatile unsigned int*)(AddrSd + 4);
	MsgExtGet.D32[2] = *(volatile unsigned int*)(AddrSd + 8);
	MsgExtGet.D32[3] = *(volatile unsigned int*)(AddrSd + 12);
	MsgExtGet.D32[4] = *(volatile unsigned int*)(AddrSd + 16);
	MsgExtGet.D32[5] = *(volatile unsigned int*)(AddrSd + 20);
}

void TControlCenter::iePushOneMsgLinkageStart(TRecordCommon aIm)
{
	unsigned char aCn, aP0, aP1, EpSta, aAssignType;
	int i,Cnt, FirstNullIndex, WritePst;
	int aStartCount, aFbCount, aMsCount, aVaCount, aHP;
	int aDelayCount, aStopCount, aBroadcastCount;
	
	aCn = aIm.Splite.PCtlNum;
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	if( (aIm.Splite.P0) && (aIm.Splite.P0 <= dPORT_MAX_COUNT )){
		if(aP1 >= dEP_MAX_COUNT_PER_PORT)return;
		if(aCn == MainCtl.fData.Split.MyNum){
			aAssignType = Port[aP0].AssignType[aP1];
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A))){
				Port[aP0].DelayTick[aP1] = 0;
				if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
					return;
				}else{
					Port[aP0].StateTable[aP1] |= dEpStateBitStart;
				}
			}
		}else{
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A))){
				EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
				EpSta |= dEpStateBitStart;
				SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
			}
		}
	}else
	if( (aIm.Splite.P0 >= dADDR_DIRECTPAD_START) && (aIm.Splite.P0 <= dADDR_DIRECTPAD_END )){
		if(aCn == MainCtl.fData.Split.MyNum){
			if(aP1 >= dDIRECTCTL_KEY_MAX_COUNT)return;
			aP0 = aIm.Splite.P0 -dADDR_DIRECTPAD_START;
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A)))DirectCtlBoard[aP0].DelayTick[aP1] = 0;
		}
	}else{
		return;
	}
	
	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	
	FirstNullIndex = ieMSG_LINKAGE_MAX_COUNT +1000;
	Cnt = 0;
	aStartCount = 0;
	aFbCount = 0;
	aMsCount = 0;
	aVaCount = 0;
	aBroadcastCount =0;
	aHP = 0;
	aDelayCount = 0;
	aStopCount = 0;
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  (MsgReadTmp.D32[2] == aIm.D32[2]) && ( etLinkageStart == MsgReadTmp.Splite.mType) ){
				LinkageMsgClearOne(i);
				if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_LINKAGE_MAX_COUNT){
				LinkageMsgCopyOne(FirstNullIndex);
				LinkageMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.mType == etLinkageStart){
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x0A)){
					aDelayCount++;
				}else
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x09)){
					aStopCount++;
				}else{
					aStartCount++;
					if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
						//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
							aVaCount++;
						//}
					}else
					if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
						aHP++;
					}else
					if(MsgReadTmp.Splite.dType == dASSIGN_TYPE_Broadcast){
						aBroadcastCount++;
					}
				}
			}else
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				aFbCount ++;
				if(MsgReadTmp.Splite.Data0 == 0x04){
					aMsCount++;
				}
			}
		}
	}
	WritePst = Cnt;
	if(Cnt >= ieMSG_LINKAGE_MAX_COUNT){
		for(i=0; i< (ieMSG_LINKAGE_MAX_COUNT -1); i++){
			LinkageGetViaPath(i+1);
			LinkageMsgCopyOne(i);
		}
		WritePst = ieMSG_LINKAGE_MAX_COUNT -1;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	MsgReadTmp.Splite.Data0 = aIm.Splite.iByte0;
	MsgReadTmp.Splite.Data1 = 0;
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.State = ieStateActive;
	LinkageMsgCopyOne(WritePst);
	
	ieMsgLinkage.Count = WritePst +1;

	if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x0A))
		aDelayCount++;
	else if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x09))
		aStopCount++;
	else 
		aStartCount++;
	
	ieMsgLinkage.StartCount = aStartCount;
	ieMsgLinkage.DelayCount = aDelayCount;
	ieMsgLinkage.StopCount = aStopCount;
	if(ieMsgLinkage.StartCount > 0)ieMsgLinkage.SatrtHasBennActive = 1;
	
	ieMsgLinkage.FbCount = aFbCount;
	ieMsgLinkage.MissingCount = aMsCount;
	if( (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x09)) && ((MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x0A))) ){
		if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
			//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
				aVaCount++;
			//}
		}else
		if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
			aHP++;
			ieMsgLinkage.HydrantPadNewActive =1;
		}else
		if(MsgReadTmp.Splite.dType == dASSIGN_TYPE_Broadcast){
			aBroadcastCount++;
		}
	}
	
	ieMsgLinkage.VaCount = aVaCount;
	ieMsgLinkage.BroadcastCount = aBroadcastCount;
	ieMsgLinkage.HydrantPadCount = aHP;
	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	
	BroadcastAlternatingUpdate();
	
	if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
		if( (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x0A)) && (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x09)) ){
			const unsigned int tInx = FiredUserCode.Count;
			FiredUserCode.uCode[tInx] = aIm.Splite.UserCode;
			FiredUserCode.AreaNum[tInx] = aIm.Splite.AreaNum;
			FiredUserCode.dType[tInx] = aIm.Splite.dType;
			FiredUserCode.AssignType[tInx] = 0;
			FiredUserCode.eType[tInx] = LinkInputTypeHydrant;
			if(FiredUserCode.Count < (dLINK_INPUT_MAX_COUNT -2))FiredUserCode.Count++;
		}
	}
	
	if(AlarmSoundWhat > 1)AlarmSoundWhat = 1;
	
	IsMuteLnk = 0;
	IsMute = 0;
	
	ieGot = 1;	
}

int TControlCenter::iePushOneMsgLinkageStartSimulate(TRecordCommon aIm)
{
	unsigned char aCn, aP0, aP1, EpSta, aAssignType;
	int i,Cnt, FirstNullIndex, WritePst;
	int aStartCount, aFbCount, aMsCount, aVaCount, aHP;
	int aDelayCount, aStopCount, aBroadcastCount;
	
	aCn = aIm.Splite.PCtlNum;
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(  (MsgReadTmp.D32[2] == aIm.D32[2]) && ( etLinkageStart == MsgReadTmp.Splite.mType) ){
			if(MsgReadTmp.Splite.Data1 != StartTypeSimulate)
				return 0;
		}
	}
	if( (aIm.Splite.P0) && (aIm.Splite.P0 <= dPORT_MAX_COUNT )){
		if(aP1 >= dEP_MAX_COUNT_PER_PORT)return 0;
		if(aCn == MainCtl.fData.Split.MyNum){
			aAssignType = Port[aP0].AssignType[aP1];
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A))){
				if(Port[aP0].DelayToDoEventType[aP1])Port[aP0].DelayTick[aP1] = 0;
				if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
					return 0;
				}else{
					//Port[aP0].StateTable[aP1] |= dEpStateBitStart;
				}
			}
		}else{
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A))){
				EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
				EpSta |= dEpStateBitStart;
				SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
			}
		}
	}else
	if( (aIm.Splite.P0 >= dADDR_DIRECTPAD_START) && (aIm.Splite.P0 <= dADDR_DIRECTPAD_END )){
		if(aCn == MainCtl.fData.Split.MyNum){
			if(aP1 >= dDIRECTCTL_KEY_MAX_COUNT)return 0;
			aP0 = aIm.Splite.P0 -dADDR_DIRECTPAD_START;
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A))){
				if(DirectCtlBoard[aP0].DelayToDoEventType[aP1]){
					DirectCtlBoard[aP0].DelayTick[aP1] = 0;
				}
			}
		}
	}else{
		return 0;
	}
	
	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	
	FirstNullIndex = ieMSG_LINKAGE_MAX_COUNT +1000;
	Cnt = 0;
	aStartCount = 0;
	aFbCount = 0;
	aMsCount = 0;
	aVaCount = 0;
	aBroadcastCount =0;
	aHP = 0;
	aDelayCount = 0;
	aStopCount = 0;
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  (MsgReadTmp.D32[2] == aIm.D32[2]) && ( etLinkageStart == MsgReadTmp.Splite.mType) ){
				LinkageMsgClearOne(i);
				if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_LINKAGE_MAX_COUNT){
				LinkageMsgCopyOne(FirstNullIndex);
				LinkageMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.mType == etLinkageStart){
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x0A)){
					aDelayCount++;
				}else
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x09)){
					aStopCount++;
				}else{
					aStartCount++;
					///if(MsgReadTmp.Splite.Data1 == StartTypeSimulate){
						
					///}else{
						if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
							//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
								aVaCount++;
							//}
						}else
						if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
							aHP++;
						}else
						if(MsgReadTmp.Splite.dType == dASSIGN_TYPE_Broadcast){
							aBroadcastCount++;
						}
					///}
				}
			}else
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				aFbCount ++;
				if(MsgReadTmp.Splite.Data0 == 0x04){
					aMsCount++;
				}
			}
		}
	}
	WritePst = Cnt;
	if(Cnt >= ieMSG_LINKAGE_MAX_COUNT){
		for(i=0; i< (ieMSG_LINKAGE_MAX_COUNT -1); i++){
			LinkageGetViaPath(i+1);
			LinkageMsgCopyOne(i);
		}
		WritePst = ieMSG_LINKAGE_MAX_COUNT -1;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	MsgReadTmp.Splite.Data1 = StartTypeSimulate;
	MsgReadTmp.Splite.Data0 = aIm.Splite.iByte0;
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.State = ieStateActive;
	LinkageMsgCopyOne(WritePst);
	
	ieMsgLinkage.Count = WritePst +1;	
	if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x0A))
		aDelayCount ++;
	else if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x09))
		aStopCount++;
	else
		aStartCount++;
	
	ieMsgLinkage.StartCount = aStartCount;
	ieMsgLinkage.DelayCount = aDelayCount;
	ieMsgLinkage.StopCount = aStopCount;
	if(ieMsgLinkage.StartCount > 0)ieMsgLinkage.SatrtHasBennActive = 1;
	
	ieMsgLinkage.FbCount = aFbCount;
	ieMsgLinkage.MissingCount = aMsCount;
	if( (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x09)) && ((MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x0A))) ){
		if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
			//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
				aVaCount++;
			//}
		}else
		if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
			aHP++;
			ieMsgLinkage.HydrantPadNewActive =1;
		}else
		if(MsgReadTmp.Splite.dType == dASSIGN_TYPE_Broadcast){
			aBroadcastCount++;
		}
	}
	
	ieMsgLinkage.VaCount = aVaCount;
	ieMsgLinkage.BroadcastCount = aBroadcastCount;
	ieMsgLinkage.HydrantPadCount = aHP;
	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	
	BroadcastAlternatingUpdate();
	
	if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
		if( (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x0A)) && (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x09)) ){
			const unsigned int tInx = FiredUserCode.Count;
			FiredUserCode.uCode[tInx] = aIm.Splite.UserCode;
			FiredUserCode.AreaNum[tInx] = aIm.Splite.AreaNum;
			FiredUserCode.dType[tInx] = aIm.Splite.dType;
			FiredUserCode.AssignType[tInx] = 0;
			FiredUserCode.eType[tInx] = LinkInputTypeHydrantSimulate;
			if(FiredUserCode.Count < (dLINK_INPUT_MAX_COUNT -2))FiredUserCode.Count++;
		}
	}
	
	if(AlarmSoundWhat > 1)AlarmSoundWhat = 1;
	
	IsMuteLnk = 0;
	IsMute = 0;
	
	ieGot = 1;

	return 1;
}

void TControlCenter::ieManualPushOneMsgLinkageStart(TRecordCommon aIm)
{
	unsigned char aCn, aP0, aP1, EpSta, aAssignType;
	int i,Cnt, FirstNullIndex, WritePst;
	int aStartCount, aFbCount, aMsCount, aVaCount, aHP;
	int aDelayCount, aStopCount, aBroadcastCount;
	
	aCn = aIm.Splite.PCtlNum;
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	aAssignType = 0;
	if( (aIm.Splite.P0) && (aIm.Splite.P0 <= dPORT_MAX_COUNT )){
		if(aP1 >= dEP_MAX_COUNT_PER_PORT)return;
		if(aCn == MainCtl.fData.Split.MyNum){
			aAssignType = Port[aP0].AssignType[aP1];
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A))){
				Port[aP0].DelayTick[aP1] = 0;
				if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
					return;
				}else{
					Port[aP0].StateTable[aP1] |= dEpStateBitStart;
				}
			}
		}else{
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A))){
				EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
				EpSta |= dEpStateBitStart;
				SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
			}
		}
	}else
	if( (aIm.Splite.P0 >= dADDR_DIRECTPAD_START) && (aIm.Splite.P0 <= dADDR_DIRECTPAD_END )){
		if(aCn == MainCtl.fData.Split.MyNum){
			if(aP1 >= dDIRECTCTL_KEY_MAX_COUNT)return;
			aP0 = aIm.Splite.P0 -dADDR_DIRECTPAD_START;
			if( (aIm.Splite.iByte0 != static_cast<unsigned char>(0x09)) && (aIm.Splite.iByte0 != static_cast<unsigned char>(0x0A)))DirectCtlBoard[aP0].DelayTick[aP1] = 0;
		}
	}else{
		return;
	}
	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	
	FirstNullIndex = ieMSG_LINKAGE_MAX_COUNT +1000;
	Cnt = 0;
	aStartCount = 0;
	aFbCount = 0;
	aMsCount = 0;
	aVaCount = 0;
	aBroadcastCount =0;
	aHP =0;
	aDelayCount = 0;
	aStopCount = 0;
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  (MsgReadTmp.D32[2] == aIm.D32[2]) && ( etLinkageStart == MsgReadTmp.Splite.mType)  ){
				LinkageMsgClearOne(i);
				if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_LINKAGE_MAX_COUNT){
				LinkageMsgCopyOne(FirstNullIndex);
				LinkageMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.mType == etLinkageStart){	
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x0A)){
					aDelayCount++;
				}else
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x09)){
					aStopCount++;
				}else{
					aStartCount++;
					//if(MsgReadTmp.Splite.Data1 == StartTypeSimulate){
						
					//}else{
						if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
							//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
								aVaCount++;
							//}
						}else
						if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
							aHP++;
						}else
						if(MsgReadTmp.Splite.dType == dASSIGN_TYPE_Broadcast){
							aBroadcastCount++;
						}
					//}
				}
			}else
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				aFbCount ++;
				if(MsgReadTmp.Splite.Data0 == 0x04){
					aMsCount++;
				}
			}
		}
	}
	WritePst = Cnt;
	if(Cnt >= ieMSG_LINKAGE_MAX_COUNT){
		for(i=0; i< (ieMSG_LINKAGE_MAX_COUNT -1); i++){
			LinkageGetViaPath(i+1);
			LinkageMsgCopyOne(i);
		}
		WritePst = ieMSG_LINKAGE_MAX_COUNT -1;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	MsgReadTmp.Splite.Data0 = aIm.Splite.iByte0;
	MsgReadTmp.Splite.Data1 = 0;
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.State = ieStateActive;
	LinkageMsgCopyOne(WritePst);
	
	ieMsgLinkage.Count = WritePst +1;

	if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x0A))
		aDelayCount++;
	else if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x09))
		aStopCount++;
	else
		aStartCount++;
	
	ieMsgLinkage.StartCount = aStartCount;
	ieMsgLinkage.DelayCount = aDelayCount;
	ieMsgLinkage.StopCount = aStopCount;
	if(ieMsgLinkage.StartCount > 0)ieMsgLinkage.SatrtHasBennActive = 1;
	
	ieMsgLinkage.FbCount = aFbCount;
	ieMsgLinkage.MissingCount = aMsCount;
	if( (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x09)) && (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x0A)) ){
		if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
			//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
				aVaCount++;
			//}
		}else
		if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
			aHP++;
			ieMsgLinkage.HydrantPadNewActive =1;
		}else
		if(MsgReadTmp.Splite.dType == dASSIGN_TYPE_Broadcast){
			aBroadcastCount++;
		}
	}
	ieMsgLinkage.VaCount = aVaCount;
	ieMsgLinkage.BroadcastCount = aBroadcastCount;
	ieMsgLinkage.HydrantPadCount = aHP;
	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	
	BroadcastAlternatingUpdate();
	
	if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
		if( (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x09)) && (MsgReadTmp.Splite.Data0 != static_cast<unsigned char>(0x0A)) ){
			const unsigned int tInx = FiredUserCode.Count;
			FiredUserCode.uCode[tInx] = aIm.Splite.UserCode;
			FiredUserCode.AreaNum[tInx] = aIm.Splite.AreaNum;
			FiredUserCode.dType[tInx] = aIm.Splite.dType;
			FiredUserCode.AssignType[tInx] = 0;
			FiredUserCode.eType[tInx] = LinkInputTypeSv;

			if(FiredUserCode.Count < (dLINK_INPUT_MAX_COUNT -2))FiredUserCode.Count++;
		}
	}
	
	if(AlarmSoundWhat > 1)AlarmSoundWhat = 1;
	
	IsMuteLnk = 0;
	IsMute = 0;
	
	ieGot = 1;	
}

void TControlCenter::ieMsgLinkageStartDelayUpdate(unsigned int aFullPath, unsigned char aNewTime)
{
	/*unsigned char aP0, aP1, EpSta;
	int i,Cnt, FirstNullIndex, WritePst;
	int aStartCount, aFbCount, aMsCount, aVaCount, aHP;

	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	
	for(i=0; i<ieMsgLinkage.Count; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == aFullPath){
			MsgReadTmp.Splite.Data1 = aNewTime;
			LinkageMsgCopyOne(i);
		}
	}

	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	ieGot = 1;	*/
}

void TControlCenter::iePushOneMsgLinkageStartCancel(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	int aStartCount, aFbCount, aMsCount, aVaCount, aDelayCount, aStopCount, aHP, aBroadcastCount;
	unsigned char aP0, aP1, EpSta;
	
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	if( (aIm.Splite.P0 >0 )  && (aIm.Splite.P0 <= dPORT_MAX_COUNT) ){
		if(aP1 >= dEP_MAX_COUNT_PER_PORT)return;
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			Port[aP0].DelayTick[aP1] = 0;
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return;
			}else{
				Port[aP0].StateTable[aP1] &= ~(dEpStateBitStart);
			}
		}else{
			EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			EpSta &= ~(dEpStateBitStart);
			SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}else
	if( (aIm.Splite.P0 >= dADDR_DIRECTPAD_START) && (aIm.Splite.P0 <= dADDR_DIRECTPAD_END )){
		if(aP1 >= dDIRECTCTL_KEY_MAX_COUNT)return;
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			aP0 = aIm.Splite.P0 -dADDR_DIRECTPAD_START;
			if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
				DirectCtlBoard[aP0].DelayTick[aP1] = 0;
			}
		}
	}
	
	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	Cnt = 0;
	i =0;
	
	FirstNullIndex = ieMSG_LINKAGE_MAX_COUNT +1000;
	Cnt = 0;
	aStartCount = 0;
	aFbCount = 0;
	aMsCount = 0;
	aVaCount = 0;
	aBroadcastCount =0;
	aHP =0;
	aDelayCount = 0;
	aStopCount = 0;
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  ( MsgReadTmp.D32[2] == aIm.D32[2]) && ( etLinkageStart == MsgReadTmp.Splite.mType ) ){
				LinkageMsgClearOne(i);
				if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_LINKAGE_MAX_COUNT){
				LinkageMsgCopyOne(FirstNullIndex);
				LinkageMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.mType == etLinkageStart){	
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x0A)){
					aDelayCount++;
				}else
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x09)){
					aStopCount++;
				}else{
					aStartCount++;
					//if(MsgReadTmp.Splite.Data1 == StartTypeSimulate){
						
					//}else{
						if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
							//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
								aVaCount++;
							//}
						}else
						if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
							aHP++;
						}else
						if(MsgReadTmp.Splite.dType == dASSIGN_TYPE_Broadcast){
							aBroadcastCount++;
						}
					//}
				}
			}else
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				aFbCount ++;
				if(MsgReadTmp.Splite.Data0 == 0x04){
					aMsCount++;
				}
			}
		}
	}
	
	ieMsgLinkage.Count = Cnt;
	ieMsgLinkage.StartCount = aStartCount;
	ieMsgLinkage.FbCount = aFbCount;
	ieMsgLinkage.MissingCount = aMsCount;
	ieMsgLinkage.VaCount = aVaCount;
	ieMsgLinkage.BroadcastCount = aBroadcastCount;
	ieMsgLinkage.HydrantPadCount = aHP;
	ieMsgLinkage.DelayCount = aDelayCount;
	ieMsgLinkage.StopCount = aStopCount;
	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	
	BroadcastAlternatingUpdate();
	
	if(IsMute == 0){
		if( (ieMsgLinkage.Count == 0) && (AlarmSoundWhat >0) ){
			if( (ieMsgSv.Count > 0) && (IsMuteSv == 0) ){
				AlarmSoundWhat = 2;
			}else
			if( (ieMsgFault.Count > 0) && (IsMuteFault == 0) ){
				AlarmSoundWhat = 3;
			}else{
				AlarmSoundWhat = 7;
			}
		}
	}
	
	ieGot = 1;
}


int TControlCenter::iePushOneMsgLinkageStartCancelSimulate(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	int aStartCount, aFbCount, aMsCount, aVaCount, aDelayCount, aStopCount, aHP, aBroadcastCount;
	unsigned char aP0, aP1, EpSta;
	int IsPadEvent;
	
	IsPadEvent = 0;
	
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(  ( MsgReadTmp.D32[2] == aIm.D32[2]) && ( etLinkageStart == MsgReadTmp.Splite.mType ) ){
			if(MsgReadTmp.Splite.Data1 != StartTypeSimulate)
				return 0;
		}
	}
	
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	if( (aIm.Splite.P0 >0 )  && (aIm.Splite.P0 <= dPORT_MAX_COUNT) ){
		if(aP1 >= dEP_MAX_COUNT_PER_PORT)return 0;
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			if(Port[aP0].DelayToDoEventType[aP1])Port[aP0].DelayTick[aP1] = 0;
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return 0;
			}
		}else{
			//EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			//EpSta &= ~(dEpStateBitStart);
			//SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}else
	if( (aIm.Splite.P0 >= dADDR_DIRECTPAD_START) && (aIm.Splite.P0 <= dADDR_DIRECTPAD_END )){
		if(aP1 >= dDIRECTCTL_KEY_MAX_COUNT)return 0;
		aP0 = aIm.Splite.P0 -dADDR_DIRECTPAD_START;
		IsPadEvent = 1;
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			if(DirectCtlBoard[aP0].DelayToDoEventType[aP1]){
				DirectCtlBoard[aP0].DelayTick[aP1] = 0;
			}
		}
	}
	
	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	Cnt = 0;
	i =0;
	
	FirstNullIndex = ieMSG_LINKAGE_MAX_COUNT +1000;
	Cnt = 0;
	aStartCount = 0;
	aFbCount = 0;
	aMsCount = 0;
	aVaCount = 0;
	aBroadcastCount =0;
	aHP =0;
	aDelayCount = 0;
	aStopCount = 0;
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  ( MsgReadTmp.D32[2] == aIm.D32[2]) && ( etLinkageStart == MsgReadTmp.Splite.mType ) && (StartTypeSimulate == MsgReadTmp.Splite.Data1) ){
				LinkageMsgClearOne(i);
				if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_LINKAGE_MAX_COUNT){
				LinkageMsgCopyOne(FirstNullIndex);
				LinkageMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.mType == etLinkageStart){	
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x0A)){
					aDelayCount++;
				}else
				if(MsgReadTmp.Splite.Data0 == static_cast<unsigned char>(0x09)){
					aStopCount++;
				}else{
					aStartCount++;
					//if(MsgReadTmp.Splite.Data1 == StartTypeSimulate){
						
					//}else{
						if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
							//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
								aVaCount++;
							//}
						}else
						if(MsgReadTmp.Splite.dType == dgTYPE_FIRE_HydrantKp){
							aHP++;
						}else
						if(MsgReadTmp.Splite.dType == dASSIGN_TYPE_Broadcast){
							aBroadcastCount++;
						}
					//}
				}
			}else
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				aFbCount ++;
				if(MsgReadTmp.Splite.Data0 == 0x04){
					aMsCount++;
				}
			}
		}
	}
	
	ieMsgLinkage.Count = Cnt;
	ieMsgLinkage.StartCount = aStartCount;
	ieMsgLinkage.FbCount = aFbCount;
	ieMsgLinkage.MissingCount = aMsCount;
	ieMsgLinkage.VaCount = aVaCount;
	ieMsgLinkage.BroadcastCount = aBroadcastCount;
	ieMsgLinkage.HydrantPadCount = aHP;
	ieMsgLinkage.DelayCount = aDelayCount;
	ieMsgLinkage.StopCount = aStopCount;
	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	
	BroadcastAlternatingUpdate();
	
	if(IsMute == 0){
		if( (ieMsgLinkage.Count == 0) && (AlarmSoundWhat >0) ){
			if( (ieMsgSv.Count > 0) && (IsMuteSv == 0) ){
				AlarmSoundWhat = 2;
			}else
			if( (ieMsgFault.Count > 0) && (IsMuteFault == 0) ){
				AlarmSoundWhat = 3;
			}else{
				AlarmSoundWhat = 7;
			}
		}
	}
	
	ieGot = 1;
	
	if(IsPadEvent)return 1;
	else return 0;
}

void TControlCenter::iePushOneMsgLinkageFb(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	int aFbCount, aMsCount;
	unsigned char aP0, aP1, EpSta;
	int tPumpFbCnt, tPumpFbLocalCnt;
	
	tPumpFbCnt = 0; tPumpFbLocalCnt = 0;
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return;
			}else{
				if(aIm.Splite.iByte0 == 0x04){
					Port[aP0].StateTable[aP1] |= dEpStateBitFbMiss;
				}else{
					Port[aP0].StateTable[aP1] |= dEpStateBitFeedBack;
				}
			}
		}else{
			EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			if(aIm.Splite.iByte0 == 0x04){
				EpSta |= dEpStateBitFbMiss;
			}else{
				EpSta |= dEpStateBitFeedBack;
			}
			SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}
	
	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	
	FirstNullIndex = ieMSG_LINKAGE_MAX_COUNT +1000;
	Cnt = 0;
	aFbCount = 0;
	aMsCount = 0;
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  (MsgReadTmp.D32[2] == aIm.D32[2]) && (etLinkageFeedBack == MsgReadTmp.Splite.mType) ){
				LinkageMsgClearOne(i);
				if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_LINKAGE_MAX_COUNT){
				LinkageMsgCopyOne(FirstNullIndex);
				LinkageMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				aFbCount ++;
				if(MsgReadTmp.Splite.dType == dFIREPUMP_ASSIGN_TYPE){
					if(MsgReadTmp.Splite.Data1 != StartTypeSimulate){
						tPumpFbCnt++;
						if(MsgReadTmp.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
							tPumpFbLocalCnt++;
						}
					}
				}
				if(MsgReadTmp.Splite.Data0 == 0x04){
					aMsCount++;
				}
			}
		}
	}
	WritePst = Cnt;
	if(Cnt >= ieMSG_LINKAGE_MAX_COUNT){
		for(i=0; i< (ieMSG_LINKAGE_MAX_COUNT -1); i++){
			LinkageGetViaPath(i+1);
			LinkageMsgCopyOne(i);
		}
		WritePst = ieMSG_LINKAGE_MAX_COUNT -1;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	if(MsgReadTmp.Splite.dType == dFIREPUMP_ASSIGN_TYPE){
		tPumpFbCnt++;
		if(MsgReadTmp.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			tPumpFbLocalCnt++;
		}
	}

	MsgReadTmp.Splite.mType = etLinkageFeedBack;
	MsgReadTmp.Splite.Data0 = aIm.Splite.iByte0;
	MsgReadTmp.Splite.Data1 = 0;
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.State = ieStateActive;
	LinkageMsgCopyOne(WritePst);
	
	ieMsgLinkage.Count = WritePst +1;
	ieMsgLinkage.FbCount = aFbCount +1;
	ieMsgLinkage.PumpFbCount = tPumpFbCnt;
	ieMsgLinkage.PumpFbLocalCount = tPumpFbLocalCnt;
	if(aIm.Splite.iByte0 == 0x04){
		ieMsgLinkage.MissingCount = aMsCount +1;
	}else{
		ieMsgLinkage.MissingCount = aMsCount;
	}
	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	
	if(AlarmSoundWhat > 1)AlarmSoundWhat = 1;
	
	IsMuteLnk = 0;
	IsMute = 0;
	
	ieGot = 1;	
}

int TControlCenter::iePushOneMsgLinkageFbSimulate(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	int aFbCount, aMsCount;
	unsigned char aP0, aP1, EpSta;
	int tPumpFbCnt, tPumpFbLocalCnt;
	
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  (MsgReadTmp.D32[2] == aIm.D32[2]) && (etLinkageFeedBack == MsgReadTmp.Splite.mType)){
			if(MsgReadTmp.Splite.Data1 != StartTypeSimulate){
				return 0;
			}
		}
	}
	
	tPumpFbCnt = 0; tPumpFbLocalCnt=0;
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return 0;
			}else{
				if(aIm.Splite.iByte0 == 0x04){
					//Port[aP0].StateTable[aP1] |= dEpStateBitFbMiss;
				}else{
					//Port[aP0].StateTable[aP1] |= dEpStateBitFeedBack;
				}
			}
		}else{
			//EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			if(aIm.Splite.iByte0 == 0x04){
				//EpSta |= dEpStateBitFbMiss;
			}else{
				//EpSta |= dEpStateBitFeedBack;
			}
			//SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}
	
	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	
	FirstNullIndex = ieMSG_LINKAGE_MAX_COUNT +1000;
	Cnt = 0;
	aFbCount = 0;
	aMsCount = 0;
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  (MsgReadTmp.D32[2] == aIm.D32[2]) && (etLinkageFeedBack == MsgReadTmp.Splite.mType) ){
				LinkageMsgClearOne(i);
				if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_LINKAGE_MAX_COUNT){
				LinkageMsgCopyOne(FirstNullIndex);
				LinkageMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				aFbCount ++;
				if(MsgReadTmp.Splite.dType == dFIREPUMP_ASSIGN_TYPE){
					if(MsgReadTmp.Splite.Data1 != StartTypeSimulate){
						tPumpFbCnt++;
						if(MsgReadTmp.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
							tPumpFbLocalCnt++;
						}
					}
				}
				if(MsgReadTmp.Splite.Data0 == 0x04){
					aMsCount++;
				}
			}
		}
	}
	WritePst = Cnt;
	if(Cnt >= ieMSG_LINKAGE_MAX_COUNT){
		for(i=0; i< (ieMSG_LINKAGE_MAX_COUNT -1); i++){
			LinkageGetViaPath(i+1);
			LinkageMsgCopyOne(i);
		}
		WritePst = ieMSG_LINKAGE_MAX_COUNT -1;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	//Is Simulate
	//if(MsgReadTmp.Splite.dType == dFIREPUMP_ASSIGN_TYPE){
	//	tPumpFbCnt++;
	//}
	MsgReadTmp.Splite.mType = etLinkageFeedBack;
	MsgReadTmp.Splite.Data0 = aIm.Splite.iByte0;
	MsgReadTmp.Splite.Data1 = StartTypeSimulate;
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.State = ieStateActive;
	LinkageMsgCopyOne(WritePst);
	
	ieMsgLinkage.Count = WritePst +1;
	ieMsgLinkage.FbCount = aFbCount +1;
	ieMsgLinkage.PumpFbCount = tPumpFbCnt;
	ieMsgLinkage.PumpFbLocalCount = tPumpFbLocalCnt;
	
	if(aIm.Splite.iByte0 == 0x04){
		ieMsgLinkage.MissingCount = aMsCount +1;
	}else{
		ieMsgLinkage.MissingCount = aMsCount;
	}
	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	
	if(AlarmSoundWhat > 1)AlarmSoundWhat = 1;
	
	IsMuteLnk = 0;
	IsMute = 0;
	
	ieGot = 1;
	return 1;
}

void TControlCenter::ieManualPushOneMsgLinkageFb(TRecordCommon aIm)
{
	iePushOneMsgLinkageFb(aIm);
	ExRecord.SetStateCodeFeedBack();
	FecBusCRT.SetStateCodeFeedBack();
}

void TControlCenter::iePushOneMsgLinkageFbCancel(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	int aFbCount, aMsCount;
	unsigned char aP0, aP1, EpSta;
	int tPumpFbCnt, tPumpFbLocalCnt;;
	
	tPumpFbCnt = 0; tPumpFbLocalCnt =0;
	
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return;
			}else{
				Port[aP0].StateTable[aP1] &= ~(dEpStateBitFeedBack + dEpStateBitFbMiss);
			}
		}else{
			EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			EpSta  &= ~(dEpStateBitFeedBack + dEpStateBitFbMiss);
			SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}
	
	ieMsgLinkage.RequestRead =0;
	ieMsgLinkage.Lock = 1;
	
	FirstNullIndex = ieMSG_LINKAGE_MAX_COUNT +1000;
	Cnt = 0;
	aFbCount = 0;
	aMsCount = 0;
	for(i=0; i<ieMSG_LINKAGE_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT)FirstNullIndex = i;
		}else
		if(  (MsgReadTmp.D32[2] == aIm.D32[2]) && (etLinkageFeedBack == MsgReadTmp.Splite.mType) ){
				LinkageMsgClearOne(i);
				if(FirstNullIndex > ieMSG_LINKAGE_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_LINKAGE_MAX_COUNT){
				LinkageMsgCopyOne(FirstNullIndex);
				LinkageMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				aFbCount ++;
				if(MsgReadTmp.Splite.dType == dFIREPUMP_ASSIGN_TYPE){
					if(MsgReadTmp.Splite.Data1 != StartTypeSimulate){
						tPumpFbCnt++;
						if(MsgReadTmp.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
							tPumpFbLocalCnt++;
						}
					}
				}
				if(MsgReadTmp.Splite.Data0 == 0x04){
					aMsCount++;
				}
			}
		}
	}
	
	
	ieMsgLinkage.Count = Cnt;
	ieMsgLinkage.FbCount = aFbCount;
	ieMsgLinkage.PumpFbCount = tPumpFbCnt;
	ieMsgLinkage.PumpFbLocalCount = tPumpFbLocalCnt;
	if(aIm.Splite.iByte0 == 0x04)
		ieMsgLinkage.MissingCount = aMsCount +1;
	else
		ieMsgLinkage.MissingCount = aMsCount;
	ieMsgLinkage.ReflashIndex++;
	ieMsgLinkage.Lock = 0;
	
	if(IsMute == 0){
		if( (ieMsgLinkage.Count == 0) && (AlarmSoundWhat >0) ){
			if( (ieMsgSv.Count > 0) && (IsMuteSv == 0) ){
				AlarmSoundWhat = 2;
			}else
			if( (ieMsgFault.Count > 0) && (IsMuteFault == 0) ){
				AlarmSoundWhat = 3;
			}else{
				AlarmSoundWhat = 7;
			}
		}
	}
	
	ieGot = 1;	
}

void TControlCenter::iePushOneMsgFault(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	int aVaCount, aFbCount, aMsCount;
	volatile unsigned char aP0, aP1, EpSta;
	
	aP0 = aIm.Splite.P0;
	aP1 = aIm.Splite.P1;
	aP0--;
	aP1--;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return;
			}else{
				Port[aP0].StateTable[aP1] |= dEpStateBitFault;
			}
		}else{
			EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			EpSta  |= dEpStateBitFault;
			SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}	
	
	ieMsgFault.RequestRead =0;
	ieMsgFault.Lock = 1;
	
	FirstNullIndex = ieMSG_FAULT_MAX_COUNT +1000;
	Cnt = 0;
	aVaCount = 0;
	for(i=0; i<ieMSG_FAULT_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		FaultGetViaPath(i);
		if( (MsgReadTmp.D32[2] == 0) || (MsgReadTmp.Splite.State == 0) ){
		//if( MsgReadTmp.D32[2] == 0 ){
			if( (MsgReadTmp.D32[2] != 0) && (MsgReadTmp.Splite.State == 0))
				aP1 = 0;
			if(FirstNullIndex > ieMSG_FAULT_MAX_COUNT)FirstNullIndex = i;
		}else
		if( MsgReadTmp.D32[2] == aIm.D32[2]){
				FaultMsgClearOne(i);
				if(FirstNullIndex > ieMSG_FAULT_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_FAULT_MAX_COUNT){
				FaultMsgCopyOne(FirstNullIndex);
				FaultMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
				//if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
					aVaCount++;
				//}
			}
		}
	}
	WritePst = Cnt;
	if(Cnt >= ieMSG_FAULT_MAX_COUNT){
		for(i=0; i< (ieMSG_FAULT_MAX_COUNT -1); i++){
			FaultGetViaPath(i+1);
			FaultMsgCopyOne(i);
		}
		WritePst = ieMSG_FAULT_MAX_COUNT -1;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	__nop();
	__nop();
	MsgReadTmp.Splite.State = ieStateActive;
	__nop();
	__nop();
	FaultMsgCopyOne(WritePst);
	if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
		if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
			aVaCount++;
		}
	}
	ieMsgFault.VaCount = aVaCount;
	
	ieMsgFault.Count = WritePst +1;
	ieMsgFault.ReflashIndex++;
	ieMsgFault.Lock = 0;
	
	ExRecord.SetStateCodeFault();
	FecBusCRT.SetStateCodeFault();
	
	if(AlarmSoundWhat > 3)AlarmSoundWhat = 3;
	IsMuteFault = 0;
	IsMute = 0;
	
	ieGot = 1;	
}

void TControlCenter::iePushOneMsgFaultCancel(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	int aVaCount;
	unsigned char aP0, aP1, EpSta;
	
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return;
			}else{
				Port[aP0].StateTable[aP1] &= ~dEpStateBitFault;
			}
		}else{
			EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			EpSta  &= ~dEpStateBitFault;
			SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}
	
	ieMsgFault.RequestRead =0;
	ieMsgFault.Lock = 1;
	
	FirstNullIndex = ieMSG_FAULT_MAX_COUNT +1000;
	Cnt = 0;
	aVaCount = 0;
	for(i=0; i<ieMSG_FAULT_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		FaultGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_FAULT_MAX_COUNT)FirstNullIndex = i;
		}else
		if( MsgReadTmp.D32[2] == aIm.D32[2]){
				FaultMsgClearOne(i);
				if(FirstNullIndex > ieMSG_FAULT_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_FAULT_MAX_COUNT){
				FaultMsgCopyOne(FirstNullIndex);
				FaultMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
			if(MsgReadTmp.Splite.dType == dgType_VAALRAM){
				if( (MsgReadTmp.Splite.P0 >0 ) && (MsgReadTmp.Splite.P0 <= dPORT_MAX_COUNT) ) {
					aVaCount++;
				}
			}
		}
	}
	
	ieMsgFault.Count = Cnt;
	ieMsgFault.VaCount = aVaCount;
	ieMsgFault.ReflashIndex++;
	ieMsgFault.Lock = 0;
	
	ExRecord.SetStateCodeFault();
	FecBusCRT.SetStateCodeFault();
	
	if(IsMute == 0){
		if( (ieMsgFault.Count == 0) && (AlarmSoundWhat >2) ){
			AlarmSoundWhat = 7;
		}
	}
	
	ieGot = 1;	
}


void TControlCenter::iePushOneMsgSv(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	unsigned char aP0, aP1, EpSta, aAssignType;
	
	aP0 = aIm.Splite.P0;
	aP1 = aIm.Splite.P1;
	aP0--;
	aP1--;
	aAssignType =0;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			aAssignType = Port[aP0].AssignType[aP1];
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return;
			}else{
				Port[aP0].StateTable[aP1] |= dEpStateBitSv;
			}
		}else{
			EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			EpSta  |= dEpStateBitSv;
			SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}	
	
	ieMsgSv.RequestRead =0;
	ieMsgSv.Lock = 1;
	
	FirstNullIndex = ieMSG_SV_MAX_COUNT +1000;
	Cnt = 0;
	for(i=0; i<ieMSG_SV_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		SvGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_SV_MAX_COUNT)FirstNullIndex = i;
		}else
		if( MsgReadTmp.D32[2] == aIm.D32[2]){
				SvMsgClearOne(i);
				if(FirstNullIndex > ieMSG_SV_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_SV_MAX_COUNT){
				SvMsgCopyOne(FirstNullIndex);
				SvMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
		}
	}
	WritePst = Cnt;
	if(Cnt >= ieMSG_SV_MAX_COUNT){
		for(i=0; i< (ieMSG_SV_MAX_COUNT -1); i++){
			SvGetViaPath(i+1);
			SvMsgCopyOne(i);
		}
		WritePst = ieMSG_SV_MAX_COUNT -1;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.Data1 = 0;
	__nop();
	__nop();
	MsgReadTmp.Splite.State = ieStateActive;
	__nop();
	__nop();
	SvMsgCopyOne(WritePst);
	
	const unsigned int tInx = FiredUserCode.Count;
	FiredUserCode.uCode[tInx] = aIm.Splite.UserCode;
	FiredUserCode.AreaNum[tInx] = aIm.Splite.AreaNum;
	FiredUserCode.dType[tInx] = aIm.Splite.dType;
	FiredUserCode.AssignType[tInx] = 0;
	FiredUserCode.eType[tInx] = LinkInputTypeSv;
	if(FiredUserCode.Count < (dLINK_INPUT_MAX_COUNT -2))FiredUserCode.Count++;
	
	ieMsgSv.Count = WritePst +1;
	ieMsgSv.ReflashIndex++;
	ieMsgSv.Lock = 0;
	
	if(AlarmSoundWhat > 2)AlarmSoundWhat = 2;
	
	IsMuteSv = 0;
	IsMute = 0;
	
	ieGot = 1;
}

int TControlCenter::iePushOneMsgSvSimulate(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	unsigned char aP0, aP1, EpSta, aAssignType;
	
	for(i=0; i<ieMSG_SV_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		SvGetViaPath(i);
		if( (MsgReadTmp.D32[2] == aIm.D32[2]) && (MsgReadTmp.Splite.Data1 != StartTypeSimulate) ){
				return 0;
		}
	}
	
	aP0 = aIm.Splite.P0;
	aP1 = aIm.Splite.P1;
	aP0--;
	aP1--;
	aAssignType =0;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			aAssignType = Port[aP0].AssignType[aP1];
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return 0;
			}else{
				Port[aP0].StateTable[aP1] |= dEpStateBitSv;
			}
		}else{
			//EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			//EpSta  |= dEpStateBitSv;
			//SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}	
	
	ieMsgSv.RequestRead =0;
	ieMsgSv.Lock = 1;
	
	FirstNullIndex = ieMSG_SV_MAX_COUNT +1000;
	Cnt = 0;
	for(i=0; i<ieMSG_SV_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		SvGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_SV_MAX_COUNT)FirstNullIndex = i;
		}else
		if( MsgReadTmp.D32[2] == aIm.D32[2]){
				SvMsgClearOne(i);
				if(FirstNullIndex > ieMSG_SV_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_SV_MAX_COUNT){
				SvMsgCopyOne(FirstNullIndex);
				SvMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
		}
	}
	WritePst = Cnt;
	if(Cnt >= ieMSG_SV_MAX_COUNT){
		for(i=0; i< (ieMSG_SV_MAX_COUNT -1); i++){
			SvGetViaPath(i+1);
			SvMsgCopyOne(i);
		}
		WritePst = ieMSG_SV_MAX_COUNT -1;
	}
	
	MsgReadTmp.D32[0] = aIm.D32[0];
	MsgReadTmp.D32[1] = aIm.D32[1];
	MsgReadTmp.D32[2] = aIm.D32[2];
	MsgReadTmp.D32[3] = aIm.D32[3];
	MsgReadTmp.D32[4] = aIm.D32[4];
	MsgReadTmp.D32[5] = aIm.D32[5];
	MsgReadTmp.Splite.iByte0 = 0; //is UnRead
	MsgReadTmp.Splite.Data1 = StartTypeSimulate;
	MsgReadTmp.Splite.State = ieStateActive;
	SvMsgCopyOne(WritePst);
	
	const unsigned int tInx = FiredUserCode.Count;
	FiredUserCode.uCode[tInx] = aIm.Splite.UserCode;
	FiredUserCode.AreaNum[tInx] = aIm.Splite.AreaNum;
	FiredUserCode.dType[tInx] = aIm.Splite.dType;
	FiredUserCode.AssignType[tInx] = 0;
	FiredUserCode.eType[tInx] = LinkInputTypeSvSimulate;
	if(FiredUserCode.Count < (dLINK_INPUT_MAX_COUNT -2))FiredUserCode.Count++;
	
	ieMsgSv.Count = WritePst +1;
	ieMsgSv.ReflashIndex++;
	ieMsgSv.Lock = 0;
	
	if(AlarmSoundWhat > 2)AlarmSoundWhat = 2;
	
	IsMuteSv = 0;
	IsMute = 0;
	
	ieGot = 1;
	return 1;
}


void TControlCenter::iePushOneMsgSvCancel(TRecordCommon aIm)
{
	int i,Cnt, FirstNullIndex, WritePst;
	unsigned char aP0, aP1, EpSta;
	
	aP0 = aIm.Splite.P0 -1;
	aP1 = aIm.Splite.P1 -1;
	if( (aP0 < dPORT_MAX_COUNT) && (aP1 < dEP_MAX_COUNT_PER_PORT) ){
		if(aIm.Splite.PCtlNum == MainCtl.fData.Split.MyNum){
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				return;
			}else{
				Port[aP0].StateTable[aP1] &= ~dEpStateBitSv;
			}
		}else{
			EpSta = GetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1);
			EpSta  &= ~dEpStateBitSv;
			SetNetworkEpState(aIm.Splite.PCtlNum, aIm.Splite.P0, aIm.Splite.P1, EpSta);
		}
	}
	
	ieMsgSv.RequestRead =0;
	ieMsgSv.Lock = 1;
	
	FirstNullIndex = ieMSG_SV_MAX_COUNT +1000;
	Cnt = 0;
	for(i=0; i<ieMSG_SV_MAX_COUNT; i++){
		//To Find Dual, And Clear it
		SvGetViaPath(i);
		if(MsgReadTmp.D32[2] == 0){
			if(FirstNullIndex > ieMSG_SV_MAX_COUNT)FirstNullIndex = i;
		}else
		if( MsgReadTmp.D32[2] == aIm.D32[2]){
				SvMsgClearOne(i);
				if(FirstNullIndex > ieMSG_SV_MAX_COUNT){
					FirstNullIndex = i;
				}
		}else{
			if(FirstNullIndex < ieMSG_SV_MAX_COUNT){
				SvMsgCopyOne(FirstNullIndex);
				SvMsgClearOne(i);
				FirstNullIndex++;
			}
			Cnt++;
		}
	}
	
	ieMsgSv.Count = Cnt;
	ieMsgSv.ReflashIndex++;
	ieMsgSv.Lock = 0;
	
	if(IsMute == 0){
		if( (ieMsgSv.Count == 0) && (AlarmSoundWhat >1) ){
			if( (ieMsgFault.Count > 0) && (IsMuteFault == 0) ){
				AlarmSoundWhat = 3;
			}else{
				AlarmSoundWhat = 7;
			}
		}
	}
	
	ieGot = 1;	
}

void TControlCenter::LoadCurrentDateTime2RecordCommon(TRecordCommon *pIm)
{
	pIm->Splite.Year = DateTime.Date.Split.Year;
	pIm->Splite.Month = DateTime.Date.Split.Month;
	pIm->Splite.Day = DateTime.Date.Split.Day;
	pIm->Splite.Hour = DateTime.Time.Split.Hour;
	pIm->Splite.Minute = DateTime.Time.Split.Minute;
	pIm->Splite.Second = DateTime.Time.Split.Second;	
}

void TControlCenter::ieAddDevFault(unsigned char aDevFaultType, unsigned char DevIndex)
{
	TRecordCommon aIm;

	LoadCurrentDateTime2RecordCommon(&aIm);	
	aIm.Splite.mType = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xD0;			//Board Index
	aIm.Splite.P1 = DevIndex;
	aIm.Splite.P2 = aDevFaultType;	//Fault Type
	aIm.Splite.dType = 0;			
	aIm.Splite.Data0 = aDevFaultType;	//Fault Type
	aIm.Splite.Data1 = 0xD1;//Is Set=1  Recover=0
	aIm.Splite.iByte0	= CmdActiveDefaultSet[cmOtherErr][8];
		
	iePushOneMsgFault(aIm);
	Record.FaultAdd(aIm);
	
	if(MainCtl.fData.Split.NetworkMode == 2)ProtoC2C.oBufMsgInsertFault(aIm, cmOtherErr);
}

void TControlCenter::ieAddDevFaultCancel(unsigned char aDevFaultType, unsigned char DevIndex)
{
	TRecordCommon aIm;
	
	LoadCurrentDateTime2RecordCommon(&aIm);
	aIm.Splite.mType = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xD0;			//Board Index
	aIm.Splite.P1 = DevIndex;
	aIm.Splite.P2 = aDevFaultType;	//Fault Type
	aIm.Splite.dType = 0;			
	aIm.Splite.Data0 = aDevFaultType;	//Fault Type
	aIm.Splite.Data1 = 0xD0;//Is Set=1  Recover=0
	aIm.Splite.iByte0	= CmdActiveDefaultSet[cmOtherErr][8];
	
	iePushOneMsgFaultCancel(aIm);
	Record.FaultAdd(aIm);
	
	if(MainCtl.fData.Split.NetworkMode == 2)ProtoC2C.oBufMsgInsertFault(aIm, cmOtherErr);
}

void TControlCenter::ieAddPadFault(unsigned char aP0, unsigned char aFaultType)
{
	TRecordCommon aIm;

	LoadCurrentDateTime2RecordCommon(&aIm);	
	aIm.Splite.mType = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xC0;			//Pad's Type
	aIm.Splite.P1 = aP0;
	aIm.Splite.P2 = aFaultType;		//Fault Type
	aIm.Splite.dType = 0;			
	aIm.Splite.Data0 = aFaultType;	//Fault Type
	aIm.Splite.Data1 = 0xC1;		//Is Set=1  Recover=0
	aIm.Splite.iByte0	= CmdActiveDefaultSet[cmOtherErr][8];
	
	iePushOneMsgFault(aIm);
	Record.FaultAdd(aIm);
	
	if(MainCtl.fData.Split.NetworkMode == 2)ProtoC2C.oBufMsgInsertFault(aIm, cmOtherErr);
}

void TControlCenter::ieAddPadFaultCancel(unsigned char aP0, unsigned char aFaultType)
{
	TRecordCommon aIm;
	
	LoadCurrentDateTime2RecordCommon(&aIm);
	aIm.Splite.mType = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xC0;			//Board Index
	aIm.Splite.P1 = aP0;			//Pad Addr
	aIm.Splite.P2 = aFaultType;	//Fault Type
	aIm.Splite.dType = 0;			
	aIm.Splite.Data0 = aFaultType;	//Fault Type
	aIm.Splite.Data1 = 0xC0;//Is Set=1  Recover=0
	aIm.Splite.iByte0	= CmdActiveDefaultSet[cmOtherErr][8];
	
	iePushOneMsgFaultCancel(aIm);
	Record.FaultAdd(aIm);
	
	if(MainCtl.fData.Split.NetworkMode == 2)ProtoC2C.oBufMsgInsertFault(aIm, cmOtherErr);
}
		
void TControlCenter::iePushOneMsg(TRecordCommon aIm, unsigned char aCmd)
{
	unsigned char aCtlNum, aP0, aP1;
	unsigned int ReturnByMask = 0;
	unsigned int CheckPathOK =0;
	aCtlNum = aIm.Splite.PCtlNum;
	if(aCtlNum == MainCtl.fData.Split.MyNum){
		aP0 = aIm.Splite.P0 -1;
		aP1 = aIm.Splite.P1 -1;
		if(aP0 < dPORT_MAX_COUNT){
			if(Port[aP0].StateTable[aP1] & dEpStateBitMask){
				ReturnByMask = 1;
			}
		}
	}
	if(aIm.Splite.mType == etFire){
		if(ReturnByMask)return;
		if(aCmd == cmPublishAlram){
			if(IsMsgReseting == 0){
				iePushOneMsgFire(aIm,0);
				//ProtoC2C.MasterDoPublishFire(aCtlNum, aIm.Splite.P0, aIm.Splite.P1,  aIm.Splite.dType);
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtFire);
				ExRecord.SetStateCodeFire();
				FecBusCRT.SetStateCodeFire();
				Record.FireAdd(aIm);
			}
		}else 
		if(aCmd == cmConfirmAlram){
			if(IsMsgReseting == 0){
				iePushOneMsgFire(aIm,0);
				ExRecord.SetStateCodeFire();
				FecBusCRT.SetStateCodeFire();
				//ProtoC2C.MasterDoPublishFire(aCtlNum, aIm.Splite.P0, aIm.Splite.P1,  aIm.Splite.dType);
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtNormal);
			}
		}else 
		if(aCmd == cmPublishPreAlramResume){
			if(IsMsgReseting == 0);
		}
	}else
	if(aIm.Splite.mType == etFault){
		if(aCmd == cmPortModuleErr){
			if(ReturnByMask)return;
			if(IsMsgReseting == 0){
				iePushOneMsgFault(aIm);
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtFault);
				Record.FaultAdd(aIm);
			}
		}else 
		if(aCmd == cmCircuitErr){
			if(aIm.Splite.Data1 & 0x01){
				iePushOneMsgFault(aIm);
			}else{
				iePushOneMsgFaultCancel(aIm);
			}
			Record.FaultAdd(aIm); 
			ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtFault);
		}else 
		if(aCmd == cmOtherErr){
			if(aIm.Splite.Data1 & 0x01){
				iePushOneMsgFault(aIm);
			}else{
				iePushOneMsgFaultCancel(aIm);
			}
			Record.FaultAdd(aIm);
			ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtFault);
		}
	}else
	if(aIm.Splite.mType == etFaultCancel){
		if(ReturnByMask)return;
		if(aCmd == cmPortModuleErrRecover){
			if(IsMsgReseting == 0){
				iePushOneMsgFaultCancel(aIm);
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtFault);
				Record.FaultAdd(aIm);
			}
		} 
	}else
	if(aIm.Splite.mType == etSuperVi){
		if(ReturnByMask)return;
		if(aCmd == cmTakeChargeAlram){
			iePushOneMsgSv(aIm);
			ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtSv);
			ExRecord.SetStateCodeSv();
			FecBusCRT.SetStateCodeSv();
			Record.SvAdd(aIm);
		}
	}else
	if(aIm.Splite.mType == etSuperViCancel){
		if(ReturnByMask)return;
		if(aCmd == cmTakeChargeAlramResume){
			//iePushOneMsgSvCancel(aIm);
			ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtSv);
			ExRecord.SetStateCodeSv();
			FecBusCRT.SetStateCodeSv();
			Record.SvAdd(aIm);
		}
	}
	if(aIm.Splite.mType == etLinkageStart){
		if(IsMsgReseting == 0){
			if((aIm.Splite.P0==0)||(aIm.Splite.P1==0))return;
			if(aIm.Splite.P0<=dPORT_MAX_COUNT){
				if(aIm.Splite.P1<=dEP_MAX_COUNT_PER_PORT)
					CheckPathOK =1;
			}
			if( (aIm.Splite.P0>=dADDR_DIRECTPAD_START) && (aIm.Splite.P0<=dADDR_DIRECTPAD_END) ){
				if(aIm.Splite.P1 <= dDIRECTCTL_KEY_MAX_COUNT)
					CheckPathOK =1;
			}
			if(CheckPathOK==0)return;
			if(aCmd == cmManualStart){
				iePushOneMsgLinkageStart(aIm);
				ExRecord.SetStateCodeStart();
				FecBusCRT.SetStateCodeStart();
				Record.LinkageAdd(aIm);
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtLink);
			}else
			if(aCmd == cmAutoStart){
				iePushOneMsgLinkageStart(aIm);
				ExRecord.SetStateCodeStart();
				FecBusCRT.SetStateCodeStart();
				Record.LinkageAdd(aIm);
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtLink);
			}else
			if(aCmd == cmVAAlramStart){
				//From Ctl
				iePushOneMsgLinkageStart(aIm);
				ExRecord.SetStateCodeStart();
				FecBusCRT.SetStateCodeStart();
				Record.LinkageAdd(aIm);
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtLink);
			}
			CheckHydrantKpAction();
		}
	}else
	if(aIm.Splite.mType == etLinkageStartCancel){
		//Record.StartAdd(aIm);
		if(IsMsgReseting == 0){
			if(aCmd == cmManualStop){
				iePushOneMsgLinkageStartCancel(aIm);
				ExRecord.SetStateCodeStart();
				FecBusCRT.SetStateCodeStart();
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtLink);
				
				aIm.Splite.iByte0 = 0xB1;
				Record.LinkageAdd(aIm);
			}else
			if(aCmd == cmAutoStop){
				iePushOneMsgLinkageStartCancel(aIm);
				ExRecord.SetStateCodeStart();
				FecBusCRT.SetStateCodeStart();
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtLink);
				
				aIm.Splite.iByte0 = 0xB1;
				Record.LinkageAdd(aIm);
			}else
			if(aCmd == cmVAAlramStop){
				//From Ctl
				iePushOneMsgLinkageStartCancel(aIm);
				ExRecord.SetStateCodeStart();
				FecBusCRT.SetStateCodeStart();
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtLink);
			}
			CheckHydrantKpAction();
		}
	}else
	if(aIm.Splite.mType == etLinkageFeedBack){
		if(IsMsgReseting == 0){
			if(aCmd == cmAck){
				int HasPrc =0;
				if(aCtlNum == MainCtl.fData.Split.MyNum){
					if( (aIm.Splite.P0) && (aIm.Splite.P1) ){
						if( (aIm.Splite.P0 <= dPORT_MAX_COUNT) && (aIm.Splite.P1 <= dEP_MAX_COUNT_PER_PORT) ){
							unsigned char tP0, tP1, tFbits;
							tP0=aIm.Splite.P0-1; tP1=aIm.Splite.P1-1; 
							if( 	(Port[aP0].dTypeTable[tP1] == dgTYPE_IN_MODULE) ||
								(Port[aP0].dTypeTable[tP1] == dgTYPE_INOUT_MODULE_NonSource) ||
								(Port[aP0].dTypeTable[tP1] == dgTYPE_INOUT_MODULE_Source) ){
								//0x01 FeedBack	0x02 Fire   0x04 SV
									if( (Port[tP0].FuncSetByte[tP1] & 0x07) == 0x02){
										if(ReturnByMask == 0){
											for(int i=0; i<6; i++)aImForceConvert.D32[i] = aIm.D32[i];
											aImForceConvert.Splite.mType = etFire;
											iePushOneMsgFire(aImForceConvert,0);
											//ProtoC2C.MasterDoPublishFire(aCtlNum, aIm.Splite.P0, aIm.Splite.P1,  aIm.Splite.dType);
											ProtoC2C.SlaveDoSend2MasterMachine(aImForceConvert, cmPublishAlram,  TProtoC2C::mtFire);
											ExRecord.SetStateCodeFire();
											FecBusCRT.SetStateCodeFire();
											Record.FireAdd(aImForceConvert);
										}
										HasPrc =1;
									}else
									if( (Port[tP0].FuncSetByte[tP1] & 0x07) ==  0x04){
										if(ReturnByMask == 0){
											for(int i=0; i<6; i++)aImForceConvert.D32[i] = aIm.D32[i];
											aImForceConvert.Splite.mType = etSuperVi;
											iePushOneMsgSv(aImForceConvert);
											ProtoC2C.SlaveDoSend2MasterMachine(aImForceConvert, cmTakeChargeAlram, TProtoC2C::mtSv);
											ExRecord.SetStateCodeSv();
											FecBusCRT.SetStateCodeSv();
											Record.SvAdd(aImForceConvert);
										}
										HasPrc =1;
									}																
							}
						}
					}
				}
				if(HasPrc == 0){
					iePushOneMsgLinkageFb(aIm);
					ExRecord.SetStateCodeFeedBack();
					FecBusCRT.SetStateCodeFeedBack();
					Record.LinkageAdd(aIm);
					ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtLink);
				}
			}else
			if(aCmd == cmAckMiss){
				iePushOneMsgLinkageFb(aIm);
				ExRecord.SetStateCodeFeedBack();
				FecBusCRT.SetStateCodeFeedBack();
				Record.LinkageAdd(aIm);
				ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd, TProtoC2C::mtLink);
			}
		}
	}else
	if(aIm.Splite.mType == etLinkageFeedBackCancel){
		if(IsMsgReseting == 0){
			if(aCmd == cmAckStop){
				int HasPrc =0;
				if(aCtlNum == MainCtl.fData.Split.MyNum){
					if( (aIm.Splite.P0) && (aIm.Splite.P1) ){
						if( (aIm.Splite.P0 <= dPORT_MAX_COUNT) && (aIm.Splite.P1 <= dEP_MAX_COUNT_PER_PORT) ){
							unsigned char tP0, tP1, tFbits;
							tP0=aIm.Splite.P0-1; tP1=aIm.Splite.P1-1; 
							if( 	(Port[aP0].dTypeTable[tP1] == dgTYPE_IN_MODULE) ||
								(Port[aP0].dTypeTable[tP1] == dgTYPE_INOUT_MODULE_NonSource) ||
								(Port[aP0].dTypeTable[tP1] == dgTYPE_INOUT_MODULE_Source) ){
								//0x01 FeedBack	0x02 Fire   0x04 SV
								if( (Port[tP0].FuncSetByte[tP1] & 0x07) == 0x02){
									if(ReturnByMask == 0){
										//Fire with No Cancel
									}										
									HasPrc =1;
								}
								if( (Port[tP0].FuncSetByte[tP1] & 0x07) == 0x04){
									if(ReturnByMask == 0){
										//SV with No Cancel 
									}
									HasPrc =1;
								}																
							}
						}
					}
				}
				if(HasPrc == 0){
					iePushOneMsgLinkageFbCancel(aIm);
					ExRecord.SetStateCodeFeedBack();
					FecBusCRT.SetStateCodeFeedBack();
					ProtoC2C.SlaveDoSend2MasterMachine(aIm, aCmd,  TProtoC2C::mtLink);
				}
			}
		}
	}else
	if(aIm.Splite.mType == etReport){
		if(aCmd == cmPortRegistFinished){
			Register.iePushOneMsgReport(aIm, aCmd);
		}else
		if(aCmd == cmPortRegistProgress){
			Register.iePushOneMsgReport(aIm, aCmd);
		}else
		if(aCmd == cmQueryPortReg){
			CtrlStartUp.iePushOneMsgReport(aIm, aCmd);
			Register.iePushOneMsgReport(aIm, aCmd);
		}
	}
}

unsigned int TControlCenter::ieFireMsgConfAddr(unsigned int FullPath)
{
	unsigned int tUc;
	int i;
	tUc = 100000000;
	if(ieMsgFire.Count >ieMSG_FIRE_MAX_COUNT)ieMsgFire.Count = ieMSG_FIRE_MAX_COUNT;
	for(i=0; i<ieMsgFire.Count; i++){
		FireGetViaPath(i);
		if(MsgReadTmp.D32[2] == FullPath){
			MsgReadTmp.Splite.iByte0 = 1;
			tUc = MsgReadTmp.Splite.UserCode;
			FireMsgCopyOne(i);
		}
	}
	return tUc;
}

void TControlCenter::ieLinkageMsgStartConfAddr(unsigned int FullPath)
{
	int i;
	for(i=0; i<ieMsgLinkage.Count; i++){
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == FullPath){
			if(MsgReadTmp.Splite.mType == etLinkageStart){
				MsgReadTmp.Splite.iByte0 = 1;
				LinkageMsgCopyOne(i);
			}
		}
	}	
}

void TControlCenter::ieLinkageMsgFbConfAddr(unsigned int FullPath)
{
	int i;
	for(i=0; i<ieMsgLinkage.Count; i++){
		LinkageGetViaPath(i);
		if(MsgReadTmp.D32[2] == FullPath){
			if(MsgReadTmp.Splite.mType == etLinkageFeedBack){
				MsgReadTmp.Splite.iByte0 = 1;
				LinkageMsgCopyOne(i);
			}
		}
	}	
}

unsigned int TControlCenter::ieFaultMsgFaultConfAddr(unsigned int FullPath)
{
	unsigned int tUc;
	int i;
	tUc = 100000000;
	if(ieMsgFault.Count >ieMSG_FAULT_MAX_COUNT)ieMsgFault.Count = ieMSG_FAULT_MAX_COUNT;
	for(i=0; i<ieMsgFault.Count; i++){
		FaultGetViaPath(i);
		if(MsgReadTmp.D32[2] == FullPath){
			MsgReadTmp.Splite.iByte0 = 1;
			tUc = MsgReadTmp.Splite.UserCode;
			FaultMsgCopyOne(i);
		}
	}
	return tUc;
}

void TControlCenter::ieManageMsgFire(void)
{

}

void TControlCenter::ieManageMsgSv(void)
{
	
}

void TControlCenter::TaskFreeRun(void)
{
	
}

void TControlCenter::InspecDataCheck()
{
	int i;
	unsigned char aP0;
	if(InspecData.IsStartCheck){
		for(i=0; i<dPORT_MAX_COUNT; i++){
			if(MainCtl.fData.Split.ExistTablePort[i]){
				
			}
		}
		for(i=0; i<dHANDCTL_MAX_COUNT; i++){
			if(HandCtlBoard[i].PadIsProhibit == 0){
				if(InspecData.BusPad[i] == 0){
					if(InspecData.ErrBusPad[i] == 0){
						//Push Err Msg
						InspecData.ErrBusPad[i] = 1;
						ieAddPadFault(i + dADDR_HANDPAD_START, 2);
					}
				}else{
					if(InspecData.ErrBusPad[i]){
						//Cancel Err Msg
						InspecData.ErrBusPad[i] = 0;
						ieAddPadFaultCancel(i + dADDR_HANDPAD_START, 2);
					}
				}
			}
		}
		for(i=0; i<dDIRECTCTL_MAX_COUNT; i++){
			if(DirectCtlBoard[i].PadIsProhibit == 0){
				if(InspecData.DirectPad[i] == 0){
					if(InspecData.ErrDirectPad[i] == 0){
						//Push Err Msg
						InspecData.ErrDirectPad[i] = 1;
						ieAddPadFault(i + dADDR_DIRECTPAD_START, 2);
					}
				}else{
					if(InspecData.ErrDirectPad[i]){
						//Cancel Err Msg
						InspecData.ErrDirectPad[i] = 0;
						ieAddPadFaultCancel(i + dADDR_DIRECTPAD_START, 2);
					}
				}
			}
		}
	}
}

void TControlCenter::InspecTask()
{
	int i;
	InspecData.tick++;
	if(InspecData.tick > 39){
		//Check State First
		InspecDataCheck();
		InspecDataRestart();
		InspecData.IsStartCheck = 1;
		InspecData.tick = 0;
		
		tData[1] =0; tData[1] =0;
		tData[2] =0; tData[3] =0; tData[4] =0; tData[5] =0; tData[6] =0; tData[7] =0;
		InnerCan.OBufInsert(1, cmInspection, tData, 1);
	}	
}

void TControlCenter::PushInspecRpy(unsigned char Path0, unsigned char Prm)
{
	unsigned char aHpPath;
	if( (Path0 >= dADDR_HANDPAD_START) && (Path0 <= dADDR_HANDPAD_END) ){
		aHpPath = Path0 - dADDR_HANDPAD_START;
		InspecData.BusPad[aHpPath] = 1;
	}else
	if( (Path0 >= dADDR_DIRECTPAD_START) && (Path0 <= dADDR_DIRECTPAD_END) ){
		aHpPath = Path0 - dADDR_DIRECTPAD_START;
		InspecData.DirectPad[aHpPath] = 1;
	}
}

void TControlCenter::CheckBatUpdate()
{
	if(PsBatData.Body.HasUpdate){
		PsBatData.Body.HasUpdate = 0;
		if( 	(PsBatData.Body.BatVoltage1.D16 != PsBatDataOld.Body.BatVoltage1.D16) ||
			(PsBatData.Body.BatVoltage2.D16 != PsBatDataOld.Body.BatVoltage2.D16) ||
			(PsBatData.Body.BatEnerger1 != PsBatDataOld.Body.BatEnerger1) ||
			(PsBatData.Body.BatEnerger2 != PsBatDataOld.Body.BatEnerger2) || 
			(PsBatDataAva == 0) 				){
				PsBatDataOld.Body.BatVoltage1.D16 = PsBatData.Body.BatVoltage1.D16;
				PsBatDataOld.Body.BatVoltage2.D16 = PsBatData.Body.BatVoltage2.D16;
				PsBatDataOld.Body.BatEnerger1 = PsBatData.Body.BatEnerger1;
				PsBatDataOld.Body.BatEnerger2 = PsBatData.Body.BatEnerger2;
				StateBarUpDateBat(1);
		}
		PsBatUpDateTick = 0;
	}else{
		PsBatUpDateTick++;
		if(PsBatUpDateTick > 20){
			PsBatUpDateTick = 30;
			StateBarUpDateBat(0);
		}
	}
}

void TControlCenter::MaskCountSet(int aCnt)
{
	ieMsgMask.Count = aCnt;
	EventShow.MsgList[4].Count = ieMsgMask.Count;
	EventShow.MsgList[4].NewCount = ieMsgMask.Count;
	EventShow.TryGetMaskData(2,20240428);
	CtlCenter.ieMsgMask.ReflashIndex ++;
	CtlCenter.ieGot = 1;
	
	ExRecord.SetStateCodeMask();
	FecBusCRT.SetStateCodeMask();
}

void TControlCenter::SingleCtlModeSendMaskInf2Crt()
{
	volatile int i, x;
	volatile unsigned int sAddr, MaskCount, suExit;
	TRecordCommon aRC;
	for(i=0; i<ieMsgMask.Count; i++){
		sAddr = dAddrSdRam_MsgMask + i *24;
		aRC.D32[0] = *(volatile unsigned int *)(sAddr + 0);
		aRC.D32[1] = *(volatile unsigned int *)(sAddr + 4);
		aRC.D32[2] = *(volatile unsigned int *)(sAddr + 8);
		aRC.D32[3] = *(volatile unsigned int *)(sAddr + 12);
		FecBusCRT.iFecBusCRTOperateInsert(aRC);
	}
	
	FecBusCRT.SetStateCodeMask();
}

void TControlCenter::Task1Ms(void)
{
	SysFreeTick1Ms++;
}

void TControlCenter::DisplayPadCheckCircuit(int Ord)
{
	int i, x, iA,bx, ex;
	unsigned char aCn, aP0, aP1;
	unsigned char BeginAddr;
	unsigned char EndAddr;
	TDMix	mVal;
	unsigned int Trigger;
	
	if(MainCtl.fData.Split.ExistTablePort[Ord]){
		if(Port[Ord].DisplayPadCount){
			if(Port[Ord].DisplayPadCount > dDISPLAYPAD_MAX_COUNT)Port[Ord].DisplayPadCount = dDISPLAYPAD_MAX_COUNT;
			for(i=0; i<Port[Ord].DisplayPadCount; i++){
				//if(DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].CtlNum > dNETWORK_MACHINE_COUNT)continue;
				//if(DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].CtlNum == 0)continue;
				//if(DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].P0 > dPORT_MAX_COUNT)continue;
				//if(DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].P0 == 0)continue;
				Trigger = 0;
				for(x=0; x<3; x++){
					//aCn = DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].CtlNum;
					//aP0 = DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].P0;
					//BeginAddr = DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].BeginAddr;
					//EndAddr = DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].EndAddr;
					aP0--;
					BeginAddr--;
					EndAddr--;
					if(aCn == MainCtl.fData.Split.MyNum){
						for(iA=BeginAddr; iA<EndAddr; iA++){
							if(Port[aP0].StateTable[iA] & dEpStateBitFire){
								Trigger = 1;
								break;
							}
						}
					}else{
						for(iA=BeginAddr; iA<EndAddr; iA++){
							mVal.D16[0] = GetNetworkEpData(aCn,aP0,iA);
							if(mVal.D8[0] & dEpStateBitFire){
								Trigger = 1;
								break;
							}
						}
					}
				}
				if(Trigger){
					DisplayPadBuf.WriteIndex++;
					if(DisplayPadBuf.WriteIndex >= dDiplayPadCtlBufMaxCount)DisplayPadBuf.WriteIndex = 0;
					
					//DisplayPadBuf.Body[DisplayPadBuf.WriteIndex].P0 = Ord;
					//DisplayPadBuf.Body[DisplayPadBuf.WriteIndex].P1 = Port[Ord].DisplayPadAddr[i];
					
					//DisplayPadBuf.Source[DisplayPadBuf.WriteIndex].CtlNum = DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].CtlNum;;
					//DisplayPadBuf.Source[DisplayPadBuf.WriteIndex].P0 = DisplayPadRt.Entry[Ord][i].Spl.UsingPath[x].P0;
					//DisplayPadBuf.Source[DisplayPadBuf.WriteIndex].P1 = iA +1;;
					//DisplayPadBuf.Source[DisplayPadBuf.WriteIndex].dType = mVal.D8[1];
					break;
				}
			}
		}
	}	
}

void TControlCenter::DisplayPadCheckByIndex()
{
	int ex, AreaGot;
	unsigned char tP0, tP1;
	unsigned short cArea;
	unsigned int Addr_Sd;
	TUserCodeStr tCode, tCodeNot;
	TUserCodeStr cCode, cmpCode;
	if(DisplayPadPrcFireIndex < ieMsgFire.Count){
		FireGetViaPath(DisplayPadPrcFireIndex);
		cArea = MsgReadTmp.Splite.AreaNum;
		cCode.Spl.BcdText_7 = this->MsgReadTmp.Splite.UserCode / 10000000 % 10; 
		cCode.Spl.BcdText_6 = this->MsgReadTmp.Splite.UserCode / 1000000 % 10;
		cCode.Spl.BcdText_5 = this->MsgReadTmp.Splite.UserCode / 100000 % 10;
		cCode.Spl.BcdText_4 = this->MsgReadTmp.Splite.UserCode / 10000 % 10;
		cCode.Spl.BcdText_3 = this->MsgReadTmp.Splite.UserCode / 1000 % 10;
		cCode.Spl.BcdText_2 = this->MsgReadTmp.Splite.UserCode / 100 % 10;
		cCode.Spl.BcdText_1 = this->MsgReadTmp.Splite.UserCode / 10 % 10;
		cCode.Spl.BcdText_0 = this->MsgReadTmp.Splite.UserCode / 1 % 10;
		for(tP0=0; tP0<dPORT_MAX_COUNT; tP0++){
			if(MainCtl.fData.Split.ExistTablePort[tP0]){
				if(Port[tP0].DisplayPadCount){
					for(ex=0; ex<dDISPLAYPAD_MAX_COUNT; ex++){
						if(Port[tP0].DisplayPadSet[ex].Addr){
							tP1 = Port[tP0].DisplayPadSet[ex].Addr-1;
							if( (Port[tP0].ExistTable[tP1] == 0xA5) && (Port[tP0].dTypeTable[tP1] == dgTYPE_DISPLAY_PAD) ){
								if(Port[tP0].DisplayPadSet[ex].CfgBits & TPort::DisplayPadByAreaModeBit){
									//Area Mode
									AreaGot =0;
									if( (Port[tP0].DisplayPadSet[ex].CfgBits & TPort::DisplayPadUsingAreaEx0) && (Port[tP0].DisplayPadSet[ex].AreaEx[0] != 0) ){
										//Area Num 0
										if(cArea == Port[tP0].DisplayPadSet[ex].AreaEx[0]){
											DisplayPadBuf.WriteIndex++;
											if(DisplayPadBuf.WriteIndex >= dDiplayPadCtlBufMaxCount)DisplayPadBuf.WriteIndex = 0;
											DisplayPadBuf.BodyTmp.Body.P0 = tP0 +1;
											DisplayPadBuf.BodyTmp.Body.P1 = tP1 +1;
											DisplayPadBuf.BodyTmp.Body.SourceInx = DisplayPadPrcFireIndex;
											Addr_Sd = dAddrSdRam_DisplayPadBuf + (DisplayPadBuf.WriteIndex * 8);
											*(volatile unsigned int*)(Addr_Sd + 0) = DisplayPadBuf.BodyTmp.D32[0];
											*(volatile int*)(Addr_Sd + 4) = DisplayPadBuf.BodyTmp.D32[1];
											AreaGot =1;
										}
									}
									if( (Port[tP0].DisplayPadSet[ex].CfgBits & TPort::DisplayPadUsingAreaEx1) && (Port[tP0].DisplayPadSet[ex].AreaEx[1] != 0) ){
										//Area Num 1
										if( (cArea == Port[tP0].DisplayPadSet[ex].AreaEx[1]) && (AreaGot == 0) ){
											DisplayPadBuf.WriteIndex++;
											if(DisplayPadBuf.WriteIndex >= dDiplayPadCtlBufMaxCount)DisplayPadBuf.WriteIndex = 0;
											DisplayPadBuf.BodyTmp.Body.P0 = tP0 +1;
											DisplayPadBuf.BodyTmp.Body.P1 = tP1 +1;
											DisplayPadBuf.BodyTmp.Body.SourceInx = DisplayPadPrcFireIndex;
											Addr_Sd = dAddrSdRam_DisplayPadBuf + (DisplayPadBuf.WriteIndex * 8);
											*(volatile unsigned int*)(Addr_Sd + 0) = DisplayPadBuf.BodyTmp.D32[0];
											*(volatile int*)(Addr_Sd + 4) = DisplayPadBuf.BodyTmp.D32[1];
											AreaGot =1;
										}
									}
									if( (Port[tP0].DisplayPadSet[ex].CfgBits & TPort::DisplayPadUsingAreaEx2) && (Port[tP0].DisplayPadSet[ex].AreaEx[2] != 0) ){
										//Area Num 2
										if( (cArea == Port[tP0].DisplayPadSet[ex].AreaEx[2]) && (AreaGot == 0) ){
											DisplayPadBuf.WriteIndex++;
											if(DisplayPadBuf.WriteIndex >= dDiplayPadCtlBufMaxCount)DisplayPadBuf.WriteIndex = 0;
											DisplayPadBuf.BodyTmp.Body.P0 = tP0 +1;
											DisplayPadBuf.BodyTmp.Body.P1 = tP1 +1;
											DisplayPadBuf.BodyTmp.Body.SourceInx = DisplayPadPrcFireIndex;
											Addr_Sd = dAddrSdRam_DisplayPadBuf + (DisplayPadBuf.WriteIndex * 8);
											*(volatile unsigned int*)(Addr_Sd + 0) = DisplayPadBuf.BodyTmp.D32[0];
											*(volatile int*)(Addr_Sd + 4) = DisplayPadBuf.BodyTmp.D32[1];
										}
									}
								}else{
									if( (Port[tP0].DisplayPadSet[ex].CfgBits & TPort::DisplayPadUsingUcEx0) && (Port[tP0].DisplayPadSet[ex].UcList[0].Full != 0) ){
										//User Code 0
										tCode.Full = Port[tP0].DisplayPadSet[ex].UcList[0].Full;
										tCodeNot.Full =0;
										if(tCode.Spl.BcdText_0 == 10){tCode.Spl.BcdText_0 = 0xF; tCodeNot.Spl.BcdText_0 = 0xF;}
										if(tCode.Spl.BcdText_1 == 10){tCode.Spl.BcdText_1 = 0xF; tCodeNot.Spl.BcdText_1 = 0xF;}
										if(tCode.Spl.BcdText_2 == 10){tCode.Spl.BcdText_2 = 0xF; tCodeNot.Spl.BcdText_2 = 0xF;} 
										if(tCode.Spl.BcdText_3 == 10){tCode.Spl.BcdText_3 = 0xF; tCodeNot.Spl.BcdText_3 = 0xF;}
										if(tCode.Spl.BcdText_4 == 10){tCode.Spl.BcdText_4 = 0xF; tCodeNot.Spl.BcdText_4 = 0xF;} 
										if(tCode.Spl.BcdText_5 == 10){tCode.Spl.BcdText_5 = 0xF; tCodeNot.Spl.BcdText_5 = 0xF;} 
										if(tCode.Spl.BcdText_6 == 10){tCode.Spl.BcdText_6 = 0xF; tCodeNot.Spl.BcdText_6 = 0xF;} 
										if(tCode.Spl.BcdText_7 == 10){tCode.Spl.BcdText_7 = 0xF; tCodeNot.Spl.BcdText_7 = 0xF;}
										cmpCode.Full = cCode.Full | tCodeNot.Full; 
										if(cmpCode.Full == tCode.Full){
											DisplayPadBuf.WriteIndex++;
											if(DisplayPadBuf.WriteIndex >= dDiplayPadCtlBufMaxCount)DisplayPadBuf.WriteIndex = 0;
											DisplayPadBuf.BodyTmp.Body.P0 = tP0 +1;
											DisplayPadBuf.BodyTmp.Body.P1 = tP1 +1;
											DisplayPadBuf.BodyTmp.Body.SourceInx = DisplayPadPrcFireIndex;
											Addr_Sd = dAddrSdRam_DisplayPadBuf + (DisplayPadBuf.WriteIndex * 8);
											*(volatile unsigned int*)(Addr_Sd + 0) = DisplayPadBuf.BodyTmp.D32[0];
											*(volatile int*)(Addr_Sd + 4) = DisplayPadBuf.BodyTmp.D32[1];
										}
									}
									if( (Port[tP0].DisplayPadSet[ex].CfgBits & TPort::DisplayPadUsingUcEx1) && (Port[tP0].DisplayPadSet[ex].UcList[1].Full != 0) ){
										//User Code 1
										tCode.Full = Port[tP0].DisplayPadSet[ex].UcList[1].Full;
										tCodeNot.Full =0;
										if(tCode.Spl.BcdText_0 == 10){tCode.Spl.BcdText_0 = 0xF; tCodeNot.Spl.BcdText_0 = 0xF;}
										if(tCode.Spl.BcdText_1 == 10){tCode.Spl.BcdText_1 = 0xF; tCodeNot.Spl.BcdText_1 = 0xF;}
										if(tCode.Spl.BcdText_2 == 10){tCode.Spl.BcdText_2 = 0xF; tCodeNot.Spl.BcdText_2 = 0xF;} 
										if(tCode.Spl.BcdText_3 == 10){tCode.Spl.BcdText_3 = 0xF; tCodeNot.Spl.BcdText_3 = 0xF;}
										if(tCode.Spl.BcdText_4 == 10){tCode.Spl.BcdText_4 = 0xF; tCodeNot.Spl.BcdText_4 = 0xF;} 
										if(tCode.Spl.BcdText_5 == 10){tCode.Spl.BcdText_5 = 0xF; tCodeNot.Spl.BcdText_5 = 0xF;} 
										if(tCode.Spl.BcdText_6 == 10){tCode.Spl.BcdText_6 = 0xF; tCodeNot.Spl.BcdText_6 = 0xF;} 
										if(tCode.Spl.BcdText_7 == 10){tCode.Spl.BcdText_7 = 0xF; tCodeNot.Spl.BcdText_7 = 0xF;}
										cmpCode.Full = cCode.Full | tCodeNot.Full; 
										if(cmpCode.Full == tCode.Full){
											DisplayPadBuf.WriteIndex++;
											if(DisplayPadBuf.WriteIndex >= dDiplayPadCtlBufMaxCount)DisplayPadBuf.WriteIndex = 0;
											DisplayPadBuf.BodyTmp.Body.P0 = tP0 +1;
											DisplayPadBuf.BodyTmp.Body.P1 = tP1 +1;
											DisplayPadBuf.BodyTmp.Body.SourceInx = DisplayPadPrcFireIndex;
											Addr_Sd = dAddrSdRam_DisplayPadBuf + (DisplayPadBuf.WriteIndex * 8);
											*(volatile unsigned int*)(Addr_Sd + 0) = DisplayPadBuf.BodyTmp.D32[0];
											*(volatile int*)(Addr_Sd + 4) = DisplayPadBuf.BodyTmp.D32[1];
										}
									}
								}
							}
						}
					}
					
				}
			}
		}
		DisplayPadPrcFireIndex++;
	}
}

int TControlCenter::DipalayPadSendPathType()
{
	TCanHeaderID aIde;
	unsigned int i;
	unsigned int Len;
	
	if(get_can_tx_complete() == 0)return 0;
	
	Len =8;
	
	aIde.BitF.Cmd = cmSendDisplayPadInf;
	for(i=0; i<8; i++){
		tData[i] = 0;
	}
	
	tData[0] = 0;
	tData[1] = DisplayPadPath.P0;
	tData[2] = DisplayPadPath.P1;
	tData[3] = 1;
	tData[4] = DisplayPadTriggerSource.CtlNum;
	tData[5] = DisplayPadTriggerSource.P0;
	tData[6] = DisplayPadTriggerSource.P1;
	tData[7] = DisplayPadTriggerSource.dType;
	
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	InnerCan.CmdSendCustom(aIde, tData, Len);
	return 1;
}

int TControlCenter::DipalayPadSendYearMonth()
{
	TCanHeaderID aIde;
	unsigned int i;
	unsigned int Len;
	
	
	if(get_can_tx_complete() == 0)return 0;
	Len =6;
	aIde.BitF.Cmd = cmSendDisplayPadInf;
	for(i=0; i<8; i++){
		tData[i] = 0;
	}
	tData[0] = 0;
	tData[1] = DisplayPadPath.P0;
	tData[2] = DisplayPadPath.P1;
	tData[3] = 2;
	tData[4] = DisplayYearMonth.D8[1];
	tData[5] = DisplayYearMonth.D8[0];
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	InnerCan.CmdSendCustom(aIde, tData, Len);
	return 1;
}

int TControlCenter::DipalayPadSendDayTime()
{
	TCanHeaderID aIde;
	unsigned int i;
	unsigned int Len;
	
	if(get_can_tx_complete() == 0)return 0;
	
	Len =8;
	
	aIde.BitF.Cmd = cmSendDisplayPadInf;
	for(i=0; i<8; i++){
		tData[i] = 0;
	}
	
	tData[0] = 0;
	tData[1] = DisplayPadPath.P0;
	tData[2] = DisplayPadPath.P1;
	tData[3] = 3;
	tData[4] = DisplayDayTime.D8[3];
	tData[5] = DisplayDayTime.D8[2];
	tData[6] = DisplayDayTime.D8[1];
	tData[7] = DisplayDayTime.D8[0];

	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	InnerCan.CmdSendCustom(aIde, tData, Len);
	
	return 1;
}

void TControlCenter::DisplayPadGoSend()
{  
	if(DisplaySendingWhat == 1){
		if(get_can_tx_complete()){
			//0:ACK	1:»ØÂ·ºÅ	2:µØÖ·ºÅ	3:·ÖÖ¡ºÅ    4:»úÆ÷ºÅ 5:»ØÂ·ºÅ 6:µØÖ· 7:ÀàÐÍ 
			if(DipalayPadSendPathType())
				DisplaySendingWhat ++;
		}
	}else
	if(DisplaySendingWhat == 2){
		//dAddrSdram_FireTime
		if(get_can_tx_complete()){
			//0:ACK	1:»ØÂ·ºÅ	2:µØÖ·ºÅ	3:·ÖÖ¡ºÅ     4:Äê 5:ÔÂ
			if(DipalayPadSendYearMonth())
				DisplaySendingWhat++;
		}
	}else
	if(DisplaySendingWhat >2) {
		if(get_can_tx_complete()){
			//0:ACK	1:»ØÂ·ºÅ	2:µØÖ·ºÅ	3:·ÖÖ¡ºÅ    4:ÈÕ 5:Ê±   6:·Ö 7:Ãë
			if(DipalayPadSendDayTime())
				DisplaySendingWhat = 0;
		}
	}
}

void TControlCenter::DisplayPadCheckToSend()
{
	unsigned int Addr_Sd;
	if(DisplayPadBuf.WriteIndex != DisplayPadBuf.ReadIndex){
		if(0 == DisplaySendingWhat){
			DisplayPadBuf.ReadIndex++;
			if(DisplayPadBuf.ReadIndex >= dDiplayPadCtlBufMaxCount)DisplayPadBuf.ReadIndex = 0;
			Addr_Sd = dAddrSdRam_DisplayPadBuf + (DisplayPadBuf.ReadIndex * 8);
			DisplayPadBuf.BodyTmp.D32[0] = *(volatile unsigned int*)(Addr_Sd + 0);
			DisplayPadBuf.BodyTmp.D32[1] = *(volatile int*)(Addr_Sd + 4);
			DisplayPadPath.P0 = DisplayPadBuf.BodyTmp.Body.P0;
			DisplayPadPath.P1 = DisplayPadBuf.BodyTmp.Body.P1;
			FireGet4DisplayPadViaIndex(DisplayPadBuf.BodyTmp.Body.SourceInx);	
			DisplayPadTriggerSource.CtlNum = DisplayPadMsg.Splite.PCtlNum; 
			DisplayPadTriggerSource.P0 = DisplayPadMsg.Splite.P0; 
			DisplayPadTriggerSource.P1 = DisplayPadMsg.Splite.P1;
			DisplayPadTriggerSource.dType = DisplayPadMsg.Splite.dType; 
			DisplayDayTime.D32 = DisplayPadMsg.D32[0];
			DisplayYearMonth.D32 = DisplayPadMsg.D32[1];
			DisplaySendingWhat = 1;
		}
	}
}

void TControlCenter::ModuleInOutCountDown()
{

}

void TControlCenter::CheckFeedBackMiss()
{
	int i,x;
	unsigned char aInx;
	FeedBackMissCount = 0;
	for(i=0; i<dPORT_MAX_COUNT; i++){
		if(MainCtl.fData.Split.ExistTablePort[i]){
			for(x=0; x<Port[i].NeedFeedBackCount; x++){
				aInx = Port[i].NeedFeedBackAddr[x];
				if(Port[i].StateTable[aInx] & dEpStateBitStart){
					if((Port[i].StateTable[aInx] & dEpStateBitFeedBack) == 0)FeedBackMissCount++;
				}
			}
		}
	}
	
	for(i=0; i<dDIRECTCTL_MAX_COUNT;i++){
		if(DirectCtlBoard[i].PadIsProhibit == 0){
			for(x=0; x<dDIRECTCTL_KEY_MAX_COUNT; x++){
				if(DirectCtlBoard[i].OutputState[x]){
					if(DirectCtlBoard[i].FeedbackState[x] ==0){
						FeedBackMissCount++;
					}
				}
			}
		}
	}
}

void TControlCenter::CheckDelayStart()
{
	int i,x;
	unsigned char StillNotStart;
	StillNotStart = 0;
	for(i=0; i<dPORT_MAX_COUNT; i++){
		if(MainCtl.fData.Split.ExistTablePort[i]){
			for(x=0; x<250; x++){
				if(Port[i].StateTable[x] & dEpStateBitDelayStart){
					if((Port[i].StateTable[x] & dEpStateBitStart) == 0){
						StillNotStart =1;
						break;
					}
				}
			}
		}
		if(StillNotStart)break;
	}
	
	for(i=0; i<dDIRECTCTL_MAX_COUNT;i++){
		if(DirectCtlBoard[i].PadIsProhibit == 0){
			for(x=0; x<dDIRECTCTL_KEY_MAX_COUNT; x++){
				if(DirectCtlBoard[i].StartDelay[x]){
					if(DirectCtlBoard[i].OutputState[x] ==0){
						StillNotStart =1;
						break;
					}
				}
			}
		}
		if(StillNotStart)break;
	}
	
	if(IsStartDelay){
		if(StillNotStart == 0){
			IsStartDelay = StillNotStart;
			//Send to Master
			if(MainCtl.fData.Split.NetworkMode == 2){
				//ProtoC2C.SlaveDoUploadStartDelay();
			}
		}
	}else{
		if(StillNotStart){
			IsStartDelay = StillNotStart;
			//Send to Master
			if(MainCtl.fData.Split.NetworkMode == 2){
				//ProtoC2C.SlaveDoUploadStartDelay();
			}
		}
	}
}

void TControlCenter::TaskDiplayPad()
{
	DisplayPadCheckByIndex();
}

void TControlCenter::DeviceRequest(unsigned char aCmd, unsigned char aReq, unsigned char aPrm)
{
	unsigned char aP0;
	if(aCmd == cmBusCtlPadConfigReq){
		if(aReq == 0){
			if( (aPrm >= dADDR_HANDPAD_START) && (aPrm <= dADDR_HANDPAD_END) ){
				aP0 = aPrm - dADDR_HANDPAD_START;
				HandCtlBoard[aP0].SendPadCfg2Pad(aP0);
				if(HandCtlBoard[aP0].PadIsProhibit == 0){
					InspecData.BusPad[aP0] = 1;
					if(InspecData.ErrBusPad[aP0]){
						//Cancel Err Msg
						InspecData.ErrBusPad[aP0] = 0;
						ieAddPadFaultCancel(aP0 + dADDR_HANDPAD_START, 2);
					}
				}
			}
		}
	}else
	if(aCmd == cmDirectPadConfigReq){
		if(aReq == 0){
			if( (aPrm >= dADDR_DIRECTPAD_START) && (aPrm <= dADDR_DIRECTPAD_END) ){
				aP0 = aPrm - dADDR_DIRECTPAD_START;
				DirectCtlBoard[aP0].SendPadCfg2Pad(aP0);
				if(DirectCtlBoard[aP0].PadIsProhibit == 0){
					InspecData.DirectPad[aP0] = 1;
					if(InspecData.ErrDirectPad[aP0]){
						//Cancel Err Msg
						InspecData.ErrDirectPad[aP0] = 0;
						ieAddPadFaultCancel(aP0 + dADDR_DIRECTPAD_START, 2);
					}
				}
			}
		}
	}
}

void TControlCenter::CheckHydrantKpAction()
{
	int i,x;
	TCanHeaderID aIde;
	if(ieMsgLinkage.HydrantPadCount >0){
		if(ieMsgLinkage.HydrantPadNewActive){
			//Make Pump On
			ieMsgLinkage.HydrantPadNewActive = 0;
			ieMsgLinkage.HydrantPadCountOld = ieMsgLinkage.HydrantPadCount;
			
			for(i=0; i<dPORT_MAX_COUNT; i++){
				if(MainCtl.fData.Split.ExistTablePort[i] && Port[i].IsIncludePump){
					for(x=0;x<dEP_MAX_COUNT_PER_PORT;x++){
						if( (Port[i].ExistTable[x] ) && (Port[i].AssignType[x] == dFIREPUMP_ASSIGN_TYPE) ){
							if( ( (Port[i].StateTable[x] & dEpStateBitStart) == 0) && ( (Port[i].StateTable[x] & dEpStateBitMask) == 0) ){
								for(int g=0; g<8; g++){
									tData[g] = 0;
								}
								tData[0] = 0;
								tData[1] = MainCtl.fData.Split.MyNum;
								tData[2] = i+1;
								tData[3] = x+1;
								tData[4] = 0;
								tData[5] = dFIREPUMP_ASSIGN_TYPE;
							
								InnerCan.OBufFastInsert(1, cmAutoStart, tData, 6);
							}
						}
					}
				}
			}
			
			//cmDirectCtlPadLinkageState	4	»úÆ÷ºÅ	¶àÏßÅÌºÅ	·ûºÏÁª¶¯Æô¶¯±êÖ¾	·ûºÏÁª¶¯Í£Ö¹±êÖ¾
			for(i=0; i<dDIRECTCTL_MAX_COUNT; i++){
				if( (DirectCtlBoard[i].PadIsProhibit == 0) && (DirectCtlBoard[i].IsIncludePump) ){
					for(x=0; x<8; x++){
						if( DirectCtlBoard[i].IsPump[x] && DirectCtlBoard[i].IsRegisted[x] ){
							if(DirectCtlBoard[i].OutputState[x] == 0){
								tData[0] = 0;
								tData[1] = MainCtl.fData.Split.MyNum;
								tData[2] = i + dADDR_DIRECTPAD_START;
								tData[3] = x +1;
								//if(AllowAuto){
									tData[4] = 2;
								//}else{
									//tData[4] = 1;
								//}
								tData[5] = 0;
								InnerCan.OBufInsert(1, cmDirectCtlPadLinkageState, tData, 6);
							}
						}
					}
				}
			}
		}
	}else{
		if(ieMsgLinkage.HydrantPadCountOld != 0){
			//Make Pump Off
			ieMsgLinkage.HydrantPadCountOld = ieMsgLinkage.HydrantPadCount;
			
			for(i=0; i<dPORT_MAX_COUNT; i++){
				if(MainCtl.fData.Split.ExistTablePort[i] && Port[i].IsIncludePump){
					for(x=0;x<dEP_MAX_COUNT_PER_PORT;x++){
						if( (Port[i].ExistTable[x] ) && (Port[i].AssignType[x] == dFIREPUMP_ASSIGN_TYPE) ){
							if( (Port[i].StateTable[x] & dEpStateBitStart) && ( (Port[i].StateTable[x] & dEpStateBitMask) == 0) ){
								for(int g=0; g<8; g++){
									tData[g] = 0;
								}
								tData[0] = 0;
								tData[1] = MainCtl.fData.Split.MyNum;
								tData[2] = i+1;
								tData[3] = x+1;
								tData[4] = 0;
								tData[5] = dFIREPUMP_ASSIGN_TYPE;
							
								InnerCan.OBufFastInsert(1, cmAutoStop, tData, 6);
							}
						}
					}
				}
			}
			
			for(i=0; i<dDIRECTCTL_MAX_COUNT; i++){
				if( (DirectCtlBoard[i].PadIsProhibit == 0) && (DirectCtlBoard[i].IsIncludePump) ){
					for(x=0; x<8; x++){
						if( DirectCtlBoard[i].IsPump[x] && DirectCtlBoard[i].IsRegisted[x] ){
							tData[0] = 0;
							tData[1] = MainCtl.fData.Split.MyNum;
							tData[2] = i +dADDR_DIRECTPAD_START;
							tData[3] = x +1;
							tData[4] = 0;
							tData[5] = 1;
							InnerCan.OBufInsert(1, cmDirectCtlPadLinkageState, tData, 6);
						}
					}
				}
			}
		}
	}
}

void TControlCenter::CheckHydrantKpActionForce()
{
	int i,x;
	if(CtlCenter.ieMsgLinkage.HydrantPadCount){
		for(i=0; i<dPORT_MAX_COUNT; i++){
			if(MainCtl.fData.Split.ExistTablePort[i] && Port[i].IsIncludePump){
				for(x=0;x<dEP_MAX_COUNT_PER_PORT;x++){
					if( (Port[i].ExistTable[x] ) && (Port[i].AssignType[x] == dFIREPUMP_ASSIGN_TYPE) ){
						if( ( (Port[i].StateTable[x] & dEpStateBitStart) == 0) && ( (Port[i].StateTable[x] & dEpStateBitMask) == 0) ){
							for(int g=0; g<8; g++){
								tData[g] = 0;
							}
							tData[0] = 0;
							tData[1] = MainCtl.fData.Split.MyNum;
							tData[2] = i+1;
							tData[3] = x+1;
							tData[4] = 0;
							tData[5] = dFIREPUMP_ASSIGN_TYPE;
						
							InnerCan.OBufFastInsert(1, cmAutoStart, tData, 6);
						}
					}
				}
			}
		}
		//Make Pump On
		CtlCenter.ieMsgLinkage.HydrantPadCountOld = CtlCenter.ieMsgLinkage.HydrantPadCount;
		//cmDirectCtlPadLinkageState	4	»úÆ÷ºÅ	¶àÏßÅÌºÅ	·ûºÏÁª¶¯Æô¶¯±êÖ¾	·ûºÏÁª¶¯Í£Ö¹±êÖ¾
		for(i=0; i<dDIRECTCTL_MAX_COUNT; i++){
			if( (DirectCtlBoard[i].PadIsProhibit == 0) && (DirectCtlBoard[i].IsIncludePump) ){
				for(x=0; x<8; x++){
					if( DirectCtlBoard[i].IsPump[x] && DirectCtlBoard[i].IsRegisted[x] ){
						tData[0] = 0;
						tData[1] = MainCtl.fData.Split.MyNum;
						tData[2] = i + dADDR_DIRECTPAD_START;
						tData[3] = x +1;
						tData[4] = 2;
						tData[5] = 0;
						InnerCan.OBufInsert(1, cmDirectCtlPadLinkageState, tData, 6);
					}
				}
			}
		}
	}
}

void TControlCenter::CheckPumpFeedBack()
{
	int i,x;//, FbTimes, NoFbTimes;
	/*FbTimes = 0;
	NoFbTimes = 0;
	for(i=0; i<dDIRECTCTL_MAX_COUNT; i++){
		if(DirectCtlBoard[i].IsIncludePump){
			for(x=0; x<8; x++){
				if( DirectCtlBoard[i].IsPump[x] ){
					if(DirectCtlBoard[i].FeedbackState[x]){
						FbTimes++;
					}else{
						NoFbTimes++;
					}
				}
			}
		}
	}*/
	if(ieMsgLinkage.PumpFbLocalCount >0){
		if(hydrantKpFbHasSend == 0){
			hydrantKpFbHasSend =1;
			//Send Ack to Hudrant
			tData[0] = 0;
			InnerCan.OBufInsert(1, cmAckHydrantCommon, tData, 1);
		}
	}else{
		if(hydrantKpFbHasSend){
			hydrantKpFbHasSend =0;
			//Send NotAck to Hudrant
			tData[0] = 0;
			InnerCan.OBufInsert(1, cmAckHydrantCancel, tData, 1);
		}
	}
}


void TControlCenter::Task1000Ms(void)
{
	PrcBroadcastAlternating();
	RelayTask();
	PortSyncTask();
	CheckPumpFeedBack();
	
	if(IsSendResetToPad){
		KeyPad.SendResetCmd();
		IsSendResetToPad = 0;
	}else
	if(IsSendSelfCheckToPad){
		KeyPad.SendSelfCheckCmd();
		IsSendSelfCheckToPad =0;
	}else
	if(KeyPad.IsSendPowerSuplyCount){
		KeyPad.SendPowerSuplyCount();
		KeyPad.IsSendPowerSuplyCount =0;
	}else{		
		if(IsSelfChecking == 0){
			InspecTask();
			SelfCheckCountDown();
			ModuleInOutCountDown();
			CheckFeedBackMiss();
			CheckDelayStart();
			//Mute
			if(  	(ieMsgFire.Count <1) && (ieMsgLinkage.Count <1) &&
				(ieMsgSv.Count <1) && (ieMsgFault.Count <1)	){
					IsMute =0;
					IsMuteFire = 0;
					IsMuteLnk= 0;
					IsMuteSv= 0;
					IsMuteFault= 0;
			}
			if(IsMute == 0xA5){
				TKeyPad::sKeyPadLedSetMute(&cState, FullOn);
			}else{
				TKeyPad::sKeyPadLedSetMute(&cState, Off);
			}
			TKeyPad::sKeyPadLedSetBuz(&cState,static_cast<unsigned char>(AlarmSoundWhat));
			//Fire
			if(ieMsgFire.Count >0){
				TKeyPad::sKeyPadLedSetAlarm(&cState,FullOn);
			}else{
				TKeyPad::sKeyPadLedSetAlarm(&cState,Off);
			}
			//Linkage
			if(ieMsgLinkage.FbCount){
				TKeyPad::sKeyPadLedSetFeedBack(&cState,FullOn);
			}else{
				TKeyPad::sKeyPadLedSetFeedBack(&cState,Off);
			}
			if(ieMsgLinkage.DelayCount){
				TKeyPad::sKeyPadLedSetStartDelay(&cState,FullOn);
			}else{
				TKeyPad::sKeyPadLedSetStartDelay(&cState,Off);
			}

			//Sv
			if(ieMsgSv.Count >0){
				TKeyPad::sKeyPadLedSetSuperSv(&cState,FullOn);
			}else{
				TKeyPad::sKeyPadLedSetSuperSv(&cState,Off);
			}
			//Fault
			if(ieMsgFault.Count >0){
				TKeyPad::sKeyPadLedSetFault(&cState,FullOn);
			}else{
				TKeyPad::sKeyPadLedSetFault(&cState,Off);
			}
			//Mask
			if(ieMsgMask.Count >0){
				TKeyPad::sKeyPadLedSetMask(&cState,FullOn);
			}else{
				TKeyPad::sKeyPadLedSetMask(&cState,Off);
			}
			
			//Alram Start
			if(ieMsgLinkage.VaCount>0){
				//Don't Care AlramVaOnOff
				TKeyPad::sKeyPadLedSetAlarmStart(&cState,FullOn);
			}else{
				TKeyPad::sKeyPadLedSetAlarmStart(&cState,Off);
			}
			
			//Alram Fault
			if(ieMsgFault.VaCount){
				TKeyPad::sKeyPadLedSetAlarmFault(&cState,FullOn);
			}else{
				TKeyPad::sKeyPadLedSetAlarmFault(&cState,Off);
			}
			
			//Load Allow State
			if(AllowAuto){
				TKeyPad::sKeyPadLedSetAutoAllowState(&cState,1);
			}else{
				TKeyPad::sKeyPadLedSetAutoAllowState(&cState,0);
			}
			
			if(AllowManual){
				TKeyPad::sKeyPadLedSetManualAllowState(&cState,1);
			}else{
				TKeyPad::sKeyPadLedSetManualAllowState(&cState,0);
			}
			
			//Screen Save
			if(GeneralDev.LcdScreenSaving){
				//TKeyPad::sKeyPadLedSetScreenSaveState(&cState,FullOn);
				TKeyPad::sKeyPadLedSetScreenSaveState(&cState,Off);
			}else{
				TKeyPad::sKeyPadLedSetScreenSaveState(&cState,Off);
			}
			
			if(MainCtl.fData.Split.NetworkMode ==1){
				if(ieMsgLinkage.StartCount >0){
					if( (FeedBackMissCount) || (NwIsFbMiss) )TKeyPad::sKeyPadLedSetStart(&cState,Flicker);
					else TKeyPad::sKeyPadLedSetStart(&cState,FullOn);
				}else{
					if(ieMsgLinkage.SatrtHasBennActive)
						TKeyPad::sKeyPadLedSetStart(&cState,Flicker);
					else
						TKeyPad::sKeyPadLedSetStart(&cState,Off);
				}
				
				
				if( ( IsSelfChecking ) || (NwIsSelfCheck) ){
					TKeyPad::sKeyPadLedSetSelfCheck(&cState,FullOn);
				}else{
					TKeyPad::sKeyPadLedSetSelfCheck(&cState,Off);
				}
				
				if( (CheckNormal.IsShowing) || (NwIsNormalCheck) ){
					TKeyPad::sKeyPadLedSetNormalCheck(&cState, FullOn);
				}else{
					TKeyPad::sKeyPadLedSetNormalCheck(&cState, Off);
				}
				
				//if( (IsStartDelay) || (NwIsStartDelay) ){
				if(ieMsgLinkage.DelayCount >0){
					TKeyPad::sKeyPadLedSetStartDelay(&cState, FullOn);
				}else{
					TKeyPad::sKeyPadLedSetStartDelay(&cState, Off);
				}
			}else
			if(MainCtl.fData.Split.NetworkMode ==2){
				if(ieMsgLinkage.StartCount >0){
					if(FeedBackMissCount)TKeyPad::sKeyPadLedSetStart(&cState,Flicker);
					else TKeyPad::sKeyPadLedSetStart(&cState,FullOn);
				}else{
					if(ieMsgLinkage.SatrtHasBennActive)
						TKeyPad::sKeyPadLedSetStart(&cState,Flicker);
					else
						TKeyPad::sKeyPadLedSetStart(&cState,Off);
				}
				
				if( IsSelfChecking ){
					TKeyPad::sKeyPadLedSetSelfCheck(&cState,FullOn);
				}else{
					TKeyPad::sKeyPadLedSetSelfCheck(&cState,Off);
				}
				
				if( (CheckNormal.IsShowing) ){
					TKeyPad::sKeyPadLedSetNormalCheck(&cState, FullOn);
				}else{
					TKeyPad::sKeyPadLedSetNormalCheck(&cState, Off);
				}
				
				//if( IsStartDelay ){
				if(ieMsgLinkage.DelayCount >0){
					TKeyPad::sKeyPadLedSetStartDelay(&cState, FullOn);
				}else{
					TKeyPad::sKeyPadLedSetStartDelay(&cState, Off);
				}
				
				if(FeedBackMissCount){
					if(KeyPad.FbMissCountOld == 0){
						ProtoC2C.SlaveReportFbMissCount(1);
						KeyPad.FbMissCountOld = 1;
					}
				}else{
					if(KeyPad.FbMissCountOld){
						ProtoC2C.SlaveReportFbMissCount(0);
						KeyPad.FbMissCountOld = 0;
					}
				}
			}else{
				if(ieMsgLinkage.StartCount >0){
					if(FeedBackMissCount)TKeyPad::sKeyPadLedSetStart(&cState,Flicker);
					else TKeyPad::sKeyPadLedSetStart(&cState,FullOn);
				}else{
					if(ieMsgLinkage.SatrtHasBennActive)
						TKeyPad::sKeyPadLedSetStart(&cState,Flicker);
					else
						TKeyPad::sKeyPadLedSetStart(&cState,Off);
				}
				
				if( IsSelfChecking ){
					TKeyPad::sKeyPadLedSetSelfCheck(&cState,FullOn);
				}else{
					TKeyPad::sKeyPadLedSetSelfCheck(&cState,Off);
				}
				
				if( (CheckNormal.IsShowing) ){
					TKeyPad::sKeyPadLedSetNormalCheck(&cState, FullOn);
				}else{
					TKeyPad::sKeyPadLedSetNormalCheck(&cState, Off);
				}
				
				//if( IsStartDelay ){
				if(ieMsgLinkage.DelayCount >0){
					TKeyPad::sKeyPadLedSetStartDelay(&cState, FullOn);
				}else{
					TKeyPad::sKeyPadLedSetStartDelay(&cState, Off);
				}
				
				KeyPad.FbMissCountOld = FeedBackMissCount;
			}
			
			KeyPad.SetLedStateViaInteger(cState.D32);

		}
	}
}


void TControlCenter::Task10Ms(void)
{
	TaskDiplayPad();
	DisplayPadCheckToSend();
	DisplayPadGoSend();
}









