#ifndef MAINCTL_H_
#define MAINCTL_H_

#include "gvalue.h"
#include "Device.h"
#include "EpDevice.h"
#include "RuntimeData.h"


typedef union{
	unsigned int  D32[35];
	unsigned char D8[140];
	struct{
		unsigned char MyNum;
		unsigned char MotherBoardCount;
		unsigned char PortCount;
		unsigned char HandCtlCount;
		
		unsigned char DirectCtlCount;
		unsigned char CommModuleCount;
		unsigned char InputKeyboard_1;
		unsigned char InputKeyBoard_2;
		
		unsigned char InputTouchPad;
		unsigned char PowerSupplyCount;
		unsigned char NetworkMode;
		unsigned char MasterNum;
		
		unsigned char CanNetworkMethod;
		unsigned char Rsv1;
		unsigned char Rsv2;
		unsigned char Rsv3;
		
		unsigned char ExistSlaveTabel[dNETWORK_MACHINE_COUNT];
		unsigned char ExistTablePort[dPORT_MAX_COUNT];
		unsigned char ExistTableHandCtl[dHANDCTL_MAX_COUNT];
		unsigned char ExistTableDirectCtl[dDIRECTCTL_MAX_COUNT];
		unsigned char ExistTableMotherBrd[dMOTHERBOARD_MAX_COUNT];
		unsigned char ExistTableCommBrd[dCOMMBOARD_MAX_COUNT];
	}Split;
}TMainCtlData;

class TThisMainCtl{
	public:
		TMainCtlData fData;
		unsigned char ReqUploadToCRT;
		unsigned int Permission;
	
		unsigned int CountAllDevice;
		unsigned int CountRootDev;
		unsigned int CountPort;
		unsigned int CountHandCtl;
		unsigned int CountDirectCtl;
		unsigned int CountMotherBoard;
		unsigned int CountCommBoard;
		unsigned int CountEpAll;
		struct{
			unsigned int UnDefine;
			unsigned int Smoker;
			unsigned int Tempe;
			unsigned int HandReport;
			unsigned int Fire_hydrant_Kp;
			unsigned int Input;
			unsigned int InOut;
			unsigned int Output;
			unsigned int VaAlram;
			unsigned int DisplayPad;
			unsigned int LnkPs;
			unsigned int Unknown;
			
			unsigned int SmokeTempe;
			unsigned int BusBroker;
		}CountEp, CountEpNormal, CountEpFault, CountEpMask;
		unsigned int CountHandCtlPad;
		unsigned int CountDirectCtlPad;
		char Sn[36];
		char GenSn[12];
		unsigned int CrcPortList;
		struct{
			unsigned char PortList;
			unsigned char Dump0;
			unsigned char Dump1;
			unsigned char Dump2;
			void Clear(){
				PortList=0;
				Dump0=0;
				Dump1=0;
				Dump2=0;
			}
		}CrcFlag;
	public:
		TThisMainCtl(void){CrcFlag.Clear();};
		TThisMainCtl(unsigned char Addr, unsigned char aPms){
			Init(Addr,aPms);
			CrcFlag.Clear();
		}
		void Init(unsigned char Addr, unsigned char aPms){
			unsigned int i;
			for(i=0;i<35;i++){
				fData.D32[i]=0;
			}
			if( (aPms ==0) || (aPms >3) ){
				Permission = 1;
			}else{
				Permission = aPms;
			}
			fData.Split.MyNum = Addr;
			
			ClearVisioInf();
			
			for(int i=0; i<32; i++){
				Sn[i] = i + '0';
			}
			Sn[32] = '\0';
			Sn[33] = '\0';
		};
		void AssignByData(unsigned int *da);
		void GetDescp(unsigned char *StrGot);
		void SetDescp(unsigned char *StrPut);
		void ClearState();
		
		void ClearVisioInf(void);
		void ClearNormalInf(void);
		void ClearFaultInf(void);
		void ClearMaskInf(void);
		void LoadVisioInf();
		void LoadNormalInf();
		void LoadFaultInf();
		void LoadMaskInf();
		
		void LnkRdyGoUpdata();
		
		void LoadCirciutInf();
		void RecallCrcFaultMsg();
};



#endif

