#include "ProtoInnerCan.h"
#include "ProtoC2C.h"

#include "CnCpp.h"
#include "record.h"
#include "Runtime.h"
#include "server.h"
#include "Gui.h"

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

unsigned int TProtoC2C::DevDelayStartTick;

void TProtoC2C::Init()
{
	unsigned int i,x;
	NeedReply = 0;
	ErrReport = 0;
	ErrHasReport =0;
	iBufInCount = 0;
	iBufInCountPer2Sec = 0;
	
	iBuf.ReadIndex = 0;
	iBuf.WriteIndex = 0;
	oBuf.ReadIndex = 0;
	oBuf.WriteIndex = 0;
	
	oEntryBasicService.Reset();
	oEntryFire.Reset();
	oEntrySv.Reset();
	oEntryLink.Reset();
	oEntryFault.Reset();
	oEntryNormal.Reset();
	
	CheckOnlineHasStart = 0;
	CheckOnlineUpdateTick = 0;
	SlaveOnlineListOld[0] = 1;
	for(i=1; i<=dNETWORK_MACHINE_COUNT; i++)SlaveOnlineListOld[i] = 1;
	
	for(i=0; i<dNETWORK_MACHINE_COUNT; i++){
		ReportSlaveOffline[i] = 0;;
		NoAckList[i] =0;
	}
	ReportMasterOffline = 0;
	NoAckMaster = 0;
	
	for(i=0; i<dNetworkInBufMaxLength; i++){
		iBuf.Body[i].D32[0] = 0;
		iBuf.Body[i].D32[1] = 0;
		iBuf.Body[i].D32[2] = 0;
	}
	
	ShouldSyncTime = 0;
	TProtoC2C::DevDelayStartTick = 0;
	
	RemoteReq.Reg.IsRequsting = 0;
}

void TProtoC2C::iBufInsert()
{
	iBuf.WriteIndex++;
	if(iBuf.WriteIndex >= dNetworkInBufMaxLength)iBuf.WriteIndex = 0;
	RxMsg.D32[0] = iBuf.Body[iBuf.WriteIndex].D32[0];
	RxMsg.D32[1] = iBuf.Body[iBuf.WriteIndex].D32[1];
	RxMsg.D32[2] = iBuf.Body[iBuf.WriteIndex].D32[2];
	RxMsg.D32[3] = iBuf.Body[iBuf.WriteIndex].D32[3];
}

void TProtoC2C::iBufProcess()
{
	if(iBuf.ReadIndex != iBuf.WriteIndex){
		iBuf.ReadIndex++;
		if(iBuf.ReadIndex >= dNetworkInBufMaxLength)iBuf.ReadIndex = 0;
		RxMsg.D32[0] = iBuf.Body[iBuf.ReadIndex].D32[0];
		RxMsg.D32[1] = iBuf.Body[iBuf.ReadIndex].D32[1];
		RxMsg.D32[2] = iBuf.Body[iBuf.ReadIndex].D32[2];
		RxMsg.D32[3] = iBuf.Body[iBuf.ReadIndex].D32[3];
		if(RxMsg.Data.Routing == 0){
			if(MainCtl.fData.Split.NetworkMode == 1){
				MasterRxMsgProcess();
			}else
			if(MainCtl.fData.Split.NetworkMode == 2){
				SlaveRxMsgProcess();
			}
		}else
		if(RxMsg.Data.Routing == 1){
			//Master To Master M2M
			
		}else{
			// undefine
			
		}
	}
}

void TProtoC2C::MasterRxMsgProcess()
{
	unsigned char aCmd, aCtlNum, CtlByte, aEventType, NewOrder, tForceIdf;
	int i,HasPrc = 0;
	unsigned int aAddr,AllDataOK;
	unsigned int aDl, aDL2;
	
	aCtlNum = RxMsg.Data.Data[1];
	if( (aCtlNum==0) || (aCtlNum >dNETWORK_MACHINE_COUNT) )return;
	if( (aCtlNum >= CtlMask.StartNum) && (aCtlNum <= CtlMask.EndNum) ) return;
	
	aCmd = RxMsg.Data.Cmd;
	tForceIdf = RxMsg.Data.Identification;
	
	if(aCmd == dNetworkCmd_Ack){
		if(CheckIsInSlaveList(aCtlNum)){
			ProcessAckRecFromSlave(RxMsg.Data.Order, RxMsg.Data.Data);
		}
		return;
	}
	
	if(aCmd == dNetworkCmd){
		if(1){
			NwSubCmd = RxMsg.Data.Data[2];
			switch(NwSubCmd){
				case CmdC2C_AskExist:
					HasPrc =1;
					break;
				case CmdC2C_AskType:
					HasPrc =1;
					if(RxMsg.Data.Data[3] == MainCtl.fData.Split.MyNum){
						ReplyCtrlType();
					}
					break;
				case CmdC2C_AskNameLen:
					HasPrc =1;
					break;
				case CmdC2C_AskNameContent:
					HasPrc =1;
					if(RxMsg.Data.Data[3] == MainCtl.fData.Split.MyNum){
						ReplyDescp();
					}
					break;
			}
			if(HasPrc == 0){
				switch(NwSubCmd){
					case CmdC2C_RpyExist:
					case CmdC2C_RpyType:
					case CmdC2C_RpyNameLen:
					case CmdC2C_RpyNameContent:
						HasPrc =1;
						if(CanNetworkRegister.IsOnSearching){
							CanNetworkRegister.PushfNetMsg(NwSubCmd, RxMsg.Data.Data, 8);
						}
						//if(fNetworkRegManual.IsShowing){
						//	fNetworkRegManual.PushfNetMsg(NwSubCmd, RxMsg.Data.Data, 8);
						//}
						break;
					case CmdC2C_SaveMasterList:
						HasPrc =1;
						SaveM2MCfgData(RxMsg.Data.Data);
						break;
					case CmdC2C_ClearMasterList:
						HasPrc =1;
						ClearM2MCfgData(RxMsg.Data.Data);
						break;
				}
			}
			if(HasPrc == 0){
				//Master
				if(CheckIsInSlaveList(aCtlNum)){
					if(Register.IsOnShow && Register.IsOnGo && Register.IsOnNetwork && (Register.Nw.CtlNum == aCtlNum)){
						switch(NwSubCmd){
							case 	CmdC2C_DevRegRpyStart:
								Register.Nw.SlaveState =RxMsg.Data.Data[3];
								if(Register.Nw.SlaveState == 1)Register.Nw.PortCountHasUpdate =1;
								break;
							case 	CmdC2C_DevRegRpyPortCnt:
								if(RxMsg.Data.Data[3] <= 40){
									Register.MasterCanNetGetPortCount(RxMsg.Data.Data[3]);
								}
								break;
							case 	CmdC2C_DevRegRpyProgress:
								if(RxMsg.Data.Data[3] <= 100){
									Register.MasterCanNetGetProgressVal(RxMsg.Data.Data[3]);
								}
								break;
							case 	CmdC2C_DevRegRpyEpCount:
								Register.MasterCanNetGetEpCount(RxMsg.Data.Data[3], RxMsg.Data.Data[4], RxMsg.Data.Data[5]);
								break;
							case 	CmdC2C_DevRegRpyEpCompleted:
								Register.MasterCanNetGetEpCountFinished();
								break;

						}
					}
				}
			}
		}
		return;
	}else
	if(aCmd == dNetworkCmd_ReqDateTime){
		if(CheckIsInSlaveList(aCtlNum)){
			DateTimeSet();
		}
	}else
	if(aCmd == dNetworkCmd_PortExistRpy){
		fNetworkReg.PortExistGet(RxMsg.Data.Data[1], RxMsg.Data.Data[2], RxMsg.Data.Data[3]);
	}else
	if(aCmd == dNetworkCmd_DescpRpy){
		fNetworkReg.DescpListGet(RxMsg.Data.Data[1], RxMsg.Data.Data[2], RxMsg.Data.Data[3], RxMsg.Data.Data);
	}else
	if(aCmd == dNetworkCmd_CheckNormalData){
		
	}
	
	if(0 == CheckIsInSlaveList(aCtlNum))return;
	
	NewOrder = RxMsg.Data.Order;
	if(tForceIdf)OnReceive.IsProcessDone[aCtlNum] = 0;
	if(OnReceive.OrderLast[aCtlNum] != NewOrder)OnReceive.IsProcessDone[aCtlNum] = 0;
	if( OnReceive.IsProcessDone[aCtlNum] && (OnReceive.OrderAck[aCtlNum] == NewOrder ) ){
		Ack(aCtlNum, NewOrder);
		return;
	}
	OnReceive.OrderLast[aCtlNum] = NewOrder;
	
	if(CmdActiveDefaultSet[aCmd][6] == FastCall){
		aCtlNum = RxMsg.Data.Data[1];
		if( (aCtlNum !=0) && (aCtlNum <=dNETWORK_MACHINE_COUNT)){
			if(1){
				AllDataOK = 0;
				
				Record.iMsgRx.Splite.Year = RecDateTime[aCtlNum].Dt.Year;
				Record.iMsgRx.Splite.Month = RecDateTime[aCtlNum].Dt.Mon;
				Record.iMsgRx.Splite.Day = RecDateTime[aCtlNum].Dt.Day;
				Record.iMsgRx.Splite.Hour = RecDateTime[aCtlNum].Dt.Hour;
				Record.iMsgRx.Splite.Minute = RecDateTime[aCtlNum].Dt.Min;
				Record.iMsgRx.Splite.Second = RecDateTime[aCtlNum].Dt.Sec;
				
				Record.InnerMsgSet_mType	(0, CmdActiveDefaultSet[aCmd][7]);
				Record.InnerMsgSet_CtlNum	(0, RxMsg.Data.Data[1]);
				Record.InnerMsgSet_P0		(0, RxMsg.Data.Data[2]);
				Record.InnerMsgSet_P1		(0, RxMsg.Data.Data[3]);
				Record.InnerMsgSet_P2		(0, RxMsg.Data.Data[4]);
				Record.InnerMsgSet_dType	(0, RxMsg.Data.Data[5]);
				Record.InnerMsgSet_Data0	(0, 0);
				Record.InnerMsgSet_Data1	(0, 0);
				Record.InnerMsgSet_iByte0	(0, CmdActiveDefaultSet[aCmd][8]);
				Record.InnerMsgSet_iByte1	(0, 0);
				
				if(OnReceive.Piece[aCtlNum] && (OnReceive.OrderDt[aCtlNum] == NewOrder) ){
					if(aCmd == cmCircuitErr){
							Record.InnerMsgSet_P0		(0,RxMsg.Data.Data[2]);	//Cir Index
							Record.InnerMsgSet_P1		(0,0);
							Record.InnerMsgSet_P2		(0,0);
							Record.InnerMsgSet_dType	(0,0);			
							Record.InnerMsgSet_Data0	(0,0);
							Record.InnerMsgSet_Data1	(0, RxMsg.Data.Data[7]);	//Is Set=1  Recover=0
							Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[aCmd][8]);
							CtlCenter.iePushOneMsg(Record.iMsgRx, aCmd);
							AllDataOK = 1;
					}else
					if(aCmd == cmOtherErr){					
							Record.InnerMsgSet_P2		(0,RxMsg.Data.Data[6]);
							Record.InnerMsgSet_Data0	(0,RxMsg.Data.Data[6]);	//Fault Type
							Record.InnerMsgSet_Data1	(0,RxMsg.Data.Data[7]);	//Is Set=1  Recover=0
							Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[aCmd][8]);
							Record.InnerMsgSet_iByte1	(0,CtlByte);	
							CtlCenter.iePushOneMsg(Record.iMsgRx, aCmd);
							AllDataOK = 1;
					}else
					if(aCmd == cmVAAlramStart){
						if(RxMsg.Data.Data[0] == 0){
							if(OnReceive.Piece[aCtlNum]){
								Record.OperateAdd_AlramSoundOn(RxMsg.Data.Data[1], &RxMsg.Data.Data[2]);
								AllDataOK = 1;
							}
						}
					}else
					if(aCmd == cmVAAlramStop){
						if(RxMsg.Data.Data[0] == 0){
							if(OnReceive.Piece[aCtlNum]){
								Record.OperateAdd_AlramSoundOff(RxMsg.Data.Data[1], &RxMsg.Data.Data[2]);
								AllDataOK = 1;
							}
						}
					}else
					if(aCmd == cmPortModuleErr){
							Record.InnerMsgSet_P0		(0,RxMsg.Data.Data[2]);
							Record.InnerMsgSet_P1		(0,RxMsg.Data.Data[3]);
							Record.InnerMsgSet_P2		(0,RxMsg.Data.Data[4]);
							Record.InnerMsgSet_dType	(0,RxMsg.Data.Data[5]);
							Record.InnerMsgSet_Data0	(0,RxMsg.Data.Data[4]);	//Fault Type
							Record.InnerMsgSet_Data1	(0,0x01);			//Set
							Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[aCmd][8]);
							Record.InnerMsgSet_iByte1	(0,CtlByte);
						
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[1] = RxMsg.Data.Data[0];
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[2] = RxMsg.Data.Data[6];
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[3] = RxMsg.Data.Data[7];
							Record.iMsgRx.Splite.UserCode = RecUserCodeAreaNum[aCtlNum].UC.Full;
							Record.iMsgRx.Splite.AreaNum = RecUserCodeAreaNum[aCtlNum].AN.Full;
						
							CtlCenter.iePushOneMsg(Record.iMsgRx, aCmd);
							AllDataOK = 1;
					}else
					if(aCmd == cmPortModuleErrRecover){
							Record.InnerMsgSet_P0		(0,RxMsg.Data.Data[2]);
							Record.InnerMsgSet_P1		(0,RxMsg.Data.Data[3]);
							Record.InnerMsgSet_P2		(0,RxMsg.Data.Data[4]);
							Record.InnerMsgSet_dType	(0,RxMsg.Data.Data[5]);
							Record.InnerMsgSet_Data0	(0,RxMsg.Data.Data[4]);	//Fault Type
							Record.InnerMsgSet_Data1	(0,0x00);			//Recover
							Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[aCmd][8]);
							Record.InnerMsgSet_iByte1	(0,CtlByte);
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[1] = RxMsg.Data.Data[0];
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[2] = RxMsg.Data.Data[6];
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[3] = RxMsg.Data.Data[7];
							Record.iMsgRx.Splite.UserCode = RecUserCodeAreaNum[aCtlNum].UC.Full;
							Record.iMsgRx.Splite.AreaNum = RecUserCodeAreaNum[aCtlNum].AN.Full;
							CtlCenter.iePushOneMsg(Record.iMsgRx, aCmd);
							AllDataOK = 1;
					}else{
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[1] = RxMsg.Data.Data[0];
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[2] = RxMsg.Data.Data[6];
							RecUserCodeAreaNum[aCtlNum].UC.Bytes[3] = RxMsg.Data.Data[7];
							
							switch(aCmd){
								case 	cmAutoStart:
								case 	cmAutoStop:
								case 	dNetworkCmd_AutoStartDelay:
								case 	cmAck:
								case 	cmAckStop:
									//aDL2 |= ((RxMsg.Data.Idf >> 4) & 0x0F);
									//aDL2 <<= 8;
									//aDL2 |= RxMsg.Data.Data[4];
									sIm.Splite.Year = ProtoC2C.RecDateTime[RxMsg.Data.Data[1]].Dt.Year;
									sIm.Splite.Month = ProtoC2C.RecDateTime[RxMsg.Data.Data[1]].Dt.Mon;
									sIm.Splite.Day = ProtoC2C.RecDateTime[RxMsg.Data.Data[1]].Dt.Day;
									sIm.Splite.Hour = ProtoC2C.RecDateTime[RxMsg.Data.Data[1]].Dt.Hour;
									sIm.Splite.Minute = ProtoC2C.RecDateTime[RxMsg.Data.Data[1]].Dt.Min;
									sIm.Splite.Second = ProtoC2C.RecDateTime[RxMsg.Data.Data[1]].Dt.Sec;
									
									sIm.Splite.PCtlNum = RxMsg.Data.Data[1];
									sIm.Splite.P0 = RxMsg.Data.Data[2];
									sIm.Splite.P1 = RxMsg.Data.Data[3];
									sIm.Splite.P2 = 0;
									sIm.Splite.dType = RxMsg.Data.Data[5];
								
									sIm.Splite.UserCode = RecUserCodeAreaNum[aCtlNum].UC.Full;
								
									if(RxMsg.Data.Data[2] == 0){
										
									}else
									if(RxMsg.Data.Data[2] <= dPORT_MAX_COUNT){
										MasterDoEpMsg(aCmd, RxMsg.Data.Data);
									}else
									if( (RxMsg.Data.Data[2] >= dADDR_DIRECTPAD_START) && (RxMsg.Data.Data[2] <= dADDR_DIRECTPAD_END) ){
										MasterDoDirectPadNwPutLnkState(aCmd, RxMsg.Data.Data);
									}
									break;
								default:
									Record.InnerMsgSet_P0		(0,RxMsg.Data.Data[2]);
									Record.InnerMsgSet_P1		(0,RxMsg.Data.Data[3]);
									Record.InnerMsgSet_P2		(0,0);
									Record.InnerMsgSet_dType	(0,RxMsg.Data.Data[5]);
									Record.InnerMsgSet_Data0	(0,RxMsg.Data.Data[6]);
									Record.InnerMsgSet_Data1	(0,RxMsg.Data.Data[7]);
									Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[aCmd][8]);
									Record.InnerMsgSet_iByte1	(0,CtlByte);
										
									RecUserCodeAreaNum[aCtlNum].AN.Full = RxMsg.Data.CarryByte;
									RecUserCodeAreaNum[aCtlNum].AN.Full <<= 6;
									RecUserCodeAreaNum[aCtlNum].AN.Full |= RxMsg.Data.Data[4];
								
									Record.iMsgRx.Splite.UserCode = RecUserCodeAreaNum[aCtlNum].UC.Full;
									Record.iMsgRx.Splite.AreaNum = RecUserCodeAreaNum[aCtlNum].AN.Full;
									CtlCenter.iePushOneMsg(Record.iMsgRx, aCmd);
									break;
							}
							AllDataOK = 1;
					}
				}
				
				if(AllDataOK){
					Ack(aCtlNum, NewOrder);
				}
			}			
		}
	}else
	if(CmdActiveDefaultSet[aCmd][6] == StdCall){
		/*if(aCmd == cmReset){
			if(RxMsg.Data.Data[0] == 0){
				if(OnReceive.Piece[aCtlNum]){
					Record.OperateAdd_Reset(RxMsg.Data.Data[1], &RxMsg.Data.Data[2]);
					CtlCenter.NwMachineStateClear(RxMsg.Data.Data[1]);
					CtlCenter.NwMachineMsgFireClear(RxMsg.Data.Data[1]);
					CtlCenter.NwMachineMsgLinkageClear(RxMsg.Data.Data[1]);
					//CtlCenter.NwMachineMsgSvClear(RxMsg.Data.Data[1]);
					CtlCenter.NwMachineMsgFaultClear(RxMsg.Data.Data[1]);
					OnReceive.IsProcessDone[aCtlNum] = 1;
					Ack(aCtlNum, OnReceive.ProcessingOrder[aCtlNum]);
				}
			}
		}else
		if(aCmd == cmMuteBell){
			if(RxMsg.Data.Data[0] == 0){
				if(OnReceive.Piece[aCtlNum]){
					Record.OperateAdd_Mute(RxMsg.Data.Data[1], &RxMsg.Data.Data[2]);
					OnReceive.IsProcessDone[aCtlNum] = 1;
					Ack(aCtlNum, OnReceive.ProcessingOrder[aCtlNum]);
				}
			}
		}*/
		if(aCmd == dNetworkCmd_MaskListSend){
			if(OnReceive.Piece[aCtlNum] && (OnReceive.OrderDt[aCtlNum] == NewOrder) ){
				MasterDoMaskListGet(RxMsg.Data.Data);
				Ack(aCtlNum, NewOrder);
			}
		}else
		if(aCmd == dNetworkCmd_DelayStartSend){
			if(RxMsg.Data.Data[2]){
				NwIsStartDelay |= 1 << aCtlNum;
			}else{
				NwIsStartDelay &= ~(1 << aCtlNum);
			}
			Ack(aCtlNum, NewOrder);
		}else
		if(aCmd == dNetworkCmd_SlaveFbMissReport){
			if(RxMsg.Data.Data[2]){
				NwIsFbMiss |= 1<< RxMsg.Data.Data[1];
			}else{
				NwIsFbMiss &= ~(1<< RxMsg.Data.Data[1]);
			}
			Ack(aCtlNum, NewOrder);
		}else
		if(aCmd == dNetworkCmd_CheckNormalData){
			Ack(aCtlNum, NewOrder);
			MasterGetCheckNormalData(RxMsg.Data.Data);
		}		
	}else
	if(CmdActiveDefaultSet[aCmd][6] == NetNormalCall){
		if(aCmd == dNetworkCmd_PublishOperate){
			if(OnReceive.Piece[aCtlNum] && (OnReceive.OrderDt[aCtlNum] == NewOrder) ){
				if(RxMsg.Data.Data[6] == otCfgDateTime){
					if( (OnReceive.Piece[aCtlNum] == 0x03) && (OnReceive.OrderNewDt[aCtlNum] == NewOrder) ){
						OperateGet(aCmd,RxMsg.Data.Data);
						Ack(aCtlNum, NewOrder);
					}
				}else{
					OperateGet(aCmd,RxMsg.Data.Data);
					Ack(aCtlNum, NewOrder);
				}
			}
		}else
		if(aCmd == dNetworkCmd_EventTime){
			OnReceive.OrderDt[aCtlNum] = NewOrder;
			RecDateTime[aCtlNum].D32[0] = RxMsg.D32[2];
			RecDateTime[aCtlNum].D32[1] = RxMsg.D32[3];
			RecDateTime[aCtlNum].D32[2] = 1;
			RecUserCodeAreaNum[aCtlNum].AN.Full = RxMsg.Data.CarryByte;
			RecUserCodeAreaNum[aCtlNum].UC.Bytes[0] = RxMsg.Data.Data[0];
			OnReceive.Piece[aCtlNum] |= 0x01;
		}else
		if(aCmd == dNetworkCmd_NewTime){
			OnReceive.OrderNewDt[aCtlNum] = NewOrder;
			RecNewDateTime[aCtlNum].D32[0] = RxMsg.D32[2];
			RecNewDateTime[aCtlNum].D32[1] = RxMsg.D32[3];
			RecNewDateTime[aCtlNum].D32[2] = 1;
			OnReceive.Piece[aCtlNum] |= 0x02;
		}else
		if(aCmd == dNetworkCmd_DevDescp){
			//ProcessDevDescpRec();
		}
	}else
	if(CmdActiveDefaultSet[aCmd][6] == SimEvent){
		if(OnReceive.Piece[aCtlNum] && (OnReceive.OrderDt[aCtlNum] == NewOrder) ){
			sIm.Splite.Year = 	RecDateTime[aCtlNum].Dt.Year;
			sIm.Splite.Month = 	RecDateTime[aCtlNum].Dt.Mon;
			sIm.Splite.Day = 		RecDateTime[aCtlNum].Dt.Day;
			sIm.Splite.Hour = 	RecDateTime[aCtlNum].Dt.Hour;
			sIm.Splite.Minute = 	RecDateTime[aCtlNum].Dt.Min;
			sIm.Splite.Second = 	RecDateTime[aCtlNum].Dt.Sec;
			
			sIm.Splite.mType = CmdActiveDefaultSet[aCmd][7];
			sIm.Splite.iByte0 = CmdActiveDefaultSet[aCmd][8];

			sIm.Splite.PCtlNum = RxMsg.Data.Data[1];
			sIm.Splite.P0 = RxMsg.Data.Data[2];
			sIm.Splite.P1 = RxMsg.Data.Data[3];
			sIm.Splite.P2 = 0;
			sIm.Splite.dType = RxMsg.Data.Data[5];
			
			RecUserCodeAreaNum[aCtlNum].UC.Bytes[1] = RxMsg.Data.Data[0];
			RecUserCodeAreaNum[aCtlNum].UC.Bytes[2] = RxMsg.Data.Data[6];
			RecUserCodeAreaNum[aCtlNum].UC.Bytes[3] = RxMsg.Data.Data[7];
			
			RecUserCodeAreaNum[aCtlNum].AN.Full = RxMsg.Data.CarryByte;
			RecUserCodeAreaNum[aCtlNum].AN.Full <<= 6;
			RecUserCodeAreaNum[aCtlNum].AN.Full |= RxMsg.Data.Data[4];
			
			sIm.Splite.UserCode = RecUserCodeAreaNum[aCtlNum].UC.Full;
			Record.iMsgRx.Splite.AreaNum = RecUserCodeAreaNum[aCtlNum].AN.Full;
			
			
			switch(aCmd){
				case 	cmVIrtualStart:
					TControlCenter::sSimStartGot(&sIm);
					break;
				case 	smVIrtualStop:
					TControlCenter::sSimStartCancelGot(&sIm);
					break;
				case 	cmVIrtualAck:
					TControlCenter::sSimFeedBackGot(&sIm);
					break;
				case 	cmVIrtualAckStop:
					
					break;
				case  cmVIrtualAlram:
					TControlCenter::sSimFireGot(&sIm);
					break;
				case  cmVIrtualSuperVi:
					TControlCenter::sSimSvGot(&sIm);
					break;
				case  dNetworkCmd_AutoStartDelaySimulate:
					unsigned short aDl;
					aDl = RxMsg.Data.CarryByte & 0x0F;
					aDl &= 0x000F;
					aDl <<= 8;
					aDl |= RxMsg.Data.Data[4];
					sSimGetStartDelay(&sIm, aDl);
					break;
			}
			Ack(aCtlNum, NewOrder);
		}
	}
}

void TProtoC2C::SlaveRxMsgProcess()
{
	unsigned char aCmd, aCtlNum, CtlByte, aEventType, NewOrder, tForceIdf;
	int i,HasPrc = 0;
	unsigned int aAddr;
	TDMix DMix;
	
	aCtlNum = RxMsg.Data.Data[1];
	if( (aCtlNum==0) || (aCtlNum >32) )return;
	if( (aCtlNum >= CtlMask.StartNum) && (aCtlNum <= CtlMask.EndNum) ) return;
	
	
	aCmd = RxMsg.Data.Cmd;
	tForceIdf = RxMsg.Data.Identification;
	
	if(aCmd == dNetworkCmd_Ack){
		if(aCtlNum == MasterNum){
			if(CheckIsInSlaveList(MainCtl.fData.Split.MyNum)){
				ProcessAckRecFromMaster(RxMsg.Data.Order, RxMsg.Data.Data);
			}
		}
		return;
	}
	
	if(aCmd == dNetworkCmd){
		if(1){
			NwSubCmd = RxMsg.Data.Data[2];
			switch(NwSubCmd){
				case CmdC2C_AskExist:
					HasPrc =1;
					break;
				case CmdC2C_AskType:
					HasPrc =1;
					if(RxMsg.Data.Data[3] == MainCtl.fData.Split.MyNum){
						ReplyCtrlType();
					}
					break;
				case CmdC2C_AskNameLen:
					HasPrc =1;
					break;
				case CmdC2C_AskNameContent:
					HasPrc =1;
					if(RxMsg.Data.Data[3] == MainCtl.fData.Split.MyNum){
						ReplyDescp();
					}
					break;
			}
			if(HasPrc == 0){
				switch(NwSubCmd){
					case CmdC2C_RpyExist:
					case CmdC2C_RpyType:
					case CmdC2C_RpyNameLen:
					case CmdC2C_RpyNameContent:
						HasPrc =1;
						if(CanNetworkRegister.IsOnSearching){
							CanNetworkRegister.PushfNetMsg(NwSubCmd, RxMsg.Data.Data, 8);
						}
						break;
					case CmdC2C_SaveData:
						HasPrc =1;
						SaveCfgData(RxMsg.Data.Data);
						break;
					case CmdC2C_ClearReg:
						HasPrc =1;
						ClearCfgData(RxMsg.Data.Data);
						break;
				}
			}
			if(HasPrc == 0){
				//Slave
				if(aCtlNum == MasterNum){
					if(CheckIsInSlaveList(MainCtl.fData.Split.MyNum)){
						if(RxMsg.Data.Data[3] == MainCtl.fData.Split.MyNum){
							switch(NwSubCmd){
								case 	CmdC2C_DevRegStartSeq:
									CtlByte = Register.SlaveGetStartSeq(RxMsg.Data.Data);
									if(CtlByte <=dPORT_MAX_COUNT){
										int Res = CheckIsRemoteRegFeasible();
										if(1 == Res){
											RemoteReq.Reg.RegPath = CtlByte;
											RemoteReq.Reg.IsRequsting =1;
										}else
										if(-1 == Res){
											Register.SlaveReplyStartState(3);
										}else{										
											Register.SlaveReplyStartState(2);
										}
									}else
									if(CtlByte == 254){
										Register.SlaveReplyStartState(2);
									}
									break;
								case  CmdC2C_DevRegReqEpCount:
									Register.SlaveRpyEpCount();
									break;
								case  CmdC2C_DevRegEpCountCorrect:
									Register.SlaveRecMasterGotCompleted();
									break;

							}
						}
					}
				}
			}
		}
		return;
	}else
	if(aCmd == dNetworkCmd_SetDateTime){
		//Record.OperateAdd_GetDateTime(RxMsg.Data.Data[2], RxMsg.Data.Data[3], RxMsg.Data.Data[4], RxMsg.Data.Data[5], RxMsg.Data.Data[6] ,RxMsg.Data.Data[7]);
		//DataTimeSet(RxMsg.Data.Data[2], RxMsg.Data.Data[3], RxMsg.Data.Data[4], RxMsg.Data.Data[5], RxMsg.Data.Data[6] ,RxMsg.Data.Data[7], 1);	//aWk 1..7
	}else
	if(aCmd == dNetworkCmd_PortExistAsk){
		PortExistRpy(RxMsg.Data.Data[1], RxMsg.Data.Data[2]);
	}else
	if(aCmd == dNetworkCmd_DescpAsk){
		if(RxMsg.Data.Data[4]){
			if(RxMsg.Data.Data[2] < 41)
				DescpListRpy(RxMsg.Data.Data[1], RxMsg.Data.Data[2], RxMsg.Data.Data[4]);
			if(RxMsg.Data.Data[2] == 41)
				DescpListDirectPadRpy(RxMsg.Data.Data[1],RxMsg.Data.Data[4]);
		}
		if(RxMsg.Data.Data[5]){
			if(RxMsg.Data.Data[2] < 41)
				DescpListRpy(RxMsg.Data.Data[1], RxMsg.Data.Data[2], RxMsg.Data.Data[5]);
			if(RxMsg.Data.Data[2] == 41)
				DescpListDirectPadRpy(RxMsg.Data.Data[1],RxMsg.Data.Data[5]);
		}
		if(RxMsg.Data.Data[6]){
			if(RxMsg.Data.Data[2] < 41)
				DescpListRpy(RxMsg.Data.Data[1], RxMsg.Data.Data[2], RxMsg.Data.Data[6]);
			if(RxMsg.Data.Data[2] == 41)
				DescpListDirectPadRpy(RxMsg.Data.Data[1],RxMsg.Data.Data[6]);
		}
		if(RxMsg.Data.Data[7]){
			if(RxMsg.Data.Data[2] < 41)
				DescpListRpy(RxMsg.Data.Data[1], RxMsg.Data.Data[2], RxMsg.Data.Data[7]);
			if(RxMsg.Data.Data[2] == 41)
				DescpListDirectPadRpy(RxMsg.Data.Data[1],RxMsg.Data.Data[7]);
		}
	}else
	if(aCmd == dNetworkCmd_DescpOnePortAsk){
		SlaveDoNetDescpRpy(RxMsg.Data.Data[1], RxMsg.Data.Data[2]);
	}
		
	if(aCtlNum != MasterNum)return;
	if(0 == CheckIsInSlaveList(MainCtl.fData.Split.MyNum))return;
	
	NewOrder = RxMsg.Data.Order;
	
	if(tForceIdf)OnReceive.IsProcessDone[aCtlNum] = 0;
	if(OnReceive.OrderLast[aCtlNum] != NewOrder)OnReceive.IsProcessDone[aCtlNum] = 0;
	if( OnReceive.IsProcessDone[aCtlNum] && (OnReceive.OrderAck[aCtlNum] == NewOrder ) ){
		if(OnReceive.IsCheckOnline){
			AckOnlineCheck(aCtlNum, NewOrder);
		}else{
			Ack(aCtlNum, NewOrder);
		}
		return;
	}
	OnReceive.OrderLast[aCtlNum] = NewOrder;
	
	if(CmdActiveDefaultSet[aCmd][6] == FastCall){
		if(OnReceive.Piece[aCtlNum] && (OnReceive.OrderDt[aCtlNum] == NewOrder) ){
			if(aCmd == cmVAAlramStart){
				if(RxMsg.Data.Data[0]){	
					if(OnReceive.Piece[aCtlNum]){
						SlaveDoAlramOnOff(1);
						Ack(aCtlNum, NewOrder);
					}
				}
			}else
			if(aCmd == cmVAAlramStop){
				if(RxMsg.Data.Data[0]){
					if(OnReceive.Piece[aCtlNum]){
						SlaveDoAlramOnOff(0);
						Ack(aCtlNum, NewOrder);
					}
				}
			}
		}
	}else
	if(CmdActiveDefaultSet[aCmd][6] == StdCall){
		/*if(aCmd == cmReset){
			if(RxMsg.Data.Data[0]){
				//Reset 
				if(OnReceive.Piece[aCtlNum]){
					ResetCallBack();
					OnReceive.IsProcessDone[aCtlNum] = 1;
					Ack(aCtlNum, OnReceive.ProcessingOrder[aCtlNum]);
				}
			}
		}*/
		if(aCmd == dNetworkCmd_CheckOnline){
			if( (RxMsg.Data.Data[2] == 0xA5) && ( RxMsg.Data.Data[3] == 0x5A) ){
				CheckOnlineUpdateTick =0;
				AckOnlineCheck(aCtlNum, NewOrder);
			}
		}else
		if(aCmd == dNetworkCmd_CheckNormalData){
			if( (RxMsg.Data.Data[2] == MainCtl.fData.Split.MyNum) && (RxMsg.Data.Data[3] == 0x5A) ){
				Ack(aCtlNum, NewOrder);
				SlaveDoRpyCheckNormalData();
			}
		}else
		if(aCmd == dNetworkCmd_SetSlaveAllow){
			if( RxMsg.Data.Data[2] == MainCtl.fData.Split.MyNum ){
				Ack(aCtlNum, NewOrder);
				SlaveSetAllowStateBySpc(MainCtl.fData.Split.MyNum, RxMsg.Data.Data[3]);
			}
		}
	}else
	if(CmdActiveDefaultSet[aCmd][6] == NetNormalCall){
		if(aCmd == dNetworkCmd_ClearCtlFire){
			ClearNwCtlFire(RxMsg.Data.Data[0]);
			Ack(aCtlNum, NewOrder);
		}else
		if(aCmd == dNetworkCmd_PublishFireCancel){
			
		}else
		if(aCmd == dNetworkCmd_PublishFire){
			ProtoC2C.SetNwFire(RxMsg.Data.Data[0], RxMsg.Data.Data[2], RxMsg.Data.Data[3], 0xA5A5A500 + RxMsg.Data.Data[5]);
			Ack(aCtlNum, NewOrder);
		}else
		if(aCmd == dNetworkCmd_PublishOperate){
			if(OnReceive.Piece[aCtlNum] && (OnReceive.OrderDt[aCtlNum] == NewOrder) ){
				if(RxMsg.Data.Data[6] == otCfgDateTime){
					if( (OnReceive.Piece[aCtlNum] == 0x03) && (OnReceive.OrderNewDt[aCtlNum] == NewOrder) ){
						OperateGet(aCmd,RxMsg.Data.Data);
						Ack(aCtlNum, NewOrder);
					}
				}else{
					if(otReset == RxMsg.Data.Data[6]){
						OnReceive.CallResetCtlNum = aCtlNum;
						OnReceive.CallResetNetOrder = NewOrder;
						OperateGet(aCmd,RxMsg.Data.Data);
					}else{
						OperateGet(aCmd,RxMsg.Data.Data);
						Ack(aCtlNum, NewOrder);
					}
				}
			}
		}else
		if(aCmd == dNetworkCmd_EventTime){
			OnReceive.OrderDt[aCtlNum] = NewOrder;
			RecUserCodeAreaNum[aCtlNum].UC.Bytes[0] = RxMsg.Data.Data[0];
			RecDateTime[aCtlNum].D32[0] = RxMsg.D32[2];
			RecDateTime[aCtlNum].D32[1] = RxMsg.D32[3];
			RecDateTime[aCtlNum].D32[2] = 1;
			OnReceive.Piece[aCtlNum] |= 0x01;
		}else
		if(aCmd == dNetworkCmd_NewTime){
			OnReceive.OrderNewDt[aCtlNum] = NewOrder;
			RecNewDateTime[aCtlNum].D32[0] = RxMsg.D32[2];
			RecNewDateTime[aCtlNum].D32[1] = RxMsg.D32[3];
			RecNewDateTime[aCtlNum].D32[2] = 1;
			OnReceive.Piece[aCtlNum] |= 0x02;
		}else
		if(aCmd == dNetworkCmd_RemoteStartStop){
			if(RxMsg.Data.Data[0] == MainCtl.fData.Split.MyNum){
				SlaveDoGetRemoteStartStop(MainCtl.fData.Split.MyNum, RxMsg.Data.Data[2], RxMsg.Data.Data[3], RxMsg.Data.Data[5]);
			}
			Ack(aCtlNum, NewOrder);
		}else
		if(aCmd == dNetworkCmd_RemoteStartStopViaUserCode){
			unsigned short aDelay;
			Ack(aCtlNum, NewOrder);
			CtlByte = RxMsg.Data.Data[0] & 0x0F;
			aDelay = RxMsg.Data.Data[0] & 0xF0;
			aDelay <= 4; 
			aDelay &= 0x0F00;
			aDelay |= RxMsg.Data.Data[7];
			DMix.D8[0] = RxMsg.Data.Data[2];
			DMix.D8[1] = RxMsg.Data.Data[3];
			DMix.D8[2] = RxMsg.Data.Data[4];
			DMix.D8[3] = RxMsg.Data.Data[6];
			SlaveDoGetRemoteStartStopUserCode(DMix.D32, RxMsg.Data.Data[5], aDelay, CtlByte);
		}else
		if(aCmd == dNetworkCmd_RemoteStartStopViaUserCodeSimulate){
			unsigned short aDelay;
			Ack(aCtlNum, NewOrder);
			CtlByte = RxMsg.Data.Data[0] & 0x0F;
			aDelay = RxMsg.Data.Data[0] & 0xF0;
			aDelay <= 4; 
			aDelay &= 0x0F00;
			aDelay |= RxMsg.Data.Data[7];
			DMix.D8[0] = RxMsg.Data.Data[2];
			DMix.D8[1] = RxMsg.Data.Data[3];
			DMix.D8[2] = RxMsg.Data.Data[4];
			DMix.D8[3] = RxMsg.Data.Data[6];
			SlaveDoGetRemoteStartStopUserCodeSimulate(DMix.D32, RxMsg.Data.Data[5], aDelay, CtlByte);
		}
	}else
	if(CmdActiveDefaultSet[aCmd][6] == SimEvent){
		if(OnReceive.Piece[aCtlNum] && (OnReceive.OrderDt[aCtlNum] == NewOrder) ){
			if(aCmd == cmVIrtualStart){
				//if(RxMsg.Data.Data[0]){	
					if(OnReceive.Piece[aCtlNum]){
						//SlaveDoAlramOnOff(1);
						Ack(aCtlNum, NewOrder);
					}
				//}
			}else
			if(aCmd == smVIrtualStop){
				//if(RxMsg.Data.Data[0]){
					if(OnReceive.Piece[aCtlNum]){
				//		SlaveDoAlramOnOff(0);
						Ack(aCtlNum, NewOrder);
					}
				//}
			}
		}
	}
}

void TProtoC2C::ProcessoEntry()
{
	int i, pNum, IsAckOk, IsAckNotOk, CanLoadNew, aNewCtlNotAck;
	if(MainCtl.fData.Split.MyNum == 0)return;
	if(MainCtl.fData.Split.NetworkMode == 1){
		if(OnTransmite.OnGoing){
			IsAckOk = 0;
			IsAckNotOk = 0;
			CanLoadNew = 0;
			if(OnTransmite.IsBroadCast){
				for(i=0; i<SlaveCount; i++){
					pNum = SlaveList[i];
					if(pNum > dNETWORK_MACHINE_COUNT)pNum = 0;
					if (pNum){
						if( (pNum <CtlMask.StartNum) || (pNum >CtlMask.EndNum) ){
							if(OnTransmite.AckOk[pNum]){
								NoAckList[pNum] = 0;
								if( ReportSlaveOffline[pNum] ==1){
									RemoveMasterCommFault(pNum);
									ReportSlaveOffline[pNum] = 0;
								}
							}else{
								if( ReportSlaveOffline[pNum] == 0 ){
									IsAckNotOk = 1;
								}							
							}
						}
					}
				}
				//if(AckOkCnt >= SlaveCount){
				if(IsAckNotOk == 0){
					CanLoadNew = 1;
					OnTransmite.OnGoing = 0;
				}else{
					//Lost At Less 1 Ctl Not Ack
					OnTransmite.TimeOutTick++;
					if(OnTransmite.TimeOutTick >50){
						if(iBufInCountPer2Sec > 40){
							//Bus Is Busy
							OnTransmite.TimeOutTick = 0;
						}else{
							OnTransmite.RetryTimes++;
							if( OnTransmite.RetryTimes > 10){
								//Abort
								CanLoadNew = 1;
								OnTransmite.OnGoing = 0;
								
								for(i=0; i<SlaveCount; i++){
									pNum = SlaveList[i];
									if( (pNum) && (pNum <=dNETWORK_MACHINE_COUNT) ){
										if( (pNum <CtlMask.StartNum) || (pNum >CtlMask.EndNum ) ){
											if(OnTransmite.AckOk[pNum] == 0){
												if(CommLostCount[pNum] <201)CommLostCount[pNum]++;
												if( ReportSlaveOffline[pNum] ==0){
													AddMasterCommFault(pNum);
													ReportSlaveOffline[pNum] = 1;
												}
												NoAckList[pNum] = 1;
											}
											ErrReport = 1;
										}
									}
								}
							}else{
								//Check Is New Ctl Not ACK
								aNewCtlNotAck = 0;
								for(i=0; i<SlaveCount; i++){
									pNum = SlaveList[i];
									if( (pNum) && (pNum <=dNETWORK_MACHINE_COUNT) ){
										if( (pNum <CtlMask.StartNum) || (pNum >CtlMask.EndNum ) ){
											if(OnTransmite.AckOk[pNum] == 0){
												if( NoAckList[pNum] == 0){
													aNewCtlNotAck = 1;
												}
											}
										}
									}
								}
								if(aNewCtlNotAck == 0){
									//No New Ctl Not Ack , Abort
									CanLoadNew = 1;
									OnTransmite.OnGoing = 0;
								}else{
									//a New Ctl Not Ack , ReSend All Data Pkg With Old Order
									OnTransmite.TimeOutTick = 0;
									ExportEntry2oBuf(0);
									OnTransmite.OnGoing = 1;
									
									MasterRetrySendEntryCount++;
								}
							}
						}
					}
				}
			}else{
				if( (OnTransmite.SlaveCtlNum >0) && (OnTransmite.SlaveCtlNum <= dNETWORK_MACHINE_COUNT) ){
					pNum = OnTransmite.SlaveCtlNum;
					if(OnTransmite.AckOk[pNum]){
						NoAckList[pNum] = 0;
						IsAckOk =1;
						if( ReportSlaveOffline[pNum] ==1){
							RemoveMasterCommFault(pNum);
							ReportSlaveOffline[pNum] = 0;
						}
					}else{
						if ( (pNum >= CtlMask.StartNum) || (pNum <= CtlMask.EndNum) ) {
							IsAckOk =1;
						}
					}
					if(IsAckOk){
						CanLoadNew = 1;
						OnTransmite.OnGoing = 0;
					}else{
						//Lost At Less 1 Ctl Not Ack
						OnTransmite.TimeOutTick++;
						if(OnTransmite.TimeOutTick >50){
							if(iBufInCountPer2Sec > 40){
								//Bus Is Busy
								OnTransmite.TimeOutTick = 0;
							}else{
								OnTransmite.RetryTimes++;
								if( OnTransmite.RetryTimes > 10){
									//Abort
									CanLoadNew = 1;
									OnTransmite.OnGoing = 0;
									
									if(OnTransmite.AckOk[pNum] == 0){
										if(OnTransmite.IsReportErr){
											if(CommLostCount[pNum] <201)CommLostCount[pNum]++;
											if( ReportSlaveOffline[pNum] ==0){
												AddMasterCommFault(pNum);
												ReportSlaveOffline[pNum] = 1;
											}
											NoAckList[pNum] = 1;
										}
									}
									ErrReport = 1;
								}else{
									//Check Is New Ctl Not ACK
									aNewCtlNotAck = 0;
									if(OnTransmite.AckOk[pNum] == 0){
										if( NoAckList[pNum] == 0){
											aNewCtlNotAck = 1;
										}
									}
									if(aNewCtlNotAck == 0){
										//No New Ctl Not Ack , Abort
										CanLoadNew = 1;
										OnTransmite.OnGoing = 0;
									}else{
										//a New Ctl Not Ack , ReSend All Data Pkg With Old Order
										OnTransmite.TimeOutTick = 0;
										ExportEntry2oBuf(0);
										OnTransmite.OnGoing = 1;
										
										MasterRetrySendEntryCount++;
									}
								}
							}
						}
					}
				}
			}
		}else{
			CanLoadNew = 1;
			OnTransmite.OnGoing = 0;
		}
		
		if(CanLoadNew){
			//Check And Load New Entry
			if(TryLoadNewEntry()){
				OnTransmite.Order++;
				if(OnTransmite.Order == 0)OnTransmite.Order = 1;
				OnTransmite.TimeOutTick = 0;
				OnTransmite.RetryTimes = 0;
				NeedRpyCount = 0;
				for(int i=0; i<SlaveCount; i++){
					pNum = SlaveList[i];
					if(pNum <= dNETWORK_MACHINE_COUNT){
						if( (pNum <CtlMask.StartNum) || (pNum >CtlMask.EndNum ) ){
							OnTransmite.DesireAckOrder[pNum] = OnTransmite.Order;
							OnTransmite.AckOk[pNum] = 0;
							NeedRpyCount ++;
						}
					}
				}
				ExportEntry2oBuf(1);
				OnTransmite.OnGoing = 1;
			}
		}
	}else
	if(MainCtl.fData.Split.NetworkMode == 2){
		if( (MasterNum == 0) || (MasterNum > dNETWORK_MACHINE_COUNT) ){
			OnTransmite.OnGoing = 0;
			return;
		}
		if ( (MasterNum >= CtlMask.StartNum) and (MasterNum <= CtlMask.EndNum) ) {
			OnTransmite.OnGoing = 0;
			return;
		}
		if(OnTransmite.OnGoing){
			IsAckOk = 0;
			CanLoadNew = 0;
			if(OnTransmite.AckOk[MasterNum]){
				IsAckOk =1;
			}
			if(IsAckOk){
				CanLoadNew = 1;
				OnTransmite.OnGoing = 0;
				if(ReportMasterOffline){
					RemoveSlaveCommFault(MasterNum);
					ReportMasterOffline = 0;
				}
			}else{
				OnTransmite.TimeOutTick++;
				if(OnTransmite.TimeOutTick >50){
					if(iBufInCountPer2Sec > 40){
						//Bus Is Busy
						OnTransmite.TimeOutTick = 0;
					}else{
						OnTransmite.RetryTimes++;
						if(OnTransmite.RetryTimes > 10){
							//Abort
							CanLoadNew = 1;
							OnTransmite.OnGoing = 0;
							
							if(CommLostCount[0] <201)CommLostCount[0]++;
							if(ReportMasterOffline == 0){
								AddSlaveCommFault(MasterNum);
								ReportMasterOffline = 1;
							}
							ErrReport = 1;
						}else{
							//ReSend All Data Pkg With Old Order
							OnTransmite.TimeOutTick = 0;
							ExportEntry2oBuf(0);
							OnTransmite.OnGoing = 1;
							SlaveRetrySendEntryCount++;
						}
					}
				}
			}
		}else{
			CanLoadNew = 1;
			OnTransmite.OnGoing = 0;
		}
		
		if(CanLoadNew){
			//Check And Load New Entry
			if(TryLoadNewEntry()){
				OnTransmite.Order++;
				if(OnTransmite.Order == 0)OnTransmite.Order = 1;
				OnTransmite.TimeOutTick = 0;
				OnTransmite.RetryTimes = 0;
				if( (MasterNum <CtlMask.StartNum) || (MasterNum >CtlMask.EndNum ) ){
					if(CheckIsInSlaveList(MainCtl.fData.Split.MyNum)){
						OnTransmite.DesireAckOrder[MasterNum] = OnTransmite.Order;
						OnTransmite.AckOk[MasterNum] = 0;
						ExportEntry2oBuf(1);
						OnTransmite.OnGoing = 1;
					}
				}
			}
		}		
	}else{
		OnTransmite.OnGoing = 0;
	}
}

int TProtoC2C::TryLoadNewEntry()
{
	int Loaded =0;
	if(oEntryBasicService.CheckDataAvalibel()){
		oEntryBasicService.Read(oEntry.rBody.D32);
		Loaded=1;
	}else
	if(oEntryFire.CheckDataAvalibel()){
		oEntryFire.Read(oEntry.rBody.D32);
		Loaded=1;
	}else
	if(oEntrySv.CheckDataAvalibel()){
		oEntrySv.Read(oEntry.rBody.D32);
		Loaded=1;
	}else
	if(oEntryLink.CheckDataAvalibel()){
		oEntryLink.Read(oEntry.rBody.D32);
		Loaded=1;
	}else
	if(oEntryFault.CheckDataAvalibel()){
		oEntryFault.Read(oEntry.rBody.D32);
		Loaded=1;
	}else
	if(oEntryNormal.CheckDataAvalibel()){
		oEntryNormal.Read(oEntry.rBody.D32);
		Loaded=1;
	}
	return Loaded;
}

void TProtoC2C::oBufInsert()
{
	unsigned int aAddr;
	
	oBuf.WriteIndex++;
	if(oBuf.WriteIndex >= dNetworkOutBufMaxLength)oBuf.WriteIndex = 0;
	
	aAddr = dAddrSdram_C2cOutBuf + (oBuf.WriteIndex * 16);
	TxMsg.Data.Routing = 0;
	* (volatile unsigned int *)(aAddr +  0) = TxMsg.D32[0];
	* (volatile unsigned int *)(aAddr +  4) = TxMsg.D32[1];
	* (volatile unsigned int *)(aAddr +  8) = TxMsg.D32[2];
	* (volatile unsigned int *)(aAddr + 12) = TxMsg.D32[3];
}

void TProtoC2C::oBufInsert(TC2CBufBody aNsBuf)
{
	unsigned int aAddr;
	
	oBuf.WriteIndex++;
	if(oBuf.WriteIndex >= dNetworkOutBufMaxLength)oBuf.WriteIndex = 0;
	
	aAddr = dAddrSdram_C2cOutBuf + (oBuf.WriteIndex * 16);
	* (volatile unsigned int *)(aAddr +  0) = aNsBuf.D32[0];
	* (volatile unsigned int *)(aAddr +  4) = aNsBuf.D32[1];
	* (volatile unsigned int *)(aAddr +  8) = aNsBuf.D32[2];
	* (volatile unsigned int *)(aAddr + 12) = aNsBuf.D32[3];	
}

void TProtoC2C::oBufMsgPreload(TRecordCommon aIm,  unsigned char aCmd)
{
	if(MainCtl.fData.Split.NetworkMode == 0)return;

	oEntry.wBody.Split.Cmd 	= aCmd;
	oEntry.wBody.Split.CtlNum = MainCtl.fData.Split.MyNum;
	oEntry.wBody.Split.Year 	= DateTime.Date.Split.Year;
	oEntry.wBody.Split.Mon 	= DateTime.Date.Split.Month;
	oEntry.wBody.Split.Day 	= DateTime.Date.Split.Day;
	oEntry.wBody.Split.Hour 	= DateTime.Time.Split.Hour;
	oEntry.wBody.Split.Min 	= DateTime.Time.Split.Minute;
	oEntry.wBody.Split.Sec 	= DateTime.Time.Split.Second;
	
	oEntry.wBody.Split.P0 = aIm.Splite.P0;
	oEntry.wBody.Split.P1 = aIm.Splite.P1;
	oEntry.wBody.Split.Prm = aIm.Splite.P2;
	oEntry.wBody.Split.dType = aIm.Splite.dType;
	oEntry.wBody.Split.Prm1 = aIm.Splite.Data0;
	oEntry.wBody.Split.Prm2 = aIm.Splite.Data1;
	oEntry.wBody.Split.sType = aIm.Splite.iByte0;
}
void TProtoC2C::oBufMsgInsertBasicService()
{
	oEntryBasicService.Write(oEntry.wBody.D32);
}
void TProtoC2C::oBufMsgInsertFire()
{
	oEntryFire.Write(oEntry.wBody.D32);
}
void TProtoC2C::oBufMsgInsertSv()
{
	oEntrySv.Write(oEntry.wBody.D32);	
}
void TProtoC2C::oBufMsgInsertLink()
{
	oEntryLink.Write(oEntry.wBody.D32);		
}
void TProtoC2C::oBufMsgInsertFault()
{
	oEntryFault.Write(oEntry.wBody.D32);	
}
void TProtoC2C::oBufMsgInsertNormal()
{
	oEntryNormal.Write(oEntry.wBody.D32);	
}
void TProtoC2C::oBufMsgInsertBasicService(TRecordCommon aIm,  unsigned char aCmd)
{
	oBufMsgPreload(aIm,aCmd);
	oEntryBasicService.Write(oEntry.wBody.D32);
}
void TProtoC2C::oBufMsgInsertFire(TRecordCommon aIm,  unsigned char aCmd)
{
	oBufMsgPreload(aIm,aCmd);
	oEntryFire.Write(oEntry.wBody.D32);
}
void TProtoC2C::oBufMsgInsertSv(TRecordCommon aIm,  unsigned char aCmd)
{
	oBufMsgPreload(aIm,aCmd);
	oEntrySv.Write(oEntry.wBody.D32);	
}
void TProtoC2C::oBufMsgInsertLink(TRecordCommon aIm,  unsigned char aCmd)
{
	oBufMsgPreload(aIm,aCmd);
	oEntryLink.Write(oEntry.wBody.D32);	
}
void TProtoC2C::oBufMsgInsertFault(TRecordCommon aIm,  unsigned char aCmd)
{
	oBufMsgPreload(aIm,aCmd);
	oEntryFault.Write(oEntry.wBody.D32);	
}
void TProtoC2C::oBufMsgInsertNormal(TRecordCommon aIm,  unsigned char aCmd)
{
	oBufMsgPreload(aIm,aCmd);
	oEntryNormal.Write(oEntry.wBody.D32);	
}

void TProtoC2C::oBufProcess()
{
	unsigned int aAddr, aVal, aLoad;
	if(oBuf.ReadIndex != oBuf.WriteIndex){
		if(get_excan_linkage_tx_complete()){
			oBuf.ReadIndex++;
			if(oBuf.ReadIndex >= dNetworkOutBufMaxLength)oBuf.ReadIndex = 0;
			aAddr = dAddrSdram_C2cOutBuf + (oBuf.ReadIndex * 16);
			oBuf.aBody.D32[0] = * (volatile unsigned int *)(aAddr +  0);
			oBuf.aBody.D32[1] = * (volatile unsigned int *)(aAddr +  4);
			oBuf.aBody.D32[2] = * (volatile unsigned int *)(aAddr +  8);
			oBuf.aBody.D32[3] = * (volatile unsigned int *)(aAddr + 12);
			aLoad = static_cast<unsigned int>(oBuf.aBody.Data.Identification);
			aVal = (aLoad << 24 ) & (1<<24);
			aLoad = static_cast<unsigned int>(oBuf.aBody.Data.Routing);
			aVal |= (aLoad << 25 ) & (3<<25);
			aLoad = static_cast<unsigned int>(oBuf.aBody.Data.Priority);
			aVal |= (aLoad << 27 ) & (3<<27);
			oBuf.aBody.D32[0] &= 0x00FFFFFF;
			oBuf.aBody.D32[0] |= aVal; 
			outer_can_send_data(oBuf.aBody.D32[0], oBuf.aBody.Data.Data, oBuf.aBody.Data.Len);
		}
	}
}

void TProtoC2C::ReplyCtrlType()
{
	unsigned char aType;
	//CmdC2C_RpyType		:    	D0=Len, D1=Pri, D2=CMD, 		D3=CTLBYTE D4=SubCmd 		D5=CtlNum  D6=Type	(Master or Slave, See Define)
	if(MainCtl.fData.Split.NetworkMode == 1){
		aType = dNetworkTypeMaster;
	}else
	if(MainCtl.fData.Split.NetworkMode == 2){
		aType = dNetworkTypeSlave;
	}else{
		aType = dNetworkTypeNone;
	}

	TxMsg.Data.Cmd = dNetworkCmd;
	TxMsg.Data.Len = 6;
	TxMsg.Data.Data[0] = 0;
	TxMsg.Data.Data[1] = MainCtl.fData.Split.MyNum ;
	TxMsg.Data.Data[2] = CmdC2C_RpyType; 
	TxMsg.Data.Data[3] = aType;
	if(MainCtl.fData.Split.NetworkMode == 1){
		TxMsg.Data.Data[4] = this->SlaveCount;
	}else
	if(MainCtl.fData.Split.NetworkMode == 2){
		TxMsg.Data.Data[4] = this->MasterNum;
	}
	oBufInsert();
	
	if(0){
		TxMsg.Data.Cmd = dNetworkCmd;
		TxMsg.Data.Len = 4;
		TxMsg.Data.Data[0] = 0;
		TxMsg.Data.Data[1] = 6;
		TxMsg.Data.Data[2] = CmdC2C_RpyType; 
		TxMsg.Data.Data[3] = dNetworkTypeSlave; 
		
		oBufInsert();
		
		TxMsg.Data.Cmd = dNetworkCmd;
		TxMsg.Data.Len = 4;
		TxMsg.Data.Data[0] = 0;
		TxMsg.Data.Data[1] = 7;
		TxMsg.Data.Data[2] = CmdC2C_RpyType; 
		TxMsg.Data.Data[3] = dNetworkTypeSlave; 
		
		oBufInsert();
		
		TxMsg.Data.Cmd = dNetworkCmd;
		TxMsg.Data.Len = 4;
		TxMsg.Data.Data[0] = 0;
		TxMsg.Data.Data[1] = 8;
		TxMsg.Data.Data[2] = CmdC2C_RpyType; 
		TxMsg.Data.Data[3] = dNetworkTypeSlave; 
		
		oBufInsert();
		
		TxMsg.Data.Cmd = dNetworkCmd;
		TxMsg.Data.Len = 4;
		TxMsg.Data.Data[0] = 0;
		TxMsg.Data.Data[1] = 9;
		TxMsg.Data.Data[2] = CmdC2C_RpyType; 
		TxMsg.Data.Data[3] = dNetworkTypeSlave; 
		
		oBufInsert();
	}
}

void TProtoC2C::ReplyDescp()
{
	char *p;
	int Offset;
	
	p = "ccccccccccccccc";
}

void TProtoC2C::NwDevDescpInit()
{
	unsigned int i;
	volatile unsigned int aAddr;
	aAddr = dAddrSdRam_DescpNw;
	for(i=0;i<2621440;i++){
		*(volatile unsigned int *)(aAddr) =0;
		aAddr += 4;
	}
}

void TProtoC2C::BufInit()
{
	unsigned int i;
	volatile unsigned int aAddr;
	aAddr = dAddrSdram_C2cOutBuf;
	for(i=0;i<262144;i++){
		*(volatile unsigned int *)(aAddr) =0;
		aAddr += 4;
	}
}

void TProtoC2C::ExportMachineEventTime2Master(unsigned char IsNew)
{
		TDMix DMix;
		TxMsg.Data.Routing =0;
		TxMsg.Data.Priority = 1;
		TxMsg.Data.Identification = 0;
	
		TxMsg.Data.Cmd = dNetworkCmd_EventTime;
		TxMsg.Data.Order = OnTransmite.Order;
		if(IsNew)TxMsg.Data.Identification = 1;
		TxMsg.Data.Len = 8;
		TxMsg.Data.Data[0] = 0;
		TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum;

		if(CmdFillAreaNum){
			TxMsg.Data.CarryByte = static_cast<unsigned char>(((oEntry.rBody.Split.AreaNum & 0x0F00) >> 8 ));
		}
		if(CmdFillUserCode){
			DMix.D32 = oEntry.rBody.Split.UserCode;
			TxMsg.Data.Data[0] = DMix.D8[0];
		}
	
		if( (oEntry.rBody.Split.Cmd == dNetworkCmd_PublishOperate) && (otSetNwTime == oEntry.rBody.Split.sType) ){
			TxMsg.Data.Data[2] = DateTime.Date.Split.Year;
			TxMsg.Data.Data[3] = DateTime.Date.Split.Month;
			TxMsg.Data.Data[4] = DateTime.Date.Split.Day;
			TxMsg.Data.Data[5] = DateTime.Time.Split.Hour;
			TxMsg.Data.Data[6] = DateTime.Time.Split.Minute;
			TxMsg.Data.Data[7] = DateTime.Time.Split.Second;
		}else{
			TxMsg.Data.Data[2] = oEntry.rBody.Split.Year;
			TxMsg.Data.Data[3] = oEntry.rBody.Split.Mon;
			TxMsg.Data.Data[4] = oEntry.rBody.Split.Day;
			TxMsg.Data.Data[5] = oEntry.rBody.Split.Hour;
			TxMsg.Data.Data[6] = oEntry.rBody.Split.Min;
			TxMsg.Data.Data[7] = oEntry.rBody.Split.Sec;
		}
		
		oBufInsert();

}

void TProtoC2C::ExportMachineEventNewTime2Master(unsigned char IsNew)
{
	unsigned int i,aAddr;
	if(MainCtl.fData.Split.NetworkMode == 2){
		TxMsg.Data.Routing =0;
		TxMsg.Data.Priority = 1;
		TxMsg.Data.Identification = IsNew;
		TxMsg.Data.Cmd = dNetworkCmd_NewTime;
		TxMsg.Data.Order = OnTransmite.Order;
		TxMsg.Data.Len = 8;
		TxMsg.Data.Data[0] = 1;
		TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum;
		TxMsg.Data.Data[2] = oEntry.rBody.Split.P0;
		TxMsg.Data.Data[3] = oEntry.rBody.Split.P1;
		TxMsg.Data.Data[4] = oEntry.rBody.Split.Prm;
		TxMsg.Data.Data[5] = oEntry.rBody.Split.dType;
		TxMsg.Data.Data[6] = oEntry.rBody.Split.Prm1;
		TxMsg.Data.Data[7] = oEntry.rBody.Split.Prm2;
		
		oBufInsert();
	}
}

void TProtoC2C::Ack(unsigned char TargetNum, unsigned char aOrder)
{
	OnReceive.IsCheckOnline = 0;
	
	OnReceive.IsProcessDone[TargetNum] = 1;
	OnReceive.OrderAck[TargetNum] = aOrder;
	OnReceive.Piece[TargetNum] =0;
	OnReceive.OrderDt[TargetNum] = 0;
	
	TxMsg.Data.Routing =0;
	TxMsg.Data.Priority = 1;
	TxMsg.Data.Identification = 0;
	
	TxMsg.Data.Cmd = dNetworkCmd_Ack;
	TxMsg.Data.Order = aOrder;
	TxMsg.Data.Len = 4;
	TxMsg.Data.Data[0] = 0;
	TxMsg.Data.Data[1] = MainCtl.fData.Split.MyNum;
	TxMsg.Data.Data[2] = TargetNum;
	TxMsg.Data.Data[3] = 0;
	
	oBufInsert();
}

void TProtoC2C::AckOnlineCheck(unsigned char TargetNum, unsigned char aOrder)
{
	OnReceive.IsCheckOnline = 1;
	
	OnReceive.IsProcessDone[TargetNum] = 1;
	OnReceive.OrderAck[TargetNum] = aOrder;
	OnReceive.Piece[TargetNum] =0;
	OnReceive.OrderDt[TargetNum] = 0;
	
	TxMsg.Data.Routing =0;
	TxMsg.Data.Priority = 1;
	TxMsg.Data.Identification = 0;
	
	TxMsg.Data.Cmd = dNetworkCmd_Ack;
	TxMsg.Data.Order = aOrder;
	TxMsg.Data.Len = 4;
	TxMsg.Data.Data[0] = 0x55;
	TxMsg.Data.Data[1] = MainCtl.fData.Split.MyNum;
	TxMsg.Data.Data[2] = TargetNum;
	TxMsg.Data.Data[3] = 0xAA;

	oBufInsert();
}

void TProtoC2C::ProcessAckRecFromSlave(unsigned char aOrder, unsigned char *Data)
{
	if(Data[2] == MainCtl.fData.Split.MyNum){
		if(aOrder == OnTransmite.DesireAckOrder[Data[1]]){
			if( Data[1] && (Data[1] <=dNETWORK_MACHINE_COUNT) ){
				OnTransmite.AckOk[Data[1]] = 1;
				if( (Data[0] == 0x55) && (Data[3] == 0xAA) ){
					SlaveOnlineList[Data[1]] = 1;
				}					
			}
		}
	}
}

void TProtoC2C::ProcessAckRecFromMaster(unsigned char aOrder, unsigned char *Data)
{
	if(Data[2] == MainCtl.fData.Split.MyNum){
		if(aOrder == OnTransmite.DesireAckOrder[Data[1]]){
			if( Data[1] && (Data[1] <= dNETWORK_MACHINE_COUNT) ){
				if(Data[1] == ProtoC2C.MasterNum)	CheckOnlineUpdateTick = 0;
				OnTransmite.AckOk[Data[1]] = 1;					
			}
		}
	}
}

void TProtoC2C::ExportEntry2oBuf(unsigned char IsNew)
{
	unsigned short aRemainCountDown;
	TDMix DMix;
	unsigned char aEt;
	if(MainCtl.fData.Split.NetworkMode == 0)return;
	CmdFillAreaNum =0;
	CmdFillDelayTime =0;
	CmdFillUserCode =0;
	OnTransmite.IsReportErr = 1;
	OnTransmite.IsBroadCast =1;
	switch(oEntry.rBody.Split.Cmd){
		case 	cmPublishAlram:
		case	cmVIrtualAlram:
		case 	cmConfirmAlram:
		case 	cmAutoStart:
		case 	cmAutoStop:
		case 	cmAck:
		case 	cmAckStop:
		case  cmTakeChargeAlram:
		case  cmTakeChargeAlramResume:
		case 	cmVIrtualStart:
		case 	smVIrtualStop:
		case 	cmVIrtualAck:
		case 	cmVIrtualAckStop:
		case  cmVIrtualSuperVi:
			CmdFillAreaNum =1;
			CmdFillUserCode =1;
			ExportMachineEventTime2Master(IsNew);
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Identification = 0; 
			TxMsg.Data.Len = 8;
			TxMsg.Data.Order = OnTransmite.Order;
			if(IsNew)TxMsg.Data.Identification =1;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			TxMsg.Data.Data[0] =0;
			TxMsg.Data.Data[1] =oEntry.rBody.Split.CtlNum;
			TxMsg.Data.Data[2] =oEntry.rBody.Split.P0;
			TxMsg.Data.Data[3] =oEntry.rBody.Split.P1;
			TxMsg.Data.Data[4] =oEntry.rBody.Split.Prm;
			TxMsg.Data.Data[5] =oEntry.rBody.Split.dType;
			TxMsg.Data.Data[6] =oEntry.rBody.Split.Prm1;
			TxMsg.Data.Data[7] =oEntry.rBody.Split.Prm2;
			if(CmdFillAreaNum){
					TxMsg.Data.Data[4] = static_cast<unsigned char>(oEntry.rBody.Split.AreaNum & 0x00FF);
					TxMsg.Data.CarryByte = static_cast<unsigned char>(((oEntry.rBody.Split.AreaNum & 0x0F00) >> 8 ));
			}
			if(CmdFillUserCode){
				DMix.D32 = oEntry.rBody.Split.UserCode;
				TxMsg.Data.Data[0] = DMix.D8[1];
				TxMsg.Data.Data[6] = DMix.D8[2];
				TxMsg.Data.Data[7] = DMix.D8[3];
			}
		
			oBufInsert();
			break;
		case  dNetworkCmd_AutoStartDelay:
		case  dNetworkCmd_AutoStartDelaySimulate:
			CmdFillDelayTime =1;
			CmdFillUserCode =1;
			ExportMachineEventTime2Master(IsNew);
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Len = 8;
			TxMsg.Data.Order = OnTransmite.Order;
			TxMsg.Data.Identification = 0;
			if(IsNew)TxMsg.Data.Identification =1;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
		
			//Is Delay Start
			TxMsg.Data.Data[1] =oEntry.rBody.Split.CtlNum;
			TxMsg.Data.Data[2] =oEntry.rBody.Split.P0;
			TxMsg.Data.Data[3] =oEntry.rBody.Split.P1;
			//TxMsg.Data.Data[4] =oEntryBuf.rBody.Split.Prm;
			TxMsg.Data.Data[5] =oEntry.rBody.Split.dType;
			if(CmdFillDelayTime){
					aRemainCountDown = GetThisCtlCountDownTime(oEntry.rBody.Split.CtlNum, oEntry.rBody.Split.P0, oEntry.rBody.Split.P1);
					TxMsg.Data.Data[4] = static_cast<unsigned char>(aRemainCountDown & 0x00FF);
					TxMsg.Data.CarryByte |= static_cast<unsigned char>(((aRemainCountDown & 0x0F00) >> 8 ));
			}
			if(CmdFillUserCode){
				DMix.D32 = oEntry.rBody.Split.UserCode;
				TxMsg.Data.Data[0] = DMix.D8[1];
				TxMsg.Data.Data[6] = DMix.D8[2];
				TxMsg.Data.Data[7] = DMix.D8[3];
			}
			oBufInsert();
			break;
		case 	cmPortModuleErr:
		case 	cmPortModuleErrRecover:
			CmdFillUserCode =1;
			ExportMachineEventTime2Master(IsNew);
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Len = 8;
			TxMsg.Data.Order = OnTransmite.Order;
			TxMsg.Data.Identification = 0;
			if(IsNew)TxMsg.Data.Identification =1;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;

			TxMsg.Data.Data[0] =0;
			TxMsg.Data.Data[1] =oEntry.rBody.Split.CtlNum;
			TxMsg.Data.Data[2] =oEntry.rBody.Split.P0;
			TxMsg.Data.Data[3] =oEntry.rBody.Split.P1;
			TxMsg.Data.Data[4] =oEntry.rBody.Split.Prm;
			TxMsg.Data.Data[5] =oEntry.rBody.Split.dType;
			TxMsg.Data.Data[6] =oEntry.rBody.Split.Prm1;
			TxMsg.Data.Data[7] =oEntry.rBody.Split.Prm2;
			if(CmdFillUserCode){
				DMix.D32 = oEntry.rBody.Split.UserCode;
				TxMsg.Data.Data[0] = DMix.D8[1];
				TxMsg.Data.Data[6] = DMix.D8[2];
				TxMsg.Data.Data[7] = DMix.D8[3];
			}
			oBufInsert();
			break;
		case cmCircuitErr:
		case cmOtherErr:
			ExportMachineEventTime2Master(IsNew);
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Len = 8;
			TxMsg.Data.Order = OnTransmite.Order;
			TxMsg.Data.Identification = IsNew;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
		
			TxMsg.Data.Data[0] =oEntry.rBody.Split.sType;
			TxMsg.Data.Data[1] =oEntry.rBody.Split.CtlNum;
			TxMsg.Data.Data[2] =oEntry.rBody.Split.P0;
			TxMsg.Data.Data[3] =oEntry.rBody.Split.P1;
			TxMsg.Data.Data[4] =oEntry.rBody.Split.Prm;
			TxMsg.Data.Data[5] =oEntry.rBody.Split.dType;
			TxMsg.Data.Data[6] =oEntry.rBody.Split.Prm1;
			TxMsg.Data.Data[7] =oEntry.rBody.Split.Prm2;
		
			oBufInsert();
			break;
		
		case cmVAAlramStart:
		case cmVAAlramStop:
			ExportMachineEventTime2Master(IsNew);
			if(MainCtl.fData.Split.NetworkMode == 1){	
				TxMsg.Data.Data[0] =1;
			}else
			if(MainCtl.fData.Split.NetworkMode == 2){	
				TxMsg.Data.Data[0] =0;
			}
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Len = 8;
			TxMsg.Data.Order = OnTransmite.Order;
			TxMsg.Data.Identification = IsNew;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum;
			TxMsg.Data.Data[2] = oEntry.rBody.Split.Year;
			TxMsg.Data.Data[3] = oEntry.rBody.Split.Mon;
			TxMsg.Data.Data[4] = oEntry.rBody.Split.Day;
			TxMsg.Data.Data[5] = oEntry.rBody.Split.Hour;
			TxMsg.Data.Data[6] = oEntry.rBody.Split.Min;
			TxMsg.Data.Data[7] = oEntry.rBody.Split.Sec;
			oBufInsert();
			break;
		case 	dNetworkCmd_PublishOperate:
			CmdFillAreaNum =0;
			CmdFillDelayTime =0;
			CmdFillUserCode =0;
			aEt = oEntry.rBody.Split.sType;
			if(aEt == otMask){
				CmdFillUserCode =1;
			}else
			if(aEt == otUnMask){
				CmdFillUserCode =1;
			}
			ExportMachineEventTime2Master(IsNew);
		
			if(oEntry.rBody.Split.sType == otCfgDateTime){
				ExportMachineEventNewTime2Master(IsNew);
			}
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Len = 8;
			TxMsg.Data.Identification = IsNew;
			TxMsg.Data.Order = OnTransmite.Order;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
		
			TxMsg.Data.Data[0] =0;
			TxMsg.Data.Data[1] =oEntry.rBody.Split.CtlNum;
			TxMsg.Data.Data[2] =oEntry.rBody.Split.P0;
			TxMsg.Data.Data[3] =oEntry.rBody.Split.P1;
			TxMsg.Data.Data[4] =oEntry.rBody.Split.mType;
			TxMsg.Data.Data[5] =oEntry.rBody.Split.dType;
			TxMsg.Data.Data[6] =oEntry.rBody.Split.sType;
			TxMsg.Data.Data[7] =oEntry.rBody.Split.Prm2;
			
			if(  (oEntry.rBody.Split.sType == otReset) && (MainCtl.fData.Split.NetworkMode == 1) ){
				TxMsg.Data.Data[0] =1;
				TxMsg.Data.Data[7] =1;
			}
			if(otFaultRemoteConfirm == oEntry.rBody.Split.sType){
				TxMsg.Data.Data[0] =oEntry.rBody.Split.Prm1;
				TxMsg.Data.Data[1] =MainCtl.fData.Split.MyNum;
				TxMsg.Data.Data[2] =oEntry.rBody.Split.P0;
				TxMsg.Data.Data[3] =oEntry.rBody.Split.P1;
				TxMsg.Data.Data[4] =oEntry.rBody.Split.Prm;
				TxMsg.Data.Data[5] =oEntry.rBody.Split.dType;
				TxMsg.Data.Data[6] =oEntry.rBody.Split.sType;
				TxMsg.Data.Data[7] =oEntry.rBody.Split.Prm2;				
			}else
			if(otRegisterByManual == oEntry.rBody.Split.sType){
				TxMsg.Data.Data[0] =0;
				TxMsg.Data.Data[1] =MainCtl.fData.Split.MyNum;
				TxMsg.Data.Data[2] =oEntry.rBody.Split.P0;
				TxMsg.Data.Data[3] =oEntry.rBody.Split.P1;
				TxMsg.Data.Data[4] =oEntry.rBody.Split.Prm;
				TxMsg.Data.Data[5] =oEntry.rBody.Split.dType;
				TxMsg.Data.Data[6] =oEntry.rBody.Split.sType;
				TxMsg.Data.Data[7] =oEntry.rBody.Split.Prm2;	
			}
			
			if(CmdFillUserCode){
				DMix.D32 = oEntry.rBody.Split.UserCode;
				TxMsg.Data.Data[0] =DMix.D8[1];
				TxMsg.Data.Data[4] =DMix.D8[2];
				TxMsg.Data.Data[7] =DMix.D8[3];	
			}
			
			oBufInsert();
			break;
		case dNetworkCmd_MaskListSend:
			CmdFillUserCode =1;
			ExportMachineEventTime2Master(IsNew);
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Len = 8;
			TxMsg.Data.Identification = IsNew;
			TxMsg.Data.Order = OnTransmite.Order;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			
			TxMsg.Data.Data[0] =0;
			TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
			TxMsg.Data.Data[2] = oEntry.rBody.Split.P0;
			TxMsg.Data.Data[3] = oEntry.rBody.Split.P1;
			TxMsg.Data.Data[4] = 0;
			TxMsg.Data.Data[5] = oEntry.rBody.Split.dType;
		
			if(CmdFillUserCode){
				DMix.D32 = oEntry.rBody.Split.UserCode;
				TxMsg.Data.Data[0] =DMix.D8[1];
				TxMsg.Data.Data[6] =DMix.D8[2];
				TxMsg.Data.Data[7] =DMix.D8[3];	
			}
			
			oBufInsert();
			break;
		case dNetworkCmd_SlaveFbMissReport:
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Len = 4;
			TxMsg.Data.Identification = IsNew;
			TxMsg.Data.Order = OnTransmite.Order;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			
			TxMsg.Data.Data[0] =0;
			TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
			TxMsg.Data.Data[2] = oEntry.rBody.Split.P0;
			TxMsg.Data.Data[3] = oEntry.rBody.Split.P1;
			TxMsg.Data.Data[4] = 0;
			TxMsg.Data.Data[5] = oEntry.rBody.Split.dType;
			
			oBufInsert();
			break;
		case dNetworkCmd_CheckOnline:
			TxMsg.Data.Routing =0;
			TxMsg.Data.Priority = 1;
			TxMsg.Data.Len = 4;
			TxMsg.Data.Identification = IsNew;
			TxMsg.Data.Order = OnTransmite.Order;
			TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
		
			TxMsg.Data.Data[0] =0;
			TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
			TxMsg.Data.Data[2] = oEntry.rBody.Split.P0;
			TxMsg.Data.Data[3] = oEntry.rBody.Split.P1;
			TxMsg.Data.Data[4] = 0;
		
			CheckOnlineHasSend = 1;
		
			oBufInsert();
			break;
		case dNetworkCmd_CheckNormalData:
			if(oEntry.rBody.Split.Year == 0){
				TxMsg.Data.Routing =0;
				TxMsg.Data.Priority = 1;
				TxMsg.Data.Len = 4;
				TxMsg.Data.Identification = IsNew;
				TxMsg.Data.Order = OnTransmite.Order;
				TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			
				TxMsg.Data.Data[0] = oEntry.rBody.Split.Year ;
				TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
				TxMsg.Data.Data[2] = oEntry.rBody.Split.P0;
				TxMsg.Data.Data[3] = oEntry.rBody.Split.P1;
				
				OnTransmite.IsReportErr = 0;
				OnTransmite.IsBroadCast =0;
				OnTransmite.SlaveCtlNum = oEntry.rBody.Split.P0;
				oBufInsert();
			}else
			if(oEntry.rBody.Split.Year){
				TxMsg.Data.Routing =0;
				TxMsg.Data.Priority = 1;
				TxMsg.Data.Len = 8;
				TxMsg.Data.Identification = IsNew;
				TxMsg.Data.Order = OnTransmite.Order;
				TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			
				TxMsg.Data.Data[0] = oEntry.rBody.Split.Year ;
				TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
				TxMsg.Data.Data[2] = oEntry.rBody.Split.P0;
				TxMsg.Data.Data[3] = oEntry.rBody.Split.P1;
				TxMsg.Data.Data[4] = oEntry.rBody.Split.Prm;
				TxMsg.Data.Data[5] = oEntry.rBody.Split.dType;
				TxMsg.Data.Data[6] = oEntry.rBody.Split.Prm1;
				TxMsg.Data.Data[7] = oEntry.rBody.Split.Prm2;
			
				oBufInsert();
			}
			break;
		case dNetworkCmd_RemoteStartStop:
				TxMsg.Data.Routing =0;
				TxMsg.Data.Priority = 1;
				TxMsg.Data.Len = 8;
				TxMsg.Data.Identification = IsNew;
				TxMsg.Data.Order = OnTransmite.Order;
				TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			
				TxMsg.Data.Data[0] = oEntry.rBody.Split.Prm ;
				TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
				TxMsg.Data.Data[2] = oEntry.rBody.Split.P0;
				TxMsg.Data.Data[3] = oEntry.rBody.Split.P1;
				TxMsg.Data.Data[4] = 0;
				TxMsg.Data.Data[5] = oEntry.rBody.Split.dType;
				TxMsg.Data.Data[6] = oEntry.rBody.Split.Prm1;
				TxMsg.Data.Data[7] = oEntry.rBody.Split.Prm2;
			
				oBufInsert();
				break;
		case dNetworkCmd_RemoteStartStopViaUserCode:
		case dNetworkCmd_RemoteStartStopViaUserCodeSimulate:
				TxMsg.Data.Routing =0;
				TxMsg.Data.Priority = 1;
				TxMsg.Data.Len = 8;
				TxMsg.Data.Identification = IsNew;
				TxMsg.Data.Order = OnTransmite.Order;
				TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			
				DMix.D32 = oEntry.rBody.Split.UserCode;
		
				TxMsg.Data.Data[0] = oEntry.rBody.Split.Prm & 0x0F;	//Load Sta
				TxMsg.Data.Data[0] |= (oEntry.rBody.Split.Prm2 << 4);
				
				TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
				TxMsg.Data.Data[2] = DMix.D8[0];
				TxMsg.Data.Data[3] = DMix.D8[1];
				TxMsg.Data.Data[4] = DMix.D8[2];
				TxMsg.Data.Data[5] = oEntry.rBody.Split.dType;
				TxMsg.Data.Data[6] = DMix.D8[3];
				TxMsg.Data.Data[7] = oEntry.rBody.Split.Prm1;
			
				oBufInsert();
				break;
		case 	dNetworkCmd_ClearCtlFire:
				TxMsg.Data.Routing =0;
				TxMsg.Data.Priority = 1;
				TxMsg.Data.Len = 6;
				TxMsg.Data.Identification = IsNew;
				TxMsg.Data.Order = OnTransmite.Order;
				TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			
				TxMsg.Data.Data[0] = oEntry.rBody.Split.Prm ;
				TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
				TxMsg.Data.Data[2] = oEntry.rBody.Split.P0;
				TxMsg.Data.Data[3] = oEntry.rBody.Split.P1;
				TxMsg.Data.Data[4] = 0;
				TxMsg.Data.Data[5] = oEntry.rBody.Split.dType;

				oBufInsert();
				break;
		case  dNetworkCmd_PublishFireCancel:
		case  dNetworkCmd_PublishFire:
				TxMsg.Data.Routing =0;
				TxMsg.Data.Priority = 1;
				TxMsg.Data.Len = 6;
				TxMsg.Data.Identification = IsNew;
				TxMsg.Data.Order = OnTransmite.Order;
				TxMsg.Data.Cmd = oEntry.rBody.Split.Cmd;
			
				DMix.D32 = oEntry.rBody.Split.UserCode;
		
				TxMsg.Data.Data[0] = oEntry.rBody.Split.Prm ;
				TxMsg.Data.Data[1] = oEntry.rBody.Split.CtlNum ;
				TxMsg.Data.Data[2] = DMix.D8[0];
				TxMsg.Data.Data[3] = DMix.D8[1];
				TxMsg.Data.Data[4] = DMix.D8[2];
				TxMsg.Data.Data[5] = oEntry.rBody.Split.dType;
				TxMsg.Data.Data[6] = DMix.D8[3];
				TxMsg.Data.Data[7] = oEntry.rBody.Split.Prm2;

				oBufInsert();
				break;
	}
}

void TProtoC2C::PublishEventAlramOnOff(int aOnOff)
{
	if(aOnOff){
		oEntry.wBody.Split.Cmd = cmVAAlramStart;
	}else{
		oEntry.wBody.Split.Cmd = cmVAAlramStop;
	}
	oEntry.wBody.Split.CtlNum = MainCtl.fData.Split.MyNum;
	oEntry.wBody.Split.Year =DateTime.Date.Split.Year;
	oEntry.wBody.Split.Mon =DateTime.Date.Split.Month;
	oEntry.wBody.Split.Day = DateTime.Date.Split.Day;
	oEntry.wBody.Split.Hour = DateTime.Time.Split.Hour;
	oEntry.wBody.Split.Min = DateTime.Time.Split.Minute;
	oEntry.wBody.Split.Sec = DateTime.Time.Split.Second;
	
	oBufMsgInsertNormal();
}

void TProtoC2C::PublishEventMute()
{
	if(MainCtl.fData.Split.NetworkMode != 2)return;
	oEntry.wBody.Split.Cmd = cmMuteBell;
	oEntry.wBody.Split.CtlNum = MainCtl.fData.Split.MyNum;
	oEntry.wBody.Split.Year =DateTime.Date.Split.Year;
	oEntry.wBody.Split.Mon =DateTime.Date.Split.Month;
	oEntry.wBody.Split.Day = DateTime.Date.Split.Day;
	oEntry.wBody.Split.Hour = DateTime.Time.Split.Hour;
	oEntry.wBody.Split.Min = DateTime.Time.Split.Minute;
	oEntry.wBody.Split.Sec = DateTime.Time.Split.Second;
	
	oBufMsgInsertNormal();	
}

void TProtoC2C::PublishEventReset()
{	
	if(MainCtl.fData.Split.NetworkMode == 0)return;
	oBufInsert();
	oEntry.wBody.Split.Cmd = cmReset;
	oEntry.wBody.Split.CtlNum = MainCtl.fData.Split.MyNum;
	oEntry.wBody.Split.Year =DateTime.Date.Split.Year;
	oEntry.wBody.Split.Mon =DateTime.Date.Split.Month;
	oEntry.wBody.Split.Day = DateTime.Date.Split.Day;
	oEntry.wBody.Split.Hour = DateTime.Time.Split.Hour;
	oEntry.wBody.Split.Min = DateTime.Time.Split.Minute;
	oEntry.wBody.Split.Sec = DateTime.Time.Split.Second;
	
	if(MainCtl.fData.Split.NetworkMode == 1){
		oEntry.wBody.Split.Prm1 =1;
	}else{
		oEntry.wBody.Split.Prm1 =0;
	}
	oBufMsgInsertNormal();	
}





/*
void TRecord::OperateAdd_CfgDateTime(u8 aY, u8 aM, u8 aD, u8 aH, u8 aMin, u8 aSec)
{
	eOperateEvent.Splite.Year 	= DateTime.Date.Split.Year;
	eOperateEvent.Splite.Month 	= DateTime.Date.Split.Month;
	eOperateEvent.Splite.Day 	= DateTime.Date.Split.Day;
	eOperateEvent.Splite.Hour 	= DateTime.Time.Split.Hour;
	eOperateEvent.Splite.Minute 	= DateTime.Time.Split.Minute;
	eOperateEvent.Splite.Second 	= DateTime.Time.Split.Second;
	
	eOperateEvent.Splite.PCtlNum = MainCtl.fData.Split.MyNum;
	
	eOperateEvent.Splite.mType = etOperate;
	eOperateEvent.Splite.Data0 = otCfgDateTime;
	
	eOperateEvent.Splite.P0 = aY;
	eOperateEvent.Splite.P1 = aM;
	eOperateEvent.Splite.P2 = aD;
	eOperateEvent.Splite.Data1 = aH;
	eOperateEvent.Splite.iByte0 = aMin;
	eOperateEvent.Splite.iByte1 = aSec;
	
	OperateAdd(eOperateEvent);
	
	ProtoC2C.PublishOperate(eOperateEvent);	
}

void TProtoC2C::ExportMachineEventNewTime2Master(unsigned char IsNew)
{
	unsigned int i,aAddr;
	if(MainCtl.fData.Split.IsMaster == 0){
		TxMsg.Data.Pri = 1;
		TxMsg.Data.Cmd = dNetworkCmd_EventTime;
		TxMsg.Data.Order = OnTransmite.Order;
		TxMsg.Data.Idf = IsNew;
		TxMsg.Data.Len = 8;
		TxMsg.Data.Data[0] = 1;
		TxMsg.Data.Data[1] = oEntryBuf.rBody.Split.CtlNum;
		TxMsg.Data.Data[2] = oEntryBuf.rBody.Split.P0;
		TxMsg.Data.Data[3] = oEntryBuf.rBody.Split.P1;
		TxMsg.Data.Data[4] = oEntryBuf.rBody.Split.Prm;
		TxMsg.Data.Data[5] = oEntryBuf.rBody.Split.dType;
		TxMsg.Data.Data[6] = oEntryBuf.rBody.Split.Prm1;
		TxMsg.Data.Data[7] = oEntryBuf.rBody.Split.Prm2;
		
		oBufInsert();
	}
}

*/

void TProtoC2C::PublishOperate(TRecordCommon aIm)
{
		oEntry.wBody.Split.Cmd 	= dNetworkCmd_PublishOperate;
		oEntry.wBody.Split.Year 	= aIm.Splite.Year;
		oEntry.wBody.Split.Mon 	= aIm.Splite.Month;
		oEntry.wBody.Split.Day 	= aIm.Splite.Day;
		oEntry.wBody.Split.Hour 	= aIm.Splite.Hour;
		oEntry.wBody.Split.Min 	= aIm.Splite.Minute;
		oEntry.wBody.Split.Sec 	= aIm.Splite.Second;
	
		oEntry.wBody.Split.CtlNum = aIm.Splite.PCtlNum;
		
		if( aIm.Splite.Data0 == otCfgDateTime){
			oEntry.wBody.Split.P0 = aIm.Splite.P0;
			oEntry.wBody.Split.P1 = aIm.Splite.P1;
			oEntry.wBody.Split.Prm = aIm.Splite.P2;
			
			oEntry.wBody.Split.dType = aIm.Splite.Data1; 
			oEntry.wBody.Split.Prm1 = aIm.Splite.iByte0;
			oEntry.wBody.Split.Prm2 = aIm.Splite.iByte1;
			
			oEntry.wBody.Split.mType = aIm.Splite.mType;
			oEntry.wBody.Split.sType = aIm.Splite.Data0;
		}else{
			oEntry.wBody.Split.P0 = aIm.Splite.P0;
			oEntry.wBody.Split.P1 = aIm.Splite.P1;
			oEntry.wBody.Split.Prm = aIm.Splite.P2;
			oEntry.wBody.Split.dType = aIm.Splite.dType;
			oEntry.wBody.Split.Prm2 = aIm.Splite.Data1;
			
			oEntry.wBody.Split.mType = aIm.Splite.mType;
			oEntry.wBody.Split.sType = aIm.Splite.Data0;
			
			if(oEntry.wBody.Split.sType == otFaultRemoteConfirm)
				oEntry.wBody.Split.Prm1 =  aIm.Splite.iByte0;
		}
		
		oEntry.wBody.Split.UserCode = aIm.Splite.UserCode;
		oBufMsgInsertNormal();
}

void TProtoC2C::OperateGet(unsigned char aCmd, unsigned char *Data)
{
	unsigned int tUc;
	unsigned char aEt;
	TDMix	Dm;
	TDMix16 Dm16;
	
	if(MainCtl.fData.Split.NetworkMode == 0)return;
	
	if( (Data[1] == 0) || (Data[1] > 32) ) return;
	OperateEntry.Splite.Year = RecDateTime[Data[1]].Dt.Year;
	OperateEntry.Splite.Month = RecDateTime[Data[1]].Dt.Mon;
	OperateEntry.Splite.Day = RecDateTime[Data[1]].Dt.Day;
	OperateEntry.Splite.Hour = RecDateTime[Data[1]].Dt.Hour;
	OperateEntry.Splite.Minute = RecDateTime[Data[1]].Dt.Min;
	OperateEntry.Splite.Second = RecDateTime[Data[1]].Dt.Sec;
	
	OperateEntry.Splite.PCtlNum = Data[1];
	OperateEntry.Splite.P0 = Data[2];
	OperateEntry.Splite.P1 = Data[3];
	OperateEntry.Splite.mType = Data[4];
	OperateEntry.Splite.iByte0 = Data[5];
	OperateEntry.Splite.Data0 = Data[6];
	OperateEntry.Splite.Data1 = Data[7];
	
	aEt = Data[6];
	
	if(MainCtl.fData.Split.NetworkMode == 1){
		if(aEt == otReset){
			//CtlCenter.NwMachineStateClear(RxMsg.Data.Data[1]);
			//CtlCenter.NwMachineMsgFireClear(RxMsg.Data.Data[1]);
			//CtlCenter.CheckSoundFire();
			//CtlCenter.NwMachineMsgLinkageClear(RxMsg.Data.Data[1]);
			//CtlCenter.CheckSoundLinkage();
			//CtlCenter.NwMachineMsgSvClear(RxMsg.Data.Data[1]);
			//CtlCenter.CheckSoundSv();
			//CtlCenter.NwMachineMsgFaultClear(RxMsg.Data.Data[1]);
			//CtlCenter.CheckSoundFault();
			//MasterDoMaskListRemove(RxMsg.Data.Data[1]); 
			//ProtoC2C.ClearNwCtlFire(RxMsg.Data.Data[1]);
			//ProtoC2C.MasterDoPublishClearNwCtlFire(RxMsg.Data.Data[1]);
		}else
		if(aEt == otCfgDateTime){
			if(OnReceive.Piece[Data[1]] == 3){
				OperateEntry.Splite.P0 	= RecNewDateTime[Data[1]].Dt.Year;
				OperateEntry.Splite.P1 	= RecNewDateTime[Data[1]].Dt.Mon;
				OperateEntry.Splite.P2 	= RecNewDateTime[Data[1]].Dt.Day;
				OperateEntry.Splite.Data1 	= RecNewDateTime[Data[1]].Dt.Hour;
				OperateEntry.Splite.iByte0	= RecNewDateTime[Data[1]].Dt.Min;
				OperateEntry.Splite.iByte1 	= RecNewDateTime[Data[1]].Dt.Sec;
				
				//TxMsg.Data.Data[2] = oEntryBuf.rBody.Split.P0;
				//TxMsg.Data.Data[3] = oEntryBuf.rBody.Split.P1;
				//TxMsg.Data.Data[4] = oEntryBuf.rBody.Split.Prm;
				//TxMsg.Data.Data[5] = oEntryBuf.rBody.Split.dType;
				//TxMsg.Data.Data[6] = oEntryBuf.rBody.Split.Prm1;
				//TxMsg.Data.Data[7] = oEntryBuf.rBody.Split.Prm2;
				
				
				//eOperateEvent.Splite.P0 = aY;
				//eOperateEvent.Splite.P1 = aM;
				//eOperateEvent.Splite.P2 = aD;
				//eOperateEvent.Splite.Data1 = aH;
				//eOperateEvent.Splite.iByte0 = aMin;
				//eOperateEvent.Splite.iByte1 = aSec;
			}
		}else
		if(aEt == otMask){
			Dm.D8[0] = RecUserCodeAreaNum[Data[1]].UC.Bytes[0];
			Dm.D8[1] = Data[0];
			Dm.D8[2] = Data[4];
			Dm.D8[3] = Data[7];
			MasterDoAddRemoveMask(Data[1], Data[2], Data[3], Data[5], Dm.D32, 1);
			ExRecord.SetStateCodeMask();
			FecBusCRT.SetStateCodeMask();
			
			OperateEntry.Splite.mType = etOperate;
			OperateEntry.Splite.Data0 = otMask;
			OperateEntry.Splite.dType = Data[5];
			OperateEntry.Splite.UserCode = Dm.D32;
		}else
		if(aEt == otUnMask){
			Dm.D8[0] = RecUserCodeAreaNum[Data[1]].UC.Bytes[0];
			Dm.D8[1] = Data[0];
			Dm.D8[2] = Data[4];
			Dm.D8[3] = Data[7];
			MasterDoAddRemoveMask(Data[1], Data[2], Data[3], Data[5], 0, 0);
			ExRecord.SetStateCodeMask();
			FecBusCRT.SetStateCodeMask();
			
			OperateEntry.Splite.dType = Data[5];
			OperateEntry.Splite.mType = etOperate;
			OperateEntry.Splite.Data0 = otUnMask;
			OperateEntry.Splite.UserCode = Dm.D32;
		}else
		if(aEt == otUserCheck){
			if(Data[2]){
				NwIsNormalCheck |= 1 << Data[1];
			}else{
				NwIsNormalCheck &= ~(1<<Data[1]);
				return;
			}
		}else
		if(aEt == otFireRemoteConfirm){
			Dm.D8[0] = Data[7];
			Dm.D8[1] = Data[2];
			Dm.D8[2] = Data[3];
			Dm.D8[3] = 0;
			tUc = CtlCenter.ieFireMsgConfAddr(Dm.D32);
			CtlCenter.ieMsgFire.ReflashIndex++;
			CtlCenter.ieGot = 1;
			
			OperateEntry.Splite.PCtlNum = Data[7];
			OperateEntry.Splite.P0 = Data[2];
			OperateEntry.Splite.P1 = Data[3];
			OperateEntry.Splite.P2 = Data[1];
			OperateEntry.Splite.dType = Data[5];
			OperateEntry.Splite.Data1 = Data[0];
			
			OperateEntry.Splite.mType = etOperate;
			OperateEntry.Splite.Data0 = otFireRemoteConfirm;
			
			OperateEntry.Splite.UserCode = tUc;
		}else
		if(aEt == otFireSimRemoteConfirm){
			Dm.D8[0] = Data[7];
			Dm.D8[1] = Data[2];
			Dm.D8[2] = Data[3];
			Dm.D8[3] = 0;
			tUc = CtlCenter.ieFireMsgConfAddr(Dm.D32);
			CtlCenter.ieMsgFire.ReflashIndex++;
			CtlCenter.ieGot = 1;
			
			OperateEntry.Splite.PCtlNum = Data[7];
			OperateEntry.Splite.P0 = Data[2];
			OperateEntry.Splite.P1 = Data[3];
			OperateEntry.Splite.P2 = Data[1];
			OperateEntry.Splite.dType = Data[5];
			OperateEntry.Splite.Data1 = Data[0];
			
			OperateEntry.Splite.mType = etOperate;
			OperateEntry.Splite.Data0 = otFireSimRemoteConfirm;
			
			OperateEntry.Splite.UserCode = tUc;
		}else
		if(aEt == otFaultRemoteConfirm){
			Dm.D8[0] = Data[0];
			Dm.D8[1] = Data[2];
			Dm.D8[2] = Data[3];
			Dm.D8[3] = Data[4];
			tUc = CtlCenter.ieFaultMsgFaultConfAddr(Dm.D32);
			CtlCenter.ieMsgFault.ReflashIndex++;
			CtlCenter.ieGot = 1;	
			
			OperateEntry.Splite.PCtlNum = Data[0];
			OperateEntry.Splite.P0 = Data[2];
			OperateEntry.Splite.P1 = Data[3];
			OperateEntry.Splite.P2 = Data[4];
 			OperateEntry.Splite.dType = Data[5];
			OperateEntry.Splite.Data0 = Data[6];
			OperateEntry.Splite.Data1 = Data[7];
			
			OperateEntry.Splite.mType = etOperate;
			OperateEntry.Splite.Data0 = otFaultRemoteConfirm;
			
			OperateEntry.Splite.UserCode = tUc;
		}else
		if(aEt == otSelfCheck){
			NwSelfCheckTick[Data[1]] = 12;
		}else
		if(aEt == otRegisterByManual){
			OperateEntry.Splite.PCtlNum = Data[1];
			OperateEntry.Splite.P0 = Data[2];
			OperateEntry.Splite.P1 = Data[3];
			OperateEntry.Splite.P2 = Data[4];
 			OperateEntry.Splite.dType = Data[5];
			OperateEntry.Splite.Data0 = Data[6];
			OperateEntry.Splite.Data1 = Data[7];
			
			OperateEntry.Splite.mType = etOperate;
			OperateEntry.Splite.Data0 = otRegisterByManual;
		}
	}else
	if(MainCtl.fData.Split.NetworkMode == 2){
		if(otReset == aEt){
			if(RxMsg.Data.Data[0]){
				//Reset 
				OperateEntry.Splite.PCtlNum = MainCtl.fData.Split.MyNum;
				OperateEntry.Splite.Data1 = 1;
				if(Register.IsOnGo == 0){
					ProtoC2C.ResetCoomm();
					ProtoC2C.ClearNwAllCtlFire();
					FecBusCRT.ResetCallBack();
					FecStd.ResetCallBack();
					ResetCallBack();
				}
				Ack(OnReceive.CallResetCtlNum, OnReceive.CallResetNetOrder);
			}
		}else
		if(otSetNwTime == aEt){
			unsigned int tToClear, ClearOk;
			OperateEntry.Splite.PCtlNum = MainCtl.fData.Split.MyNum;
			TDateTime::sDateTimeIncSec(&RecDateTime[Data[1]].D8[2], 1);
			Record.OperateAdd_GetDateTime(RecDateTime[Data[1]].Dt.Year, RecDateTime[Data[1]].Dt.Mon, RecDateTime[Data[1]].Dt.Day, \
								RecDateTime[Data[1]].Dt.Hour, RecDateTime[Data[1]].Dt.Min,RecDateTime[Data[1]].Dt.Sec);
			tToClear = Check4ModifiedDate2ClearLastMaintain(RecDateTime[Data[1]].Dt.Year, RecDateTime[Data[1]].Dt.Mon, RecDateTime[Data[1]].Dt.Day);
			DataTimeSet(	RecDateTime[Data[1]].Dt.Year, RecDateTime[Data[1]].Dt.Mon, RecDateTime[Data[1]].Dt.Day, \
						RecDateTime[Data[1]].Dt.Hour, RecDateTime[Data[1]].Dt.Min,RecDateTime[Data[1]].Dt.Sec,  1);	//aWk 1..7
			if(tToClear){
				LastMaintain.Day = 0x01;
				LastMaintain.Month = 0x01;
				LastMaintain.Year = 0x20;
				LastMaintain.Cent = 0x20;
				ClearOk = Record.WriteLastMaintainTime();
			}
			if(DateTimeCfg.IsShow !=0 ){
				if(DateTimeCfg.SlaveDateTimeHasBeenSet == 0){
					if(tToClear){
						if(ClearOk == 0){
							DateTimeCfg.ShowSta(14);
						}else{
							DateTimeCfg.ShowSta(24);
						}
					}else{
						DateTimeCfg.ShowSta(4);
					}
				}
			}
			FecStd.TriggerCmd04SyncTime();
			Check4MaintainToShow();
			if(IsSelfChecking == 0)
				StateBarReflashMaintain();
			return;
		}else
		if(aEt == otRemoteSetAutoAllowState){
			SlaveSetManualState(Data[7]);
			OperateEntry.Splite.PCtlNum = MainCtl.fData.Split.MyNum;
		}else
		if(aEt == otRemoteSetManualAllowState){
			SlaveSetManualState(Data[7]);
			OperateEntry.Splite.PCtlNum = MainCtl.fData.Split.MyNum;
		}else
		if(aEt == otFireRemoteConfirm){
			Dm.D8[0] = Data[7];
			Dm.D8[1] = Data[2];
			Dm.D8[2] = Data[3];
			Dm.D8[3] = 0;
			tUc = CtlCenter.ieFireMsgConfAddr(Dm.D32);
			CtlCenter.ieMsgFire.ReflashIndex++;
			CtlCenter.ieGot = 1;
			
			OperateEntry.Splite.PCtlNum = Data[7];
			OperateEntry.Splite.P0 = Data[2];
			OperateEntry.Splite.P1 = Data[3];
			OperateEntry.Splite.P2 = Data[1];
			OperateEntry.Splite.dType = Data[5];
			OperateEntry.Splite.Data1 = Data[1];
			
			OperateEntry.Splite.mType = etOperate;
			OperateEntry.Splite.Data0 = otFireRemoteConfirm;
			
			OperateEntry.Splite.UserCode = tUc;
			
			if(OperateEntry.Splite.PCtlNum != MainCtl.fData.Split.MyNum)return;
		}else
		if(aEt == otFaultRemoteConfirm){
			Dm.D8[0] = Data[0];
			Dm.D8[1] = Data[2];
			Dm.D8[2] = Data[3];
			Dm.D8[3] = Data[4];
			tUc = CtlCenter.ieFaultMsgFaultConfAddr(Dm.D32);
			CtlCenter.ieMsgFault.ReflashIndex++;
			CtlCenter.ieGot = 1;
			
			OperateEntry.Splite.PCtlNum = Data[0];
			OperateEntry.Splite.P0 = Data[2];
			OperateEntry.Splite.P1 = Data[3];
			OperateEntry.Splite.P2 = Data[4];
 			OperateEntry.Splite.dType = Data[5];
			OperateEntry.Splite.Data0 = Data[6];
			OperateEntry.Splite.Data1 = Data[1];
			
			OperateEntry.Splite.mType = etOperate;
			OperateEntry.Splite.Data0 = otFaultRemoteConfirm;
			
			OperateEntry.Splite.UserCode = tUc;
			
			if(OperateEntry.Splite.PCtlNum != MainCtl.fData.Split.MyNum)return;
		}else
		if( (aEt == otLinkageGo) && (OperateEntry.Splite.Data1 == 3) ){
			OperateEntry.Splite.PCtlNum = MainCtl.fData.Split.MyNum;
			OperateEntry.Splite.Data1 = 3;
			LinkageManualGo = 1;
			CtlCenter.CheckHydrantKpActionForce();
		}else
		if(aEt == otRemoteSetAllowState){
			SlaveSetAllowState(Data[7]);
			OperateEntry.Splite.PCtlNum = MainCtl.fData.Split.MyNum;
		}
	}
	ExRecord.SetStateCodeAll();	
	FecBusCRT.SetStateCodeAll();
	sIm.D32[0] = OperateEntry.D32[0];
	sIm.D32[1] = OperateEntry.D32[1];
	sIm.D32[2] = OperateEntry.D32[2];
	sIm.D32[3] = OperateEntry.D32[3];
	sIm.D32[4] = OperateEntry.D32[4];
	sIm.D32[5] = OperateEntry.D32[5];
	Record.OperateAddFromNw(sIm);
}

void TProtoC2C::AddRemoveNwCommFault(unsigned char aCtlNum, unsigned int IsAdd)
{
	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 = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xD0;			//Board Index
	aIm.Splite.P1 = aCtlNum;
	aIm.Splite.P2 = 11;	//Fault Type			
	aIm.Splite.Data0 = 11;	//Fault Type
	if(IsAdd)
		aIm.Splite.Data1 = 0xD1;//Is Set=1  Recover=0
	else
		aIm.Splite.Data1 = 0xD0;//Is Set=1  Recover=0
	
	aIm.Splite.dType = 0;
	aIm.Splite.mType	= CommLostCount[aCtlNum];
	
	
	if(IsAdd)
		CtlCenter.iePushOneMsgFault(aIm);
	else
		CtlCenter.iePushOneMsgFaultCancel(aIm);
	
	Record.FaultAdd(aIm);	
}

void TProtoC2C::AddMasterCommFault(unsigned char aCtlNum)
{
	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 = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xD0;			//Board Index
	aIm.Splite.P1 = aCtlNum;
	aIm.Splite.P2 = 16;	//Fault Type			
	aIm.Splite.Data0 = 16;	//Fault Type
	aIm.Splite.Data1 = 0xD1;//Is Set=1  Recover=0
	
	aIm.Splite.dType = 0;
	aIm.Splite.mType	= CommLostCount[aCtlNum];
	
		
	CtlCenter.iePushOneMsgFault(aIm);
	Record.FaultAdd(aIm);
}

void TProtoC2C::RemoveMasterCommFault(unsigned char aCtlNum)
{
	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 = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xD0;			//Board Index
	aIm.Splite.P1 = aCtlNum;
	aIm.Splite.P2 = 16;	//Fault Type			
	aIm.Splite.Data0 = 16;	//Fault Type
	aIm.Splite.Data1 = 0xD0;//Is Set=1  Recover=0
	
	aIm.Splite.dType = 0;
	aIm.Splite.mType	= CommLostCount[aCtlNum];
		
	CtlCenter.iePushOneMsgFaultCancel(aIm);
	Record.FaultAdd(aIm);
}

void TProtoC2C::AddSlaveCommFault(unsigned char aCtlNum)
{
	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 = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xD0;			//Board Index
	aIm.Splite.P1 = aCtlNum;
	aIm.Splite.P2 = 15;	//Fault Type			
	aIm.Splite.Data0 = 15;	//Fault Type
	aIm.Splite.Data1 = 0xD1;//Is Set=1  Recover=0
	
	aIm.Splite.dType = 0;
	aIm.Splite.mType = CommLostCount[0];
	
		
	CtlCenter.iePushOneMsgFault(aIm);
	Record.FaultAdd(aIm);
}

void TProtoC2C::RemoveSlaveCommFault(unsigned char aCtlNum)
{
	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 = CmdActiveDefaultSet[cmOtherErr][7];
	aIm.Splite.PCtlNum = MainCtl.fData.Split.MyNum ;	//(0,aRxMsg.Data.D8[1]);
	
	aIm.Splite.P0 = 0xD0;			//Board Index
	aIm.Splite.P1 = aCtlNum;
	aIm.Splite.P2 = 15;	//Fault Type			
	aIm.Splite.Data0 = 15;	//Fault Type
	aIm.Splite.Data1 = 0xD0;//Is Set=1  Recover=0
	
	aIm.Splite.dType = 0;
	aIm.Splite.mType = CommLostCount[0];
	
		
	CtlCenter.iePushOneMsgFaultCancel(aIm);
	Record.FaultAdd(aIm);
}

void TProtoC2C::ReInit()
{
	int i;
	OnTransmite.OnGoing = 0;
	OnTransmite.TimeOutTick = 0;
	OnReceive.OnGoing = 0;
	for(i=0; i<32; i++){
		OnReceive.State[i] =0;
		CommLostCount[i]= 0;
	}
	
	ErrReport = 0;
	ErrHasReport =0;
	iBufInCount = 0;
	iBufInCountPer2Sec =0;
	
	for(i=0; i<32; i++){
		ReportSlaveOffline[i] = 0;;
		NoAckList[i] =0;
	}
	ReportMasterOffline = 0;
}

void TProtoC2C::ResetCoomm()
{
	int i;
	Init();
	MasterRetrySendEntryCount = 0;
	SlaveRetrySendEntryCount =0;
	OnTransmite.OnGoing = 0;
	OnTransmite.TimeOutTick = 0;
	OnReceive.OnGoing = 0;
	for(i=0; i<64; i++){
		OnReceive.State[i] =0;
		CommLostCount[i]= 0;
		OnReceive.Piece[i] = 0;
		OnReceive.IsProcessDone[i] =0;
		OnReceive.OrderAck[i] = 0;
		OnReceive.OrderDt[i] = 0;
		OnReceive.OrderNewDt[i] =0;
	}
	
	for(i=0; i<32; i++){
		ReportSlaveOffline[i] = 0;;
		NoAckList[i] =0;
	}
	ReportMasterOffline = 0;
	
	CheckOnlineTick =0;
	CheckOnlineUpdateTick =0;
	CheckOnlineHasSend = 0;
	CheckOnlineHasStart = 0;
	SlaveOnlineListOld[0] = 1;
	CheckOnlineAfterSendTick = 0;
	
	ErrReport = 0;
	ErrHasReport = 0;
	iBufInCount = 0;
	iBufInCountPer2Sec = 0;
	
	RemoteReq.Reg.IsRequsting =0;
}

void TProtoC2C::CheckInBufCount()
{
	if(iBufInCountOdd){
		iBufInCountOdd = 0;
	}else{
		iBufInCountOdd = 1;
		iBufInCountPer2Sec = iBufInCount;
		iBufInCount = 0;
	}
}

void TProtoC2C::SetNwFire(unsigned char aNum, unsigned char aP0, unsigned char aP1, unsigned int Sta)
{
	unsigned int aAddr;
	unsigned int NumOffSet, P0OffSet, P1OffSet;
	if(aNum > dNETWORK_MACHINE_COUNT)return;
	if(aP0 > dPORT_MAX_COUNT)return;
	
	NumOffSet = (static_cast<unsigned int>(aNum)) * 40960;
	P0OffSet = (static_cast<unsigned int>(aP0)) * 1024;
	P1OffSet = (static_cast<unsigned int>(aP1)) * 4;
	
	aAddr = dAddrSdram_NwFireIdf + NumOffSet + P0OffSet + P1OffSet;
	*(volatile unsigned int *)aAddr = Sta;
}

unsigned int TProtoC2C::GetNwFire(unsigned char aNum, unsigned char aP0, unsigned char aP1)
{
	unsigned int aAddr;
	unsigned int NumOffSet, P0OffSet, P1OffSet;
	unsigned int aSta;
	if(aNum > dNETWORK_MACHINE_COUNT)return 0;
	if(aP0 > dPORT_MAX_COUNT)return 0;
	
	NumOffSet = (static_cast<unsigned int>(aNum)) * 40960;
	P0OffSet = (static_cast<unsigned int>(aP0)) * 1024;
	P1OffSet = (static_cast<unsigned int>(aP1)) * 4;
	
	aAddr = dAddrSdram_NwFireIdf + NumOffSet + P0OffSet + P1OffSet;
	aSta = *(volatile unsigned int *)aAddr;
	return aSta;
}

void TProtoC2C::ClearNwCtlFire(unsigned char aNum)
{
	unsigned int aAddr;
	unsigned int NumOffSet, i;
	if(aNum > dNETWORK_MACHINE_COUNT)return;

	NumOffSet = (static_cast<unsigned int>(aNum)) * 40960;
	
	aAddr = dAddrSdram_NwFireIdf + NumOffSet;
	for(i=0; i<10240; i++){
		*(volatile unsigned int *)aAddr = 0;
		aAddr += 4;
	}
}

void TProtoC2C::ClearNwAllCtlFire()
{
	unsigned int i;
	for(i=1; i<=dNETWORK_MACHINE_COUNT; i++)ClearNwCtlFire(i);
}

void TProtoC2C::IdfCmdExternFill(unsigned char aCmd, unsigned char aPrm)
{
	CmdFillAreaNum =0;
	CmdFillDelayTime =0;
	CmdFillUserCode =0;
	
	if(aCmd == cmPublishAlram){
		CmdFillAreaNum =1;
		CmdFillUserCode =1;
	}else
	if(aCmd == cmTakeChargeAlram){
		CmdFillAreaNum =1;
		CmdFillUserCode =1;
	}else
	if(aCmd == cmConfirmAlram){
		CmdFillAreaNum =1;
		CmdFillUserCode =1;
	}else
	if(aCmd == cmAutoStart){
		if(aPrm){
			//Start Delay 
			CmdFillDelayTime =1;
			CmdFillUserCode =1;
		}else{
			//Start
			CmdFillAreaNum =1;
			CmdFillUserCode =1;
		}
	}else
	if(aCmd == cmAutoStop){
		CmdFillAreaNum =1;
		CmdFillUserCode =1;
	}else
	if(aCmd == cmAck){
		CmdFillAreaNum =1;
		CmdFillUserCode =1;
	}else
	if(aCmd == cmAckStop){
		CmdFillAreaNum =1;
		CmdFillUserCode =1;
	}else
	if(aCmd == cmPortModuleErr){
		CmdFillAreaNum =1;
		CmdFillUserCode =1;
	}else
	if(aCmd == cmPortModuleErrRecover){
		CmdFillAreaNum =1;
		CmdFillUserCode =1;
	}
}

void TProtoC2C::GetFireRemoteConfirm(unsigned char *Data)
{
	unsigned char aEt;
	TDMix	Dm;
	TDMix16 Dm16;
	
	if(MainCtl.fData.Split.NetworkMode == 0)return;
	
	if( (Data[1] == 0) || (Data[1] > 32) ) return;
	OperateEntry.Splite.Year = RecDateTime[Data[1]].Dt.Year;
	OperateEntry.Splite.Month = RecDateTime[Data[1]].Dt.Mon;
	OperateEntry.Splite.Day = RecDateTime[Data[1]].Dt.Day;
	OperateEntry.Splite.Hour = RecDateTime[Data[1]].Dt.Hour;
	OperateEntry.Splite.Minute = RecDateTime[Data[1]].Dt.Min;
	OperateEntry.Splite.Second = RecDateTime[Data[1]].Dt.Sec;
	
	OperateEntry.Splite.PCtlNum = Data[0];
	OperateEntry.Splite.P0 = Data[2];
	OperateEntry.Splite.P1 = Data[3];
	OperateEntry.Splite.mType = Data[4];
	OperateEntry.Splite.iByte0 = Data[5];
	OperateEntry.Splite.Data0 = Data[6];
	OperateEntry.Splite.Data1 = Data[7];
	
	Dm.D8[0] = Data[0];
	Dm.D8[1] = Data[2];
	Dm.D8[2] = Data[3];
	Dm.D8[3] = 0;
	CtlCenter.ieFireMsgConfAddr(Dm.D32);
	CtlCenter.ieMsgFire.ReflashIndex++;
	CtlCenter.ieGot = 1;
	
	OperateEntry.Splite.PCtlNum = Data[7];
	OperateEntry.Splite.P0 = Data[2];
	OperateEntry.Splite.P1 = Data[3];
	OperateEntry.Splite.P2 = Data[1];
	OperateEntry.Splite.dType = Data[5];
	OperateEntry.Splite.Data1 = Data[0];
	
	OperateEntry.Splite.mType = etOperate;
	OperateEntry.Splite.Data0 = otFireRemoteConfirm;
}

void TProtoC2C::GetFaultRemoteConfirm(unsigned char *Data)
{
	unsigned char aEt;
	TDMix	Dm;
	TDMix16 Dm16;
	
	if(MainCtl.fData.Split.NetworkMode == 0)return;
	
	if( (Data[1] == 0) || (Data[1] > 32) ) return;
	OperateEntry.Splite.Year = RecDateTime[Data[1]].Dt.Year;
	OperateEntry.Splite.Month = RecDateTime[Data[1]].Dt.Mon;
	OperateEntry.Splite.Day = RecDateTime[Data[1]].Dt.Day;
	OperateEntry.Splite.Hour = RecDateTime[Data[1]].Dt.Hour;
	OperateEntry.Splite.Minute = RecDateTime[Data[1]].Dt.Min;
	OperateEntry.Splite.Second = RecDateTime[Data[1]].Dt.Sec;
	
	OperateEntry.Splite.PCtlNum = Data[0];
	OperateEntry.Splite.P0 = Data[2];
	OperateEntry.Splite.P1 = Data[3];
	OperateEntry.Splite.mType = Data[4];
	OperateEntry.Splite.iByte0 = Data[5];
	OperateEntry.Splite.Data0 = Data[6];
	OperateEntry.Splite.Data1 = Data[7];
	
	if((MainCtl.fData.Split.NetworkMode == 2) && (OperateEntry.Splite.PCtlNum != MainCtl.fData.Split.MyNum))return;
	
	Dm.D8[0] = Data[0];
	Dm.D8[1] = Data[2];
	Dm.D8[2] = Data[3];
	Dm.D8[3] = 0;
	CtlCenter.ieFaultMsgFaultConfAddr(Dm.D32);
	CtlCenter.ieMsgFault.ReflashIndex++;
	CtlCenter.ieGot = 1;	
	
	OperateEntry.Splite.PCtlNum = Data[0];
	OperateEntry.Splite.P0 = Data[2];
	OperateEntry.Splite.P1 = Data[3];
	OperateEntry.Splite.P2 = Data[4];
	OperateEntry.Splite.dType = Data[5];
	OperateEntry.Splite.Data0 = Data[6];
	OperateEntry.Splite.Data1 = Data[7];
	
	OperateEntry.Splite.mType = etOperate;
	OperateEntry.Splite.Data0 = otFaultRemoteConfirm;
}

void TProtoC2C::sSimGetStartDelay(TRecordCommon *aRc, unsigned short aDelayTimes)
{
	aRc->Splite.P2 = 0;
	if(aRc->Splite.P0 == 0){
										
	}else
	if(aRc->Splite.P0 <= dPORT_MAX_COUNT){
		aRc->Splite.mType = etLinkageStart;
		aRc->Splite.iByte0 = 0x0A;
		aRc->Splite.Data1 = TControlCenter::StartTypeSimulate;
		sSetNwDevDelayStartPoint(aRc->Splite.PCtlNum, aRc->Splite.P0, aRc->Splite.P1, aDelayTimes);
		if(CtlCenter.IsMsgReseting == 0){
			CtlCenter.iePushOneMsgLinkageStartSimulate(*aRc);
		}
	}else
	if( (aRc->Splite.P0 >= dADDR_DIRECTPAD_START) && (aRc->Splite.P0 <= dADDR_DIRECTPAD_END) ){
		aRc->Splite.mType = etLinkageStart;
		aRc->Splite.iByte0 = 0x0A;
		aRc->Splite.Data1 = TControlCenter::StartTypeSimulate;
		sSetNwDirectPadDelayStartPoint(aRc->Splite.PCtlNum, aRc->Splite.P0 - dADDR_DIRECTPAD_START + 1, aRc->Splite.P1, aDelayTimes);
		if(CtlCenter.IsMsgReseting == 0){
			CtlCenter.iePushOneMsgLinkageStartSimulate(*aRc);
		}
	}
}


void TProtoC2C::Task10Ms()
{
	if(MainCtl.fData.Split.NetworkMode == 0)return;
	ProcessoEntry();
	oBufProcess();
	
	if(MainCtl.fData.Split.NetworkMode == 1)MasterDoCheckOnlineTask();
	else if(MainCtl.fData.Split.NetworkMode == 2)SlaveDoCheckOnlineTask();
	
	if(NeedReply){
		if(ReplyWhat == dNetworkRpyType){
			ReplyCtrlType();
		}else
		if(ReplyWhat == dNetworkRpyDescp){
			ReplyDescp();
		}
	}	
}











