#ifndef FNETWORKREG_H_
#define FNETWORKREG_H_

#include "gType.h" 
#include "GraphBase.h"
#include "string.h"
#include "my_string.h"
#include "Device.h"
#include "EpDevice.h"
#include "StaticText.h"
#include "CtlPanel1.h"

class TfNetworkReg{
	public:
		TCtlPanel1 *aPanel;
	public:
		TStaticText Caption;
		TStaticText SText;
		u32 Color;
	
		int TabOrder;
	
		TPoint OwnerLeftTop; //ParrentLeftTop;
		TRect Bound;	
		TRect Content;
		TMyString Str;
	
		int IsShowing;
		int IsOnGoing;
		int IsLoadingDescp;
		unsigned char IsViewList;
		unsigned char CtlIndex;
	
		unsigned char Count;
		unsigned char CountMater;
		unsigned char CountSlave;
		unsigned char PageIndex;
		unsigned char PageCount;
		unsigned char Done;
	
		unsigned char DescpGetCmp;
		unsigned char TxDataByNetworkFind[12];
		unsigned char RecData[12];
		
		unsigned char Path;
		unsigned char aNewGot;
		unsigned char SearchNumExist;
		unsigned char FoundIndex;
		
		unsigned char SearchingNum;
		unsigned char SearchingTick;
		
		unsigned char RecBlock;
		unsigned char IncMaster;
		
		unsigned char LoadingIndex;
		unsigned char LoadingNum;
		
		struct{
			unsigned int BusyTick;
			unsigned int IsBusy;
			unsigned int Tick;
			unsigned int NoUpdateTick;
			unsigned int AvaEntry;
			unsigned int WaitTimeOutTick;
			unsigned char P0ExistTable[48];
			unsigned char P1GetTable[256];
			unsigned char RetryP1[16];
			unsigned char ExistPortAskRetryTimes;
			unsigned char pNumInx;
			unsigned char pNum;
			unsigned char P0;
			unsigned char P1;
			unsigned char IsAll;
			unsigned char IsStart;
			unsigned char P0State;
			unsigned char P1State;
			unsigned char RemainCount;
			unsigned char EmptyCount;
			unsigned char Err;
			unsigned char IsSaving;
			unsigned char IsSaveOk;
			unsigned char Completed;
		}DescpGo;
		
		char Text[68];
		
		union{
			unsigned char D8[256];
			unsigned int  D32[64];
		}ReadWriteData;
		
		struct{
			unsigned int CtlNum;
			unsigned int PortX;
			union{
				unsigned int D32[8];
				unsigned char D8[32];	
			}Body[256];
		}PortDevDescp;

	public:
		TfNetworkReg(){};
		TfNetworkReg(int x1, int y1, int aW, int aH, int OwnerX, int OwnerY, u32 aColor){
			Init(x1, y1, aW, aH, OwnerX, OwnerY, aColor);
		}
		void Init(int x1, int y1, int aW, int aH, int OwnerX, int OwnerY, u32 aColor);
	
		void SetAndShowCaption(unsigned char aType);
		void RenderBackGround(void);
		void RenderBackGround(unsigned int aClr);
		void DrawSelf(void);
		void ClearOutText();
		static void sDelayMs(unsigned int aMs);

		void Show(void);
		void ShowCaption();
		void ReDraw(void);
		void FullRedraw(int Prm);
		void DrawCaption2(void);
		void DrawList();
		void DrawListStatic();
		void SetPanelCaptionColor();
		
		void DrawCount();
		void ShowSearchCompleted();
		void ShowSaveOk();
		void ShowSaveNotOk();
		
		void ShowDescpState();
		
		void LoadDescpShowCtlNum();
		void LoadDescpShowCircuit();
		
		void ClearData();
		void LoadData();
		void LoadData2Last();
		
		void SendAskType(unsigned char aNum);
		void SendAskDescp(unsigned char aNum);
		void SendNwList();
		TGuiMsgReturn KeyIn(unsigned char aKey);
		
		void InitPanel(void);
		void InitPanel4Going(void);
		void InitPanel4LoadDescp(void);
		void Check4Selected(void);
		void Check4SelectedInDescp();
		
		unsigned char GetRecType(unsigned char aNum);
		unsigned char CheckRecTypeAva(unsigned char aNum);
		unsigned char CheckDescpAva(unsigned char aNum);
		unsigned char GetCtlCount();
		
		void ClearDescpContent();
		void ClearDescpGoData();
		void DescpGoAll();
		void DescpGoOneCtl();
		
		void Task1000Ms();
		void Task10Ms();
		
		void SendfNetMsg(unsigned char aSubCmd, unsigned char *data, int Len);
		void PushfNetMsg(unsigned char aSubCmd, unsigned char *data, int Len);
		
		void PortExistGet(unsigned char aNum, unsigned char aP0, unsigned char aExist);
		void DescpListGet(unsigned char aNum, unsigned char aP0, unsigned char Addr, unsigned char *Data);
		
		void SavePortDescp(unsigned char aPNum, unsigned char aP0);
		void ReadPortDescp(unsigned char aPNum, unsigned char aP0);
		
		void SaveDirectPadDescp(unsigned char aPNum);
		void ReadDirectPadDescp(unsigned char aPNum);
		
		void ReadNwDevDescp();
		
		static void sRecoverSetDefaultNetworkDescp();
		
		int ExtRequst(unsigned char Prm);

};



#endif

