#ifndef RECORD_H_
#define RECORD_H_

#include "gType.h"
#include "TDateTime.h"

#define PagePrg_Time	5
#define Erase4K_Time	420
#define Erase32K_Time	1620
#define Erase64K_Time	2020

#define SizeOf64K		0x10000
#define SizeOf32K		0x8000
#define SizeOf4K		0x1000
#define SizeOfPage	0x100

#define dRECORD_ITEMS_COUNT	256

#define dFrashFireUsingBlockCount		(22)
#define dFrashLinkageUsingBlockCount	(22)
#define dFrashSvUsingBlockCount		(22)
#define dFrashFaultUsingBlockCount		(22)
#define dFrashOperateUsingBlockCount	(22)

#define dFlashRegisterDataChip	(0)
#define dFlashRegisterDataAddr	(0x00CC'0000)
#define dFlashRegisterPortDataLen	(0x1000)
#define dFlashRegisterPortCount	(64)

#define dFlashDisplayPadSetChip		(0)
#define dFlashDisplayPadSet			(0x00DA'0000)
#define dEepFloorDescpChip			(0)
#define dFlashAddrFloorDescp			(0x00DB'0000)
#define dEepDescpChip		(0)
#define dFlashAddrDescpBase	(0x00DC'0000)

#define dFlashMaskChip		0x0
#define dFlashAddrMask		(0x00E7'0000)
#define dFlashAddrMask_II	(0x00EB'0000)
#define dMaskCrcCntOffset	((65536*3) + (4096*15))	
#define dMaskNonDataIdf		(0xB8F6'7C26)
#define dMaskBackupExistIdf	(0xF765'DC69)

#define dFlashNwUserCodeChipX		(0)
#define dFlashNwUserCode		(0x009C'0000)

#define dFlash4AreaChip			(0)
#define dFlash4Area			(0x00BB'0000)

#define dFlash4DevAreaNumChip		(0)
#define dFlash4DevAreaNum		(0x00D8'0000)

//Flash Chip 1
#define dFlashAddrDevUserCodeChip 	(1)
#define dFlashAddrDevUserCode			(0x00D1'0000)
#define dFlashAddrDirectPadUserCode		(0x00D3'8000)

#define dFlashBusPadLnkChipX		(1)
#define dFlashAddrBusPadLnk		(0x00D6'0000)
#define dFlashDirectPadLnkChipX	(1)
#define dFlashAddrDirectPadLnk	(0x00D8'0000)




//EEP 0 512 K______________________________________>
#define dEepAddrFireWritingBlock	(0x6000)
#define dEepAddrLinkageWritingBlock	(0x6001)
#define dEepAddrSvWritingBlock	(0x6002)
#define dEepAddrFaultWritingBlock	(0x6003)
#define dEepAddrOperateWritingBlock	(0x6004)

#define dEepAddrMainSet			(0)
#define dEepAddrProjectName		(0x80)
#define dEepAddrCtlName			(0xA0)
#define dEepAddrPassWordII		(0x0100)
#define dEepAddrPassWordIII		(0x0120)
#define dEepAddrCtlShutDownTime	(384)

#define dEepAddrDesignPrmXXXX		(512)
#define dEepAddrNetworkCfg		(768)

//Page 7
#define dEepAddrLicsence		(896)			//128*7=
//Page 8
#define dEepAddrMainTain		(1024)		//128*8=

//Page 9	Page 10   Page 11		Page 12..Page 19 
#define dEepAddrDesignPrm		(1152)

//Page 23
#define dEepAddrBroadcastSetting		(2944)
//Page 24
#define dEepAddrFecBusSetting		(3072)
//Page 25
#define dEepAddrCtlMaskNum		(3200)
//Page 26
#define dEepAddrCrtCfg			(3328)
//Page 27
#define dEepAddrMaintainLast		(3456)

//Page 510
#define dEepAddrAuthorizePrm			(510*128)//pcs 0

#define dFlashLinkageExpChipX	(1)
#define dFlashAddrLinkageExp	(0x00DE'0000)
#define dFlashBlock64kCount4LinkageExp	(32)


//_________________________________________________<
//Sdram
#define dSdramHistoryBytesLength			(0x160000)
#define dSdramHistoryEntryCount			(20000)
#define dSdramFireHistoryContentBaseAddr		(0xC260'0000)
#define dSdramLinkageHistoryContentBaseAddr	(0xC2A0'0000)
#define dSdramSvHistoryContentBaseAddr		(0xC2E0'0000)
#define dSdramFaultHistoryContentBaseAddr		(0xC320'0000)
#define dSdramOperateHistoryContentBaseAddr	(0xC360'0000)

typedef enum{
	otPowerOn =0,
	otPowerOff =1,
	otReset =2,
	otMute,
	otMask,
	otUnMask,
	otRegiste,
	otUnRegiste,
	otSetCanNetwork,
	otCfgBoard,
	otCfgCrt,
	otCfgPriter,
	otCfgDevice,
	otCfgDateTime,
	otCfgPermissionAllow,
	otAllowSet,
	otAlramSetOnOff,
	
	otBusPadOn,
	otBusPadOff,
	
	otDirectPadManualAllowOn,
	otDirectPadManualAllowOff,
	otDirectPadNodeOn,
	otDirectPadNodeOff,
	
	otUserCheck,
	otLinkageGo,
	otSetNwTime,
	otReqNwTime,
	
	otSelfCheck,
	
	otSetManualAllowState,
	otSetAutoAllowState,
	otRemoteSetManualAllowState,
	otRemoteSetAutoAllowState,
	otReportManualAllowState,
	otReportAutoAllowState,
	
	otFireConfirm,
	otFaultConfirm,
	otFireRemoteConfirm,
	otFaultRemoteConfirm,
	
	otSetSmokeSensViaCircuit,
	otSetSmokeSensViaAddr,
	
	otCleanUp,
	otLinkageExpsSaveRemove,
	otBusPadModify,
	otDirectPadModify,
	otDescpModify,
	otPassWdModify,
	otRegisterByManual,
	otAddRemoveNwCtl,
	
	otRegCanNetwork,
	otStartStop,
	otClearNetworkCfg,
	otBroadcastVa,
	
	otSetAllowState,
	otRemoteSetAllowState,
	otReportAllowState,
	
	otFireSimConfirm,
	otFireSimRemoteConfirm
	
}TOperateType;

typedef enum{
	csIdle  = 0,
	csErassing = 1,
	csCanTryResume =2,
	csDoErase =3,
	csBusy
}TChipState;

/*typedef union{
	unsigned int D32[4];
	unsigned char D8[16];
	struct{
		unsigned char Second;
		unsigned char Minute;
		unsigned char Hour;					
		unsigned char Day;
		
		unsigned char Month;
		unsigned char Year;					
		unsigned char HasRead;
		unsigned char SourceProto;
		
		unsigned char PCtlNum;
		unsigned char P0;
		unsigned char P1;
		unsigned char P2;
		
		unsigned char mType;
		unsigned char dType;
		unsigned char Data0;
		unsigned char Data1;
	}Splite;
}TRecordInnerMsg;*/
typedef union{
	unsigned int D32[4];
	unsigned char D8[16];
}TrcEepToWriteBuf;

typedef union{
	unsigned int D32[4];
	unsigned short D16[8];
	unsigned char D8[16];
	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;
	}Splite;
}TRecordBody;

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;
}TRecordCommon;

typedef union{
	unsigned char D8;
	struct{
		unsigned char Bit0 :1;
		unsigned char Bit1 :1;
		unsigned char Bit2 :1;
		unsigned char Bit3 :1;
		unsigned char Bit4 :1;
		unsigned char Bit5 :1;
		unsigned char Bit6 :1;
		unsigned char Bit7 :1;
	}BitF;
	struct{
		unsigned char IsAutomatic :1;			//0:Manual; 1:Automatic
		unsigned char IsUsingStandByPower :1;	//0:Using Main Power; 1:Using Standby Power
		unsigned char IsPowerError :1;
		unsigned char IsAlram :1;
		unsigned char IsAction :1;
		unsigned char IsFeedBack :1;
		unsigned char IsSuperVisory :1;
		unsigned char IsFault :1;
	}BitFlag;
}TFecStateLowByte;

typedef union{
	unsigned char D8;
	struct{
		unsigned char Bit0 :1;
		unsigned char Bit1 :1;
		unsigned char Bit2 :1;
		unsigned char Bit3 :1;
		unsigned char Bit4 :1;
		unsigned char Bit5 :1;
		unsigned char Bit6 :1;
		unsigned char Bit7 :1;
	}BitF;
	struct{
		unsigned char IsMask :1;			
		unsigned char IsGasSpay :1;			
		unsigned char IsEmergency :1;
		unsigned char Rsv0 :1;
		unsigned char Rsv1 :1;
		unsigned char Rsv2 :1;
		unsigned char Rsv3 :1;
		unsigned char Rsv4 :1;
	}BitFlag;
}TFecStateHiByte;

typedef union{
	unsigned char D8[18];
	struct{
		unsigned char Dump;
		unsigned char MainCtlNumLowByte;
		unsigned char MainCtlNumHiByte;
		unsigned char UnitNum;
		unsigned char DeviceNum;
		unsigned char ChannelNum;
		unsigned char dTypeLowByte;
		unsigned char dTypeHiByte;
		unsigned char EventCodeLowByte;
		unsigned char EventCodeHiByte;
		TFecStateLowByte StateCodeLowByte;
		TFecStateHiByte  StateCodeHiByte;
		unsigned char Year;	// -2000
		unsigned char Month;	// 1..12
		unsigned char Day;	// 1..31
		unsigned char Hour;
		unsigned char Minute;
		unsigned char Second;
	}Data;
	struct{
		unsigned char code;
		unsigned char Dump[17];
	}MyMsgCode;
}TRecordFecMsg;

typedef union{
	//17 Bytes  GB4717--202X 表B.2 数据信息格式
	unsigned char d8[20];
	struct{
		unsigned char CtlNumLoByte;
		unsigned char CtlNumHiByte;
		unsigned char UnitNum;
		unsigned char DeviceNum;
		unsigned char ChannelNum;
		unsigned char DeviceTypeLoByte;
		unsigned char DeviceTypeHiByte;
		unsigned char EventCodeLoByte;
		unsigned char EventCodeHiByte;
		unsigned char StateCodeLoByte;
		unsigned char StateCodeHiByte;
		unsigned char Year;
		unsigned char Month;
		unsigned char Day;
		unsigned char Hour;
		unsigned char Minute;
		unsigned char Second;
		unsigned char Rsv0;
		unsigned char Rsv1;
		unsigned char Rsv2;		
	}spl;
}TRecodeOneMsg;

typedef union{
	//using 27 byte
	unsigned char D8[28];
	struct{
		unsigned char StartCode;	//0x40
		unsigned char rNumLoByte;
		unsigned char rNumMiByte;
		unsigned char rNumHiByte;
		unsigned char CtlAddr;
		unsigned char CtlTypeLoByte;
		unsigned char CtlTypeHiByte;
		unsigned char CtlPn[20];
	}spl;
}TRecordMappingHeader;

typedef union{
	unsigned char D8[4];
	struct{
		unsigned char CrcLoByte;
		unsigned char CrcHiByte;
		unsigned char EndCode;	//0x40
		unsigned char Rsv0;
	}spl;
}TRecordMappingEnding;


typedef union{
	unsigned char D8[16];
	struct{
		unsigned char StartCode;	//0x40
		unsigned char CommanderIdf[8];//数据导出装置识别码，识别数据导出装置的权限。
		unsigned char Ver;		//2
		unsigned char Addr;		//数据导出专用工具地址，固定 0x7E
		unsigned char ExporterType;	//数据导出专用工具代码，固定 0x7F
		unsigned char CmdLen;		//1 	表 B.4
		unsigned char Cmd;		//表 B.4 ;   1=Read; 2=Repeat; 3=Read The First Fire Msg;  4=Read Fire Msg;
		unsigned char CrcLoByte;
		unsigned char CrcHiByte;
		unsigned char EndCode;		//0x40
	}spl;
}TExportData;

typedef struct{
	union{
		unsigned long long fIndex;
		struct{
			unsigned int Inx0;
			unsigned int Inx1;
		}D32;
	}fIndex;
	int WriteIndex;
	int ReadIndex;
	int EntryX;
	int PageX;
	int BlockX;
	int sBlock;
	int NeedCheckBlockEmpty;
	int NeedCheckBlockEmpty2;
	unsigned int BlockToBeErase;
	unsigned int BlockToBeErase2;
	
	int NeedMarkWriteBlcokToEep;
	unsigned char WritingBlockReadFromEep;
	unsigned char wBlockWriteToEep;
	
	unsigned int SdramAddrStart;
	unsigned int SdramAddrCurrent;
	int Count;
}TBufToFlash;

typedef union{
	unsigned char D8[64];
	unsigned int  D32[16];
	struct{
		union {
			unsigned long long fIndex;
			struct{
				unsigned int sIndex0;
				unsigned int sIndex1;
			}spl;
		}sIndex;	//D32 0..1
		unsigned int UserCode;	//D32 2
		TRecordBody Body;	//D32 3..6
		unsigned char Descp[32];//D32 7..14
		unsigned int Crc;
	}fData;
}TRecordEntry;

typedef union{
	unsigned int D32[6];
	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 State;
		
		unsigned char PCtlNum;
		unsigned char P0;
		unsigned char P1;
		unsigned char P2;
		
		unsigned char IsMask;
		unsigned char dType;
		unsigned char Dump3;
		unsigned char Dump4;
		
		unsigned int UserCode;
		unsigned short AreaNum;
		unsigned short DumpShort;
	}Body;
}TRecordMaskMsg;

typedef union{
	unsigned long long fIndex;
	struct{
		unsigned int sIndex0;
		unsigned int sIndex1;
	}spl;
}THisIndex;

extern const unsigned char NwDescpUsingChip[68];
extern const unsigned int NwDescpUsingFlashAddr[68];

class TRecord{
	public:
		TRecordCommon FastBuf;
		TRecordCommon iMsgRx;
		TRecordCommon eOperateEvent;
	public:
		unsigned int PrimaryKeyWarning;
		unsigned int fAddr;
		union{
			unsigned char D8[64];
			unsigned int  D32[16];
		}ToWriteBuf[4];
		
		union{
			unsigned long long fIndex;
			struct{
				unsigned int Inx0;
				unsigned int Inx1;
			}D32;
		}sysIndex;
	
		unsigned char TmpIsAva[128];
		THisIndex TmpllIndex[128];
		union{
			unsigned long long fIndex;
			struct{
				unsigned int sIndex0;
				unsigned int sIndex1;
			}spl;
		}CmpllIndex1, CmpllIndex2;
		
		TBufToFlash Buf4Fire;
		TBufToFlash Buf4Linkage;
		TBufToFlash Buf4Sv;
		TBufToFlash Buf4Fault;
		TBufToFlash Buf4Operate;
		
		struct{
			TChipState Sta;
			int FireOrSv;
			int NeedCheckSvEmpty;
			int SecX;
			unsigned int Tick4_10Ms;
		}RtChip0;
		
		struct{
			TChipState Sta;
			int SvFaultOpa;
			int NeedCheckSvEmpty;
			int SecX;
			unsigned int Tick4_10Ms;
		}RtChip1;
		//unsigned int Eep0WriteTick;
		//unsigned int Eep1WriteTick;
		
		TRecordEntry EntryRead;
		TRecordEntry EntryWrite;
		
		union{
			unsigned char D8[256];
			unsigned short D16[128];
			unsigned int D32[64];
		}FlashPageReadData;
		unsigned char tData[8];
		
		unsigned int aCsum;
		TDMix Actu;
	public:
		TRecord(){};
		void Init();
		
		int InnerMsgGetIfReadOk(unsigned int aIndex);	
		unsigned int InnerMsgGetDate(unsigned int aIndex);
		unsigned char InnerMsgGetYear(unsigned int aIndex);
		unsigned char InnerMsgGetMonth(unsigned int aIndex);
		unsigned char InnerMsgGetDay(unsigned int aIndex);
		unsigned int InnerMsgGetTime(unsigned int aIndex);
		unsigned char InnerMsgGetHour(unsigned int aIndex);
		unsigned char InnerMsgGetMinute(unsigned int aIndex);
		unsigned char InnerMsgGetSecond(unsigned int aIndex);	
		unsigned char InnerMsgGet_mType(unsigned int aIndex);
		unsigned char InnerMsgGet_dType(unsigned int aIndex);
		unsigned char InnerMsgGet_CtlNum(unsigned int aIndex);
		unsigned char InnerMsgGet_P0(unsigned int aIndex);
		unsigned char InnerMsgGet_P1(unsigned int aIndex);
		unsigned char InnerMsgGet_P2(unsigned int aIndex);
		unsigned char InnerMsgGet_ValueHi(unsigned int aIndex);
		unsigned char InnerMsgGet_ValueLow(unsigned int aIndex);
			
		void InnerMsgSetIfReadOk	(unsigned int aIndex, unsigned char isReadOk);	
		void InnerMsgSetDate		(unsigned int aIndex, unsigned int aDate);
		void InnerMsgSetYear		(unsigned int aIndex, unsigned char aYear);
		void InnerMsgSetMonth		(unsigned int aIndex, unsigned char aMonth);
		void InnerMsgSetDay		(unsigned int aIndex, unsigned char aDay);
		void InnerMsgSetTime		(unsigned int aIndex, unsigned int aTime);
		void InnerMsgSetHour		(unsigned int aIndex, unsigned char aHour);
		void InnerMsgSetMinute		(unsigned int aIndex, unsigned char aMinute);
		void InnerMsgSetSecond		(unsigned int aIndex, unsigned char aSecond);	
		void InnerMsgSet_mType		(unsigned int aIndex, unsigned char aMtype);
		void InnerMsgSet_dType		(unsigned int aIndex, unsigned char aDtype);
		void InnerMsgSet_CtlNum		(unsigned int aIndex, unsigned char aCtlNum);
		void InnerMsgSet_P0		(unsigned int aIndex, unsigned char aP0);
		void InnerMsgSet_P1		(unsigned int aIndex, unsigned char aP1);
		void InnerMsgSet_P2		(unsigned int aIndex, unsigned char aP2);
		void InnerMsgSet_Data0		(unsigned int aIndex, unsigned char aVh);
		void InnerMsgSet_Data1		(unsigned int aIndex, unsigned char aVl);	
		void InnerMsgSet_iByte0		(unsigned int aIndex, unsigned char aB);
		void InnerMsgSet_iByte1		(unsigned int aIndex, unsigned char aB);
		
		void FlushToWriteBuf();
		
		//_____________________________________>>>>>
		unsigned int CheckChipF0Idle(void);
		unsigned int CheckChipF1Idle(void);
		unsigned int CheckChipF0_SectorEmpty(unsigned int aAddr);
		unsigned int CheckChipF1_SectorEmpty(unsigned int aAddr);
		
		void LoadOperateEventDateTimeFromCharPointer(unsigned char *aDt);
		void LoadOperateEventDateTimeFromCurrent();
		
		//Add Function
		//_____________________________________>>>>>	Fire	Add
		void FireAdd(TRecordCommon aRC);
		void TryFireWriteToFlash();
		
		//Linkage	ADD
		void LinkageAdd(TRecordCommon aRC);
		
		//Sv Add
		void SvAdd(TRecordCommon aRC);
		
		//_____________________________________>>>>>	Fault	Add
		void FaultAdd(TRecordCommon aRC);
		
		//_____________________________________>>>>>
		void OperateAdd(TRecordCommon aRC);
		void OperateAddFromNw(TRecordCommon aRC);
		void OperateFindNextSector();
		void OperateWriteToEepRom();
		void OperateTryEraseSector();
		//_______________________________________________________________>
		void OperateAdd_PowerOff(unsigned char aCn);
		void OperateAdd_PowerUp(unsigned char aCn);
		void OperateAdd_Reset(unsigned char aCn);
		void OperateAdd_Mute(unsigned char aCn);
		void OperateAdd_Mask(TDMix aFullPath, unsigned char aDType, unsigned int aUc);
		void OperateAdd_UnMask(TDMix aFullPath, unsigned char aDType, unsigned int aUc);
		void OperateAdd_Registe(unsigned char Sta);
		void OperateAdd_UnRegiste(TDMix aFullPath, unsigned char aDType);
		void OperateAdd_SetCanNetwork(unsigned char NwType, unsigned char aCn);
		void OperateAdd_CfgBoard(TDMix aFullPath, unsigned char aDType);
		void OperateAdd_CfgCrt();
		void OperateAdd_CfgPriter(unsigned char aOnOff, unsigned int aEvevtInc);
		void OperateAdd_CfgPritEventType();
		void OperateAdd_CfgDevice(TDMix aFullPath, unsigned char aDType);
		void OperateAdd_CfgDateTime(u8 aY, u8 aM, u8 aD, u8 aH, u8 aMin, u8 aSec);
		void OperateAdd_SetNwDateTime(u8 aY, u8 aM, u8 aD, u8 aH, u8 aMin, u8 aSec);
		void OperateAdd_ReqNwDateTime();
		void OperateAdd_CfgPermissionAllow(unsigned char aPa);
		
		void OperateAdd_AllowState(unsigned char aCn, unsigned char aAllowAuto, unsigned char aAllowManual);
		void OperateAdd_ScreenKeyLock(unsigned char aScreenSave, unsigned char EnterSaveTime, unsigned char aLock, char *aCr);
		
		void OperateAdd_ManualStart		(unsigned int aPath, unsigned char aType, unsigned char aSubType);
		void OperateAdd_ManualStartCancel	(unsigned int aPath, unsigned char aType, unsigned char aSubType);
		void OperateAdd_ManualFb		(unsigned int aPath, unsigned char aType, unsigned char aSubType);
		
		void OperateAdd_AlramSoundOn(unsigned char aCn);
		void OperateAdd_AlramSoundOff(unsigned char aCn);
		
		void OperateAdd_BusPadOn(unsigned char aCn, unsigned char aP0, unsigned char aP1);
		void OperateAdd_BusPadOff(unsigned char aCn, unsigned char aP0, unsigned char aP1);
		
		void OperateAdd_DirectPadManualAllowOn(unsigned char aCn, unsigned char aP0);
		void OperateAdd_DirectPadManualAllowOff(unsigned char aCn, unsigned char aP0);
		void OperateAdd_DirectPadNodeOn(unsigned char aCn, unsigned char aP0, unsigned char aP1);
		void OperateAdd_DirectPadNodeOff(unsigned char aCn, unsigned char aP0, unsigned char aP1);
		void OperateAdd_UserCheck(unsigned char aCn, unsigned char OnOff);
		void OperateAdd_SelfCheck(unsigned char aCn);
		void OperateAdd_MasterLinkageGo(unsigned char aCn);
		void OperateAdd_SlaveLinkageGo(unsigned char aCn);
		
		void OperateAdd_PowerOff(unsigned char aCn, unsigned char *aDt);
		void OperateAdd_PowerUp(unsigned char aCn, unsigned char *aDt);
		void OperateAdd_Reset(unsigned char aCn, unsigned char *aDt);
		void OperateAdd_Mute(unsigned char aCn, unsigned char *aDt);
		void OperateAdd_Mask(TDMix aFullPath, unsigned char aDType, unsigned char *aDt, unsigned int aUserCode, unsigned short aAreaNum);
		void OperateAdd_UnMask(TDMix aFullPath, unsigned char aDType, unsigned char *aDt, unsigned int aUserCode, unsigned short aAreaNum);
		void OperateAdd_Registe(TDMix aFullPath, unsigned char aDType, unsigned char *aDt);
		void OperateAdd_UnRegiste(TDMix aFullPath, unsigned char aDType, unsigned char *aDt);
		void OperateAdd_SetCanNetwork(unsigned char aCn, unsigned char sAddr, unsigned char mAddr, unsigned char *aDt);
		void OperateAdd_CfgBoard(TDMix aFullPath, unsigned char aDType, unsigned char *aDt);
		void OperateAdd_CfgCrt(unsigned char *aDt);
		void OperateAdd_CfgPriter(unsigned char *aDt);
		void OperateAdd_CfgPritEventType(unsigned char *aDt);
		void OperateAdd_CfgDevice(TDMix aFullPath, unsigned char aDType, unsigned char *aDt);
		void OperateAdd_CfgCircuitSmokeSensGrade(unsigned int aFullPath, unsigned char Grade);
		void OperateAdd_CfgAddrSmokeSensGrade(unsigned int aFullPath, unsigned char Grade);
		void OperateAdd_CfgDateTime(u8 aY, u8 aM, u8 aD, u8 aH, u8 aMin, u8 aSec, unsigned char *aDt);
		void OperateAdd_CfgPermissionAllow(unsigned char aPa, unsigned char *aDt);
		
		void OperateAdd_AllowState(unsigned char aCn, unsigned char aAllowAuto, unsigned char aAllowManual, unsigned char *aDt);
		void OperateAdd_ScreenKeyLock(unsigned char aScreenSave, unsigned char EnterSaveTime, unsigned char aLock, char *aCr, unsigned char *aDt);
		
		void OperateAdd_AlramSoundOn(unsigned char aCn, unsigned char *aDt);
		void OperateAdd_AlramSoundOff(unsigned char aCn, unsigned char *aDt);
		
		void OperateAdd_BusPadOn(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char *aDt);
		void OperateAdd_BusPadOff(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char *aDt);
		
		void OperateAdd_DirectPadManualAllowOn(unsigned char aCn, unsigned char aP0, unsigned char *aDt);
		void OperateAdd_DirectPadManualAllowOff(unsigned char aCn, unsigned char aP0, unsigned char *aDt);
		void OperateAdd_DirectPadNodeOn(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char *aDt);
		void OperateAdd_DirectPadNodeOff(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char *aDt);
		void OperateAdd_UserCheck(unsigned char aCn, unsigned char OnOff, unsigned char *aDt);
		void OperateAdd_SelfCheck(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char *aDt);
		void OperateAdd_LinkageGo(unsigned char aCn, unsigned char *aDt);
		
		void OperateAdd_GetDateTime(u8 aY, u8 aM, u8 aD, u8 aH, u8 aMin, u8 aSec);
		
		void OperateAdd_ManualAllowSet(unsigned char aCn, unsigned char aAllow);
		void OperateAdd_AutoAllowSet(unsigned char aCn, unsigned char aAllow);
		void OperateAdd_AllowSet(unsigned char aCn, unsigned char aAllow);
		void OperateAdd_ManualAllowRemoteSet(unsigned char aCn, unsigned char aAllow);
		void OperateAdd_AutoAllowRemoteSet(unsigned char aCn, unsigned char aAllow);
		void OperateAdd_AllowRemoteSet(unsigned char aCn, unsigned char aAllow);
		void OperateAdd_ManualAllowReport(unsigned char aCn, unsigned char aAllow);
		void OperateAdd_AutoAllowReport(unsigned char aCn, unsigned char aAllow);
		void OperateAdd_AllowReport(unsigned char aCn, unsigned char aAllow);
		
		void OperateAdd_FireConfirm(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char aType, unsigned int aUc, unsigned char IsSim);
		void OperateAdd_FaultConfirm(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char dType, unsigned char fType, unsigned char Data1, unsigned int aUc);
		
		void OperatePublic_FireRemoteConfirm(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char aType, unsigned char IsSim);
		void OperatePublic_FaultRemoteConfirm(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char dType, unsigned char fType, unsigned char Data1);
		//----2024 07 10  -->
		void OperateAdd_CleanUp(unsigned char cType);
		void OperateAdd_LinkageExpsModify(unsigned char IsAdd, unsigned int eInx);
		void OperateAdd_BusPadModifyModify(unsigned char aP0, unsigned int aP1);
		void OperateAdd_DirectPadModify(unsigned char aP0);
		void OperateAdd_DescpModify(unsigned char aP0, unsigned char aP1);
		void OperateAdd_PassWdModify(unsigned char aLvl);
		void OperateAdd_RegisterByManual(unsigned char aP0, unsigned char sAddr, unsigned char eAddr, unsigned char aType, unsigned char IsAdd);
		void OperateAdd_AddRemoveNwCtl(unsigned char Act, unsigned char aCtlNum);
		void OperateAdd_RegCanNetwork(unsigned char NwType, unsigned char aCtlNum, unsigned char SlaveCount);
		void OperateAdd_StartStop(unsigned char aCn, unsigned char aP0, unsigned char aP1, unsigned char aType, unsigned char IsSatrt);
		void OperateAdd_ClearNetworkCfg();
		void OperateAdd_BroadcastVa(unsigned char aPadNum, unsigned char aAddr, unsigned char aMode);

		
		//_____________________________________<<<<<
		void DelayMs(unsigned int aMs);
		void Task10Ms();
		void Task1000Ms();
		void Task5000Ms();
		
		void Wait10Ms();

		void GetFireEntry(int aInx);
		void PrcFireWrite();
		void GetLinkageEntry(int aInx);
		void PrcLinkageWrite();
		void WaitChipIdle(unsigned int ChipX);
		
		void GetSvEntry(int aInx);
		void PrcSvWrite();
		void GetFaultEntry(int aInx);
		void PrcFaultWrite();
		void GetOperateEntry(int aInx);
		void PrcOperateWrite();
		
		void MsgReadInit(unsigned int aChip, TBufToFlash *aBuf, unsigned int aFlashBaseAddr, int aPstY);
		void MsgReadInit2(unsigned int aChip, TBufToFlash *aBuf, unsigned int aFlashBaseAddr, int aPstY);
		void MsgReadInit3(unsigned int aChip, TBufToFlash *aBuf, unsigned int aFlashBaseAddr, int aPstY);
		
		void Chip0Prc();
		void Chip1Prc();
		
		void AllMsgReadInit();
		
		void ClearFireHistory();
		void ClearLinkageHistory();
		void ClearSvHistory();
		void ClearFaultHistory();
		void ClearOperateHistory();
		
		void LoadFireHistory();
		void LoadLinkageHistory();
		void LoadSvHistory();
		void LoadFaultHistory();
		void LoadOperateHistory();
		
		int CheckHistoryCSum(unsigned char *p);
		void WriteRegisterData();
		void ReadRegisterDataOnePort(unsigned char aPort);
		void ReadRegisterData();
		void ReadProjAndCtlDescp();
		void ReadDescp();
		void ReadDescpNw();
		void FloorDescp();
		
		void LoadBusPadLnk(unsigned char aPad);
		void LoadBusPadLnk();
		void LoadDirectPadCfg(unsigned char aPath0);
		void LoadDirectPadCfg();
		void ReadPortDisplayPadSet(unsigned char aPort);
		void ReadDisplayPadSet();
		void ReadDesignPrm();
		void ReadMainSet();
		void ReadAllowSet();
		void ReadPrintSet();
		void ReadScreenSave();
		void ReadLanguage();
		
		void WriteMaintain(unsigned char *p);
		void ReadMaintain();
		
		void SaveNewTime2Eep();
		void WriteMainSetMainCtl(unsigned char aIsMaster, unsigned char aCtlNum);
		void WritePrinterState(unsigned char aSta);
		void WritePrinterEvent(unsigned char aEvent);
		void WriteAllow(unsigned char aAllowAuto, unsigned char aAllowManual);
		void WriteScreenKeyLock(unsigned char aScreenSave, unsigned char EnterSaveTime, unsigned char aLock, char *aCr);
		void WriteGraphSet(unsigned int aBrd, unsigned char aIntavalMs, unsigned char aIsHaft, unsigned char RpyDelayUs, unsigned char RpyTimeMs);
		void WriteLanguage(unsigned char aNew);
		
		void WritePowerSuplyCount(unsigned char aSubExist0, unsigned char aSubExist1);
		void ReadPowerSuplyCount();
		
		void SaveNwCfg(unsigned char aMasterNum, unsigned char aSlaveCount, unsigned char *aList);
		void ReadNwCfg();
		void SaveNwM2MCfg(unsigned char aCnt, unsigned char *aList);
		void ReadNwM2MCfg();
		
		void ReadDevUserSet();
		void ReadDirectPadUserSet(unsigned char aPath0);
		void ReadDirectPadUserSet();
		
		void Read4Area();
		void ReadDevAreaNum();
		void ReadDirectPadAreaNum();
		
		int WriteLastMaintainTime();
		void ReadLastMaintainTime();
		
		void CheckPrimaryKeyWarning();
};























#endif


