#ifndef DEVSTARTSTOP_H_
#define DEVSTARTSTOP_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"
#include "DevProperty.h"
#include "ItemList.h"

class TDevStartStop{
	public:
		static constexpr unsigned short hList[12] = {72,72,72,72,	72,72,34,34,	34,34,34,34};
		static constexpr unsigned short wList[12] = {800,290,290,290,	290,290,290,290,	290,290,290,290};
		static constexpr TLv Lv = {
			.Caption.Left = 0,
			.Caption.Top = 36,
			.Caption.Width = 800,
			.Caption.Heigh = 32,
			.Caption.Right = 800 -0 -1,
			.Caption.Bottom = 36 + 32,
			
			.Grid.Left = {0,0,0,0,	0,0,0,0,	0,0,0,0},
			.Grid.Right = {wList[0]-1,wList[1]-1,wList[2]-1,wList[3]-1,	wList[4]-1,wList[5]-1,wList[6]-1,wList[7]-1,	wList[8]-1,wList[9]-1,wList[10]-1,wList[11]-1},
			.Grid.Top[0] = (36 + 32 +2),
			.Grid.Top[1] = (36 + 32 +2) + (2 + hList[0]),
			.Grid.Top[2] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]),
			.Grid.Top[3] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]),
			.Grid.Top[4] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]),
			.Grid.Top[5] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]),
			.Grid.Top[6] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]),
			.Grid.Top[7] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]),
			.Grid.Top[8] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]),
			.Grid.Top[9] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]),
			.Grid.Top[10] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]),
			.Grid.Top[11] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + (2 + hList[10]),
				
			.Grid.Bottom[0] = (36 + 32 +2) + hList[0],
			.Grid.Bottom[1] = (36 + 32 +2) + (2 + hList[0]) + hList[1],
			.Grid.Bottom[2] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + hList[2],
			.Grid.Bottom[3] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + hList[3],
			.Grid.Bottom[4] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + hList[4],
			.Grid.Bottom[5] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + hList[5],
			.Grid.Bottom[6] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + hList[6],
			.Grid.Bottom[7] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + hList[7],
			.Grid.Bottom[8] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + hList[8],
			.Grid.Bottom[9] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + hList[9],
			.Grid.Bottom[10] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + hList[10],
			.Grid.Bottom[11] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + (2 + hList[10]) + hList[11],
			
			.Grid.UsingCount = 5,
			
			.Panel.Active = 1,
			.Panel.ItemType = piMemo,
			.Panel.Left = wList[1] + 6,
			.Panel.Top = (36 + 32 +2) + hList[0] +6,
			.Panel.Width = 502,
			.Panel.Heigh = 220,
			.Panel.Right = wList[1] + 6 + 502 -1,
			.Panel.Bottom = (36 + 32 +2) + hList[0] +6 + 220 -1,
			
			.PanelSmall.Active = 1,
			.PanelSmall.Left = wList[1] + 6,
			.PanelSmall.Top = (36 + 32 +2) + hList[0] +6 + 220 -1 + 1,
			.PanelSmall.Width = 502,
			.PanelSmall.Heigh = 72,
			.PanelSmall.Right = wList[1] + 6 + 502 -1,
			.PanelSmall.Bottom = (36 + 32 +2) + hList[0] +6 + 220 -1 + 1 + 72 -1,
		};
		static constexpr TRect ModuleRectLv3 = {
			.Top = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]),
			.Bottom = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + hList[3] + 30, 
			
		};
		static constexpr TRect ModuleRectLv4 = {
			.Top = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + 30,
			.Bottom = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + hList[4], 
		};
		static const unsigned int LvGridHighBottom3 = 102;
		static constexpr unsigned char dTypeList[256] = {
			dgTYPE_SMOKE_DETECTOR,
			dgTYPE_TEMPE_DETECTOR,
			dgType_VAALRAM,
		};
		static constexpr unsigned char dSmokeSensGrade_MarkValue[8] = {
			//100, 75, 50, 25
			0, 100, 75, 50, 25, 0, 0, 0
		};
		
		enum TDrawTextType{
			dtNone = 0,
			dtHex =1,
			dtDec =2
		};
	private:
		unsigned char VaReadWriteSta;
	public:
		class TItemList	*IList;
		int IsShow;
		TCtlPanel1	*aPanel;
		unsigned char CtlNum;
		unsigned char Path0;
		unsigned char Path1;
		unsigned char dType;
		unsigned char pNumFound;
		unsigned char IsRegisted;
		unsigned char IsSelfCtl;
		TStaticText Caption;
	
		int IsPermission;
		TDevProperty::TPermissionCmd PermissionCmd;
		int EdittingDescp;
		int IsExtInput;
		unsigned char CtlNumValid;
		unsigned char PortNumValid;
		unsigned char AddrNumValid;
		unsigned char PanelIsUsingText;
		
		TDevProperty::THwDevType HwDevType;
		TRootDevice *RootDev;
		TEpDevice *EpDev;
	
		struct{
			unsigned char Inx;
			unsigned char InxMin;
			void Reset(){
				Inx = 0;
				InxMin =0;
			}
		}Tag;
		
		TUserCode aUcSetting;
		
		unsigned char RecData[8];
		
		char TextTmp[24];
		struct{
			int TextDrawLine;
			int FigInx;
			unsigned char IsHexList[8];
			unsigned char DesertTextHex;
			unsigned char UsingTextHex;
			void Reset(){
				for(int i=0; i<8; i++)IsHexList[i]=dtNone;
				TextDrawLine = 0;
				FigInx = 0;
				//DesertTextHex = 0;
				//UsingTextHex = 0;
			}
			void ResetNotFull(){
				TextDrawLine = 0;
				FigInx = 0;
			}
		}PanelDrawData;
	
		struct{
			TUserCode UserCode;
			unsigned char SmokerSens;
			unsigned char TempeSenType;
			unsigned char ModuleDefineType;
			unsigned char ModuleSignalInType;
			unsigned char ModuleSignalInOutType;
			unsigned char ModuleSignalOutType;
			unsigned char VaIs4Linkage;
			unsigned char VaVisionType;
			unsigned char VaSoundType;
			unsigned char DisplayPadMatchMode;	//0:By User Code;	1:By Area Assign
			unsigned char DisplayPadAreaUsing[3];
			unsigned char DisplayPadUserCodeUsing[2];
			unsigned short DisplayPadArea0;
			unsigned short DisplayPadArea1;
			unsigned short DisplayPadArea2;
			unsigned int DisplayUserCode0;
			unsigned int DisplayUserCode1;		
			unsigned char GotTempeSensType[8];
			void Reset(){
				UserCode.Full =0;
				SmokerSens = 0;
				TempeSenType = 0;
				ModuleDefineType =0;
				ModuleSignalInType =0;
				ModuleSignalInOutType =0;
				ModuleSignalOutType =0;
				VaIs4Linkage =0;
				VaVisionType =0;
				VaSoundType =0;
				DisplayPadMatchMode =0;	//0:By User Code;	1:By Area Assign
				DisplayPadAreaUsing[0] = 0;
				DisplayPadAreaUsing[1] = 0;
				DisplayPadAreaUsing[2] = 0;
				DisplayPadUserCodeUsing[0] = 0;
				DisplayPadUserCodeUsing[1] = 0;
				DisplayPadArea0 =0;
				DisplayPadArea1 =0;
				DisplayPadArea2 =0;
				DisplayUserCode0 =0;
				DisplayUserCode1 =0;
				GotTempeSensType[0] =0;
				GotTempeSensType[1] =0;
				GotTempeSensType[2] =0;
				GotTempeSensType[3] =0;
				GotTempeSensType[4] =0;
			}
		}Data;
		struct{
			unsigned int voltage;
			unsigned int SmokerPrmM;
			unsigned int SmokerIR;
			unsigned int SmokerBR;
			unsigned int Celsius;
			unsigned int AlramCount0;
			unsigned int AlramCount1;
			unsigned int OutputVoltage;
			unsigned int OutputCurrent;
			unsigned int PwrLoaddingPercent;
			unsigned char Mac[8];
			void Reset(){
				voltage =0;
				SmokerPrmM =0;
				SmokerIR =0;
				SmokerBR =0;
				Celsius =0;
				AlramCount0 =0;
				AlramCount1 =0;
				OutputVoltage =0;
				OutputCurrent =0;
				PwrLoaddingPercent =0;
				for(int i=0; i<8; i++)Mac[i] =0;
			}
		}RuntimeData;
		
		unsigned char CommData[16];
		struct{
			unsigned char Method;
			unsigned char P0;
			unsigned char P1;
			unsigned char DevType;
			unsigned char DataType;

			unsigned char dVal[4];
			unsigned char dValGot[4];
			unsigned char dType;
		}ProcessingRt;
		struct{
			unsigned char  IsWait4ReadSens;
			unsigned char  IsWait4WriteSens; 
			unsigned char  RecRdy;
			unsigned char  RecCmd;
			unsigned char  WaitTick;
		}SmokerRt;
		struct{
			unsigned char  IsWait4ReadSensType;
			unsigned char  RecRdy;
			unsigned char  RecCmd;
			unsigned char  WaitTick;
		}TempeRt;
		struct{
			unsigned char  IsWait4ReadSignalType;
			unsigned char  IsWait4WriteSignalType;
			unsigned char  RecRdy;
			unsigned char  RecCmd;
			unsigned char  WaitTick;
		}ModuleInRt;
		struct{
			unsigned char  IsWait4ReadSignalType;
			unsigned char  IsWait4WriteSignalType;
			unsigned char  RecRdy;
			unsigned char  RecCmd;
			unsigned char  WaitTick;
		}ModuleInOutRt;
		struct{
			unsigned char  IsWait4ReadSignalType;
			unsigned char  IsWait4WriteSignalType;
			unsigned char  RecRdy;
			unsigned char  RecCmd;
			unsigned char  WaitTick;
		}ModuleOutRt;
		struct{
			unsigned char  IsWait4ReadVaSetting;
			unsigned char  IsWait4WriteVaSetting;
			unsigned char  RecRdy;
			unsigned char  RecCmd;
			unsigned char  WaitTick;
		}VaRt;
		struct{
			unsigned char  IsMute;
			unsigned char  IsDownloadDescp;
			unsigned char  RecRdy;
			unsigned char  RecCmd;
			unsigned char  WaitTick;
			char DescpText[36];
		}DisplayPadRt;
		struct{
			unsigned char VaIs4Linkage;
			unsigned char VaVisionType;
			unsigned char VaSoundType;
			unsigned char Dump0;
		}ExData;
		char TextDraw[40];
		TPoint PtStart;
		TPoint PtStop;
	private:
		void SetListColWidth(int w0, int w1, int w2, int w3, int w4,int w5,int w6, int w7, int w8, int w9);
	public:
		TDevStartStop(){};
		void Init(TDevProperty::THwDevType aDevType, int aMode);
		void DelayMs(unsigned int aMs);
		void DrawSelf();
		void RedrawCommonByExReturn();
		void DrawHtInf(int aPrm);
		void DrawState(unsigned char aSta);
		void DrawStateNone();
		void DrawMac();
		void SetPath(unsigned char aCtlNum, unsigned char aPath0, unsigned char aPath1);
			
		void RenderBackGround(void);
		void RenderBackGround(unsigned int aClr);
		void PermissionCmdReturnDraw();
		void ReDrawPanel();
		void ClearCommonInf();
			
		void DrawCommonInfTitle();
		void ReDrawCommonInf();
		void RenewCommonInf();
		void Redraw4NewLoad();
		void RedrawModuleInSignalInType();
		void RedrawModuleInOutSignalType();
		void RedrawModuleOutSignalType();
		void RedrawVaIs4Linkage();
		void RedrawVaSetting();
		void RedrawDisplayPadMatchMode();
		void RedrawDisplayPadMatchData();
		void RedrawSmallPanelData();
		
		void DrawFixTextNoType();
		void DrawFixTextSmoker();
		void DrawFixTextTempe();
		void DrawFixTextHandPad();
		void DrawFixTextHydrantPad();
		void DrawFixTextModuleIn();
		void DrawFixTextModuleInOut();
		void DrawFixTextModuleOut();
		void DrawFixTextVa();
		void DrawFixTextDisplayPad();
		void DrawFixTextLinkagePowerSuply();
			
		void ResetTargetData();
		
		void Init4DType();
		void InitNoType();
		void InitHtSmoker();
		void InitHtTempe();
		void InitHtHandPad();
		void InitHtHydrantPad();
		void InitHtModuleIn();
		void InitHtModuleInOut();
		void InitHtModuleOut();
		void InitHtVa();
		void InitHtDisplayPad();
		void InitHtLinkagePowerSuply();
		
		void ReReadCmdSend();
		
		void Show(void);
		void ReDraw(void);
		void FullRedraw(int Prm);
		void PanelCanvasOut();
		void DrawCaption2(void);
		
		TGuiMsgReturn KeyIn(unsigned char aKey);
		TGuiMsgReturn KeyInCommonEdit(unsigned char aKey);
		TGuiMsgReturn KeyInCommonEnter(unsigned char aKey);
		
		void InitPanel();
		void ShowStartNewMsg(unsigned char Hour, unsigned char Min, unsigned char Sec);
		void ClearSelected();
		void Check4Selected();
		void CheckPathDev();
		void SendCmd(unsigned int IsStart);
		
		void SendStartStopCmd(unsigned int IsStart);
		void SendSmokeCmdRead();
		void SendTempeCmdRead();
		void SendModuleSignalInOutTypeRead();
		void SendVaSettingRead();
		
		void RealTimeSendCmd(const int StartStop);
		void RealTimeSendCmdAbort();
		void RunTimeSendCmd(const int StartStop);
		void PermissionCmdGO();
		void ClearReqDataState();
		void UpdataOnlineData();
		
		void PushOneRealDataReport(u8 aP0, u8 aP1, u8 aInx, u8 D0, u8 D1, u8 D2, u8 D3);
		void PushInnerCanData(unsigned char aCmd, unsigned char *pData);
		void PushInnerRuntimeCanData(unsigned char aCmd, unsigned char *pData);
		
		void LoadUcBcdText(unsigned int aUcFull, char *pText);
		void DrawVaReadWriteStates();
		void DrawVaReadWriteStates(unsigned char aNewState);
		
		void Task1000Ms();
		
		int ExtRequst(unsigned char Prm);
};



#endif


