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

extern "C"{
	#include "user_norflash.h"
	#include "user_eeprom.h"
	#include "uart_key_drv.h"
	#include "task.h"
	#include "HW_config.h"
}

#define cmDeviceRuntimeDataStart	207
#define cmDeviceRuntimeDataStop	208

static const char CharBcdText[20]= {"0123456789*------\0"};
static const unsigned char stHexNum[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

//For Query Device Function to PopUp Show One Device Property   Key:Value      Edit or View

//Root Device
//static const char cAvtive[12]	= {"已挂载数量"};
//static const char cCarry[12] 	= {"登记数量"};
//static const char cVoltage[12] = {"电压V"};
//static const char cCurrent[8] = {"电流A"};
//static const char cTempe[8] 	= {"摄氏度"};
//static const char cVer[8]		= {"版本V"};

//static const char cFBV[16]		= {"回码电压"};
//static const char cFBC[16]		= {"回码电流"};
	
//static const char cFBCZero[12]	= {"静态电流mA"};
//static const char cFBCFull[12]	= {"动态电流mA"};
//static const char cFBVZero[12]	= {"静态电压V"};
//static const char cFBVOL[12]		= {"动态电压V"};

//static const char cConnectCount[12] = "已连接数量";
//static const char cK[4] 	= "K";
//static const char cCAN[8] 	= "CAN";
//static const char cRS485[8] 	= "RS485";
//static const char cEth[8] 	= "以太网";
//static const char cSpeed[12]	= "速度 KHz";
//static const char cEth100M[12] = "100M 以太网";
//static const char cEth1G[12]   = "1G 以太网";
//static const char cCommType[12] = "通讯类型";


char TDevProperty::Text4CmpInc[16] = "芃\0\0" ;

class TItemList *TDevProperty::sIList;

void TDevProperty::DrawCommonInfTitleFixText()
{
	if(LanguageEnCn == 0){
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +6, clNearWhite, "回路号");
		TextRender_string24(Lv.Grid.Left[0] + 160, Lv.Grid.Top[0] +6, clNearWhite, "机器号");
		
		TextDigitRender2Right24(Lv.Grid.Left[0] + 232, Lv.Grid.Top[0] +6, clNearWhite, CtlNum);
		TextRender_string24(Lv.Grid.Left[0] + 254, Lv.Grid.Top[0] +6, clNearWhite, "本机");
		
		TextRender_string24(Lv.Grid.Left[0] + 340, Lv.Grid.Top[0] +6, clNearWhite, "类型:");
		TextRender_string24(Lv.Grid.Left[0] + 640, Lv.Grid.Top[0] +6, clNearWhite, "状态:");
		
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] + 40, clNearWhite, "地址号");
		TextRender_string24(Lv.Grid.Left[0] + 280, Lv.Grid.Top[0] + 40, clNearWhite, "注释信息:");
		
		//User Code & Area Assign
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "二次码");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +40, clNearWhite, "分区号");
	}else
	if(LanguageEnCn == 1){
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +6, clNearWhite, "LoopID");
		TextRender_string24(Lv.Grid.Left[0] + 160, Lv.Grid.Top[0] +6, clNearWhite, "HostID");

		TextDigitRender2Right24(Lv.Grid.Left[0] + 232, Lv.Grid.Top[0] +6, clNearWhite, CtlNum);
		TextRender_string24(Lv.Grid.Left[0] + 254, Lv.Grid.Top[0] +6, clNearWhite, " Local");

		TextRender_string24(Lv.Grid.Left[0] + 340, Lv.Grid.Top[0] +6, clNearWhite, "Type:");
		TextRender_string24(Lv.Grid.Left[0] + 640, Lv.Grid.Top[0] +6, clNearWhite, "State");
		
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] + 40, clNearWhite, "Addr");
		TextRender_string24(Lv.Grid.Left[0] + 320, Lv.Grid.Top[0] + 40, clNearWhite, "Note:");
		
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "AuxID");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +40, clNearWhite, "Zone");
	}	
}

void TDevProperty::Init(THwDevType aDevType, int aMode)
{
	HwDevType = aDevType;
	IsPermission = 0;
	PanelIsUsingText = 1;
	Tag.Reset();
	EdittingDescp = 0;
	IsExtInput = 1;
	SetEnterMethod(aMode);
	RuntimeData.Reset();
	PanelDrawData.Reset();
	PanelDrawData.TextDrawLine = 0;
	
	SmokerReadWriteSta =0;
	TempeReadSta = 0;
	VaReadWriteSta =0;
	DisplayPadReadWriteSta =0;
	DisplayPadDownloadDescpSta =0;
	
	
	for(int i=0; i<16; i++)DebugBytes[i] = Text4CmpInc[i];
}

void TDevProperty::FullRedraw(int Prm)
{
	if(Prm == 0){
		RenderBackGround();
		for(int i=0; i<2; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);		
	}else
	if(Prm == 1){
		RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], ContentColor);
		for(int i=0; i<2; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	}
	RedrawCommonInfTitle();
	switch(HwDevType){
		case htNoType:
			FullRedrawNoType(Prm);
			break;
		case htSmoker:
			FullRedrawhtSmoker(Prm);
			break;
		case htTempe:
			FullRedrawhtTempe(Prm);
			break;
		case htHandPad:
			FullRedrawhtHandPad(Prm);
			break;
		case htHydrantPad:
			FullRedrawhtHydrantPad(Prm);
			break;
		case htModuleIn:
			FullRedrawhtModuleIn(Prm);
			break;
		case htModuleInOut:
			FullRedrawhtModuleInOut(Prm);
			break;
		case htModuleOut:
			FullRedrawhtModuleOut(Prm);		
			break;
		case htVa:		
			FullRedrawhtVa(Prm);
			break;
		case htDisplayPad:
			FullRedrawhtDisplayPad(Prm);
			break;
		case htLinkagePowerSuply:
			FullRedrawhtLinkagePowerSuply(Prm);
			break;
		default :
			break;
	}
}

void TDevProperty::DrawStateCn(unsigned char aSta)
{
	
}

void TDevProperty::DrawStateEn(unsigned char aSta)
{
		
}

void TDevProperty::DrawState(unsigned char aSta)
{
	if(LanguageEnCn == 0){
		if(aSta & dEpStateBitFire){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clRed, 0xF);
			IList->STextState.SetText("报警", 24);
		}else 
		if(aSta & dEpStateBitStart){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clOrange, 0xF);
			IList->STextState.SetText("启动", 24);
		}else 
		if(aSta & dEpStateBitSv){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clOrange, 0xF);
			IList->STextState.SetText("启动", 24);
		}else 
		if(aSta & dEpStateBitFault){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clOrange, 0xF);
			IList->STextState.SetText("故障", 24);
		}else 
		if(aSta & dEpStateBitFeedBack){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clBlue, 0xF);
			IList->STextState.SetText("反馈", 24);
		}else 
		if(aSta & dEpStateBitMask){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clOrange, 0xF);
			IList->STextState.SetText("屏蔽", 24);
		}else{
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clDeepGreen, 0xF);
			IList->STextState.SetText("正常", 24);
		}	
	}else
	if(LanguageEnCn == 1){
		if(aSta & dEpStateBitFire){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clRed, 0xF);
			IList->STextState.SetText("Fire", 24);
		}else 
		if(aSta & dEpStateBitStart){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clOrange, 0xF);
			IList->STextState.SetText("LINK", 24);
		}else 
		if(aSta & dEpStateBitSv){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clOrange, 0xF);
			IList->STextState.SetText("SUPV", 24);
		}else 
		if(aSta & dEpStateBitFault){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clOrange, 0xF);
			IList->STextState.SetText("Fail", 24);
		}else 
		if(aSta & dEpStateBitFeedBack){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clBlue, 0xF);
			IList->STextState.SetText("FBCK", 24);
		}else 
		if(aSta & dEpStateBitMask){
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clOrange, 0xF);
			IList->STextState.SetText("Mask", 24);
		}else{
			TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, clDeepGreen, 0xF);
			IList->STextState.SetText("Idle", 24);
		}
	}
}

void TDevProperty::DrawMac()
{
	unsigned char Num, Num10;
	TMyString::sClear(TextDraw);
	TMyString::sAddOnStr("MAC:", TextDraw);
	for(int i=0; i<6; i++){
		Num = RuntimeData.Mac[i] % 16;
		Num10 = RuntimeData.Mac[i] / 16 % 16;
		TMyString::sAddOnChar(stHexNum[Num10], TextDraw);
		TMyString::sAddOnChar(stHexNum[Num], TextDraw);
		if(i&0x01)TMyString::sAddOnChar(' ', TextDraw);
	}
	TextRender_string24(Lv.PanelSmall.Left + 256, Lv.PanelSmall.Top + 36, clNearWhite, SmallPanelColor, TextDraw);
}

void TDevProperty::sDelayMs(unsigned int aMs)
{
	volatile unsigned int mTick;
	volatile unsigned int Tick;
	for(Tick=0; Tick<aMs; Tick++){
		for(mTick=0; mTick<160000; mTick++);
		sys_error_led_task();
	}
}

void TDevProperty::SetEnterMethod(int aMt)
{
	EnterMethod = aMt;
	if(EnterMethod){
		Tag.InxMin = 2;
	}else{
		Tag.InxMin = 1;
	}
	Tag.Inx = Tag.InxMin;
}

void TDevProperty::SetEditMode(unsigned int aMode)
{
	
}

void TDevProperty::RenderBackGround(void)
{
	RectFillRender(ContentGeometry.Left, ContentGeometry.Top, ContentGeometry.Right, ContentGeometry.Bottom, ContentColor);
}

void TDevProperty::RenderBackGround(unsigned int aClr)
{
	RectFillRender(ContentGeometry.Left, ContentGeometry.Top, ContentGeometry.Right, ContentGeometry.Bottom, aClr);
}

void TDevProperty::DrawSelf(void)
{
	RenderBackGround();
	RectFillRender(Lv.Caption.Left, Lv.Caption.Top, Lv.Caption.Right, Lv.Caption.Bottom, CaptionColor);
	if(LanguageEnCn == 0){
		if(EnterMethod)
			TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "回路->注册信息->单回路部件数据");
		else
			TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "回路->部件数据");
	}else{
		if(EnterMethod)
			TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "Loop->Registed Info->Single Loop Device");
		else
			TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "Loop->Device");
	}
	
	for(int i=0; i<2; 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);
}

void TDevProperty::DrawCaption(void)
{

}

void TDevProperty::InitPanel()
{
	int x,y,x2,y2, aW,aH,i;

	x = 20;
	y = 150;
	x2 = 799;
	y2 = 340;
	aW = x2 - x +1;
	aH = y2 -y +1;
	
	aPanel->Init(x,y,aW,aH,0,0,clMoneyGreen, bvRaised);
	
	aPanel->Caption.Init(1,1,aW-3,32,x,y,clNearWhite,clBlue);
	if(LanguageEnCn == 0){
		aPanel->Caption.SetText("按中/EN键切换输入法,设置键保存更改,返回键放弃更改并返回",24);
	}else
	if(LanguageEnCn == 1){
		aPanel->Caption.SetText("Key 中/EN To Switch Input Method,Key Set To Save",24);
	}
	aPanel->Caption.Enable = 1;
	aPanel->Caption.Visible = 1;

	aPanel->SText[0].Init(460,40,300,34,x,y,clNearBlack,clMoneyGreen);
	if(LanguageEnCn == 0){
		TMyString::sFromStr("请根据以下输入法提示输入", aPanel->SText[0].Text);
	}else{
		TMyString::sFromStr("Pay Attention To The Tip", aPanel->SText[0].Text);
	}
	aPanel->SText[0].Enable = 1;
	aPanel->SText[0].Visible = 1;
	
	aPanel->Edit[ 0].Init(10,40,420,30,x,y,1,clNearBlack);
	aPanel->Edit[ 0].Str.FromStr(IList->EditDescpShow.Str.Text);
	
	for(i=0; i<1;i++){
		aPanel->Edit[i].Enable = 1;
		aPanel->Edit[i].Visible = 1;
		aPanel->Edit[i].SetMaxLen(32);
		aPanel->Edit[i].SetPstTail();
		aPanel->Edit[i].Selected = 1;
	}
	
	aPanel->Show();
	aPanel->Caption.Show();
	aPanel->SText[0].Show();
	aPanel->Edit[0].Show();
	aPanel->Edit[0].ShowCursor();
	
	IsExtInput = 1;
	CnInput.Init(aPanel->Bound.Left + 10, aPanel->Bound.Top +80, 760, 90, 0, 0, clGray);
	CnInput.Show();
	if(LanguageEnCn == 0){
		TMyString::sFromStr("请根据以下输入法提示输入", aPanel->SText[0].Text);
	}else{
		TMyString::sFromStr("Pay Attention To The Tip", aPanel->SText[0].Text);
	}
	aPanel->SText[0].Show();
}

void TDevProperty::SetPath(unsigned char aCtlNum, unsigned char aPath0, unsigned char aPath1)
{
	unsigned char tP0, tP1, tT;
	this->CtlNum = aCtlNum;
	if(aPath0 && (aPath0 <= dPORT_MAX_COUNT)) PortNumValid = 1; else PortNumValid = 0;
	if(aPath1 && (aPath1 <= dEP_MAX_COUNT_PER_PORT)) AddrNumValid = 1; else AddrNumValid = 0;
	this->Path0 = aPath0;
	this->Path1 = aPath1;
	
	tP0 = aPath0-1;
	tP1 = aPath1-1;
	if(Port[tP0].ExistTable[tP1] == 0xA5){
		dType = Port[tP0].dTypeTable[tP1];
	}else{
		dType = 0;
	}
}

void TDevProperty::Init4DType()
{
	Data.Reset();
	IList->TextOutClear();
	RectFillRender(Lv.Grid.Left[0], Lv.Grid.Top[3], Lv.Grid.Right[3], Lv.Grid.Bottom[4], ContentColor);
	if(dType == dgTYPE_SMOKE_DETECTOR){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htSmoker;
		InitHtSmoker();
		ResetTargetData();
		RealTimeSendCmd(1);
		SendReqMac();
		CurveInit(Lv.Panel.Left+8, Lv.Panel.Top+8, Lv.Panel.Width-16, Lv.Panel.Heigh-16, 3);
		CurveSetMargin(60, 2, 60, 2);
		CurveSetGrid(6, 6, 50, 50);
		CurveSetColor(clRed, clBlue, clPurple, clDeepGreen);
		CurveSetScaling();
	}else
	if(dType == dgTYPE_TEMPE_DETECTOR){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htTempe;
		InitHtTempe();
		ResetTargetData();
		CurveInit(Lv.Panel.Left+8, Lv.Panel.Top+8, Lv.Panel.Width-16, Lv.Panel.Heigh-16, 2);
		CurveSetMargin(60, 2, 60, 2);
		CurveSetGrid(6, 6, 50, 50);
		CurveSetColor(clDeepGreen, clPurple, clDeepGreen, clDeepGreen);
		CurveSetScaling();
	}else
	if(dType == dgTYPE_HAND_REPORT){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htHandPad;
		InitHtHandPad();
		ResetTargetData();
	}else
	if(dType == dgTYPE_FIRE_HydrantKp){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htHydrantPad;
		InitHtHydrantPad();
		ResetTargetData();
	}else
	if(dType == dgTYPE_IN_MODULE){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htModuleIn;
		InitHtModuleIn();
		ResetTargetData();
	}else
	if(dType == dgTYPE_OUT_MODULE){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htModuleOut;
		InitHtModuleOut();
		ResetTargetData();
	}else
	if(dType == dgTYPE_INOUT_MODULE_NonSource){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htModuleInOut;
		InitHtModuleInOut();
		ResetTargetData();
	}else
	if(dType == dgType_VAALRAM){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htVa;
		InitHtVa();
		ResetTargetData();
	}else
	if(dType == dgTYPE_DISPLAY_PAD){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htDisplayPad;
		InitHtDisplayPad();
		ResetTargetData();
	}else
	if(dType == dgTYPE_LINKAGE_POWERSUPLY){
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htLinkagePowerSuply;
		InitHtLinkagePowerSuply();
		ResetTargetData();
	}else{
		PanelDrawData.TextDrawLine = 0;
		HwDevType = htNoType;
		ResetTargetData();
		InitNoType();
	}		
}

void TDevProperty::UpdataOnlineData()
{
	if(dType == dgTYPE_SMOKE_DETECTOR){
		SmokerRt.IsWait4ReadSens = 1;
		SmokerRt.IsWait4WriteSens = 0;
		SmokerRt.RecRdy = 0;
		SmokerRt.RecCmd = 0;
		SmokerRt.WaitTick = 0;
		SendSmokeCmdRead();
		if(EdittingDescp == 0){
			if(LanguageEnCn == 0){
				TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "获取中  ");
			}else{
				TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "Reading ");
			}
		}
	}else
	if(dType == dgTYPE_TEMPE_DETECTOR){
		TempeRt.IsWait4ReadSensType = 1;
		TempeRt.RecRdy = 0;
		TempeRt.RecCmd = 0;
		TempeRt.WaitTick = 0;
		SendTempeCmdRead();
		if(EdittingDescp == 0){
			if(LanguageEnCn == 0){
				TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "获取中  ");
			}else{
				TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "Reading ");
			}
		}
	}else
	if(dType == dgTYPE_HAND_REPORT){

	}else
	if(dType == dgTYPE_FIRE_HydrantKp){

	}else
	if(dType == dgTYPE_IN_MODULE){

	}else
	if(dType == dgTYPE_OUT_MODULE){

	}else
	if(dType == dgTYPE_INOUT_MODULE_NonSource){

	}else
	if(dType == dgType_VAALRAM){

	}else
	if(dType == dgTYPE_DISPLAY_PAD){

	}else
	if(dType == dgTYPE_LINKAGE_POWERSUPLY){

	}	
}

void TDevProperty::RenewCommonInf()
{
	unsigned char tP0, tP1, Found, tType, tSta;
	unsigned int tAddr;
	//Draw Port Num
	IList->EditPortNum.Str.FromUInt2Dg(Path0);
	IList->EditPortNum.SetPstTail();
	IList->EditPortNum.Show();
	if(IList->EditPortNum.Selected)IList->EditPortNum.ShowCursor();
	
	//Draw Addr Num
	IList->EditAddrNum.Str.FromUInt3Dg(Path1);
	IList->EditAddrNum.SetPstTail();
	IList->EditAddrNum.Show();
	if(IList->EditAddrNum.Selected)IList->EditAddrNum.ShowCursor();
	
	Found = 0;
	if(CtlNum == MainCtl.fData.Split.MyNum){
		//Draw If Registed
		if( (Path0) && (Path0 <= dPORT_MAX_COUNT) ){
			if( (Path1) && (Path1 <= dEP_MAX_COUNT_PER_PORT) ){
				tP0 = Path0-1;
				tP1 = Path1-1;
				if(Port[tP0].ExistTable[tP1] == 0xA5){
					Found = 1;
					tType = Port[tP0].dTypeTable[tP1];
					dType = tType;
					tSta = Port[tP0].StateTable[tP1];
				}
			}
		}
		if(Found){
			if(LanguageEnCn==0)IList->STextDType.SetText(StrTypeShortName[tType],24);
			else IList->STextDType.SetText(StrTypeShortNameEn[tType],24);
			DrawState(tSta);
			if(LanguageEnCn == 0){
				IList->STextRegisted.SetText("已注册", 24);
			}else{
				IList->STextRegisted.SetText("Reg", 24);
			}
			IsRegisted = 1;
		}else{
			IList->STextDType.SetText("---------", 24);
			IList->STextState.SetText("----", 24);
			if(LanguageEnCn == 0){
				IList->STextRegisted.SetText("未注册", 24);
			}else{
				IList->STextRegisted.SetText("Not Reg", 24);
			}
			IsRegisted = 0;
		}
		tAddr = dAddrSdRam_Descp + (tP0 * 256 * 32) + (tP1 * 32);
		for(int g=0; g<32; g++){
			IList->EditDescpShow.Str.Text[g] = *(volatile unsigned char *)(tAddr + g);
			if(  (IList->EditDescpShow.Str.Text[g] == '\0') || (IList->EditDescpShow.Str.Text[g] == 0) ){
				break;
			}
		}
		IList->EditDescpShow.Str.Text[32] = '\0';
		IList->EditDescpShow.Str.Text[33] = '\0';
		
		IList->EditUserCode.Str.FromUInt8Dg(Port[tP0].UcList[tP1].Full);
		IList->EditAreaAssign.Str.FromUInt4Dg(Port[tP0].Area[tP1]);
		
		IList->STextDType.Show();
		IList->STextState.Show();
		IList->STextRegisted.Show();
		IList->EditDescpShow.Show();
		
		IList->EditUserCode.Show();
		IList->EditAreaAssign.Show();
		
		Check4Selected();
	}else{
		
	}
}

void TDevProperty::ReDrawCommonInf()
{
	unsigned char tP0, tP1, Found, tType, tSta;
	unsigned int tAddr;
	//Draw Port Num

	Found = 0;
	if(CtlNum == MainCtl.fData.Split.MyNum){
		//Draw If Registed
		if( (Path0) && (Path0 <= dPORT_MAX_COUNT) ){
			if( (Path1) && (Path1 <= dEP_MAX_COUNT_PER_PORT) ){
				tP0 = Path0-1;
				tP1 = Path1-1;
				if(Port[tP0].ExistTable[tP1] == 0xA5){
					Found = 1;
					tType = Port[tP0].dTypeTable[tP1];
					tSta = Port[tP0].StateTable[tP1];
				}
			}
		}
		if(Found){
			if(LanguageEnCn==0)IList->STextDType.SetText(StrTypeShortName[tType],24);
			else IList->STextDType.SetText(StrTypeShortNameEn[tType],24);
			DrawState(tSta);
			if(LanguageEnCn == 0){
				IList->STextRegisted.SetText("已注册", 24);
			}else{
				IList->STextRegisted.SetText("Reg", 24);
			}
			IsRegisted = 1;
		}else{
			IList->STextDType.SetText("---------", 24);
			IList->STextState.SetText("----", 24);
			if(LanguageEnCn == 0){
				IList->STextRegisted.SetText("未注册", 24);
			}else{
				IList->STextRegisted.SetText("Not Reg", 24);
			}
			IsRegisted = 0;
		}
		tAddr = dAddrSdRam_Descp + (tP0 * 256 * 32) + (tP1 * 32);
		for(int g=0; g<32; g++){
			IList->EditDescpShow.Str.Text[g] = *(volatile unsigned char *)(tAddr + g);
			if(  (IList->EditDescpShow.Str.Text[g] == '\0') || (IList->EditDescpShow.Str.Text[g] == 0) ){
				break;
			}
		}
		IList->EditDescpShow.Str.Text[32] = '\0';
		IList->EditDescpShow.Str.Text[33] = '\0';
		
		IList->EditUserCode.Str.FromUInt8Dg(Port[tP0].UcList[tP1].Full);
		IList->EditAreaAssign.Str.FromUInt4Dg(Port[tP0].Area[tP1]);
		
		IList->STextDType.Show();
		IList->STextState.Show();
		IList->STextRegisted.Show();
		IList->EditDescpShow.Show();
		
		IList->EditUserCode.Show();
		IList->EditAreaAssign.Show();
	}else{
		
	}
}

void TDevProperty::ClearCommonInf()
{
	IList->STextDType.SetText("------",24);
	IList->STextState.SetText("----", 24);
	IList->STextRegisted.SetText("------", 24);
	IList->EditDescpShow.Str.Text[0] = '\0';
	IList->EditDescpShow.Str.Text[1] = '\0';
	IList->EditUserCode.Str.FromStr("--------");
	IList->EditAreaAssign.Str.FromStr("----");
		
	IList->STextDType.Show();
	TCircle::sRender(IList->STextState.Bound.Left -12, IList->STextState.Bound.Top +14, 10, ItemColor, 0xF);
	IList->STextState.Show();
	IList->STextRegisted.Show();
	IList->EditDescpShow.Show();
	IList->EditUserCode.Show();
	IList->EditAreaAssign.Show();

}

void TDevProperty::ReLoadAndDrawDescp()
{
	unsigned char tP0, tP1, Ava, tType, tSta;
	unsigned int tAddr;

	Ava = 0;
	if(CtlNum == MainCtl.fData.Split.MyNum){
		//Draw If Registed
		if( (Path0) && (Path0 <= dPORT_MAX_COUNT) ){
			if( (Path1) && (Path1 <= dEP_MAX_COUNT_PER_PORT) ){
				tP0 = Path0-1;
				tP1 = Path1-1;
				Ava = 1;
			}
		}
		if(Ava){
			tAddr = dAddrSdRam_Descp + (tP0 * 256 * 32) + (tP1 * 32);
			for(int g=0; g<32; g++){
				IList->EditDescpShow.Str.Text[g] = *(volatile unsigned char *)(tAddr + g);
				if(  (IList->EditDescpShow.Str.Text[g] == '\0') || (IList->EditDescpShow.Str.Text[g] == 0) ){
					break;
				}
			}
			IList->EditDescpShow.Str.Text[32] = '\0';
			IList->EditDescpShow.Str.Text[33] = '\0';
			IList->EditDescpShow.Show();
		}
	}
}


void TDevProperty::DrawCommonInfTitle()
{
	DrawCommonInfTitleFixText();
	
	IList->STextDType.Init(Lv.Grid.Left[0] + 400, Lv.Grid.Top[0] + 2, 240, 30, 0, 0, clNearWhite, ItemColor);
	IList->STextState.Init(Lv.Grid.Left[0] + 730, Lv.Grid.Top[0] + 2, 70, 30, 0, 0, clNearWhite, ItemColor);
	IList->STextRegisted.Init(Lv.Grid.Left[0] + 160, Lv.Grid.Top[0] + 36, 120, 30, 0, 0, clNearWhite, ItemColor);
	IList->STextCtlNum.Init(Lv.Grid.Left[0] + 236, Lv.Grid.Top[0] + 6, 120, 30, 0, 0, clNearWhite, ItemColor);
	
	IList->EditPortNum.Init(Lv.Grid.Left[0] + 86, Lv.Grid.Top[0] + 2, 50, 30, 0, 0, 1, clNearWhite);
	IList->EditAddrNum.Init(Lv.Grid.Left[0] + 86, Lv.Grid.Top[0] + 36, 50, 30, 0, 0, 1, clNearWhite);
	IList->EditDescpShow.Init(Lv.Grid.Left[0] + 390, Lv.Grid.Top[0] + 36, 400, 30, 0, 0, 1, clNearWhite);
	
	IList->STextDType.Enable = 1;
	IList->STextDType.Visible =1;
	IList->STextState.Enable = 1;
	IList->STextState.Visible =1;
	IList->STextRegisted.Enable = 1;
	IList->STextRegisted.Visible =1;
	IList->STextCtlNum.Enable = 1;
	IList->STextCtlNum.Visible =1;
	
	IList->EditPortNum.SetMaxLen(2);
	IList->EditAddrNum.SetMaxLen(3);
	if(EnterMethod)
		IList->EditPortNum.Enable = 0;
	else
		IList->EditPortNum.Enable = 1;
	IList->EditPortNum.Visible = 1;
	IList->EditAddrNum.Enable = 1;
	IList->EditAddrNum.Visible = 1;
	IList->EditDescpShow.Enable = 1;
	IList->EditDescpShow.Visible = 1;
	IList->EditDescpShow.IsShowCursor = 0;
	
	//User Code & Area Assign
	if(LanguageEnCn == 0){
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "二次码");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +40, clNearWhite, "分区号");
	}else{
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "AuxID");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +40, clNearWhite, "Zone");
	}
	IList->EditUserCode.Init(Lv.Grid.Left[1] + 84, Lv.Grid.Top[1] + 6, 108, 30, 0, 0, 1, clNearWhite);
	IList->EditAreaAssign.Init(Lv.Grid.Left[1] + 84, Lv.Grid.Top[1] + 40, 108, 30, 0, 0, 1, clNearWhite);
	
	IList->EditUserCode.Enable = 1;
	IList->EditUserCode.Visible =1;
	IList->EditUserCode.SetMaxLen(8);
	IList->EditAreaAssign.Enable = 1;
	IList->EditAreaAssign.Visible =1;
	IList->EditAreaAssign.SetMaxLen(4);
}

void TDevProperty::RedrawCommonInfTitle()
{
	DrawCommonInfTitleFixText();
	
	IList->EditPortNum.Show();
	IList->EditAddrNum.Show();
}

void TDevProperty::Redraw4DescpEdit()
{
	IList->EditDescpShow.Selected = 1;
	IList->EditDescpShow.SetPstTail();
	IList->EditDescpShow.Show();
	
	RectFillRender(aPanel->Bound.Left, aPanel->Bound.Top, aPanel->Bound.Right, aPanel->Bound.Bottom, ContentColor);
	if( (HwDevType == htVa ) || (HwDevType == htModuleIn) || (HwDevType == htModuleInOut) ) {
		for(int i=1; i<3; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	}else{
		for(int i=1; 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);
	if(LanguageEnCn == 0){
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "二次码");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +40, clNearWhite, "分区号");
	}else
	if(LanguageEnCn == 1){
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "AuxID");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +40, clNearWhite, "Zone");
	}
	IList->EditUserCode.Show();
	IList->EditAreaAssign.Show();
	
	switch(HwDevType){
		case htNoType:
			EditDescpReturnHtNoType();
			break;
		case htSmoker:
			EditDescpReturnHtSmoker();
			break;
		case htTempe:
			EditDescpReturnHtTempe();
			break;
		case htHandPad:
			EditDescpReturnHtHandPad();
			break;
		case htHydrantPad:
			EditDescpReturnHtHydrantPad();
			break;
		case htModuleIn:
			EditDescpReturnHtModuleIn();
			break;
		case htModuleInOut:
			EditDescpReturnHtModuleInOut();
			break;
		case htModuleOut:
			EditDescpReturnHtModuleOut();
			break;
		case htVa:
			EditDescpReturnHtVa();
			break;
		case htDisplayPad:
			EditDescpReturnHtDisplayPad();
			break;
		case htLinkagePowerSuply:
			EditDescpReturnHtLinkagePowerSuply();
			break;
		default :

			break;
	}	
}

void TDevProperty::Redraw4NewLoad()
{
	Data.Reset();
	IList->TextOutClear();
	switch(HwDevType){
		case htNoType:
			Redraw4NoTypeNewLoad();
			break;
		case htSmoker:
			Redraw4SmokerNewLoad();
			break;
		case htTempe:
			Redraw4TempeNewLoad();
			break;
		case htHandPad:
			Redraw4HandPadNewLoad();
			break;
		case htHydrantPad:
			Redraw4HydrantPadNewLoad();
			break;
		case htModuleIn:
			Redraw4ModuleInNewLoad();
			break;
		case htModuleInOut:
			Redraw4ModuleInOutNewLoad();
			break;
		case htModuleOut:
			Redraw4ModuleOutNewLoad();
			break;
		case htVa:
			Redraw4VaNewLoad();
			break;
		case htDisplayPad:
			Redraw4DisplayPadNewLoad();
			break;
		case htLinkagePowerSuply:
			Redraw4LinkagePowerSuplyNewLoad();
			break;
		default :

			break;
	}
}

TGuiMsgReturn TDevProperty::KeyIn(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	TGuiMsgReturn SubRtnMsg = guiMsgNone;
	TGuiMsgReturn PmsRtnMsg = guiMsgNone;
	if(IsPermission){
		PmsRtnMsg = PmsIntervene4Gui.KeyIn(aKey);
		if(PmsRtnMsg == guiMsgOkAndReturn){
			//Enter And Run Go
			IsPermission = 0;
			PermissionCmdReturnDraw();
			PermissionCmdGO();
		}else
		if(PmsRtnMsg == guiMsgReturn){
			//Not Enter Redraw
			IsPermission = 0;
			PermissionCmdReturnDraw();
		}
	}else
	if(EdittingDescp){
		const char *p;
		if(aKey == dfKEY_SETUP){
			//Save and return
			TMyString::sFromStr(aPanel->Edit[0].Str.Text, IList->EditDescpShow.Str.Text);
			TMyString::sBrokeFixLen(IList->EditDescpShow.Str.Text, 32);
			Redraw4DescpEdit();
			EdittingDescp = 0;
		}else
		if(IsExtInput){
			if(aKey == dfKEY_ENCN){
				CnInput.KeyIn(aKey);
				if(0){
					IsExtInput = 1;
					CnInput.OverPrint(this->aPanel->Color);
					aPanel->Show();
					aPanel->Caption.Show();
					aPanel->SText[0].Show();
					aPanel->Edit[0].Show();
					aPanel->Edit[0].ShowCursor();
					if(LanguageEnCn == 0){
						TMyString::sFromStr("当前快捷输入数字", aPanel->SText[0].Text);
					}else{
						TMyString::sFromStr("Enter The Numbers Directly", aPanel->SText[0].Text);
					}
					aPanel->SText[0].Show();
				}
			}else
			if(aKey == VK_RETURN){
				//Just return
				Redraw4DescpEdit();
				EdittingDescp = 0;
			}else{
				if(  (aKey == VK_DELETE)  &&  (CnInput.sEdit.Pst == -1) ){
					aPanel->Edit[0].KeyIn(aKey);
					aPanel->Edit[0].Show();
					aPanel->Edit[0].ShowCursor();
				}else{
					p = CnInput.KeyIn(aKey);
					if(p != nullptr){
						if(CnInput.GotChar[0] != '\0'){
							aPanel->Edit[0].Pst = aPanel->Edit[0].Str.Insert(CnInput.GotChar, aPanel->Edit[0].Pst);
							aPanel->Edit[0].Str.BrokeFixLen(32);
							aPanel->Edit[0].CorrectPst();
							aPanel->Edit[0].Show();
						}
					}
				}
			}
		}else{
			switch(aKey){
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
				case VK_LEFT:
				case VK_RIGHT:
				case VK_DELETE:
					aPanel->Edit[0].KeyIn(aKey);
					aPanel->Edit[0].Str.BrokeFixLen(32);
					aPanel->Edit[0].CorrectPst();
					aPanel->Edit[0].Show();
					break;
				case dfKEY_ENCN:
					if(IsExtInput == 0){
						IsExtInput = 1;
						CnInput.Init(aPanel->Bound.Left + 10, aPanel->Bound.Top +80, 760, 90, 0, 0, clGray);
						CnInput.Show();
						if(LanguageEnCn == 0){
							TMyString::sFromStr("当前根据输入法输入", aPanel->SText[0].Text);
						}else{
							TMyString::sFromStr("Enter The Numbers Directly", aPanel->SText[0].Text);
						}
						aPanel->SText[0].Show();
					}
					break;
				case VK_EXECUTE:

					break;
				case VK_RETURN:
					Redraw4DescpEdit();
					EdittingDescp = 0;
					break;
			}
		}
	}else{
		if( (aKey == dfKEY_SETUP) && (Tag.Inx == 3) ){
			//Descp Show
			PermissionCmd = pcEditDescp;
			if(SystemPermission >2){
				PermissionCmdGO();
			}else{
				IsPermission = 1;
				PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
			}
		}
		switch(HwDevType){
			case htNoType:
				SubRtnMsg = KeyInHtNoType(aKey);
				break;
			case htSmoker:
				SubRtnMsg = KeyInHtSmoker(aKey);
				break;
			case htTempe:
				SubRtnMsg = KeyInHtTempe(aKey);
				break;
			case htHandPad:
				SubRtnMsg = KeyInHtHandPad(aKey);
				break;
			case htHydrantPad:
				SubRtnMsg = KeyInHtHydrantPad(aKey);
				break;
			case htModuleIn:
				SubRtnMsg = KeyInHtModuleIn(aKey);
				break;
			case htModuleInOut:
				SubRtnMsg = KeyInHtModuleInOut(aKey);
				break;
			case htModuleOut:
				SubRtnMsg = KeyInHtModuleOut(aKey);		
				break;
			case htVa:
				SubRtnMsg = KeyInHtVa(aKey);				
				break;
			case htDisplayPad:
				SubRtnMsg = KeyInHtDisplayPad(aKey);	
				break;
			case htLinkagePowerSuply:
				SubRtnMsg = KeyInHtLinkagePowerSuply(aKey);		
				break;
			default :
				SubRtnMsg = guiMsgReturn;
				break;
		}
		return SubRtnMsg;
	}
	return aMsg;
}



TGuiMsgReturn TDevProperty::KeyInCommonEdit(unsigned char aKey)
{
	int tVal;
	unsigned char tP0, tP1, NewType, IsNewTarget;
	TGuiMsgReturn aMsg = guiMsgNone;
	int HasPrcKey = 0;
	if(Tag.Inx == 0){
		//Ctl Num
	}else
	if(Tag.Inx == 1){
		//Port Num
		IsNewTarget = 0;
		IList->EditPortNum.KeyIn(aKey);
		tVal = IList->EditPortNum.Str.ToInteger();
		if( (tVal >0) && (tVal <= dPORT_MAX_COUNT) )PortNumValid = 1; else PortNumValid = 0;
		if( PortNumValid && AddrNumValid){
			if(Path0 != tVal){
				ClearReqDataState();
				Path0 = tVal;
				IList->EditPortNum.SelectedColor = clBlue;
				ReDrawCommonInf();
				Check4Selected();
				RealTimeSendCmdAbort();
				tP0 = Path0-1;
				tP1 = Path1-1;
				if(Port[tP0].ExistTable[tP1] == 0xA5){
					NewType = Port[tP0].dTypeTable[tP1];
				}else{
					NewType = 0;
				}
				if(NewType == dType){
					//Load New Addr Inf
					Redraw4NewLoad();
					UpdataOnlineData();
					ResetTargetData();
				}else{
					//Load 4 New Type
					dType = NewType;
					Init4DType();
				}
			}
		}else{
			ClearReqDataState();
			Path0 = 0;
			if(dType != 0){
				dType = 0;
				Init4DType();
			}
			RealTimeSendCmdAbort();
			IList->EditPortNum.SelectedColor = clRed;
			ClearCommonInf();
		}
		IList->EditPortNum.Show();
	}else
	if(Tag.Inx == 2){
		//Addr Num
		if(aKey == VK_RIGHT){
			if(IList->EditAddrNum.Pst >= IList->EditAddrNum.Str.GetEndPst()){
				if( PortNumValid && AddrNumValid){
					IList->EditAddrNum.Selected = 0;
					IList->EditAddrNum.Show();
					Tag.Inx = 3;
					IList->EditDescpShow.Selected = 1;
					IList->EditDescpShow.Show();
					HasPrcKey = 1;
				}
			}
		}
		if(HasPrcKey == 0){
			IsNewTarget = 0;
			IList->EditAddrNum.KeyIn(aKey);
			tVal = IList->EditAddrNum.Str.ToInteger();
			if( (tVal >0) && (tVal <= dEP_MAX_COUNT_PER_PORT) )AddrNumValid = 1; else AddrNumValid = 0;
			if( PortNumValid && AddrNumValid){
				if(Path1 != tVal){
					ClearReqDataState();
					Path1 = tVal;
					IList->EditAddrNum.SelectedColor = clBlue;
					ReDrawCommonInf();
					Check4Selected();
					RealTimeSendCmdAbort();
					tP0 = Path0-1;
					tP1 = Path1-1;
					if(Port[tP0].ExistTable[tP1] == 0xA5){
						NewType = Port[tP0].dTypeTable[tP1];
					}else{
						NewType = 0;
					}
					if(NewType == dType){
						//Load New Addr Inf
						
						Redraw4NewLoad();
						UpdataOnlineData();
					}else{
						//Load 4 New Type
						dType = NewType;
						Init4DType();
					}
					ResetTargetData();
				}
			}else{
				ClearReqDataState();
				Path1 = 0;
				if(dType != 0){
					dType = 0;
					Init4DType();
				}
				RealTimeSendCmdAbort();
				IList->EditAddrNum.SelectedColor = clRed;
				ClearCommonInf();
			}
			IList->EditAddrNum.Show();
		}
	}else
	if(Tag.Inx == 3){
		//Descp Show
		if(aKey == VK_LEFT){
			IList->EditAddrNum.Selected = 1;
			IList->EditAddrNum.SetPstTail();
			IList->EditAddrNum.Show();
			IList->EditAddrNum.ShowCursor();
			Tag.Inx = 2;
			IList->EditDescpShow.Selected = 0;
			IList->EditDescpShow.Show();
		}
	}else
	if(Tag.Inx == 4){
		//User Code
		IList->EditUserCode.KeyIn(aKey);
		IList->EditUserCode.Show();
	}else
	if(Tag.Inx == 5){
		//Area
		IList->EditAreaAssign.KeyIn(aKey);
		IList->EditAreaAssign.Show();
	}
	return aMsg;
}

TGuiMsgReturn TDevProperty::KeyInCommonEnter(unsigned char aKey)
{
	int aVal;
	TGuiMsgReturn aMsg = guiMsgNone;
	if(Tag.Inx == 0){
		//Ctl Num
	}else
	if(Tag.Inx == 1){
		//Port Num
	}else
	if(Tag.Inx == 2){
		//Addr Num
	}else
	if(Tag.Inx == 3){
		//Descp Show
		PermissionCmd = pcWriteDescp;
		if(SystemPermission >2){
			PermissionCmdGO();
		}else{
			IsPermission = 1;
			PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
		}
	}else
	if(Tag.Inx == 4){
		//User Code
		if(SystemPermission >2){
			if( Path0 && Path1 && (Path0 <= dPORT_MAX_COUNT) && (Path1<=dEP_MAX_COUNT_PER_PORT) ){
				aVal = IList->EditUserCode.Str.ToInteger();
				if( (aVal < 100000000) && (aVal>0) ){
					aUcSetting.Full = aVal;
					WriteAUserCode2Flash(Path0, Path1, aUcSetting);
					ReadAllEpUserCode();
					if(aVal == Port[Path0-1].UcList[Path1-1].Full){
						if(LanguageEnCn == 0){
							TextRender_string24(IList->EditUserCode.Bound.Right + 2, IList->EditUserCode.Bound.Top +4, clNearWhite, ItemColor, "保存成功");
						}else{
							TextRender_string24(IList->EditUserCode.Bound.Right + 2, IList->EditUserCode.Bound.Top +4, clNearWhite, ItemColor, "Save OK ");
						}
					}else{
						if(LanguageEnCn == 0){
							TextRender_string24(IList->EditUserCode.Bound.Right + 2, IList->EditUserCode.Bound.Top +4, clNearWhite, ItemColor, "保存失败");
						}else{
							TextRender_string24(IList->EditUserCode.Bound.Right + 2, IList->EditUserCode.Bound.Top +4, clNearWhite, ItemColor, "Save Err");
						}
					}
					IList->EditUserCode.Str.FromUInt8Dg(Port[Path0-1].UcList[Path1-1].Full);
					IList->EditUserCode.Show();
				}
			}
		}else{
			ClearSelected();
			IsPermission = 1;
			PermissionCmd = pcWriteUserCode;
			PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
		}
	}else
	if(Tag.Inx == 5){
		//Area
		aVal = IList->EditAreaAssign.Str.ToInteger();
		aVal &= 0x0000FFFF;
		AreaNum = aVal;
		if((AreaNum >-1) && (AreaNum <= dAreaCountMax)){
			if(SystemPermission >2){
				if( Path0 && Path1 && (Path0 <= dPORT_MAX_COUNT) && (Path1<=dEP_MAX_COUNT_PER_PORT) ){
					PermissionCmd = pcWriteAreaInx;
					PermissionCmdGO();
				}
			}else{
				ClearSelected();
				IsPermission = 1;
				PermissionCmd = pcWriteAreaInx;
				PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
			}
		}
	}
	return aMsg;
}


void TDevProperty::ReadAllEpUserCode()
{
	Record.ReadDevUserSet();
}

void TDevProperty::ResetTargetData()
{
	RuntimeData.Reset();
	IList->RealtimeData.Reset();
	IList->TextOutClear();
	PanelDrawData.ResetNotFull();
	switch(HwDevType){
		case htNoType:
			
			break;
		case htSmoker:
			RealTimeSendCmd(1);
			SendSmokeCmdRead();
			SendReqMac();
			break;
		case htTempe:
			RealTimeSendCmd(1);
			SendTempeCmdRead();
			SendReqMac();
			break;
		case htHandPad:
			RealTimeSendCmd(1);
			SendReqMac();
			break;
		case htHydrantPad:
			RealTimeSendCmd(1);
			SendReqMac();
			break;
		case htModuleIn:
			RealTimeSendCmd(1);
			SendModuleSignalInOutTypeRead();
			SendReqMac();
			break;
		case htModuleInOut:
			RealTimeSendCmd(1);
			SendModuleSignalInOutTypeRead();
			SendReqMac();
			break;
		case htModuleOut:
			RealTimeSendCmd(1);
			SendModuleSignalInOutTypeRead();
			SendReqMac();	
			break;
		case htVa:
			RealTimeSendCmd(1);
			SendVaSettingRead();
			SendReqMac();
			break;
		case htDisplayPad:
			RealTimeSendCmd(1);
			SendReqMac();	
			break;
		case htLinkagePowerSuply:
			RealTimeSendCmd(1);
			SendReqMac();	
			break;
		default :
			
			break;
	}
}

void TDevProperty::PushInnerCanData(unsigned char aCmd, unsigned char *pData)
{
	int i;
	unsigned char Inx = pData[3];
	
	if(aCmd == cmQueryMacCode){
		if(pData[0] == 1){
			if( (pData[2] == Path0) && (pData[3] == Path1) ) {
				RuntimeData.MacPath0 = Path0;
				RuntimeData.MacPath1 = Path1;
				RuntimeData.MacHasUpdate |= 1;
				RuntimeData.Mac[0] = pData[4];
				RuntimeData.Mac[1] = pData[5];
				RuntimeData.Mac[2] = pData[6];
				RuntimeData.Mac[3] = pData[7];
			}
		}else
		if(pData[0] == 2){
			if( (pData[2] == Path0) && (pData[3] == Path1) ) {
				RuntimeData.MacPath0 = Path0;
				RuntimeData.MacPath1 = Path1;
				RuntimeData.MacHasUpdate |= 2;
				
				RuntimeData.Mac[4] = pData[4];
				RuntimeData.Mac[5] = pData[5];
				RuntimeData.Mac[6] = pData[6];
				RuntimeData.Mac[7] = 0;
			}
		}
		return;
	}
	
	switch(HwDevType){
		case htNoType:
			
			break;
		case htSmoker:
			PushSmokeCanData(aCmd, pData);
			break;
		case htTempe:
			PushTempeCanData(aCmd, pData);
			break;
		case htHandPad:
			
			break;
		case htHydrantPad:
			
			break;
		case htModuleIn:
			PushModuleInCanData(aCmd, pData);
			break;
		case htModuleInOut:
			PushModuleInOutCanData(aCmd, pData);
			break;
		case htModuleOut:
			PushModuleOutCanData(aCmd, pData);			
			break;
		case htVa:
			PushVaCanData(aCmd, pData);			
			break;
		case htDisplayPad:
			PushDisplayPadCanData(aCmd, pData);
			break;
		case htLinkagePowerSuply:
			PushLinkagePowerSuplyCanData(aCmd, pData);	
			break;
		default :
			
			break;
	}
}


void TDevProperty::PushInnerCanRuntimeData(unsigned char aCmd, unsigned char *pData)
{
	int i;
	switch(HwDevType){
		case htNoType:
			
			break;
		case htSmoker:

			break;
		case htTempe:

			break;
		case htHandPad:
			
			break;
		case htHydrantPad:
			
			break;
		case htModuleIn:

			break;
		case htModuleInOut:

			break;
		case htModuleOut:
						
			break;
		case htVa:
			
			break;
		case htDisplayPad:

			break;
		case htLinkagePowerSuply:
	
			break;
		default :
			
			break;
	}
}

void TDevProperty::Show(void)
{
	IsShow = 1;
	DrawSelf();
}

void TDevProperty::Task1000Ms()
{
	if(IsShow == 0) return;
	if( (Path0) && (Path1 ) ){
		if( (Path0 <= dPORT_MAX_COUNT) && (Path1 <= dEP_MAX_COUNT_PER_PORT) ){
			if(IsRegisted){
				const unsigned char tSta = Port[Path0-1].StateTable[Path1-1];
				DrawState(tSta);
				IList->STextState.Show();
			}
		}
	}
	switch(HwDevType){
		case htNoType:
			
			break;
		case htSmoker:
			Task1000MsSmoker();
			break;
		case htTempe:
			Task1000MsTempe();
			break;
		case htHandPad:
			Task1000MsHandPad();
			break;
		case htHydrantPad:
			Task1000MsHydrantPad();
			break;
		case htModuleIn:
			Task1000MsModuleIn();
			break;
		case htModuleInOut:
			Task1000MsModuleInOut();
			break;
		case htModuleOut:
			Task1000MsModuleOut();			
			break;
		case htVa:
			Task1000MsVa();		
			break;
		case htDisplayPad:
			Task1000MsDisplayPad();
			break;
		case htLinkagePowerSuply:
			Task1000MsLinkagePowerSuply();	
			break;
		default :
			
			break;
	}
}

void TDevProperty::RunTimeSendCmd(const int StartStop)
{
	TCanHeaderID aIde;
	unsigned int i;
	unsigned int Len;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	CommData[2] = Path0;
	CommData[3] = Path1;
	
	if(StartStop != 0){
		aIde.BitF.Cmd = cmDeviceRuntimeDataStart;
	}else{
		aIde.BitF.Cmd = cmDeviceRuntimeDataStop;
	}
	Len = 4;

	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::RealTimeSendCmd(const int StartStop)
{
	TCanHeaderID aIde;
	unsigned int i;
	unsigned int Len;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	CommData[2] = Path0;
	CommData[3] = Path1;
	
	if(StartStop != 0){
		aIde.BitF.Cmd = cmQueryRuntimeData;
	}else{
		aIde.BitF.Cmd = cmQueryAbout;
	}
	Len = 4;

	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::RealTimeSendCmdAbort()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aP0,aP1;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	aIde.BitF.Cmd = cmQueryAbout;
	Len = 4;
	//Prm 
	CommData[0] = 0;
	CommData[1] = 0;
	CommData[2] = Path0;
	CommData[3] = Path1;
	
	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::SendReqMac()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aP0,aP1;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	aIde.BitF.Cmd = cmQueryMacCode;
	Len = 4;
	//Prm 
	CommData[0] = 0;
	CommData[1] = MainCtl.fData.Split.MyNum;
	CommData[2] = Path0;
	CommData[3] = Path1;
	
	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::SendCmdLightOn()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aP0,aP1;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	aIde.BitF.Cmd = cmDevLightOn;
	Len = 5;
	//Prm 
	CommData[0] = 0;
	CommData[1] = MainCtl.fData.Split.MyNum;
	CommData[2] = Path0;
	CommData[3] = Path1;
	CommData[4] = 1;
	CommData[5] = 0;
	
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	
	if( (Path0) && (Path0<=dPORT_MAX_COUNT) && (Path1) ){
		aP0 = Path0-1;
		aP1 = Path1-1;
		Port[aP0].HasSetLightOn[aP1] = 1;
	}

	InnerCan.Buf4GuiSend.Insert(aIde, CommData, Len);		
}

void TDevProperty::SendCmdLightOff()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aP0,aP1;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	aIde.BitF.Cmd = cmDevLightOn;
	Len = 6;
	//Prm 
	CommData[0] = 0;
	CommData[1] = MainCtl.fData.Split.MyNum;
	CommData[2] = 255;
	CommData[3] = 255;
	CommData[4] = 0;
	CommData[5] = 0;
	
	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::SendCmdMuteBroadcast()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aP0,aP1;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	aIde.BitF.Cmd = cmDevMute;
	Len = 4;
	//Prm 
	CommData[0] = 0;
	CommData[1] = MainCtl.fData.Split.MyNum;
	CommData[2] = 255;
	CommData[3] = 255;
	
	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::SendCmdMute()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aP0,aP1;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	aIde.BitF.Cmd = cmDevMute;
	Len = 4;
	//Prm 
	CommData[0] = 0;
	CommData[1] = MainCtl.fData.Split.MyNum;
	CommData[2] = Path0;
	CommData[3] = Path1;
	
	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::RuntimeDataPrc(u8 aInx, u8 D0, u8 D1, u8 D2, u8 D3)
{
	unsigned short tDa;
	if(aInx ==0){
		RuntimeData.voltage = D1;
		switch(HwDevType){
			case htSmoker:		tDa = D2; tDa<<=8; tDa |= D3; RuntimeData.SmokerBL = tDa;break;
			case htTempe:		tDa = D2; tDa<<=8; tDa |= D3; RuntimeData.TempeOriginData = tDa;break;
			case htModuleIn:		RuntimeData.ModuleInAdVal = D2;				break;
			case htModuleInOut: 	RuntimeData.ModuleInAdVal = D2;				break;
			case htDisplayPad:	tDa = D2; tDa<<=8; tDa |= D3; RuntimeData.DisplayPadAlramCount = tDa; break;	
			case htLinkagePowerSuply:tDa = D2; tDa<<=8; tDa |= D3; RuntimeData.BatVoltage = tDa; break;
			default :
				break;
		}
		if(HwDevType == htSmoker){
			Curve.Smoke.DataAva[0] =1;
			Curve.Smoke.Blue = RuntimeData.SmokerBL;
		}else
		if(HwDevType == htTempe){
			Curve.Tempe.DataAva[0] =1;
			Curve.Tempe.Val = RuntimeData.TempeOriginData;
		}
	}else
	if(aInx == 1){
		switch(HwDevType){
			case htSmoker:		tDa = D0; tDa<<=8; tDa |= D1; RuntimeData.SmokerIR = tDa;break;
			case htTempe:		RuntimeData.TempeCelsiusData = D0;	break;
			case htLinkagePowerSuply:
				RuntimeData.BatEnergy = D0; 
				tDa = D1; tDa<<=8; tDa |= D2;
				RuntimeData.OutputVoltage = tDa;
				RuntimeData.OutputCurrent = D3;
				RuntimeData.OutputCurrent<<=8;
				break;
			default :
				break;
		}
		if(HwDevType == htSmoker){
			Curve.Smoke.DataAva[1] =1;
			Curve.Smoke.IR = RuntimeData.SmokerIR;
		}else
		if(HwDevType == htTempe){
			Curve.Tempe.DataAva[1] =1;
			Curve.Tempe.Celsius = RuntimeData.TempeCelsiusData;
			if(Curve.Tempe.DataAva[0]){
				CurvePutDataTempe(Curve.Tempe.Val,Curve.Tempe.Celsius,0,0);
				Curve.HasUpdate =1;
			}
		}
		Curve.Tempe.DataAva[0] =0;
		Curve.Tempe.DataAva[1] =0;
	}else
	if(aInx == 2){
		switch(HwDevType){
			case htSmoker:
				tDa = D2; tDa<<=8; tDa |= D3; RuntimeData.SmokerPrmM = tDa;
				Curve.Smoke.MVal = RuntimeData.SmokerPrmM;
				Curve.Smoke.DataAva[2] =1;
				if(Curve.Smoke.DataAva[0] && Curve.Smoke.DataAva[1]){
					CurvePutDataSmoke(Curve.Smoke.IR, Curve.Smoke.Blue, Curve.Smoke.MVal, 0);
					Curve.HasUpdate =1;
				}
				break;
			case htTempe:
				//Data.GotTempeSensType[0] = 0xF1; 
				//Data.GotTempeSensType[1] = Path0;
				//Data.GotTempeSensType[2] = Path1;
				//Data.GotTempeSensType[3] = D1;
				break;
			case htLinkagePowerSuply:
				RuntimeData.OutputCurrent |= D0;
				RuntimeData.PwrLoaddingPercent = D1;
				break;
			default :
				break;
		}
		Curve.Smoke.DataAva[0] =0;
		Curve.Smoke.DataAva[1] =0;
		Curve.Smoke.DataAva[2] =0;
	}else
	if(aInx == 3){
		switch(HwDevType){
			case htSmoker:
				
				break;
			default :
				break;
		}
	}
	
	if(Curve.HasUpdate){
		if(PanelIsUsingText == 0){
			if(Curve.HasDrawOutline == 0){
				if( (EdittingDescp == 0) && (IsPermission == 0) )
					if( (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0) )
						CurveDraw(1);
			}else{
				if( (EdittingDescp == 0) && (IsPermission == 0) )
					if( (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0) )
						CurveDraw(0);
			}
		}
	}
}

void TDevProperty::PushOneRealDataReport(u8 aP0, u8 aP1, u8 aInx, u8 D0, u8 D1, u8 D2, u8 D3)
{
	unsigned int aAddr, i, Num, Num10, Pst;
	unsigned char Da[4];
	int x,y;
	
	const int MaxLen=41;
	
	if(IsShow == 0)return;
	
	if(aP0 != Path0)return;
	if(aP1 != Path1)return;
	
	RuntimeDataPrc(aInx, D0,D1,D2,D3);
	
	Da[0] = D0;
	Da[1] = D1;
	Da[2] = D2;
	Da[3] = D3;
	if(PanelDrawData.TextDrawLine >7){
		PanelDrawData.Reset();
	}	
	if(aInx == 0){
		PanelDrawData.TextDrawLine++;
		if(PanelDrawData.TextDrawLine >7){
			PanelDrawData.Reset();
		}
		
		if(PanelDrawData.TextDrawLine == 0){
			for(int z=0; z<8; z++){
				for(int g=0; g<80; g++){
					IList->TextOut[z][g] = '\0';
				}
			}
			if( (EdittingDescp == 0) && (IsPermission == 0) ){
				if( PanelIsUsingText && (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0)  ){
					RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
				}
			}
		}
		for(int g=0; g<MaxLen; g++){
			IList->TextOut[PanelDrawData.TextDrawLine][g] = ' ';
		}
		for(int g=MaxLen; g<80; g++){
			IList->TextOut[PanelDrawData.TextDrawLine][g] = '\0';
		}
		y = Lv.Panel.Top + 1;
		y = y + PanelDrawData.TextDrawLine  * 27;
		x = Lv.Panel.Left + 2;
		TMyString::sClear(TextTmp);
		PanelDrawData.UsingTextHex = PanelDrawData.DesertTextHex;
		if(PanelDrawData.IsHexList[PanelDrawData.TextDrawLine] == dtNone){
			if(PanelDrawData.UsingTextHex)PanelDrawData.IsHexList[PanelDrawData.TextDrawLine] =dtHex;
			else PanelDrawData.IsHexList[PanelDrawData.TextDrawLine] =dtDec;
		}
		if(PanelDrawData.IsHexList[PanelDrawData.TextDrawLine] == dtHex){
			for(i=0; i<4; i++){
				Pst= 0 + i*3;
				Num = Da[i] % 16;
				Num10 = Da[i] / 16 % 16;
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+0] = stHexNum[Num10];
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+1] = stHexNum[Num];
				if(i<3)IList->TextOut[PanelDrawData.TextDrawLine][Pst+2] = ' ';
				else IList->TextOut[PanelDrawData.TextDrawLine][Pst+2] = ',';
			}
			if( (EdittingDescp == 0) && (IsPermission == 0) ){
				if( PanelIsUsingText && (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0)  )
					TextRender_string24(x,y,clNearBlack, PanelColor, IList->TextOut[PanelDrawData.TextDrawLine]);
			}
		}else
		if(PanelDrawData.IsHexList[PanelDrawData.TextDrawLine] == dtDec){
			for(i=0; i<4; i++){
				Pst= 0 + i*4;
				Num = Da[i] / 100;
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+0] = Num + '0';
				Num = Da[i] % 100 / 10;
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+1] = Num + '0';
				Num = Da[i] % 10;
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+2] = Num + '0';
				if(i<3)IList->TextOut[PanelDrawData.TextDrawLine][Pst+3] = ' ';
				else IList->TextOut[PanelDrawData.TextDrawLine][Pst+3] = ',';
			}
			if( (EdittingDescp == 0) && (IsPermission == 0) ){
				if( PanelIsUsingText && (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0)  )
					TextRender_string24(x,y,clNearBlack, PanelColor, IList->TextOut[PanelDrawData.TextDrawLine]);
			}
		}
	}else
	if(aInx < 4){
		y = Lv.Panel.Top + 1;
		y = y + PanelDrawData.TextDrawLine  * 27;
		x = Lv.Panel.Left + 2;
		TMyString::sClear(TextTmp);
		if(PanelDrawData.IsHexList[PanelDrawData.TextDrawLine] == dtHex){
			for(i=0; i<4; i++){
				Pst= aInx*12 + i*3;
				if(Pst > (MaxLen-1-2))break;
				Num = Da[i] % 16;
				Num10 = Da[i] / 16 % 16;
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+0] = stHexNum[Num10];
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+1] = stHexNum[Num];
				if((Pst+2)<=(MaxLen-1)){
					if(i<3)IList->TextOut[PanelDrawData.TextDrawLine][Pst+2] = ' ';
					else IList->TextOut[PanelDrawData.TextDrawLine][Pst+2] = ',';
				}
			}
			if( (EdittingDescp == 0) && (IsPermission == 0) ){
				if( PanelIsUsingText && (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0) /*&& (aInx == 3)*/ )
					TextRender_string24(x,y,clNearBlack, PanelColor, IList->TextOut[PanelDrawData.TextDrawLine]);
			}
		}else
		if(PanelDrawData.IsHexList[PanelDrawData.TextDrawLine] == dtDec){
			for(i=0; i<4; i++){
				Pst= aInx*16 + i*4;
				if(Pst > (MaxLen-1-3))break;
				Num = Da[i] / 100;
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+0] = Num + '0';
				Num = Da[i] % 100 / 10;
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+1] = Num + '0';
				Num = Da[i] % 10;
				IList->TextOut[PanelDrawData.TextDrawLine][Pst+2] = Num + '0';
				if((Pst+3)<=(MaxLen-1)){
					if(i<3)IList->TextOut[PanelDrawData.TextDrawLine][Pst+3] = ' ';
					else IList->TextOut[PanelDrawData.TextDrawLine][Pst+3] = ',';
				}
			}
			if( (EdittingDescp == 0) && (IsPermission == 0) ){
				if( PanelIsUsingText && (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0) /*&& (aInx == 3)*/ )
					TextRender_string24(x,y,clNearBlack, PanelColor, IList->TextOut[PanelDrawData.TextDrawLine]);
			}
		}
	}
}

void TDevProperty::PermissionCmdGO()
{
	int aVal;
	unsigned char aBits;
	switch(PermissionCmd){
		case pcWriteDescp:
			TDescpWrite::sRestoreDescp(Path0, Path1, IList->EditDescpShow.Str.Text);
			IList->EditDescpShow.SelectedColor = clDeepGreen;
			if(LanguageEnCn == 0){
				IList->EditDescpShow.Str.FromStr("写入注释信息, 重新读取注释信息");
			}else{
				IList->EditDescpShow.Str.FromStr("Save And Reload");
			}
			IList->EditDescpShow.Show();
			sDelayMs(100);
			IList->EditDescpShow.SelectedColor = clBlue;
			TDescpWrite::sWrite2Flash(Path0);
			ReLoadAndDrawDescp();
			break;
		case pcWriteUserCode:
			if( Path0 && Path1 && (Path0 <= dPORT_MAX_COUNT) && (Path1<=dEP_MAX_COUNT_PER_PORT) ){
				aVal = IList->EditUserCode.Str.ToInteger();
				if( (aVal < 100000000) && (aVal>0) ){
					aUcSetting.Full = aVal;
					WriteAUserCode2Flash(Path0, Path1, aUcSetting);
					ReadAllEpUserCode();
					if(LanguageEnCn == 0){
						if(aVal == Port[Path0-1].UcList[Path1-1].Full){
							TextRender_string24(IList->EditUserCode.Bound.Right + 2, IList->EditUserCode.Bound.Top +4, clNearWhite, ItemColor, "保存成功");
						}else{
							TextRender_string24(IList->EditUserCode.Bound.Right + 2, IList->EditUserCode.Bound.Top +4, clNearWhite, ItemColor, "保存失败");
						}
					}else{
						if(aVal == Port[Path0-1].UcList[Path1-1].Full){
							TextRender_string24(IList->EditUserCode.Bound.Right + 2, IList->EditUserCode.Bound.Top +4, clNearWhite, ItemColor, "Save OK ");
						}else{
							TextRender_string24(IList->EditUserCode.Bound.Right + 2, IList->EditUserCode.Bound.Top +4, clNearWhite, ItemColor, "Save Err");
						}
					}
					IList->EditUserCode.Str.FromUInt8Dg(Port[Path0-1].UcList[Path1-1].Full);
					IList->EditUserCode.Show();
				}
			}
			break;
		case pcWriteAssignType:
			if( Path0 && Path1 && (Path0 <= dPORT_MAX_COUNT) && (Path1<=dEP_MAX_COUNT_PER_PORT) ){
				if(LanguageEnCn == 0){
					TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "写入中  ");
					WriteAAssignType2Flash(Path0, Path1, AssignTypeSetting);
					Record.ReadDevUserSet();
					if(AssignTypeSetting == Port[Path0-1].AssignType[Path1-1]){
						TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "写入成功");
					}else{
						TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "写入失败");
					}
				}else{
					TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "Saving   ");
					WriteAAssignType2Flash(Path0, Path1, AssignTypeSetting);
					Record.ReadDevUserSet();
					if(AssignTypeSetting == Port[Path0-1].AssignType[Path1-1]){
						TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "Save OK ");
					}else{
						TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "Save Err");
					}
				}
			}
			break;
		case pcWriteAreaInx:	
			if( Path0 && Path1 && (Path0 <= dPORT_MAX_COUNT) && (Path1<=dEP_MAX_COUNT_PER_PORT) ){
				if(LanguageEnCn == 0){
					TextRender_string24(IList->EditAreaAssign.Bound.Right + 2, IList->EditAreaAssign.Bound.Top + 4, clNearWhite, ItemColor, "写入中  ");
					WriteAreaNum2Flash(Path0, Path1, AreaNum);
					Record.ReadDevAreaNum();
					if(AreaNum == Port[Path0-1].Area[Path1-1]){
						TextRender_string24(IList->EditAreaAssign.Bound.Right + 2, IList->EditAreaAssign.Bound.Top + 4, clNearWhite, ItemColor, "写入成功");
					}else{
						TextRender_string24(IList->EditAreaAssign.Bound.Right + 2, IList->EditAreaAssign.Bound.Top + 4, clNearWhite, ItemColor, "写入失败");
					}
				}else{
					TextRender_string24(IList->EditAreaAssign.Bound.Right + 2, IList->EditAreaAssign.Bound.Top + 4, clNearWhite, ItemColor, "Saving  ");
					WriteAreaNum2Flash(Path0, Path1, AreaNum);
					Record.ReadDevAreaNum();
					if(AreaNum == Port[Path0-1].Area[Path1-1]){
						TextRender_string24(IList->EditAreaAssign.Bound.Right + 2, IList->EditAreaAssign.Bound.Top + 4, clNearWhite, ItemColor, "Save OK ");
					}else{
						TextRender_string24(IList->EditAreaAssign.Bound.Right + 2, IList->EditAreaAssign.Bound.Top + 4, clNearWhite, ItemColor, "Save Err");
					}
				}
			}
			break;
		case pcWriteSmokerSens:
			SmokerRt.IsWait4ReadSens = 0;
			SmokerRt.IsWait4WriteSens = 1;
			SmokerRt.RecRdy = 0;
			SmokerRt.RecCmd = 0;
			SmokerRt.WaitTick = 0;
			SendSmokeCmdCfg();
			if(LanguageEnCn == 0){
				TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "写入中  ");
			}else
			if(LanguageEnCn == 1){
				TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, "Saving  ");
			}
			break;
		case pcWriteTempeSensType:
			
			break;
		case pcWriteModuleDefineType:
			
			break;
		case pcWriteModuleSignalInType:
			//ModuleInRt.IsWait4ReadSignalType = 0;
			//ModuleInRt.IsWait4WriteSignalType = 1;
			//ModuleInRt.RecRdy = 0;
			//ModuleInRt.RecCmd = 0;
			//ModuleInRt.WaitTick = 0;
			//SendModuleSignalInOutTypeWrite();
			aBits = Data.ModuleSignalInType;
			WriteMouelaInputSignal();
			if(LanguageEnCn == 0){
				if(aBits == Data.ModuleSignalInType)
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "写入成功");
				else
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "写入失败");
			}else
			if(LanguageEnCn == 1){
				if(aBits == Data.ModuleSignalInType)
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "Save OK ");
				else
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "Save Err");
			}
			break;
		case pcWriteNoTypeSignalInOutType:
			//ModuleInOutRt.IsWait4ReadSignalType = 0;
			//ModuleInOutRt.IsWait4WriteSignalType = 1;
			//ModuleInOutRt.RecRdy = 0;
			//ModuleInOutRt.RecCmd = 0;
			//ModuleInOutRt.WaitTick = 0;
			//SendModuleSignalInOutTypeWrite();
			aBits = Data.NoTypeSignalInOutType;
			WriteNoTypeInOutSignal();
			if(LanguageEnCn == 0){
				if(aBits == Data.NoTypeSignalInOutType)
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "写入成功");
				else
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "写入失败");
			}else{
				if(aBits == Data.NoTypeSignalInOutType)
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "Save OK ");
				else
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "Save Err");
			}
			break;
		case pcWriteModuleSignalInOutType:
			//ModuleInOutRt.IsWait4ReadSignalType = 0;
			//ModuleInOutRt.IsWait4WriteSignalType = 1;
			//ModuleInOutRt.RecRdy = 0;
			//ModuleInOutRt.RecCmd = 0;
			//ModuleInOutRt.WaitTick = 0;
			//SendModuleSignalInOutTypeWrite();
			aBits = Data.ModuleSignalInOutType;
			WriteMouelaInOutSignal();
			if(LanguageEnCn == 0){
				if(aBits == Data.ModuleSignalInOutType)
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "写入成功");
				else
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "写入失败");
			}else{
				if(aBits == Data.ModuleSignalInOutType)
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "Save OK ");
				else
					TextRender_string24(Lv.Grid.Left[3] + 160, ModuleRectLv3.Top + 4, clNearWhite, ItemColor, "Save Err");
			}
			break;
		case pcWriteModuleSignalOutType:
			
			break;
		case pcWriteVaIsLinkageAble:
			//Write to Flash No This Function See WriteVaSetting
			break;
		case pcWriteVaSetting:
			SendVaSettingWrite();
			break;
		case pcWriteDisplayPadMatchData:
			WriteDisplayPadMatchData();
			break;
		case pcLightUp:
			//No Permission Requst, See KeyIn-Function
			break;
		case pcSimAlram:
			SimFire(Path0, Path1);
			break;
		case pcSimStart:
			SimStart(Path0, Path1);
			break;
		case pcSimInputActive:
			SimFeedBack(Path0, Path1);
			break;
		case pcDisplayPadMute:
			SendDisplayPadMute();
			break;
		case pcDownLoadDescp:
			SendDisplayPadDescpDownload();
			break;
		case pcEditDescp:
			IList->EditDescpShow.Selected = 0;
			IList->EditDescpShow.Show();
			InitPanel();
			EdittingDescp = 1;
			IsExtInput = 1;
			break;
	}
}

void TDevProperty::RedrawPanelData()
{
	int x,y;
	if(PanelIsUsingText){
		for(int i=0; i<8; i++){
			y = Lv.Panel.Top + 1;
			y = y + i * 27;
			x = Lv.Panel.Left + 2;
			if(EdittingDescp == 0){
				if( (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0) )
					TextRender_string24(x,y,clNearBlack, IList->TextOut[i]);
			}
		}
	}else{
		if(EdittingDescp == 0){
			if( (IsSelfChecking == 0) && (PmsIntervene.IsShow == 0) )
				CurveDraw(1);
		}
	}		
}

void TDevProperty::PermissionCmdReturnDraw()
{
	Check4Selected();
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	RedrawPanelData();
}

void TDevProperty::ReDrawPanel()
{
	PermissionCmdReturnDraw();
}

void TDevProperty::ClearSelected()
{
	switch(HwDevType){
		case htNoType: 		ClearSelectedNoType(); 			break;		
		case htSmoker:		ClearSelectedHtSmoker();		break;
		case htTempe:		ClearSelectedHtTempe();			break;
		case htHandPad:		ClearSelectedHtHandPad();		break;
		case htHydrantPad:	ClearSelectedHtHydrantPad();		break;
		case htModuleIn:		ClearSelectedHtModuleIn();		break;
		case htModuleInOut:	ClearSelectedHtModuleInOut();		break;
		case htModuleOut:		ClearSelectedHtModuleOut();		break;
		case htVa:			ClearSelectedHtVa();			break;
		case htDisplayPad:	ClearSelectedHtDisplayPad();			break;
		case htLinkagePowerSuply:ClearSelectedHtLinkagePowerSuply();	break;
		default :break;
	}	
}

void TDevProperty::Check4Selected()
{
	switch(HwDevType){
		case htNoType: 		Check4SelectedNoType(); 		break;		
		case htSmoker:		Check4SelectedHtSmoker();		break;
		case htTempe:		Check4SelectedHtTempe();		break;
		case htHandPad:		Check4SelectedHtHandPad();		break;
		case htHydrantPad:	Check4SelectedHtHydrantPad();		break;
		case htModuleIn:		Check4SelectedHtModuleIn();		break;
		case htModuleInOut:	Check4SelectedHtModuleInOut();	break;
		case htModuleOut:		Check4SelectedHtModuleOut();		break;
		case htVa:			Check4SelectedHtVa();			break;
		case htDisplayPad:	Check4SelectedHtDisplayPad();		break;
		case htLinkagePowerSuply:Check4SelectedHtLinkagePowerSuply();	break;
		default :break;
	}	
}

void TDevProperty::ClearReqDataState()
{
	SmokerRt.IsWait4ReadSens = 0;
	SmokerRt.IsWait4WriteSens = 0;
	TempeRt.IsWait4ReadSensType =0;
	ModuleInRt.IsWait4ReadSignalType =0;
	ModuleInRt.IsWait4WriteSignalType =0;
	ModuleInOutRt.IsWait4ReadStaticData =0;
	ModuleInOutRt.IsWait4WriteStaticData =0;
	ModuleOutRt.IsWait4ReadStaticData =0;
	ModuleOutRt.IsWait4WriteStaticData =0;
	VaRt.IsWait4ReadVaSetting =0;
	VaRt.IsWait4WriteVaSetting =0;
	DisplayPadRt.IsMute =0;
	DisplayPadRt.IsDownloadDescp =0;
}

void TDevProperty::sWriteAuxIdAssignTypeSignalType(unsigned char aPath0)
{
	unsigned int fAddr;
	unsigned int i;
	TDMix tCrc;
	volatile unsigned int x, GetSta;
	unsigned char aP0, aP1, wP1;
	
	if(sIList == nullptr)return;
	sIList->ReadWriteData.Reset();
	
	do{
		sDelayMs(3);
		GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
	}while(GetSta);
	
	//Erase 1 * 4K Blocks
	if( (aPath0 >0) && (aPath0 <= dPORT_MAX_COUNT) ){
		aP0 = aPath0 -1;
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096);
		nor_erase_sector_4k(dFlashAddrDevUserCodeChip,fAddr);
		sDelayMs(100);
		
		do{
			sDelayMs(10);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		
		Crc32Reset();
		for(i=0; i<dEP_MAX_COUNT_PER_PORT; i++)Crc32Feed(Port[aP0].UcList[i].Full);
		tCrc.D32 = Crc32GetResult();
		for(i=0; i<4; i++){
			for(x=0;x<64;x++){
				sIList->ReadWriteData.D32[x] = Port[aP0].UcList[i*64 + x].Full;
			}
			if(i==3){
				sIList->ReadWriteData.D32[63] = tCrc.D32;
			}
			fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (i * 256);
			nor_write_page(dFlashAddrDevUserCodeChip, fAddr, sIList->ReadWriteData.D8);
			do{
				sDelayMs(5);
				GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
			}while(GetSta);
		}
		
		Crc32Reset();
		for(x=0; x<dEP_MAX_COUNT_PER_PORT; x++)Crc32Feed(static_cast<unsigned int>(Port[aP0].AssignType[x]));
		tCrc.D32 = Crc32GetResult();
		for(x=0;x<dEP_MAX_COUNT_PER_PORT;x++){
			sIList->ReadWriteData.D8[x] = Port[aP0].AssignType[x];
		}
		sIList->ReadWriteData.D8[252] = tCrc.D8[0];
		sIList->ReadWriteData.D8[253] = tCrc.D8[1];
		sIList->ReadWriteData.D8[254] = tCrc.D8[2];
		sIList->ReadWriteData.D8[255] = tCrc.D8[3];
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (4 * 256);
		nor_write_page(dFlashAddrDevUserCodeChip, fAddr, sIList->ReadWriteData.D8);
		do{
			sDelayMs(5);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		
		//Signal Type
		Crc32Reset();
		for(x=0; x<dEP_MAX_COUNT_PER_PORT; x++)Crc32Feed(static_cast<unsigned int>(Port[aP0].FuncSetByte[x]));
		tCrc.D32 = Crc32GetResult();
		for(x=0;x<dEP_MAX_COUNT_PER_PORT;x++){
			sIList->ReadWriteData.D8[x] = Port[aP0].FuncSetByte[x];
		}
		sIList->ReadWriteData.D8[252] = tCrc.D8[0];
		sIList->ReadWriteData.D8[253] = tCrc.D8[1];
		sIList->ReadWriteData.D8[254] = tCrc.D8[2];
		sIList->ReadWriteData.D8[255] = tCrc.D8[3];
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (5 * 256);
		nor_write_page(dFlashAddrDevUserCodeChip, fAddr, sIList->ReadWriteData.D8);
		do{
			sDelayMs(5);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
	}		
}


void TDevProperty::sWriteAuxIdAssignTypeSignalTypeDefault(unsigned char aPath0)
{
	unsigned int fAddr;
	unsigned int i;
	TDMix tCrc;
	volatile unsigned int x, GetSta;
	unsigned char aP0, aP1, wP1;
	
	if(sIList == nullptr)return;
	
	do{
		sDelayMs(3);
		GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
	}while(GetSta);
	
	//Erase 1 * 4K Blocks
	if( (aPath0 >0) && (aPath0 <= dPORT_MAX_COUNT) ){
		aP0 = aPath0 -1;
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096);
		nor_erase_sector_4k(dFlashAddrDevUserCodeChip,fAddr);
		sDelayMs(100);
		
		do{
			sDelayMs(10);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		
		Crc32Reset();
		for(i=0; i<dEP_MAX_COUNT_PER_PORT; i++){
			Port[aP0].UcList[i].Full =0;
			Crc32Feed(Port[aP0].UcList[i].Full);
		}
		tCrc.D32 = Crc32GetResult();
		for(i=0; i<4; i++){
			for(x=0;x<64;x++){
				sIList->ReadWriteData.D32[x] = Port[aP0].UcList[i*64 + x].Full;
			}
			if(i==3){
				sIList->ReadWriteData.D32[63] = tCrc.D32;
			}
			fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (i * 256);
			nor_write_page(dFlashAddrDevUserCodeChip, fAddr, sIList->ReadWriteData.D8);
			do{
				sDelayMs(5);
				GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
			}while(GetSta);
			LoopCheck1S();
		}
		
		Crc32Reset();
		for(x=0; x<dEP_MAX_COUNT_PER_PORT; x++){
			Port[aP0].AssignType[x] =0;
			Crc32Feed(static_cast<unsigned int>(Port[aP0].AssignType[x]));
		}
		tCrc.D32 = Crc32GetResult();
		for(x=0;x<dEP_MAX_COUNT_PER_PORT;x++){
			sIList->ReadWriteData.D8[x] = Port[aP0].AssignType[x];
		}
		sIList->ReadWriteData.D8[252] = tCrc.D8[0];
		sIList->ReadWriteData.D8[253] = tCrc.D8[1];
		sIList->ReadWriteData.D8[254] = tCrc.D8[2];
		sIList->ReadWriteData.D8[255] = tCrc.D8[3];
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (4 * 256);
		nor_write_page(dFlashAddrDevUserCodeChip, fAddr, sIList->ReadWriteData.D8);
		do{
			sDelayMs(5);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		LoopCheck1S();
		
		//Signal Type
		Crc32Reset();
		for(x=0; x<dEP_MAX_COUNT_PER_PORT; x++){
			Port[aP0].FuncSetByte[x] =0;
			Crc32Feed(static_cast<unsigned int>(Port[aP0].FuncSetByte[x]));
		}
		tCrc.D32 = Crc32GetResult();
		for(x=0;x<dEP_MAX_COUNT_PER_PORT;x++){
			sIList->ReadWriteData.D8[x] = Port[aP0].FuncSetByte[x];
		}
		sIList->ReadWriteData.D8[252] = tCrc.D8[0];
		sIList->ReadWriteData.D8[253] = tCrc.D8[1];
		sIList->ReadWriteData.D8[254] = tCrc.D8[2];
		sIList->ReadWriteData.D8[255] = tCrc.D8[3];
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (5 * 256);
		nor_write_page(dFlashAddrDevUserCodeChip, fAddr, sIList->ReadWriteData.D8);
		do{
			sDelayMs(5);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		LoopCheck1S();
	}		
}

void TDevProperty::WriteAUserCode2Flash(unsigned char aPath0, unsigned char aAddr, TUserCode aUc)
{
	unsigned int fAddr;
	unsigned int i;
	TDMix tCrc;
	volatile unsigned int x, GetSta;
	unsigned char aP0, aP1, wP1;
	
	
	//Erase 1 * 4K Blocks
	if( (aPath0 >0) && (aPath0 <= dPORT_MAX_COUNT) ){
		aP0 = aPath0 -1;
		aP1 = aAddr -1;
		Port[aP0].UcList[aP1].Full = aUc.Full;
		sIList = IList;
		sWriteAuxIdAssignTypeSignalType(aPath0);
	}	
}

void TDevProperty::WriteAAssignType2Flash(unsigned char aPath0, unsigned char aAddr, unsigned char aNewAssignType)
{
	unsigned int fAddr;
	unsigned int i;
	unsigned int aUcFull;
	volatile unsigned int x, GetSta;
	unsigned char aP0, aP1, wP1;
	
	do{
		sDelayMs(3);
		GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
	}while(GetSta);
	
	//Erase 1 * 4K Blocks
	if( (aPath0 >0) && (aPath0 <= dPORT_MAX_COUNT) ){
		aP0 = aPath0 -1;
		aP1 = aAddr -1;
		Port[aP0].AssignType[aP1] = aNewAssignType;
		sIList = IList;
		sWriteAuxIdAssignTypeSignalType(aPath0);
	}	
}

void TDevProperty::WriteAreaNum2Flash(unsigned char aPath0, unsigned char aAddr, unsigned short aNum)
{
	unsigned int fAddr;
	unsigned int i;
	unsigned int aUcFull;
	volatile unsigned int x, GetSta;
	unsigned char aP0, aP1, wP1;
	TDMix tCrc;
	
	if(aPath0 <1)return;
	if(aPath0 >dPORT_MAX_COUNT)return;
	
	aP0 = aPath0 -1;
	aP1 = aAddr -1;
	Port[aP0].Area[aP1] = aNum;
	
	sIList = IList;
	sWriteAreaNumOnePort(aPath0);
}

void TDevProperty::sWriteAreaNumOnePort(unsigned char aPort)
{
	unsigned int fAddr;
	unsigned int i;
	unsigned int aUcFull;
	volatile unsigned int x, GetSta;
	unsigned char aP0, aP1, wP1;
	TDMix tCrc;
	
	if(aPort==0)return;
	if(aPort>dPORT_MAX_COUNT)return;
	
	if(sIList==nullptr)return;
	sIList->ReadWriteData.Reset();
	
	do{
		sDelayMs(3);
		GetSta = nor_get_busy_state(dFlash4DevAreaNumChip);
	}while(GetSta);
	
	aP0 = aPort -1;
	fAddr = dFlash4DevAreaNum + (aP0 / 8 * 4096);
	nor_erase_sector_4k(dFlash4DevAreaNumChip,fAddr);
	sDelayMs(100);
	do{
		sDelayMs(10);
		GetSta = nor_get_busy_state(dFlash4DevAreaNumChip);
	}while(GetSta);
	for(i=0; i<8; i++){
		Crc32Reset();
		for(int Gg=0; Gg<2; Gg++){
			for(x=0;x<128;x++){
				sIList->ReadWriteData.D16[x] = Port[ (aP0 & 0xF8) +i].Area[Gg * 128 + x];
				if(sIList->ReadWriteData.D16[x] > dAreaCountMax)sIList->ReadWriteData.D16[x] =0;
				if(Gg==0 or (x<(dEP_MAX_COUNT_PER_PORT-128))){
					Crc32Feed(static_cast<unsigned int>(sIList->ReadWriteData.D16[x]));
				}
			}
			if(Gg==1){
				tCrc.D32 = Crc32GetResult();
				sIList->ReadWriteData.D8[252] = tCrc.D8[0];
				sIList->ReadWriteData.D8[253] = tCrc.D8[1];
				sIList->ReadWriteData.D8[254] = tCrc.D8[2];
				sIList->ReadWriteData.D8[255] = tCrc.D8[3];
			}
			fAddr = dFlash4DevAreaNum + ( aP0/8 * 4096 + (i * 512) ) + (Gg * 256);
			nor_write_page(dFlash4DevAreaNumChip, fAddr, sIList->ReadWriteData.D8);
			do{
				sDelayMs(5);
				GetSta = nor_get_busy_state(dFlash4DevAreaNumChip);
			}while(GetSta);
		}
	}		
}

void TDevProperty::sWriteAreaNumDefault()
{
	unsigned int fAddr;
	unsigned int i,m,t;
	volatile unsigned int x, GetSta;
	TDMix tCrc;
	
	if(sIList==nullptr)return;
	
	do{
		sDelayMs(3);
		GetSta = nor_get_busy_state(dFlash4DevAreaNumChip);
	}while(GetSta);
	
	//Erase 1 * 4K Blocks
	for(t=0; t<(dPORT_MAX_COUNT/8) ;t++){
		fAddr = dFlash4DevAreaNum + (t * 4096);
		nor_erase_sector_4k(dFlash4DevAreaNumChip,fAddr);
		sDelayMs(100);
		do{
			sDelayMs(10);
			GetSta = nor_get_busy_state(dFlash4DevAreaNumChip);
		}while(GetSta);
		for(i=0; i<8; i++){
			SysLoopTick = 0;
			sIList->ReadWriteData.Reset();
			for(m=0; m<dEP_MAX_COUNT_PER_PORT; m++){
				Port[t*8 +i].Area[m] =0;
			}
			Crc32Reset();
			for(int Gg=0; Gg<2; Gg++){
				for(x=0;x<128;x++){
					sIList->ReadWriteData.D16[x] = Port[ (t *8) +i].Area[Gg * 128 + x];
					if(Gg==0 or (x<(dEP_MAX_COUNT_PER_PORT-128))){
						Crc32Feed(static_cast<unsigned int>(sIList->ReadWriteData.D16[x]));
					}
				}
				if(Gg==1){
					tCrc.D32 = Crc32GetResult();
					sIList->ReadWriteData.D8[252] = tCrc.D8[0];
					sIList->ReadWriteData.D8[253] = tCrc.D8[1];
					sIList->ReadWriteData.D8[254] = tCrc.D8[2];
					sIList->ReadWriteData.D8[255] = tCrc.D8[3];
				}
				fAddr = dFlash4DevAreaNum + ( t * 4096 + (i * 512) ) + (Gg * 256);
				nor_write_page(dFlash4DevAreaNumChip, fAddr, sIList->ReadWriteData.D8);
				do{
					sDelayMs(5);
					GetSta = nor_get_busy_state(dFlash4DevAreaNumChip);
				}while(GetSta);
			}
		}
	}	
}

void TDevProperty::sRecoverSetDefault()
{
	unsigned int fAddr;
	unsigned int i,x;
	volatile unsigned int GetSta;
	
	//User Code and Assign Type
	//First 32 Port
	
	SysLoopTick = 0;
	for(i=0; i<dPORT_MAX_COUNT; i++){
		SysLoopTick = 0;
		sWriteAuxIdAssignTypeSignalTypeDefault(i+1);
	}
	//Area Num
	SysLoopTick = 0;
	sWriteAreaNumDefault();	
	SysLoopTick = 0;
	
	Record.ReadDevUserSet();
	Record.ReadDevAreaNum();
}

void TDevProperty::LoadUcBcdText(unsigned int aUcFull, char *pText)
{
	int i;
	unsigned int f, aOrd;
	f = aUcFull;
	for(i=0; i<8; i++){
		f = aUcFull;
		f >>= ((7-i)*4);
		aOrd = (f & 0x0000'000F);
		pText[i] = CharBcdText[aOrd];

	}
	pText[8] = '\0';
}

unsigned int TDevProperty::RestoreUcBcdText(char * pText)
{
	int i;
	unsigned int f, Val, tResult;
	tResult = 0;
	for(i=0; i<8; i++){
		f = 11;
		if( (pText[i] >= '0') && (pText[i] <= '9') ) {
			f = pText[i] - '0';
		}
		if(pText[i] == '*')f = 10;
		f <<= ((7-i) * 4);
		tResult |= f;
	}
	return tResult;
}

void TDevProperty::FireSimulation(unsigned char CtlNum, unsigned char aP0, unsigned char aP1, unsigned char aType, unsigned int aUcCode, unsigned short aArea)
{
	
	if(CtlNum == MainCtl.fData.Split.MyNum){
		
	}else{
		
	}
}


void TDevProperty::SimFire(unsigned char aP0, unsigned char aP1)
{
	//Smoker Tempe HandReport
	if(aP0 == 0)return;
	if(aP1 == 0)return;
	if(aP0 >dPORT_MAX_COUNT)return;
	if(aP1 >dEP_MAX_COUNT_PER_PORT)return;
			
	Record.InnerMsgSetYear		(0, DateTime.Date.Split.Year);
	Record.InnerMsgSetMonth		(0, DateTime.Date.Split.Month);
	Record.InnerMsgSetDay		(0, DateTime.Date.Split.Day);
	Record.InnerMsgSetHour		(0, DateTime.Time.Split.Hour);
	Record.InnerMsgSetMinute	(0, DateTime.Time.Split.Minute);
	Record.InnerMsgSetSecond	(0, DateTime.Time.Split.Second);	
	Record.InnerMsgSet_mType	(0, CmdActiveDefaultSet[cmPublishAlram][7]);
	Record.InnerMsgSet_CtlNum	(0, MainCtl.fData.Split.MyNum );	//(0,aRxMsg.Data.D8[1]);
	
	Record.InnerMsgSet_P0		(0,aP0);
	Record.InnerMsgSet_P1		(0,aP1);
	Record.InnerMsgSet_P2		(0,0);
	Record.InnerMsgSet_dType	(0,0);
	Record.InnerMsgSet_Data0	(0,0);
	Record.InnerMsgSet_Data1	(0,0);
	Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[cmPublishAlram][8]);
	Record.InnerMsgSet_iByte1	(0,0);
	
	InnerCan.GetEpUserCodeAreaNumDevType(aP0, aP1, &Record.iMsgRx.Splite.UserCode, &Record.iMsgRx.Splite.AreaNum, &Record.iMsgRx.Splite.dType);

	if(Register.IsDevRegisting != 0x00A5A5A5){
		if(CtlCenter.ieMsgFire.Count <1)Record.InnerMsgSet_Data1	(0,1);
		else Record.InnerMsgSet_Data1	(0,0);
		
		Record.InnerMsgSet_Data0(0,TControlCenter::LinkInputTypeFireSimulate);
		
		if(CtlCenter.IsMsgReseting == 0){
			if(CtlCenter.iePushOneMsgFireSimulate(Record.iMsgRx,0)){
				//ProtoC2C.MasterDoPublishFire(aCtlNum, aIm.Splite.P0, aIm.Splite.P1,  aIm.Splite.dType);
				ProtoC2C.SlaveDoSend2MasterMachine(Record.iMsgRx, cmVIrtualAlram, TProtoC2C::mtFire);
				//ExRecord.SetStateCodeFire();
				//FecBusCRT.SetStateCodeFire();
				Record.FireAdd(Record.iMsgRx);
			}
		}
	}
}

void TDevProperty::SimStart(unsigned char aP0, unsigned char aP1)
{
	if(aP0 == 0)return;
	if(aP1 == 0)return;
	if(aP0 >dPORT_MAX_COUNT)return;
	if(aP1 >dEP_MAX_COUNT_PER_PORT)return;
			
	Record.InnerMsgSetYear		(0, DateTime.Date.Split.Year);
	Record.InnerMsgSetMonth		(0, DateTime.Date.Split.Month);
	Record.InnerMsgSetDay		(0, DateTime.Date.Split.Day);
	Record.InnerMsgSetHour		(0, DateTime.Time.Split.Hour);
	Record.InnerMsgSetMinute	(0, DateTime.Time.Split.Minute);
	Record.InnerMsgSetSecond	(0, DateTime.Time.Split.Second);	
	Record.InnerMsgSet_mType	(0, CmdActiveDefaultSet[cmAutoStart][7]);
	Record.InnerMsgSet_CtlNum	(0, MainCtl.fData.Split.MyNum );	//(0,aRxMsg.Data.D8[1]);
	
	Record.InnerMsgSet_P0		(0,aP0);
	Record.InnerMsgSet_P1		(0,aP1);
	Record.InnerMsgSet_P2		(0,0);
	Record.InnerMsgSet_dType	(0,0);
	Record.InnerMsgSet_Data0	(0,0);
	Record.InnerMsgSet_Data1	(0,TControlCenter::StartTypeSimulate);
	Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[cmAutoStart][8]);
	Record.InnerMsgSet_iByte1	(0,0);
	
	InnerCan.GetEpUserCodeAreaNumDevType(aP0, aP1, &Record.iMsgRx.Splite.UserCode, &Record.iMsgRx.Splite.AreaNum, &Record.iMsgRx.Splite.dType);

	if(Register.IsDevRegisting != 0x00A5A5A5){
		if(CtlCenter.iePushOneMsgLinkageStartSimulate(Record.iMsgRx)){
				//ExRecord.SetStateCodeStart();
				//FecBusCRT.SetStateCodeStart();
				Record.LinkageAdd(Record.iMsgRx);
				ProtoC2C.SlaveDoSend2MasterMachine(Record.iMsgRx, cmVIrtualStart, TProtoC2C::mtLink);
		}
	}
}

void TDevProperty::SimSv(unsigned char aP0, unsigned char aP1)
{
	if(aP0 == 0)return;
	if(aP1 == 0)return;
	if(aP0 >dPORT_MAX_COUNT)return;
	if(aP1 >dEP_MAX_COUNT_PER_PORT)return;
			
	Record.InnerMsgSetYear		(0, DateTime.Date.Split.Year);
	Record.InnerMsgSetMonth		(0, DateTime.Date.Split.Month);
	Record.InnerMsgSetDay		(0, DateTime.Date.Split.Day);
	Record.InnerMsgSetHour		(0, DateTime.Time.Split.Hour);
	Record.InnerMsgSetMinute	(0, DateTime.Time.Split.Minute);
	Record.InnerMsgSetSecond	(0, DateTime.Time.Split.Second);	
	Record.InnerMsgSet_mType	(0, CmdActiveDefaultSet[cmAutoStart][7]);
	Record.InnerMsgSet_CtlNum	(0, MainCtl.fData.Split.MyNum );	//(0,aRxMsg.Data.D8[1]);
	
	Record.InnerMsgSet_P0		(0,aP0);
	Record.InnerMsgSet_P1		(0,aP1);
	Record.InnerMsgSet_P2		(0,0);
	Record.InnerMsgSet_dType	(0,0);
	Record.InnerMsgSet_Data0	(0,0);
	Record.InnerMsgSet_Data1	(0,TControlCenter::StartTypeSimulate);
	Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[cmAutoStart][8]);
	Record.InnerMsgSet_iByte1	(0,0);
	
	InnerCan.GetEpUserCodeAreaNumDevType(aP0, aP1, &Record.iMsgRx.Splite.UserCode, &Record.iMsgRx.Splite.AreaNum, &Record.iMsgRx.Splite.dType);

	if(Register.IsDevRegisting != 0x00A5A5A5){
		if(CtlCenter.iePushOneMsgSvSimulate(Record.iMsgRx)){
			//ExRecord.SetStateCodeStart();
			//FecBusCRT.SetStateCodeStart();
			Record.SvAdd(Record.iMsgRx);
			ProtoC2C.SlaveDoSend2MasterMachine(Record.iMsgRx, cmVIrtualSuperVi, TProtoC2C::mtSv);
		}
	}
}

void TDevProperty::SimFeedBack(unsigned char aP0, unsigned char aP1)
{
	unsigned char tP0,tP1;
	if(aP0 == 0)return;
	if(aP1 == 0)return;
	if(aP0 >dPORT_MAX_COUNT)return;
	if(aP1 >dEP_MAX_COUNT_PER_PORT)return;
	
	tP0 = aP0-1;	tP1 = aP1 -1;
	
	if( (Port[tP0].FuncSetByte[tP1] & 0x07) == 0x02){
			SimFire(aP0,aP1);
			return;
	}else
	if( (Port[tP0].FuncSetByte[tP1] & 0x07) ==  0x04){
			SimSv(aP0,aP1);
			return;
	}
			
	Record.InnerMsgSetYear		(0, DateTime.Date.Split.Year);
	Record.InnerMsgSetMonth		(0, DateTime.Date.Split.Month);
	Record.InnerMsgSetDay		(0, DateTime.Date.Split.Day);
	Record.InnerMsgSetHour		(0, DateTime.Time.Split.Hour);
	Record.InnerMsgSetMinute	(0, DateTime.Time.Split.Minute);
	Record.InnerMsgSetSecond	(0, DateTime.Time.Split.Second);	
	Record.InnerMsgSet_mType	(0, CmdActiveDefaultSet[cmAck][7]);
	Record.InnerMsgSet_CtlNum	(0, MainCtl.fData.Split.MyNum );	//(0,aRxMsg.Data.D8[1]);
	
	Record.InnerMsgSet_P0		(0,aP0);
	Record.InnerMsgSet_P1		(0,aP1);
	Record.InnerMsgSet_P2		(0,0);
	Record.InnerMsgSet_dType	(0,0);
	Record.InnerMsgSet_Data0	(0,0);
	Record.InnerMsgSet_Data1	(0,TControlCenter::StartTypeSimulate);
	Record.InnerMsgSet_iByte0	(0,CmdActiveDefaultSet[cmAck][8]);
	Record.InnerMsgSet_iByte1	(0,0);
	
	InnerCan.GetEpUserCodeAreaNumDevType(aP0, aP1, &Record.iMsgRx.Splite.UserCode, &Record.iMsgRx.Splite.AreaNum, &Record.iMsgRx.Splite.dType);

	if(Register.IsDevRegisting != 0x00A5A5A5){
		if(CtlCenter.iePushOneMsgLinkageFbSimulate(Record.iMsgRx)){
			Record.LinkageAdd(Record.iMsgRx);
			ProtoC2C.SlaveDoSend2MasterMachine(Record.iMsgRx, cmVIrtualAck, TProtoC2C::mtLink);
		}
	}
}
















