#include "Gui.h"
#include "DevProperty.h"

#define dWdClr		clSkyBlue
#define dWdDisabelClr	clNearWhite

#define dWWidth	24
#define dWHeigh	24
#define dRoundR	7

void TDevProperty::DrawFixTextVa()
{
	if(LanguageEnCn==0){
		TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, "控制");
		TextRender_string24(Lv.Grid.Left[2] +42, Lv.Grid.Top[2] + 38, clNearWhite, ItemColor, "联动");
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 36, 76, 30, 7, clNearWhite, "保存", 14, clNearBlack);
		
		TextRender_string24(Lv.Grid.Left[3] +10, ModuleRectLv3.Top + 6, clNearWhite, ItemColor, "警报形式");
		TextRender_string24(Lv.Grid.Left[3] +42, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "声光");
		TextRender_string24(Lv.Grid.Left[3] +140, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "声");
		TextRender_string24(Lv.Grid.Left[3] +236, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "光");
		
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +120, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, "读取", 14, clNearBlack);
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +210, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, "保存", 14, clNearBlack);

		TextRender_string24(Lv.Grid.Left[4] +10, ModuleRectLv4.Top + 6, clNearWhite, ItemColor, "操作");
		unsigned int aClr;
		if(RunState == TRunModeCfg::RunModeAdjust)aClr = clNearBlack;else	aClr = clSilver;
		TRoundRect::sDrawBySize(Lv.Grid.Left[4] +180, ModuleRectLv4.Top + 6, 104, 30, 7, clNearWhite, "模拟启动", 4, aClr);		
	}else{
		TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, "CTRL");
		TextRender_string24(Lv.Grid.Left[2] +42, Lv.Grid.Top[2] + 38, clNearWhite, ItemColor, "LINK");
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 36, 76, 30, 7, clNearWhite, "Save", 14, clNearBlack);
		
		TextRender_string24(Lv.Grid.Left[3] +10, ModuleRectLv3.Top + 6, clNearWhite, ItemColor, "ALAEMTYP");
		TextRender_string24(Lv.Grid.Left[3] +42, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "S-L");
		TextRender_string24(Lv.Grid.Left[3] +140, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "S.");
		TextRender_string24(Lv.Grid.Left[3] +236, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "L.");
		
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +120, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, "Read", 14, clNearBlack);
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +210, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, "Save", 14, clNearBlack);

		TextRender_string24(Lv.Grid.Left[4] +10, ModuleRectLv4.Top + 6, clNearWhite, ItemColor, "Operation");
		unsigned int aClr;
		if(RunState == TRunModeCfg::RunModeAdjust)aClr = clNearBlack;else	aClr = clSilver;
		TRoundRect::sDrawBySize(Lv.Grid.Left[4] +180, ModuleRectLv4.Top + 6, 104, 30, 7, clNearWhite, " Sim Act", 4, aClr);		
	}
}

void TDevProperty::FullRedrawhtVa(int Prm)
{
	if(Prm == 0){
		for(int i=2; i<Lv.Grid.UsingCount; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
		if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
		ReDrawCommonInf();
		DrawFixTextVa();
		
		IList->Edit[0].Show();
		RedrawVaIs4Linkage();
		RedrawVaSetting();
		DrawVaReadWriteStates();
		RedrawPanelData();
		Redraw4VaSmallPanelData();
		if(EdittingDescp){
			CnInput.FullRedraw();
		}else{
			Check4SelectedHtVa();
		}
	}else{
		for(int i=2; i<3; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
		ReDrawCommonInf();
		DrawFixTextVa();
		IList->Edit[0].Show();
		RedrawVaIs4Linkage();
		DrawVaReadWriteStates();
		RedrawPanelData();
		Redraw4VaSmallPanelData();
		if(EdittingDescp){
			CnInput.FullRedraw();
		}else{
			Check4SelectedHtVa();
		}
		if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
	}
}

void TDevProperty::DrawVaReadWriteStates()
{
	char *tText;
	if(IsHotKeyCheckingPermission)return;
	if(VaReadWriteSta ==0 ){
		TextRender_string24(Lv.Grid.Left[3] + 190, Lv.Grid.Top[2] + 6, clNearWhite, 	ItemColor, 	"        ");
		tText="        ";
	}else
	if(VaReadWriteSta == 1){
		//TextRender_string24(Lv.Grid.Left[3] + 190, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, 	"读取成功");
		if(LanguageEnCn==0)tText="读取成功"; else tText="Read OK ";
	}else 
	if(VaReadWriteSta == 2){
		//TextRender_string24(Lv.Grid.Left[3] + 190, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, 	"读取失败");
		if(LanguageEnCn==0)tText="读取失败"; else tText="Read Err";
	}else
	if(VaReadWriteSta == 3){
		//TextRender_string24(Lv.Grid.Left[3] + 190, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, 	"保存成功");
		if(LanguageEnCn==0)tText="保存成功"; else tText="Save OK ";
	}else
	if(VaReadWriteSta == 4){
		//TextRender_string24(Lv.Grid.Left[3] + 190, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, 	"保存失败");
		if(LanguageEnCn==0)tText="保存失败"; else tText="Save Err";
	}else
	if(VaReadWriteSta == 5){
		//TextRender_string24(Lv.Grid.Left[3] + 190, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, 	"获取中  ");
		if(LanguageEnCn==0)tText="获取中  "; else tText="Reading ";
	}else
	if(VaReadWriteSta == 6){
		//TextRender_string24(Lv.Grid.Left[3] + 190, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, 	"写入中  ");
		if(LanguageEnCn==0)tText="写入中  "; else tText="Writing ";
	}
	TextRender_string24(Lv.Grid.Left[3] + 190, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, tText);
}

void TDevProperty::DrawVaReadWriteStates(unsigned char aNewState)
{
	VaReadWriteSta = aNewState;
	DrawVaReadWriteStates();
}

void TDevProperty::InitHtVa()
{
	PanelIsUsingText = 1;
	
	for(int i=2; i<3; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	RectFillRender(Lv.Grid.Left[3], ModuleRectLv3.Top, Lv.Grid.Right[3], ModuleRectLv3.Bottom, ItemColor);
	RectFillRender(Lv.Grid.Left[4], ModuleRectLv4.Top, Lv.Grid.Right[4], ModuleRectLv4.Bottom, ItemColor);
	
	DrawFixTextVa();
	IList->Edit[0].Init(Lv.Grid.Left[3] +10, ModuleRectLv3.Top + 72, 100,30,0,0,1,clNearBlack);
	IList->Edit[0].Str.Clear();
	IList->Edit[0].Show();
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
	
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
	
	SendVaSettingRead();
	
	RedrawVaIs4Linkage();
	RedrawVaSetting();
}

void TDevProperty::EditDescpReturnHtVa()
{
	PanelIsUsingText = 1;
	
	for(int i=2; i<3; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	RectFillRender(Lv.Grid.Left[3], ModuleRectLv3.Top, Lv.Grid.Right[3], ModuleRectLv3.Bottom, ItemColor);
	
	DrawFixTextVa();
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
	
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
	
	RedrawVaIs4Linkage();
	RedrawVaSetting();
	
	ReDrawPanel();
	DrawVaReadWriteStates();
}

void TDevProperty::Redraw4VaNewLoad()
{
	IList->Edit[0].Show();
	SendVaSettingRead();
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
}

void TDevProperty::Redraw4VaSmallPanelData()
{
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);

	TMyString::sClear(TextDraw);
	TMyString::sFrom2Dg(RuntimeData.voltage % 100, TextDraw);
	TMyString::sAddOnChar('.', TextDraw);
	TMyString::sAddOn1Dg(0, TextDraw);
	TMyString::sAddOnChar('V', TextDraw);
	TextRender_string24(Lv.PanelSmall.Left + 32, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
	
	DrawMac();
}

void TDevProperty::SendVaSettingRead()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aPx;
	
	VaRt.IsWait4ReadVaSetting = 1;
	VaRt.IsWait4WriteVaSetting = 0;
	VaRt.RecRdy = 0;
	VaRt.RecCmd = 0;
	VaRt.WaitTick = 0;
	DrawVaReadWriteStates(5);
	
	ProcessingRt.DevType = 0;	//点型烟感
	ProcessingRt.DataType = 1;	//烟感灵敏度
	
	Len =4;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	CommData[0] = 3;
	CommData[1] = MainCtl.fData.Split.MyNum;
	
	CommData[2] = Path0;
	ProcessingRt.P0 = Path0;
	
	CommData[3] = Path1;
	ProcessingRt.P1 = Path1;

	aIde.BitF.Cmd = cmQueryStaticData;
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	InnerCan.Buf4GuiSend.Insert(aIde, CommData, Len);
}

void TDevProperty::SendVaSettingWrite()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aPx;
	
	VaRt.IsWait4ReadVaSetting = 0;
	VaRt.IsWait4WriteVaSetting = 1;
	VaRt.RecRdy = 0;
	VaRt.RecCmd = 0;
	VaRt.WaitTick = 0;
	DrawVaReadWriteStates(6);
	
	ProcessingRt.DevType = 0;	//点型烟感
	ProcessingRt.DataType = 1;	//烟感灵敏度
	
	Len =7;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	CommData[0] = 0;
	CommData[1] = Path0;
	ProcessingRt.P0 = Path0;
	
	//Start Addr  End Addr
	CommData[2] = Path1;
	ProcessingRt.P1 = Path1;
	CommData[3] = 0x07;	//0x07:声光类别
	
	//Set Linkage 
	//CommData[4] = Data.VaIs4Linkage;
	//ExData.VaIs4Linkage = Data.VaIs4Linkage;
	
	//Set Tone
	CommData[4] = Data.VaSoundType;
	ExData.VaSoundType = Data.VaSoundType;
	
	//Set Sound And Visible
	CommData[5] = Data.VaVisionType;
	ExData.VaVisionType = Data.VaVisionType;
	
				Data.VaIs4Linkage =1;
	CommData[6] = Data.VaIs4Linkage;
	ExData.VaIs4Linkage = Data.VaIs4Linkage;
	
	aIde.BitF.Cmd = cmDeviceSetSens;
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	InnerCan.Buf4GuiSend.Insert(aIde, CommData, Len);
}

void TDevProperty::ClearSelectedHtVa()
{
	char *tText;
	switch(Tag.Inx){
		case 0:
			
			break;
		case 1:
			IList->EditPortNum.Selected = 0;
			IList->EditPortNum.Show();
			break;
		case 2:
			IList->EditAddrNum.Selected = 0;
			IList->EditAddrNum.Show();
			break;
		case 3:
			IList->EditDescpShow.Selected = 0;
			IList->EditDescpShow.Show();
			break;
		case 4:
			IList->EditUserCode.Selected = 0;
			IList->EditUserCode.Show();
			break;
		case 5:
			IList->EditAreaAssign.Selected = 0;
			IList->EditAreaAssign.Show();
			break;
		case 6:
			TRoundSquare::sSelected(Lv.Grid.Left[2] +12, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 7:
			if(LanguageEnCn==0)tText ="保存"; else tText="Save"; 
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 36, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		case 8:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 9:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 10:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 11:
			IList->Edit[0].Selected = 0;
			IList->Edit[0].Show();
			break;
		case 12:
			if(LanguageEnCn==0)tText ="读取"; else tText="Read";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +120, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		case 13:
			if(LanguageEnCn==0)tText ="保存"; else tText="Save";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +210, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		case 14:
			unsigned int aClr;
			if(RunState == TRunModeCfg::RunModeAdjust)aClr = clNearBlack;else	aClr = clSilver;
			if(LanguageEnCn==0)tText ="模拟启动"; else tText=" Sim Act";
			TRoundRect::sDrawBySize(Lv.Grid.Left[4] +180, ModuleRectLv4.Top + 6, 104, 30, 7, clNearWhite, tText, 4, aClr);
			break;
	}
}
void TDevProperty::Check4SelectedHtVa()
{
	char *tText;
	switch(Tag.Inx){
		case 0:
			
			break;
		case 1:
			IList->EditPortNum.Selected = 1;
			IList->EditPortNum.SetPstTail();
			IList->EditPortNum.Show();
			IList->EditPortNum.ShowCursor();
			break;
		case 2:
			IList->EditAddrNum.Selected = 1;
			IList->EditAddrNum.SetPstTail();
			IList->EditAddrNum.Show();
			IList->EditAddrNum.ShowCursor();
			break;
		case 3:
			IList->EditDescpShow.Selected = 1;
			IList->EditDescpShow.Show();
			break;
		case 4:
			IList->EditUserCode.Selected = 1;
			IList->EditUserCode.SetPstTail();
			IList->EditUserCode.Show();
			IList->EditUserCode.ShowCursor();
			break;
		case 5:
			IList->EditAreaAssign.Selected = 1;
			IList->EditAreaAssign.SetPstTail();
			IList->EditAreaAssign.Show();
			IList->EditAreaAssign.ShowCursor();
			break;
		case 6:
			TRoundSquare::sSelected(Lv.Grid.Left[2] +12, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 7:
			if(LanguageEnCn==0)tText ="保存"; else tText="Save"; 
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 36, 76, 30, 7, clDeepBlue, tText, 14, clNearWhite);
			break;
		case 8:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 9:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 10:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 11:
			IList->Edit[0].Selected = 1;
			IList->Edit[0].Show();
			break;
		case 12:
			if(LanguageEnCn==0)tText ="读取"; else tText="Read";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +120, ModuleRectLv3.Top + 72, 76, 30, 7, clDeepBlue, tText, 14, clNearWhite);
			break;
		case 13:
			if(LanguageEnCn==0)tText ="保存"; else tText="Save";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +210, ModuleRectLv3.Top + 72, 76, 30, 7, clDeepBlue, tText, 14, clNearWhite);
			break;
		case 14:
			unsigned int aClr;
			if(RunState == TRunModeCfg::RunModeAdjust)aClr = clNearWhite;else	aClr = clSilver;
			if(LanguageEnCn==0)tText ="模拟启动"; else tText=" Sim Act";
			TRoundRect::sDrawBySize(Lv.Grid.Left[4] +180, ModuleRectLv4.Top + 6, 104, 30, 7, clDeepBlue, tText, 4, aClr);
			break;
	}	
}

void TDevProperty::RedrawVaIs4Linkage()
{
	if(Data.VaIs4Linkage){
		TRoundSquare::sDrawBySize(Lv.Grid.Left[2] + 12, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
	}else{
		TRoundSquare::sDrawBySize(Lv.Grid.Left[2] + 12, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}
}

void TDevProperty::RedrawVaSetting()
{
	char *tText;
	if(Data.VaVisionType == 0){
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}else
	if(Data.VaVisionType == 1){
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);		
	}else
	if(Data.VaVisionType == 2){
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
	}else{
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}
	
	if(Data.VaSoundType == 0){
		if(LanguageEnCn==0)tText="未知  "; else tText="Unknown";
	}else
	if(Data.VaSoundType == 1){
		if(LanguageEnCn==0)tText="119   "; else tText="Std";
	}else
	if(Data.VaSoundType == 2){
		if(LanguageEnCn==0)tText="滴滴  "; else tText="Beep ";
	}else
	if(Data.VaSoundType == 3){
		if(LanguageEnCn==0)tText="警报声"; else tText="ALERTS";
	}
	
	if(LanguageEnCn==0)tText="音调 0"; else tText="Tone 0";
	IList->Edit[0].SetText(tText ,24);
	
	IList->Edit[0].Show();
}

void TDevProperty::PushVaCanData(unsigned char aCmd, unsigned char *pData)
{
	int i;
	if(aCmd == cmDeviceSetSens){
		for(i=0; i<8; i++)RecData[i] = pData[i];
		if(   (ProcessingRt.P0 == RecData[1]) &&
			(ProcessingRt.P1 == RecData[2]) &&
			(		0x07 == RecData[3]) &&
			(ExData.VaSoundType == RecData[4]) && 
			(ExData.VaVisionType == RecData[5]) &&
			(ExData.VaIs4Linkage == RecData[6]) ) {
				VaRt.RecRdy =1;
				VaRt.RecCmd =aCmd;
		}
	}else
	if(aCmd == cmQueryStaticData){
		for(i=0; i<8; i++)RecData[i] = pData[i];
		if(   (ProcessingRt.P0 == RecData[1]) &&
			(ProcessingRt.P1 == RecData[2]) &&
			( 		0    == RecData[3]) ){
				Data.VaSoundType = RecData[4];
				Data.VaVisionType = RecData[5];
				Data.VaIs4Linkage = RecData[6];
				VaRt.RecRdy =1;
				VaRt.RecCmd =aCmd;
		}
	}
}

TGuiMsgReturn TDevProperty::KeyInHtVa(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	int HasPrc = 0;
	switch(aKey){
		case VK_0:
		case VK_1:
		case VK_2:
		case VK_3:
		case VK_4:
		case VK_5:
		case VK_6:
		case VK_7:
		case VK_8:
		case VK_9:
		case VK_DELETE:
		case VK_LEFT:
		case VK_RIGHT: 
			if(Tag.Inx < 6){
				KeyInCommonEdit(aKey);
			}else{
				if(Tag.Inx == 6){
					//Change Is4Linkage Type
					if(aKey == VK_RIGHT){
						ClearSelectedHtVa();
						Tag.Inx = 7;
						Check4SelectedHtVa();
					}
				}else
				if(Tag.Inx == 7){
					//Save Define Type
					if(aKey == VK_LEFT){
						ClearSelectedHtVa();
						Tag.Inx = 6;
						Check4SelectedHtVa();
					}
				}else
				if(Tag.Inx == 8){
					//Set As Feed Back
					if(aKey == VK_RIGHT){
						ClearSelectedHtVa();
						Tag.Inx = 9;
						Check4SelectedHtVa();
					}
				}else
				if(Tag.Inx == 9){
					//Set As Alram
					if(aKey == VK_LEFT){
						ClearSelectedHtVa();
						Tag.Inx = 8;
						Check4SelectedHtVa();
					}else
					if(aKey == VK_RIGHT){
						ClearSelectedHtVa();
						Tag.Inx = 10;
						Check4SelectedHtVa();
					}
				}else
				if(Tag.Inx == 10){
					//Set As Sv
					if(aKey == VK_LEFT){
						ClearSelectedHtVa();
						Tag.Inx = 9;
						Check4SelectedHtVa();
					}
				}
				if(Tag.Inx == 11){
					//Set Output type
					if(aKey == VK_RIGHT){
						ClearSelectedHtVa();
						Tag.Inx = 12;
						Check4SelectedHtVa();
					}
				}else
				if(Tag.Inx == 12){
					//Read Input Type
					if(aKey == VK_LEFT){
						ClearSelectedHtVa();
						Tag.Inx = 11;
						Check4SelectedHtVa();
					}else
					if(aKey == VK_RIGHT){
						ClearSelectedHtVa();
						Tag.Inx = 13;
						Check4SelectedHtVa();
					}
				}else
				if(Tag.Inx == 13){
					//Save Input Type
					if(aKey == VK_LEFT){
						ClearSelectedHtVa();
						Tag.Inx = 12;
						Check4SelectedHtVa();
					}
				}else
				if(Tag.Inx == 14){
					////Sim Start
					if(aKey == VK_RIGHT){
						ClearSelectedHtVa();
						Tag.Inx = 15;
						Check4SelectedHtVa();
					}
				}
			}
			break;
		case VK_UP:
			if(PortNumValid && AddrNumValid){
				ClearSelectedHtVa();
				Tag.Inx > Tag.InxMin ? Tag.Inx-- : Tag.Inx = 16;
				Check4SelectedHtVa();
			}
			break;
		case VK_DOWN:
			if(PortNumValid && AddrNumValid){
				ClearSelectedHtVa();
				Tag.Inx < 16 ? Tag.Inx++ : Tag.Inx = Tag.InxMin;
				Check4SelectedHtVa();
			}
			break;
		case VK_TAB:
			//PanelIsUsingText = PanelIsUsingText ? 0 : 1;
			break;
		case dfKEY_SETUP:
			if(Tag.Inx == 6){
				Data.VaIs4Linkage = Data.VaIs4Linkage ? 0 :1;
				Data.VaIs4Linkage =1;
				RedrawVaIs4Linkage();
			}else
			if(Tag.Inx == 8){
				Data.VaVisionType = 0;
				RedrawVaSetting();
			}else
			if(Tag.Inx == 9){
				Data.VaVisionType = 1;
				RedrawVaSetting();
			}else
			if(Tag.Inx == 10){
				Data.VaVisionType = 2;
				RedrawVaSetting();
			}else
			if(Tag.Inx == 11){
				Data.VaSoundType++;
				if(Data.VaSoundType>3)Data.VaSoundType = 1;
				
				Data.VaSoundType = 0;
				RedrawVaSetting();
			}
			break;
		case dfKEY_QUERY:
			PanelDrawData.DesertTextHex = PanelDrawData.DesertTextHex ? 0: 1;
			break;
		case dfKEY_ENCN:
			SendReqMac();
			break;
		case VK_EXECUTE:
			if(PortNumValid && AddrNumValid){
				if(Tag.Inx <6){
					KeyInCommonEnter(aKey);
				}else{
					if(Tag.Inx == 6){
						//Change Linkage Type
						Data.VaIs4Linkage = Data.VaIs4Linkage ? 0 :1;
						Data.VaIs4Linkage =1;
						RedrawVaIs4Linkage();
					}else
					if(Tag.Inx == 7){
						//Write Va Setting
						PermissionCmd = pcWriteVaSetting;
						if(SystemPermission >2){
							SendVaSettingWrite();
						}else{
							IsPermission = 1;
							PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
						}
					}else
					if(Tag.Inx == 8){
						Data.VaVisionType = 0;
						RedrawVaSetting();
					}else
					if(Tag.Inx == 9){
						Data.VaVisionType = 1;
						RedrawVaSetting();
					}else
					if(Tag.Inx == 10){
						Data.VaVisionType = 2;
						RedrawVaSetting();
					}else
					if(Tag.Inx == 11){
						Data.VaSoundType++;
						if(Data.VaSoundType>3)Data.VaSoundType = 1;
						Data.VaSoundType = 0;
						RedrawVaSetting();
					}else
					if(Tag.Inx == 12){
						//Read Va Setting
						SendVaSettingRead();
					}else
					if(Tag.Inx == 13){
						//Write Va Setting
						PermissionCmd = pcWriteVaSetting;
						const unsigned char NeedPmsLevel = 2;
						if(SystemPermission >2){
							SendVaSettingWrite();
						}else{
							IsPermission = 1;
							PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
						}
					}else
					if(Tag.Inx == 14){
						//Sim Start
						if(RunState == TRunModeCfg::RunModeAdjust){
							PermissionCmd = pcSimStart; //pcSimAlram,pcSimStart,pcSimInputActive,
							if(SystemPermission >1){
								PermissionCmdGO();
							}else{
								IsPermission = 1;
								PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 2);
							}
						}
					}
				}
			}
			break;
		case VK_RETURN:
			IsShow = 0;
			RealTimeSendCmdAbort();
			aMsg = guiMsgReturn;
			break;
	}
	
	
	return aMsg;
	
}

void TDevProperty::Task1000MsVa()
{
	if(VaRt.IsWait4ReadVaSetting){
		if(VaRt.RecRdy){
			if(VaRt.RecCmd == cmQueryStaticData){
				VaRt.RecRdy = 0;
				VaRt.IsWait4ReadVaSetting = 0;
				//Add Record Here
				if(ProcessingRt.DataType == 1){
					if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
						DrawVaReadWriteStates(1);
						RedrawVaIs4Linkage();
						RedrawVaSetting();
					}else{
						VaReadWriteSta =1;
					}						
				}
			}
			VaRt.RecRdy = 0;
		}
		VaRt.WaitTick ++;
		if(VaRt.WaitTick > 6){
			VaRt.IsWait4ReadVaSetting = 0;
			if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
				DrawVaReadWriteStates(2);
			}else{
				VaReadWriteSta =2;
			}
		}
	}else
	if(VaRt.IsWait4WriteVaSetting){
		if(VaRt.RecRdy){
			if(VaRt.RecCmd == cmDeviceSetSens){
				VaRt.IsWait4WriteVaSetting = 0;
				//Add Record Here
				Data.VaIs4Linkage = ExData.VaIs4Linkage;
				Data.VaIs4Linkage =1;
				Data.VaSoundType = ExData.VaSoundType;
				Data.VaVisionType = ExData.VaVisionType;
				//Record.OperateAdd_CfgAddrSmokeSensGrade(aFullPath.D32, Data.Modu);
				if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
					DrawVaReadWriteStates(3);
				}else{
					VaReadWriteSta =3;
				}
			}
			VaRt.RecRdy = 0;
		}
		VaRt.WaitTick ++;
		if(VaRt.WaitTick > 6){
			VaRt.IsWait4WriteVaSetting = 0;
			if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
				DrawVaReadWriteStates(4);
			}else{VaReadWriteSta =4;
			}
		}
	}
	Redraw4VaSmallPanelData();
}





