#ifndef PROTOC2C_H_
#define PROTOC2C_H_

#include "gvalue.h"
#include "gType.h"
#include "ProtoInnerCan.h"
#include "TDateTime.h"
#include "record.h"
#include "ProtoM2M.h"

#define dNetworkInBufMaxLength		1024

#define OutputEntrySize					24
//(0xC1900000)
#define dNetworkOutEntryBufFireMaxLength		16000
#define dNetworkOutEntryBufSvMaxLength		 8000
#define dNetworkOutEntryBufLinkMaxLength		 8000
#define dNetworkOutBufMaxLength			10000

//(0xC1A00000)
#define dNetworkOutEntryBufFaultMaxLength		20000
#define dNetworkOutEntryBufNormalMaxLength		16000
#define dNetworkOutEntryBufBasicServiceMaxLength	 5000


#define dNetworkCmd			251
#define dNetworkCmd_ReqDateTime	252
#define dNetworkCmd_SetDateTime	253
#define dNetworkCmd_EventTime		254
#define dNetworkCmd_DevDescp		255

#define dNetworkCmd_PublishOperate	250
#define dNetworkCmd_Ack			249

#define dNetworkCmd_PortExistAsk	248
#define dNetworkCmd_PortExistRpy	247
#define dNetworkCmd_DescpAsk		246
#define dNetworkCmd_DescpRpy		245
#define dNetworkCmd_DescpOnePortAsk		244

#define dNetworkCmd_CheckNormalData		225
#define dNetworkCmd_CheckOnline		224
#define dNetworkCmd_SlaveFbMissReport	223
#define dNetworkCmd_DelayStartSend		222
#define dNetworkCmd_MaskListSend		221

#define dNetworkCmd_ClearCtlFire		214
#define dNetworkCmd_PublishFireCancel	213
#define dNetworkCmd_PublishFire		212
#define dNetworkCmd_RemoteStartStop		211
#define dNetworkCmd_RemoteStartStopViaUserCode		210
#define dNetworkCmd_NewTime		209

#define dNetworkCmd_AutoStartDelay 		208
#define dNetworkCmd_SetSlaveAllow	 	207
#define dNetworkCmd_SendRegSeq		206
#define dNetworkCmd_SendRegRpy		205

#define dNetworkCmd_AutoStartDelaySimulate 		204
#define dNetworkCmd_RemoteStartStopViaUserCodeSimulate		203


#define dNetworkRpyType		0x02
#define dNetworkRpyDescp	0x04

#define dNetworkTypeMaster	0x01
#define dNetworkTypeSlave	0x02
#define dNetworkTypeNone	0x03
#define dNetworkTypeDual	0x04

typedef enum{
	CmdC2C_AskExist	= 1,
	CmdC2C_RpyExist	= 2,
	CmdC2C_AskType	= 3,
	CmdC2C_RpyType	= 4,
	CmdC2C_AskNameLen	= 5,
	CmdC2C_RpyNameLen	= 6,
	CmdC2C_AskNameContent	= 7,
	CmdC2C_RpyNameContent	= 8,
	CmdC2C_SaveData = 9,
	CmdC2C_ClearReg = 10,
	CmdC2C_DevRegStartSeq = 11,
	CmdC2C_DevRegRpyStart = 12,
	CmdC2C_DevRegRpyPortCnt = 13,
	CmdC2C_DevRegRpyProgress = 14,
	CmdC2C_DevRegRpyEpCount = 15,
	CmdC2C_DevRegRpyEpCompleted =16,
	CmdC2C_DevRegReqEpCount =17,
	CmdC2C_DevRegEpCountCorrect,
	CmdC2C_SaveMasterList,
	CmdC2C_ClearMasterList,
}TSubCmdC2C;

typedef union{
	unsigned int D32[4];
	unsigned char D8[16];
	struct{
		unsigned char Cmd;
		unsigned char Order;
		unsigned char CarryByte;
		unsigned char Mix3Data;
		
		unsigned char Len;
		unsigned char Identification;
		unsigned char Routing;
		unsigned char Priority;
		
		unsigned char Data[8];
	}Data;
}TC2CBufBody;

typedef struct{
	int Count;
	int WriteIndex;
	int ReadIndex;
	TC2CBufBody Body[dNetworkInBufMaxLength];
}TC2CInOutBuf;

typedef union{
	unsigned int D32[6];
	unsigned short D16[12];
	unsigned char D8[24];
	struct{
		unsigned char Second;
		unsigned char Minute;
		unsigned char Hour;	
		unsigned char Day;
		
		unsigned char Month;
		unsigned char Year;
		unsigned char iByte0;		
		unsigned char iByte1;
		
		unsigned char PCtlNum;
		unsigned char P0;
		unsigned char P1;
		unsigned char P2;
		
		unsigned char mType;
		unsigned char dType;
		unsigned char Data0;
		unsigned char Data1;
		
		unsigned int UserCode;
		unsigned short AreaNum;
		unsigned short DumpShort;
	}Splite;
}TC2CMsgCommon;

typedef struct{
	union{
		unsigned int D32[6];
		unsigned char D8[24];
		struct{
			unsigned char Cmd;
			unsigned char CtlNum;
			unsigned char P0;
			unsigned char P1;
			
			unsigned char dType;
			unsigned char mType;
			unsigned char sType;
			unsigned char Prm;
			
			unsigned char Year;
			unsigned char Mon;
			unsigned char Day;
			unsigned char Hour;
			
			unsigned char Min;
			unsigned char Sec;
			unsigned char Prm1;
			unsigned char Prm2;
			
			unsigned int UserCode;
			unsigned short AreaNum;
			unsigned short DumpShort;
		}Split;
	}rBody,wBody;
}TC2CEntry;

template<const unsigned int BaseAddr, const unsigned int EntrySize, const unsigned int BufSize> 
struct TC2cEntryBuf{
	int Count;
	int WriteIndex;
	int ReadIndex;
	void Reset(){
		unsigned int OffSet;
		WriteIndex=0; 
		ReadIndex=0;
		for(int i=0; i<BufSize; i++){
			OffSet =i * EntrySize;
			*(volatile unsigned int *)(BaseAddr + OffSet +  0) =0;
			*(volatile unsigned int *)(BaseAddr + OffSet +  4) =0;
			*(volatile unsigned int *)(BaseAddr + OffSet +  8) =0;
			*(volatile unsigned int *)(BaseAddr + OffSet + 12) =0;
			*(volatile unsigned int *)(BaseAddr + OffSet + 16) =0;
			*(volatile unsigned int *)(BaseAddr + OffSet + 20) =0;
		}
	}
	unsigned int IncWriteIndex(){
		WriteIndex++;
		if(WriteIndex >=BufSize)WriteIndex =0;
		return dAddrSdram_C2cOutEntrySvBuf + (EntrySize * WriteIndex);
	}
	unsigned int IncReadIndex(){
		ReadIndex++;
		if(ReadIndex >=BufSize)ReadIndex =0;
		return dAddrSdram_C2cOutEntrySvBuf + (EntrySize * ReadIndex);
	}
	int CheckDataAvalibel(){
		if(ReadIndex!=WriteIndex)return 1; else return 0;
	}
	void Write(unsigned int *pEty){
		WriteIndex++;
		if(WriteIndex >=BufSize)WriteIndex =0;
		unsigned int OffSet =WriteIndex * EntrySize;
		*(volatile unsigned int *)(BaseAddr + OffSet +  0) =*pEty++;
		*(volatile unsigned int *)(BaseAddr + OffSet +  4) =*pEty++;
		*(volatile unsigned int *)(BaseAddr + OffSet +  8) =*pEty++;
		*(volatile unsigned int *)(BaseAddr + OffSet + 12) =*pEty++;
		*(volatile unsigned int *)(BaseAddr + OffSet + 16) =*pEty++;
		*(volatile unsigned int *)(BaseAddr + OffSet + 20) =*pEty;
	}
	void Read(unsigned int *pEty){
		ReadIndex++;
		if(ReadIndex >=BufSize)ReadIndex =0;
		unsigned int OffSet =ReadIndex * EntrySize;
		*pEty++ = *(volatile unsigned int *)(BaseAddr + OffSet +  0) ;
		*pEty++ = *(volatile unsigned int *)(BaseAddr + OffSet +  4) ;
		*pEty++ = *(volatile unsigned int *)(BaseAddr + OffSet +  8) ;
		*pEty++ = *(volatile unsigned int *)(BaseAddr + OffSet + 12) ;
		*pEty++ = *(volatile unsigned int *)(BaseAddr + OffSet + 16) ;
		*pEty   = *(volatile unsigned int *)(BaseAddr + OffSet + 20) ;
	}
};

class TProtoC2C{
	public:
		enum TMsgType{
			mtBasicService =0,
			mtFire =1,
			mtSv =2,
			mtLink =3,
			mtFault =4,
			mtNormal =5,
		};
		static unsigned int DevDelayStartTick;
	public:
		struct{
			unsigned int started;
			unsigned char *pData;
			unsigned int Len;
			unsigned int BlockCount;
			unsigned int SectionCount;
		}File;
		unsigned int CheckOnlineHasSend;
		unsigned int CheckOnlineAfterSendTick;
		unsigned int CheckOnlineTick;
		unsigned int CheckOnlineHasStart;
		unsigned int CheckOnlineUpdateTick;
		
		unsigned char NwSubCmd;
		unsigned int ErrReport;
		unsigned int ErrHasReport;
		unsigned int iBufInCount;
		unsigned int iBufInCountPer2Sec;
		unsigned int iBufInCountOdd;
		
		int NeedReply;
		unsigned char ReplyWhat;
		unsigned char ReplyTick;
		
		TC2CBufBody RxMsg;
		TC2CBufBody TxMsg;
		TRecordMaskMsg MaskMsg;
		
		volatile TC2CInOutBuf iBuf;
		volatile struct{
			int Count;
			int WriteIndex;
			int ReadIndex;
			TC2CBufBody aBody;
		}oBuf;
		TC2cEntryBuf<dAddrSdram_C2cOutEntryBasicServiceBuf, 	OutputEntrySize, dNetworkOutEntryBufBasicServiceMaxLength	> oEntryBasicService;
		TC2cEntryBuf<dAddrSdram_C2cOutEntryFireBuf, 	OutputEntrySize, dNetworkOutEntryBufFireMaxLength	> oEntryFire;
		TC2cEntryBuf<dAddrSdram_C2cOutEntrySvBuf, 	OutputEntrySize, dNetworkOutEntryBufSvMaxLength		> oEntrySv;
		TC2cEntryBuf<dAddrSdram_C2cOutEntryLinkBuf, 	OutputEntrySize, dNetworkOutEntryBufLinkMaxLength	> oEntryLink;
		TC2cEntryBuf<dAddrSdram_C2cOutEntryFaultBuf, 	OutputEntrySize, dNetworkOutEntryBufFaultMaxLength	> oEntryFault;
		TC2cEntryBuf<dAddrSdram_C2cOutEntryNormalBuf, 	OutputEntrySize, dNetworkOutEntryBufNormalMaxLength	> oEntryNormal;
		
		TC2CEntry oEntry;

		unsigned char SlaveOnlineList[68];
		unsigned char SlaveOnlineListOld[68];
		union{
			unsigned int D32[3];
			unsigned char D8[12];
			struct{
				unsigned char Inx;
				unsigned char CtlNum;
				unsigned char Year ;
				unsigned char Mon;
				unsigned char Day;
				unsigned char Hour;
				
				unsigned char Min;
				unsigned char Sec;
				
				unsigned char Dump2;
				unsigned char Dump3;
				unsigned char Dump4;
				unsigned char Dump5;
			}Dt;
		}RecDateTime[68];
		
		struct{
			union{
				unsigned int Full;
				unsigned char Bytes[4];
			}UC;
			union{
				unsigned short Full;
				unsigned char Bytes[2];
			}AN;
			unsigned short DumpShort;
		}RecUserCodeAreaNum[68];
		
		union{
			unsigned int D32[3];
			unsigned char D8[12];
			struct{
				unsigned char Inx;
				unsigned char CtlNum;
				unsigned char Year ;
				unsigned char Mon;
				unsigned char Day;
				unsigned char Hour;
				
				unsigned char Min;
				unsigned char Sec;
				
				unsigned char Dump2;
				unsigned char Dump3;
				unsigned char Dump4;
				unsigned char Dump5;
			}Dt;
		}RecNewDateTime[68];
		
		struct{
			unsigned char State[68];
			unsigned char AckOk[68];
			unsigned char DesireAckOrder[68];
			unsigned char OnGoing;
			unsigned char Order;
			unsigned char RetryTimes;
			unsigned char Dump0;
			unsigned int TimeOutTick;
			unsigned char AckNeedCount;
			unsigned char IsReportErr;
			unsigned char IsBroadCast;
			unsigned char SlaveCtlNum;
		}OnTransmite;
		
		struct{
			unsigned char State[68];
			unsigned char IsProcessDone[68];
			unsigned char RecOnGoing[68];
			unsigned int Piece[68];
			unsigned char OrderDt[68];
			unsigned char OrderAck[68];
			unsigned char OrderNewDt[68];
			unsigned char OrderLast[68];
			unsigned char OnGoing;
			unsigned char IsCheckOnline;
			unsigned char CallResetCtlNum;
			unsigned char CallResetNetOrder;
		}OnReceive;
		
		unsigned char NoAckList[68];
		unsigned char NoAckMaster;
		
		struct{
			unsigned char CtlNum;
			unsigned char P0;
			unsigned char P1;
			unsigned char Dump;
			union{
				unsigned int D32[64];
				unsigned char D8[256];
			}dType;
			union{
				unsigned int D32[8];
				unsigned char D8[32];
			}Descp;
			unsigned int DescpPiece;
			unsigned int dTypePiece;
		}OnSetup;
			
		union{
			unsigned int D32[8];
			unsigned char D8[32];
		}DescpBuf, DescpBufRec;
		
		unsigned int State;
		unsigned char tData[8];
		
		TC2CMsgCommon OperateEntry;
		
		unsigned char MasterNum;
		unsigned char SlaveCount;
		unsigned char SlaveList[68];

		unsigned char	CommLostCount[68];
		
		struct{
			unsigned int Cnt;
			unsigned char Items[dNETWORK_MACHINE_MASTER_COUNT];
		}M2MList;
		
		struct{
			unsigned int IsFbMiss;
			unsigned int IsVaStart;
			unsigned int IsVaFault;
		}SlaveCtlState;
		
		unsigned int MasterRetrySendEntryCount;
		unsigned int SlaveRetrySendEntryCount;
		
		union{
			unsigned int D32[60];
			unsigned short D16[120];
			unsigned char D8[240];
			struct{
				struct{
					unsigned short Smoke;
					unsigned short Tempe;
					unsigned short HandReport;
					unsigned short HydKp;
					unsigned short ModuleInput;
					unsigned short ModuleInOut;
					unsigned short ModuleOutput;
					unsigned short Va;
					unsigned short FDisplay;
					unsigned short LnkPs;
					unsigned short cOther;
				}Designed;
				struct{
					unsigned short Smoke;
					unsigned short Tempe;
					unsigned short HandReport;
					unsigned short HydKp;
					unsigned short ModuleInput;
					unsigned short ModuleInOut;
					unsigned short ModuleOutput;
					unsigned short Va;
					unsigned short FDisplay;
					unsigned short LnkPs;
					unsigned short cOther;
				}Normal;
				
				struct{
					unsigned short Smoke;
					unsigned short Tempe;
					unsigned short HandReport;
					unsigned short HydKp;
					unsigned short ModuleInput;
					unsigned short ModuleInOut;
					unsigned short ModuleOutput;
					unsigned short Va;
					unsigned short FDisplay;
					unsigned short LnkPs;
					unsigned short cOther;
				}Fault;
				struct{
					unsigned short Smoke;
					unsigned short Tempe;
					unsigned short HandReport;
					unsigned short HydKp;
					unsigned short ModuleInput;
					unsigned short ModuleInOut;
					unsigned short ModuleOutput;
					unsigned short Va;
					unsigned short FDisplay;
					unsigned short LnkPs;
					unsigned short cOther;
				}Mask;
			}Slave;
		}CheckNormalDataSlave[dNETWORK_MACHINE_COUNT];
		unsigned int CheckNormalDataSlaveGotPiece[dNETWORK_MACHINE_COUNT];
		unsigned char IsCheckNormalDataSlaveDone[dNETWORK_MACHINE_COUNT];
		
		unsigned  int ShouldSyncTime ;
		
		unsigned char ReportSlaveOffline[68];
		unsigned char ReportMasterOffline;
		
		struct{
			unsigned char StartNum;
			unsigned char EndNum;
		}CtlMask;
		struct{
			unsigned char StartNum;
			unsigned char EndNum;
		}RegMask;
		int NeedRpyCount;
		struct{
			unsigned char CtlCount;
			unsigned char CtlList[68];
		}CfgData;
		struct{
			struct{
				unsigned char IsRequsting;
				unsigned char RegPath;
			}Reg;		
		}RemoteReq;
	private:
		TRecordCommon sIm;
		unsigned char CmdFillAreaNum;
		unsigned char CmdFillDelayTime;
		unsigned char CmdFillUserCode;
	
		unsigned char IsRecAreaNum;
		unsigned char IsRecDelayTime;
		unsigned char IsRecUserCode;
	
	public:
		TProtoC2C(){};
		void Init();
		void ReInit();
		void DelayMs(unsigned int aMs);
		
		void PublishEventMute();
		void PublishEventReset();
			
		void DateTimeReq();
		void DateTimeSet();
		
		void ReplyCtrlType();
		void ReplyDescp();
		void SaveCfgData(unsigned char *data);
		void ClearCfgData(unsigned char *data);
		void SaveM2MCfgData(unsigned char *data);
		void ClearM2MCfgData(unsigned char *data);
			
		void SetNwFire(unsigned char aNum, unsigned char aP0, unsigned char aP1, unsigned int Sta);
		unsigned int GetNwFire(unsigned char aNum, unsigned char aP0, unsigned char aP1);
			
		void MasterRxMsgProcess();
		void SlaveRxMsgProcess();
		void oBufInsert();
		void oBufInsert(TC2CBufBody aNsBuf);
		void iBufInsert();
		void iBufProcess();
		void oBufProcess();
		
		void oBufMsgPreload(TRecordCommon aIm,  unsigned char aCmd);
		
		void oBufMsgInsertBasicService();
		void oBufMsgInsertFire();
		void oBufMsgInsertSv();
		void oBufMsgInsertLink();
		void oBufMsgInsertFault();
		void oBufMsgInsertNormal();
		void oBufMsgInsertBasicService(TRecordCommon aIm,  unsigned char aCmd);
		void oBufMsgInsertFire(TRecordCommon aIm,  unsigned char aCmd);
		void oBufMsgInsertSv(TRecordCommon aIm,  unsigned char aCmd);
		void oBufMsgInsertLink(TRecordCommon aIm,  unsigned char aCmd);
		void oBufMsgInsertFault(TRecordCommon aIm,  unsigned char aCmd);
		void oBufMsgInsertNormal(TRecordCommon aIm,  unsigned char aCmd);
		
		void NwDevDescpInit();
		void BufInit();
		
		void FillDescp();
		void ProcessDevDescpRec();
		void PublishEventAlramOnOff(int aOnOff);
		void PublishReset();
		void PublishMute();
		void PublishEventAllowState();
		void PublishOperate(TRecordCommon aOperateEvent);

		void OperateGet(unsigned char aCmd, unsigned char *Data);
		
		void WriteEntryBuf();
		void ReadEntryBuf();
		void ExportMachineEventTime2Master(unsigned char IsNew);
		void ExportMachineEventNewTime2Master(unsigned char IsNew);
		void ExportEntry2oBuf(unsigned char IsNew);
		void ProcessoEntry();
		void Ack(unsigned char TargetNum, unsigned char aOrder);
		void AckOnlineCheck(unsigned char TargetNum, unsigned char aOrder);
		void ProcessAckRecFromSlave(unsigned char aOrder, unsigned char *Data);
		void ProcessAckRecFromMaster(unsigned char aOrder, unsigned char *Data);
		
		void MasterDoEpMsg(unsigned char aCmd, unsigned char *Data);
		void MasterDoDirectPadNwPutLnkState(unsigned char aCmd, unsigned char *Data);
		void MasterDoMaskAdd(int aInx);
		void MasterDoMaskAdd(TRecordMaskMsg aMaskMsg, int aInx);
		void MasterDoMaskListGet(unsigned char *Data);
		void MasterDoAddRemoveMask(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned char aType,  unsigned int aUc, unsigned int IsAdd);
		void GetMsgViaIndex(int aInx);
		void ClearMsgViaIndex(int aInx);
		void MasterDoMaskListRemove(unsigned char aCtlNum);
		void MasterDoCheckOnlineTask();
		void CheckNormalSlave(unsigned char aCtlNum);
		void MasterGetCheckNormalData(unsigned char *Data);
		void MasterDoDevRemoteStart(unsigned char CtlNum, unsigned char aP0, unsigned char aP1, unsigned char aType);
		void MasterDoRemoteLnkStartStopViaUserCode(unsigned int aUc, unsigned char aType, unsigned short aDelaySec, unsigned char IsStart);
		void MasterDoPublishFire(unsigned char CtlNum, unsigned char aP0, unsigned char aP1, unsigned char aType, unsigned int aUc);
		void MasterDoPublishFireCancel(unsigned char CtlNum, unsigned char aP0, unsigned char aP1, unsigned char aType, unsigned int aUc);
		void MasterDoPublishClearNwCtlFire(unsigned char CtlNum);
		
		void SlaveDoAlramOnOff(int aOnOff);
		void SlaveDoSend2MasterMachine(TRecordCommon aIm, unsigned char aCmd, TMsgType aMsgType);
		void SlaveDoUploadMaskList();
		void SlaveDoUploadCtlState();
		void SlaveDoUploadStartDelay();
		void SlaveReportFbMissCount(unsigned char aFbCnt);
		void SlaveDoCheckOnlineTask();
		void ClearCheckNormalDataSlave();
		void SlaveDoRpyCheckNormalData();
		void SlaveDoGetRemoteStartStop(unsigned char CtlNum, unsigned char aP0, unsigned char aP1, unsigned char IsStart);
		void SlaveDoGetRemoteStartStopUserCode(unsigned int aUc, unsigned char aDType, unsigned short aDelaySec, unsigned char IsStart);
		void SlaveDoNetDescpRpy(unsigned char aCtlNum, unsigned char aP0);
		void SlaveDoSend2MasterDelayStart(TRecordCommon aIm, unsigned char aCmd);
		
		void SlaveSetAutoState(unsigned char aSta);
		void SlaveSetManualState(unsigned char aSta);
		void SlaveSetAllowState(unsigned char aSta);
		void SlaveSetAllowStateBySpc(unsigned char CtlNum, unsigned char aSta);
		
		void PortExistAsk(unsigned char aNum, unsigned char aP0);
		void DescpListAsk(unsigned char aNum, unsigned char aP0, unsigned char Inx, unsigned char *pAddrList);
		void PortExistRpy(unsigned char aNum, unsigned char aP0);
		void DescpListRpy(unsigned char aNum, unsigned char aP0, unsigned char Addr);
		void DescpListDirectPadRpy(unsigned char aNum, unsigned char aPadNum, unsigned char aKey);
		void DescpListDirectPadRpy(unsigned char aNum, unsigned char Inx);
		
		void DescpOnePortAsk(unsigned char aNum, unsigned char aP0);
		void DescpOnePortRpy(unsigned char aNum, unsigned char aP0);
		void DescpAllDirectPadRpy(unsigned char aNum);
		
		void AddRemoveNwCommFault(unsigned char aCtlNum, unsigned int IsAdd);
		void AddMasterCommFault(unsigned char aCtlNum);
		void RemoveMasterCommFault(unsigned char aCtlNum);
		void AddSlaveCommFault(unsigned char aCtlNum);
		void RemoveSlaveCommFault(unsigned char aCtlNum);
		void ResetCoomm();
		void CheckInBufCount();
		
		void ClearNwCtlFire(unsigned char aNum);
		void ClearNwAllCtlFire();
		
		static void sSetNwDevDelayStartPoint(unsigned char aNum, unsigned char aP0, unsigned char aP1, unsigned int aCountDown);
		unsigned int GetNwDevDelayCountDown(unsigned char aNum, unsigned char aP0, unsigned char aP1);
		static void sSetNwDirectPadDelayStartPoint(unsigned int aNum, unsigned int aDirectPad, unsigned int aNode, unsigned int TickZeroPoint);
		unsigned int GetNwDirectPadDelayStartPoint(unsigned int aNum, unsigned int aDirectPad, unsigned int aNode);
		void ClearNwDelayStartPoint(unsigned int aNum);
		
		unsigned int GetThisCtlCountDownTime(unsigned int aNum, unsigned int aP0, unsigned int aP1);

		void WriteMaskCtlNum(unsigned char aStart, unsigned char aEnd);
		void ReadMaskCtlNum();
		
		void IdfCmdExternFill(unsigned char aCmd, unsigned char aPrm);
		
		
		void GetFireRemoteConfirm(unsigned char *Data);
		void GetFaultRemoteConfirm(unsigned char *Data);
		void OperatePublic_FireRemoteConfirm(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char dType, unsigned int aUc);
		void OperatePublic_FaultRemoteConfirm(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char dType, unsigned char fType, unsigned char aIsDescp, unsigned int aUc);
		
		int CheckIsInSlaveList(unsigned char aCn);	
		void SyncCheckOnline();
		
		void SlaveDoSend2MasterDelayStartSimulate(TRecordCommon aIm, unsigned char aCmd);
		void SlaveDoGetRemoteStartStopUserCodeSimulate(unsigned int aUc, unsigned char aDType, unsigned short aDelaySec, unsigned char IsStart);
		void MasterDoRemoteLnkStartStopViaUserCodeSimulate(unsigned int aUc, unsigned char aType, unsigned short aDelaySec, unsigned char aSta);
		
		int  TryLoadNewEntry();
		
		static void sSimGetStartDelay(TRecordCommon *aRc, unsigned short aDelayTimes);
		
		void SyncCheckM2MOnline(){}//_____________________<
		
		void TaskSecondUpdate();
		void Task10Ms();
		void Task1000Ms();
};


























#endif


