#ifndef RUNTIME_H_
#define RUNTIME_H_

#include "gType.h"
#include "ControlCenter.h"
#include "MainCtl.h"
#include "CtrlStartUp.h"
#include "PinyinT9.h"
#include "KeyPad.h"
#include "ProtoC2C.h"
#include "ProtoM2M.h"
#include "InterLink.h"
#include "DoPrint.h"
#include "exRecord.h"
#include "ProtoFecBusCRT.h"
#include "ProtoCrt.h"
//#include "RtUserCode.h"
#include "Config.h"
#include "RemoteData.h"
#include "MqttData.h"

#define dInnerCanRxBufMaxCount		2048
#define dExtCanRxBufUsingUartMaxCount	256

typedef struct{
	int WriteIndex;
	int ReadIndex;
	struct{
		TCanHeaderID Ide;
		unsigned char Len;
		unsigned char Rsv0;
		unsigned char Rsv1;
		unsigned char Rsv2;
		unsigned char Da[8];
	}Body[dInnerCanRxBufMaxCount];
}TInnerCanRxBuf;

typedef struct{
	int WriteIndex;
	int ReadIndex;
	struct{
		unsigned char Da[12];
	}Body[dExtCanRxBufUsingUartMaxCount];
}TExtCanRxBufUsingUart;

typedef struct{
	unsigned char QueryInf;
	unsigned char ClearCtlVoice;
	unsigned char Check;
	unsigned char InfReadConfirm;
	unsigned char LinkageActive;
	unsigned char MaskAndUnMask;
	unsigned char Rsv0;
	unsigned char Rsv1;
}TPermissionDt;

typedef struct{
	unsigned char PadAddr;
	unsigned char Addr;
	unsigned char AreaNum;
	unsigned char SyncMode;
	unsigned short BroadcastTime;
	unsigned short VaTime;
}TBroadcast;

typedef struct{
	unsigned char SaveOn;
	unsigned char SaveTime;
	unsigned char IsKeyLock;
	unsigned char Dump;
	char UnLockText[4];	
}TScreenAndKeyLock;

typedef struct{
	unsigned char D8[256];
	unsigned short D16[128];
	unsigned int D32[64];
	void Clear(){
		for(int i=0;i<64;i++)D32[i]=0;
	}
}TRtReadWriteBuf256Bytes;

typedef struct{
	unsigned int Path;
	unsigned int mType;
	unsigned int SubType;
	unsigned int dType;
}TManualEventMsgAdd;

typedef struct{
	unsigned int Tick;
	unsigned int Active;
	unsigned int Sync;
	unsigned int InBroadcast;
}TBroadcastAlramAlternating;

typedef struct{
	union{
		unsigned int D32[4];
		struct{
			unsigned char ThisP0;
			unsigned char ThisP1;
			unsigned char Dump0;
			unsigned char Dump1;
			struct{
				unsigned char CtlNum;
				unsigned char P0;
				unsigned char BeginAddr;
				unsigned char EndAddr;
			}UsingPath[3];
		}Spl;
	}Entry[dPORT_MAX_COUNT][dDISPLAYPAD_MAX_COUNT];
	unsigned char Count4Circuit[dPORT_MAX_COUNT];
}TDisplayPadRt;

typedef struct{
	union{
		unsigned int D32[4];
		struct{
			unsigned char P0;
			unsigned char BeginAddr;
			unsigned char EndAddr;
			unsigned char Dump;
		}TargetPath[4];
	}Entry[dHANDCTL_MAX_COUNT][dHANDCTL_KEY_MAX_COUNT];
}TBusPadRt;

typedef union{
	unsigned int D32[16];
	unsigned char D8[64];
	struct{
		unsigned int Smoke;
		unsigned int Tempe;
		unsigned int HydrantKp;
		unsigned int HandReport;
		unsigned int ModuleInput;
		unsigned int ModuleInOut;
		unsigned int ModuleOutput;
		unsigned int Va;
		
		unsigned int DisplayPad;
		unsigned int LnkPs;
		unsigned int Other;
		unsigned int Dump1;
		unsigned int Dump2;
		unsigned int Dump3;
		unsigned int Dump4;
		unsigned int Dump5;
	}Count;
}TDesigePrmData;

typedef union{
	unsigned int D32[4];
	unsigned short D16[8];
	unsigned char D8[16];
	struct{
		TDMix16 PsVoltageCh1;
		TDMix16 PsVoltageCh2;
		TDMix16 BkVoltage;
		TDMix16 BatVoltage1;
		TDMix16 BatVoltage2;
		unsigned char BatEnerger1;
		unsigned char BatEnerger2;
		
		unsigned int HasUpdate;
	}Body;
}TPsBatData;
	
typedef struct{
	unsigned char AutoManual;
	unsigned char BatState;
	unsigned short HasUpdate;
}TKeyPadData;

typedef struct{
	unsigned int  tick;
	unsigned int  IsStartCheck;
	unsigned char Port[dPORT_MAX_COUNT];
	unsigned char BusPad[dHANDCTL_MAX_COUNT];
	unsigned char DirectPad[dDIRECTCTL_MAX_COUNT];
	unsigned char ExStroge;
	unsigned char KeyBoard;
	unsigned char Rsv0;
	unsigned char Rsv1;
	
	unsigned char ErrPort[dPORT_MAX_COUNT];
	unsigned char ErrBusPad[dHANDCTL_MAX_COUNT];
	unsigned char ErrDirectPad[dDIRECTCTL_MAX_COUNT];
	unsigned char ErrExStroge;
	unsigned char ErrKeyBoard;
	unsigned char ErrRsv0;
	unsigned char ErrRsv1;
}TInspec;

typedef struct{
	unsigned int MainCount;
	unsigned int SubExist[2];
	union{
		unsigned char D8[20];
		unsigned int D32[5];
		struct{
			unsigned short vChannel1;
			unsigned short vChannel2;
			unsigned short vBak;
			unsigned short vBat1;
			unsigned short vBat2;
			unsigned char PercentBat1;
			unsigned char PercentBat2;
			unsigned char PowerLineFault;
			unsigned char BatFault;
			unsigned char OfflineFault;
			unsigned char OutputFault;
			unsigned char Bat1VoltageLow;
			unsigned char Bat2VoltageLow;
		}Body;
	}Sub1, Sub2;
}TPowerPrmValue;

typedef union{
	unsigned char D8[16];
	struct{
		unsigned char IsCustomTime;
		unsigned char IsHalfYear;
		unsigned char LastMonth;
		unsigned char LastDay;
		unsigned char Month0;
		unsigned char Day0;
		unsigned char Month1;
		unsigned char Day1;
		unsigned char Month2;
		unsigned char Day2;
		unsigned char Month3;
		unsigned char Day3;
		unsigned char Month4;
		unsigned char Day4;
		unsigned char Month5;
		unsigned char Day5;
	}fDa;
}TMaintainData;

typedef union{
	unsigned char D8[16];
	struct{
		unsigned char Day;
		unsigned char Month;
		unsigned char Year;
		unsigned char Cent;
		
		unsigned char WholeYear;
		unsigned char YearOneOffTwo;
		unsigned char YearTwoOffTwo;
		unsigned char AssignOneOffThree;
		unsigned char AssignTwoOffThree;
		unsigned char AssignThreeOffThree;
	};
	struct{
		unsigned int FullDate;
		unsigned char Dump[12];
	};
}TLastMaintain;

typedef struct{
	unsigned char IsNormal;
	unsigned char Hours;
	unsigned char Dump0;
	unsigned char Dump1;
}TRunModeData;

typedef union{
	unsigned char D8[40];
	struct{
		unsigned int Done;
		unsigned int nDays;
		unsigned char CodeSet[32];
	}fDa;
}TSysAuthorize;

typedef union{
	unsigned int D32[9];
	char Text[36];
}TTextAnsi;

typedef union{
	unsigned int D32[36];
	char Text[136];
}TTextUtf8;

typedef struct{
	unsigned short OnOff;
	unsigned short PrintSelected; 
}TPriterSetting;

typedef struct{
	unsigned char BusEN;
	unsigned char TxEN;
	unsigned char RxEN;
}TFecBusCfg;

typedef struct{
	unsigned int Count;
	unsigned char Exist[dAreaCountMax];

}TAreaSetting;

extern const char VerString[32];
extern const char VerDateTimeString[32];
extern unsigned char OuterCanTxState;
extern TInnerCanRxBuf	InnerCanRxBuf;
extern TExtCanRxBufUsingUart	ExtCanRxBufUsingUart;
extern char CommomGuiTempText[64];

extern volatile int IsEventAddBlock;
extern TManualEventMsgAdd ManualEventMsgAdd;

extern unsigned char 	PrjName[36];
extern unsigned char 	CtlName[36];
extern class TDateTime	PrjBuildDateTime;
extern class 		TDateTime TrialEndDateTime;
extern int 			TrialCountDownDay;
extern int 			TrialEndDay;

extern unsigned char AlramVaOnOff;
extern unsigned int AlarmSoundWhat;
extern unsigned int IsMute;
extern unsigned int IsMuteFire;
extern unsigned int IsMuteLnk;
extern unsigned int IsMuteSv;
extern unsigned int IsMuteFault;
extern unsigned int IsMuteOpa;
extern unsigned char PumpOnOff;
extern unsigned char PumpFeedBack;

extern unsigned char PowerSuplyStateOld ;
extern unsigned char PowerSuplyState ;
extern unsigned char PowerSuplyCommOld ;
extern unsigned char PowerSuplyComm ;
extern unsigned char PowerBkStateOld ;
extern unsigned char PowerBkState ;
extern unsigned char BatStateOld ;
extern unsigned char BatState ;
extern unsigned char PowerSuplyOutputOld;
extern unsigned char PowerSuplyOutput;
extern unsigned char Bat1UnderVoltageOld;
extern unsigned char Bat2UnderVoltageOld;
extern unsigned char Bat1UnderVoltage;
extern unsigned char Bat2UnderVoltage;

extern unsigned int  FireVaTrenOned;

extern unsigned int IsSystemError;
extern unsigned int IsShowingMsgReset;
extern unsigned int IsShowTipPopup;
extern unsigned char RunState;
extern unsigned int AllowAuto;
extern unsigned int AllowManual;
extern unsigned char LinkageManualGo;

extern class TDateTime 		DateTime;
extern unsigned char 		SystemPermission;
extern int 				SystemPermissionTick;
extern int 				IsHotKeyCheckingPermission;

extern int PsBatDataHasUpdate;
extern int PsBatDataAva;
extern TPsBatData		PsBatData;
extern TPsBatData		PsBatDataOld;
extern TKeyPadData	KeyPadData;;
extern TInspec		InspecData;

extern TPermissionDt 	PermissionDt;
extern TPriterSetting 	PriterSetting;

extern TMaintainData 	MaintainData;
//extern TRunModeData	RunModeData;
extern TSysAuthorize	SysAuthorize;

extern unsigned int GraphUsing;
extern unsigned int GraphAddr;
extern unsigned int GraphLineType;
//extern unsigned int GraphDevBrd;
//extern unsigned short GraphDevFrameIntervalMs;
//extern unsigned short GraphDevHalfDuplex;
//extern unsigned short GraphDevReplyDelayUs;
//extern unsigned short GraphDevReplyRetainTimeMs;

extern TTextAnsi TextAnsi;
extern TTextUtf8 TextUtf8;

extern TTextInputMode CnInputMode;

extern class TDoPrint 	DoPrint;
extern class TexRecord 	ExRecord;
extern class TFecBusCRT FecBusCRT;
extern class TFecBus FecStd;
extern class TRecord		Record;
extern class TConfig 	Config;
extern class TControlCenter	CtlCenter;
extern class TCtrlStartUp	CtrlStartUp;
extern class TPinyinT9		PinyinT9;
extern class TKeyPad		KeyPad;
extern class TProtoC2C		ProtoC2C;
extern class TInterLink		InterLink;
extern class TDevPrinter	DevPrinter;
extern class TProtoCrt		Crt;
extern class TGeneralDev	GeneralDev;
//extern class TRtUserCode	RtUserCode;
extern class TRemoteData	RemoteData;
extern class TMqttData 	MqttData;

extern unsigned int C2cCompletedTick;
extern unsigned int GolbalDelayTick;

extern TBroadcast	  Broadcast;
extern TScreenAndKeyLock ScreenAndKeyLock;

//extern TDisplayPadRt	DisplayPadRt;
//extern TBusPadRt		BusPadRt;
extern TDesigePrmData	DesigePrmData;
extern unsigned int TimeSecHasRun;

extern unsigned int SysIsAuthState;
extern unsigned int SysRemainAuthTimeHour;

extern unsigned char IsStartDelay;
extern unsigned char NwIsSelfCheck;
extern unsigned char NwSelfCheckTick[32];
extern unsigned int NwIsNormalCheck;
extern unsigned int NwIsStartDelay;
extern unsigned int NwIsFbMiss;
extern unsigned int LanguageEnCn;

extern TPowerPrmValue	PowerPrmValue;

extern TFecBusCfg		FecBusCfg;
extern TAreaSetting	AreaSetting;
extern TBroadcastAlramAlternating	BroadcastAlramAlternating;

extern int SlaveInRemoteCtl;
extern int IsMaintainTip;
extern int LastMaintainTip;
extern int MaintainHourTick;
extern int MaintainHourRdy;
extern TLastMaintain LastMaintain;
extern int StartUpCompleted;

extern unsigned int TickNoKey4PopupTip;
extern unsigned int IsDulAddrChecking;
extern TRtReadWriteBuf256Bytes RtBuf256Bytes;


extern void PreventEventShow();
extern void TaskTimeUpData();
extern void LoopCheck1S();

extern void InspecDataInit();
extern void InspecDataRestart();
extern void RuntimeDataInit();
extern void RtManualPushStartMsg(unsigned char aType, unsigned char SubType, unsigned int aPath);
extern void RtManualPushStartCancelMsg(unsigned char aType, unsigned char SubType, unsigned int aPath);
extern void RtManualPushFbMissMsg(unsigned char aType, unsigned int aPath);

extern void InitAllNetworkEpData(); 
extern void ResetOneNetworkEpState(unsigned int aCtlNum);
extern void ResetAllNetworkEpState();
extern unsigned char 	GetNetworkEpState(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		SetNetworkEpState(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned char aSta);
extern unsigned char 	GetNetworkEpDType(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		SetNetworkEpDType(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned char dType);
extern unsigned short 	GetNetworkEpData(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		SetNetworkEpData(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned short aData);

extern void SelfCheckCountDown();
extern int CheckIsFrozeScreen();

extern void Test_AddMask1();
extern void Test_AddUnMask1();
extern void Test_AddMask2();
extern void Test_AddUnMask2();

extern int Conv2Utf8Text(TRecordCommon aRC);
extern int Check4ModifiedDate2ClearLastMaintain(unsigned char aYear, unsigned char aMonth, unsigned char aDay);
extern void Check4MaintainToShow();
extern void CommonDelayMs(unsigned int aMs);

extern void CoverDateTimeIllegal(TRecordBody Src, TDateTimeBytes *Dst);

/*
extern void 		FireSetEpDayTime(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned int aDt);
extern unsigned int 	FireGetEpDayTime(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		FireSetEpYearMonth(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned int aDt);
extern unsigned int 	FireGetEpYearMonth(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		LinkageStartSetEpDayTime(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned int aDt);
extern unsigned int 	LinkageStartGetEpDayTime(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		LinkageStartSetEpYearMonth(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned int aDt);
extern unsigned int 	LinkageStartGetEpYearMonth(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		LinkageFbSetEpDayTime(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned int aDt);
extern unsigned int 	LinkageFbGetEpDayTime(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		LinkageFbSetEpYearMonth(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned int aDt);
extern unsigned int 	LinkageFbGetEpYearMonth(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		FaultSetEpDayTime(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned int aDt);
extern unsigned int 	FaultGetEpDayTime(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
extern void 		FaultSetEpYearMonth(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1, unsigned int aDt);
extern unsigned int 	FaultGetEpYearMonth(unsigned char aCtlNum, unsigned char aP0, unsigned char aP1);
*/



#endif


