#include "RuntimeData.h"
#include "SimRun.h"

#define TextTopOffSet	6
#define ListLineCnt	10

#define ipdWidth0  	400
#define ipdWidth1		390

const char 	tCmd_98[16] =  "报警      ";
const char 	tCmd_99[16] =  "报警取消  ";
const char 	tCmd_100[16] = "启动      ";
const char 	tCmd_101[16] = "停止      ";
const char 	tCmd_102[16] = "应答      ";
const char 	tCmd_103[16] = "停止应答  ";
const char 	tCmd_104[16] = "消火栓应答";
const char 	tCmd_105[16] = "声光启动  ";
const char 	tCmd_106[16] = "声光停止  ";
	


void TSimRun::Init(int x1, int y1, int aW, int aH, int OwnerX, int OwnerY, u32 aColor)
{
	#define CH	30	//Caption Height
	unsigned short Left,Right, Top, Bottom, Width, Height, i;
	Bound.SetBySize(OwnerX + x1, OwnerY + y1, aW, aH);
	Left = Bound.Left +3;
	Top = Bound.Top+3;
	Width = aW - 7;
	Height = aH - 7;
	Right = Bound.Right -4;
	Bottom = Bound.Bottom -4;
	Caption.Init(Left,Top,Width, CH, 0, 0, clWhite, clMaroon);
	SText.Init(Left+358,Top,434, CH, 0, 0, clWhite, clMaroon);
	Content.Set(Left, Top+CH, Right, Bottom);
	Color = aColor;
	#undef CH
	
	Caption.Border.Color = clGray;
	TMyString::sFromStr("模拟运行与操作-本机", Caption.Text);
	Caption.Visible = 1;
	
	TextColor = clNearBlack;
	SelectedColor = clBlue;
	SelectedTextColor = clNearWhite;
	
	CtlIndex = 0;
	FastIndex = 0;
	OnActive = 0;
	SelectedCmd = 0;
	RunTick = 0;
	
	if(RunState == 0){
		IsReqAdjMode = 1;
	}else{
		IsReqAdjMode = 0;
	}
	
	IsOnShow = 1;
	IsRunCmd =0;
	
	InitData();
}

void TSimRun::RenderBackGround(void)
{
	RectFillRender(Content.Left, Content.Top, Content.Right, Content.Bottom, Color);
}

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

void TSimRun::DrawSelf(void)
{
	unsigned int x, y, x2, y2, w, h;
	
	VertLineRender(Bound.Left,		Bound.Top, 			Bound.Height -1,			0xFFFFFFFF);
	VertLineRender(Bound.Right -1,	Bound.Top +1,		Bound.Height -2,			0xFF808080);
	VertLineRender(Bound.Right,		Bound.Top,			Bound.Height,			0xFF404040);
	
	HorizLineRender(Bound.Left, 		Bound.Top, 			Bound.Width - 1, 			0xFFFFFFFF);
	HorizLineRender(Bound.Left +1, 	Bound.Bottom -1,  	Bound.Width - 2, 			0xFF808080);
	HorizLineRender(Bound.Left,		Bound.Bottom,		Bound.Width,			0xFF404040);
	
	x = Bound.Left +2 ;	
	x2 = Bound.Right -2;
	y = Bound.Top +2;
	y2 = Bound.Bottom - 2;
	w = Bound.Width -4;
	h = Bound.Height - 4;
	VertLineRender	(x,		y, 		h-1,	0xFF808080);
	HorizLineRender	(x,		y, 		w-1,	0xFF808080);
		
	VertLineRender	(x+1,		y+1, 		h-2,	0xFF404040);
	HorizLineRender	(x+1,		y+1, 		w-2,	0xFF404040);
	
	VertLineRender	(x2-1,	y+1, 		h-2,	0xFFD4D0C8);
	HorizLineRender	(x+1,		y2-1, 	w-2,	0xFFD4D0C8);

	VertLineRender	(x2,		y, 	  	h,	0xFFFFFFFF);
	HorizLineRender	(x,		y2, 		w,	0xFFFFFFFF);
}


void TSimRun::DrawCaption2(void)
{	
	//TMyString::sFromStr("TAB键在快捷命令与定义命令之间切换", SText.Text);
	//SText.Show();
}

void TSimRun::Show(void)
{	
	RenderBackGround();
	DrawSelf();
	Caption.Show();
	DrawCaption2();
	
	if(IsReqAdjMode){
		MessageBox.Init(0, 36, 800, 406, 0, 0, clMoneyGreen) ;
		MessageBox.SetReturnValue(guiMsgNone, guiMsgOkAndReturn, guiMsgReturn,guiMsgNone);
		MessageBox.SetBtnOkCancel();
		MessageBox.Show();
		MessageBox.ReqAdjMode();
	}else{
		InitPanel();
	}
}

void TSimRun::FullRedraw(int Prm)
{	
	if(Prm == 0){
		RenderBackGround();
		DrawSelf();
		Caption.Show();
		DrawCaption2();
		
		if(IsReqAdjMode){
			MessageBox.Init(0, 36, 800, 406, 0, 0, clMoneyGreen) ;
			MessageBox.SetReturnValue(guiMsgNone, guiMsgOkAndReturn, guiMsgReturn,guiMsgNone);
			MessageBox.SetBtnOkCancel();
			MessageBox.Show();
			MessageBox.ReqAdjMode();
		}else{
			aPanel->Show();
		}
	}else
	if(Prm == 1){
		RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], Color);
		
		if(IsReqAdjMode){
			MessageBox.Init(0, 36, 800, 406, 0, 0, clMoneyGreen) ;
			MessageBox.SetReturnValue(guiMsgNone, guiMsgOkAndReturn, guiMsgReturn,guiMsgNone);
			MessageBox.SetBtnOkCancel();
			MessageBox.Show();
			MessageBox.ReqAdjMode();
		}else{
			aPanel->Show();
		}
		
		//if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
	}
}

//______________________________________________________________________________________________________________________________

void TSimRun::ShowType(void)
{	
	int iVal;
	unsigned char aType;
	iVal = aPanel->Edit[4].Str.ToInteger();
	if(iVal > 255)iVal = 255;
	aPanel->Edit[5].Str.FromStr(StrTypeShortName[iVal]);
	aPanel->Edit[5].Show();
}

void TSimRun::Check4Selected(void)
{
	unsigned int i;
	for(i=0; i<5;i++)aPanel->Edit[i].Selected = 0;
	for(i=0; i<11;i++)aPanel->Btn[i].Selected = 0;
	if(1){
		switch(CtlIndex){
			case 0:
				aPanel->Edit[0].Selected = 1;
				break;
			case 1:
				aPanel->Edit[1].Selected = 1;
				break;
			case 2:
				aPanel->Edit[2].Selected = 1;
				break;
			case 3:
				aPanel->Edit[3].Selected = 1;
				break;
			case 4:
				aPanel->Edit[4].Selected = 1;
				break;
			case 5:
				aPanel->Btn[0].Selected = 1;
				break;
			case 6:
				aPanel->Btn[1].Selected = 1;
				break;
			case 7:
				aPanel->Btn[2].Selected = 1;
				break;
			case 8:
				aPanel->Btn[3].Selected = 1;
				break;
			case 9:
				aPanel->Btn[4].Selected = 1;
				break;
			case 10:
				aPanel->Btn[5].Selected = 1;
				break;
			case 11:
				aPanel->Btn[6].Selected = 1;
				break;
			case 12:
				aPanel->Btn[7].Selected = 1;
				break;
			case 13:
				aPanel->Btn[8].Selected = 1;
				break;
			case 14:
				aPanel->Btn[9].Selected = 1;
				break;
			case 15:
				aPanel->Btn[10].Selected = 1;
				break;
			default:

				break;
		}	
	}
}


void TSimRun::InitData()
{
	int i,x;
	unsigned int aAddr;
	Index =0;
	for(i=0; i<64; i++){
		Text[i] =0;
	}
	aAddr = dAddrSdRam_CtrlInf;
	for(i=0; i<10; i++){
		for(x=0; x<64; x++)
			*(volatile unsigned char *)(aAddr + i*64 + x) =0;
	}
}

void TSimRun::FillTime(char *p)
{
	#define stRadix 16
	unsigned int d,e;
	
	d = DateTime.Time.Split.Hour /stRadix % 10;
	e = DateTime.Time.Split.Hour % stRadix;
	p[0] = d + '0';
	p[1] = e + '0';
	p[2] = ':';

	d = DateTime.Time.Split.Minute /stRadix % 10;
	e = DateTime.Time.Split.Minute % stRadix;
	p[3] = d + '0';
	p[4] = e + '0';
	p[5] = ':';
	
	d = DateTime.Time.Split.Second /stRadix % 10;
	e = DateTime.Time.Split.Second % stRadix;
	p[6] = d + '0';
	p[7] = e + '0';
	p[8] = ' ';
	p[9] = 0;
}

void TSimRun::InfInc(unsigned char aCmd, unsigned char aP0, unsigned char aP1, unsigned char aType)
{
	unsigned int aAddr,z;
	aAddr = dAddrSdRam_CtrlInf  + Index * 64;
	if(1){
		FillTime(Text);
		TMyString::sAddOn2Dg(aP0, Text);
		TMyString::sAddOnStr("-", Text);
		TMyString::sAddOn3Dg(SendingAddr, Text);
		TMyString::sAddOnStr(" t", Text);
		TMyString::sAddOn3Dg(SelectedType, Text);
		TMyString::sAddOnStr(" ", Text);
			if(aCmd == 98)
				TMyString::sAddOnStr(tCmd_98,Text);
			else if(aCmd == 99)
				TMyString::sAddOnStr(tCmd_99,Text);
			else if(aCmd == 100)
				TMyString::sAddOnStr(tCmd_100,Text);
			else if(aCmd == 101)
				TMyString::sAddOnStr(tCmd_101,Text);
			else if(aCmd == 102)
				TMyString::sAddOnStr(tCmd_102,Text);
			else if(aCmd == 103)
				TMyString::sAddOnStr(tCmd_103,Text);
			else if(aCmd == 104)
				TMyString::sAddOnStr(tCmd_104,Text);
			else if(aCmd == 105)
				TMyString::sAddOnStr(tCmd_105,Text);
			else if(aCmd == 106)
				TMyString::sAddOnStr(tCmd_106,Text);
			
		TMyString::sFillFixLen(Text, 32);
		TMyString::sBrokeFixLen(Text, 32);
		for(z=0; z<41; z++){
			*(volatile unsigned char *)(aAddr + z) = Text[z];
		}
	}
	Index++;
	if(Index>9)Index=0;
}
		
void TSimRun::ReDrawInf()
{
	int i, z, aInx;
	unsigned int aAddr;
	aInx = Index;
	for(i=0; i<10; i++){
		aAddr = dAddrSdRam_CtrlInf  + aInx * 64;
		for(z=0;z<64;z++){
			Text[z] = *(volatile unsigned char *)(aAddr + z);
		}
		TMyString::sFillFixLen(Text, 32);
		TMyString::sBrokeFixLen(Text, 32);
		TextDigitRender2_24(4, i*36 + 72, clNearWhite, Color, i +1);
		TextRender_string24(40, i*36 + 72, clNearWhite, Color, Text);
		aInx++;
		if(aInx>9)aInx = 0;
	}
	
}

//_____________________________________________________________________________________________________________________________

TGuiMsgReturn TSimRun::KeyIn(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	TGuiMsgReturn MBoxMsg = guiMsgNone;
	int iVal;
	unsigned char Val;
	unsigned char x,y,aCh;

	if(IsReqAdjMode){
		switch(aKey){
			case VK_LEFT:
				MBoxMsg = MessageBox.KeyIn(aKey);
				break;
			case VK_RIGHT:
				MBoxMsg = MessageBox.KeyIn(aKey);
				break;
			case VK_EXECUTE:
				MBoxMsg = MessageBox.KeyIn(aKey);
				if(MBoxMsg == guiMsgOkAndReturn){
					IsReqAdjMode = 0;
					RunState = 1;
					STextAdjust.SetText("调试",24);
					STextAdjust.Color = clMedOrange;
					STextAdjust.Show();
					Show();
				}else
				if(MBoxMsg == guiMsgReturn){
					aMsg = guiMsgReturn;
				}
				break;
			case VK_RETURN:
				IsOnShow = 0;
				aMsg = guiMsgReturn;
				break;
		}
		return aMsg;
	}else{
		switch(aKey){
			case VK_DELETE: 
			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_LEFT:
			case  VK_RIGHT:
				if(CtlIndex < 5){
					aPanel->Edit[CtlIndex].KeyIn(aKey);
					aPanel->Edit[CtlIndex].ReDraw();
					if(CtlIndex == 4){
						ShowType();
					}
				}
				break;
			case VK_UP:
				if(CtlIndex >0){
					CtlIndex--;
					Check4Selected();
					aPanel->ReDrawItems();
				}
				break;
			case VK_DOWN:
				if(CtlIndex <4){
					CtlIndex++;
					Check4Selected();
					aPanel->ReDrawItems();
				}else{
					if(CtlIndex <13){
						CtlIndex +=2;
						if(CtlIndex > 14){
							CtlIndex = 14;
						}
						Check4Selected();
						aPanel->ReDrawItems();
					}else
					if(CtlIndex < 14){
						CtlIndex = 14;
						Check4Selected();
						aPanel->ReDrawItems();
					}else
					if(CtlIndex < 15){
						CtlIndex = 15;
						Check4Selected();
						aPanel->ReDrawItems();
					}
				}
				break;
			case VK_TAB:
				break;
			case VK_EXECUTE:
				//Save Data Here
				if( (CtlIndex >4) && (CtlIndex<14) ){
					//98  cmVIrtualAlram		模拟报警
					//99  cmVIrtualAlramCancle	模拟报警测消
					//100	cmVIrtualStart		模拟启动
					//101	smVIrtualStop		模拟停止
					//102	cmVIrtualAck		模拟应答
					//103	cmVIrtualAckStop		模拟停止应答
					//104	cmVIrtualHydrantAck	模拟消火栓应答
					//105	cmVIrtualVaActive		模拟声光启动
					//106	cmVIrtualVaNotActive	模拟声光停止
					//aP0, aAStart, aAEnd, aType;
					iVal = aPanel->Edit[0].Str.ToInteger();
					aP0 = static_cast<unsigned char>(iVal);
					iVal = aPanel->Edit[1].Str.ToInteger();
					aAStart = static_cast<unsigned char>(iVal);
					iVal = aPanel->Edit[2].Str.ToInteger();
					aAEnd = static_cast<unsigned char>(iVal);
					iVal = aPanel->Edit[3].Str.ToInteger();
					TickCount = static_cast<unsigned char>(iVal);
					iVal = aPanel->Edit[4].Str.ToInteger();
					SelectedType = static_cast<unsigned char>(iVal);
					
					SendingAddr = aAStart;
					switch (CtlIndex){
						case 5: 	SelectedCmd =  98; 	IsRunCmd = 1;	RunTick = 250; break;
						case 6: 	SelectedCmd =  99; 	IsRunCmd = 1;	RunTick = 250; break;
						case 7: 	SelectedCmd =  100; 	IsRunCmd = 1;	RunTick = 250; break;
						case 8: 	SelectedCmd =  101; 	IsRunCmd = 1;	RunTick = 250; break;
						case 9: 	SelectedCmd =  102; 	IsRunCmd = 1;	RunTick = 250; break;
						case 10: 	SelectedCmd =  103; 	IsRunCmd = 1;	RunTick = 250; break;
						case 11: 	SelectedCmd =  105; 	IsRunCmd = 1;	RunTick = 250; break;
						case 12: 	SelectedCmd =  106; 	IsRunCmd = 1;	RunTick = 250; break;
						case 13: 	SelectedCmd =  104; 	IsRunCmd = 1;	RunTick = 250; break;
						case 14: 	SelectedCmd =  0; 	IsRunCmd = 0;	RunTick = 250; break;
					}
				}else
				if(CtlIndex == 14){
					IsRunCmd = 0;
				}else
				if(CtlIndex == 15){		
					IsRunCmd =0;
					RunState = 0;
					STextAdjust.SetText("运行",24);
					STextAdjust.Color = clFrmFace;
					STextAdjust.Show();
					
					IsOnShow = 0;
					aMsg = guiMsgReturn;
				}
				break;
			case VK_RETURN:
				IsRunCmd =0;
				RunState = 0;
				STextAdjust.SetText("运行",24);
				STextAdjust.Color = clFrmFace;
				STextAdjust.Show();
			
				IsOnShow = 0;
				aMsg = guiMsgReturn;
				break;
		}
	}
	
	return aMsg;	
}

void TSimRun::InitPanel(void)
{
	int x,y,x2,y2,i;
	
	y = y+6;
	
	aPanel->Init(450,72,346,360,0,0,clFrmFace, bvRaised);
	aPanel->Caption.Init(451,73, 346-3 ,32,0,0,clFrmFace,clFrmFace);
	
	x = aPanel->Bound.Left;
	y = aPanel->Bound.Top;
	
	aPanel->SText[0].Init(6,3,102,30,x,y,clNearBlack,clFrmFace);
	aPanel->SText[1].Init(6,35,102,30,x,y,clNearBlack,clFrmFace);
	aPanel->SText[2].Init(6,67,102,30,x,y,clNearBlack,clFrmFace);
	aPanel->SText[3].Init(6,99,102,30,x,y,clNearBlack,clFrmFace);

	TMyString::sFromStr("回路", aPanel->SText[0].Text);
	TMyString::sFromStr("地址段", aPanel->SText[1].Text);
	TMyString::sFromStr("间隔时间", aPanel->SText[2].Text);
	TMyString::sFromStr("类型", aPanel->SText[3].Text);
	
	
	for(i=0; i<4;i++){
		aPanel->SText[i].Enable = 1;
		aPanel->SText[i].Visible = 1;
	}
	
	aPanel->Edit[0].Init(112,3,48,30,x,y,1,clNearWhite);
	aPanel->Edit[1].Init(112,35,48,30,x,y,1,clNearWhite);
	aPanel->Edit[2].Init(166,35,48,30,x,y,1,clNearWhite);
	aPanel->Edit[3].Init(112,67,48,30,x,y,1,clNearWhite);
	aPanel->Edit[4].Init(112,99,48,30,x,y,1,clNearWhite);
	aPanel->Edit[5].Init(166,99,176,30,x,y,1,clNearWhite);
	
	aPanel->Btn[0].Init(8,	140,156,30,x,y,1,clFrmFace);
	aPanel->Btn[1].Init(178,140,156,30,x,y,1,clFrmFace);
	aPanel->Btn[2].Init(8,	172,156,30,x,y,1,clFrmFace);
	aPanel->Btn[3].Init(178,172,156,30,x,y,1,clFrmFace);
	aPanel->Btn[4].Init(8,	204,156,30,x,y,1,clFrmFace);
	aPanel->Btn[5].Init(178,204,156,30,x,y,1,clFrmFace);
	aPanel->Btn[6].Init(8,	236,156,30,x,y,1,clFrmFace);
	aPanel->Btn[7].Init(178,236,156,30,x,y,1,clFrmFace);
	
	aPanel->Btn[8].Init(8,	268,156,30,x,y,1,clFrmFace);
	
	aPanel->Btn[9].Init(8,	310,156,30,x,y,1,clFrmFace);
	aPanel->Btn[10].Init(178,310,156,30,x,y,1,clFrmFace);
	
	aPanel->Btn[0].Caption.FromStr("  m报警    ");
	aPanel->Btn[1].Caption.FromStr(" m报警取消 ");
	
	aPanel->Btn[2].Caption.FromStr("   m启动   ");
	aPanel->Btn[3].Caption.FromStr("   m停止   ");
	
	aPanel->Btn[4].Caption.FromStr("   m应答   ");
	aPanel->Btn[5].Caption.FromStr(" m停止应答 ");
	
	aPanel->Btn[6].Caption.FromStr(" m声光启动 ");
	aPanel->Btn[7].Caption.FromStr(" m声光停止 ");
	
	aPanel->Btn[8].Caption.FromStr("m消火栓应答");
	
	aPanel->Btn[9].Caption.FromStr("所有命令停止");
	
	aPanel->Btn[10].Caption.FromStr("退出调试返回");
	
	for(i=0; i<11;i++){
		aPanel->Btn[i].Enable = 1;
		aPanel->Btn[i].Visible = 1;
		aPanel->Btn[i].SetCaptionLeftSpacing(2);
		aPanel->Btn[i].SelectedColor = clBlue;
	}
	for(i=0; i<6;i++){
		aPanel->Edit[i].Enable = 1;
		aPanel->Edit[i].Visible = 1;
		aPanel->Edit[i].SetInputMaskEn();
		aPanel->Edit[i].Str.FromStr("001");
	}
	aPanel->Edit[0].SetMaxLen(2);
	aPanel->Edit[1].SetMaxLen(3);
	aPanel->Edit[2].SetMaxLen(3);
	aPanel->Edit[3].SetMaxLen(2);
	aPanel->Edit[4].SetMaxLen(3);
	aPanel->Edit[5].SetMaxLen(62);
	aPanel->Edit[0].Pst = 1;
	aPanel->Edit[1].Pst = 2;
	aPanel->Edit[2].Pst = 2;
	aPanel->Edit[3].Pst = 1;
	aPanel->Edit[4].Pst = 1;
	aPanel->Edit[5].Pst = -1;

	aPanel->Edit[5].Enable = 0;
	
	aPanel->Btn[0].SetCaptionLeftSpacing(4);
	aPanel->Btn[1].SetCaptionLeftSpacing(4);
	aPanel->Btn[2].SetCaptionLeftSpacing(4);
	aPanel->Btn[3].SetCaptionLeftSpacing(4);
	aPanel->Btn[4].SetCaptionLeftSpacing(4);
	aPanel->Btn[5].SetCaptionLeftSpacing(4);
	aPanel->Btn[6].SetCaptionLeftSpacing(4);
	aPanel->Btn[7].SetCaptionLeftSpacing(4);
	aPanel->Btn[8].SetCaptionLeftSpacing(4);
	
	aPanel->Caption.Visible = 1;
	
	aPanel->Show();
	Check4Selected();
	aPanel->ReDrawItems();
	
	ShowType();
}

void TSimRun::SendCmd()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	
	Len = aPanel->Edit[9].Str.ToInteger();
	if(Len >8)Len =8;
	
	iVal = aPanel->Edit[0].Str.ToInteger();
	if(iVal>255)iVal=255;
	cVal = iVal;
	aIde.BitF.Cmd = cVal;
	
	for(i=0; i<8; i++){
		Data[i] = 0;
	}
	
	for(i=0; i<Len; i++){
		iVal = aPanel->Edit[i+1].Str.ToInteger();
		if(iVal>255)iVal=255;
		cVal = iVal;
		Data[i] = cVal;
	}
	
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	InnerCan.CmdSendCustom(aIde, Data, Len);
}

void TSimRun::SendFastCmd()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	
	if(FastIndex == 0){
		// 15 Start 手动启动
		aIde.BitF.Cmd = 15;
		Len = 5;
	}else
	if(FastIndex == 1){
		// 16 Stop  手动停止
		aIde.BitF.Cmd = 16;
		Len = 5;
	}else
	if(FastIndex == 2){
		//  18 自动启动
		aIde.BitF.Cmd = 18;
		Len = 5;
	}else
	if(FastIndex == 3){
		//  19 自动停止
		aIde.BitF.Cmd = 19;
		Len = 5;
	}else
	if(FastIndex == 4){
		// 25 声光启动
		aIde.BitF.Cmd = 25;
		Len = 3;
	}else
	if(FastIndex == 5){
		// 26 声光停止
		aIde.BitF.Cmd = 26;
		Len = 2;
	}
	
	for(i=0; i<8; i++){
		Data[i] = 0;
	}
	
	for(i=0; i<Len; i++){
		iVal = aPanel->Edit[i+1].Str.ToInteger();
		if(iVal>255)iVal=255;
		cVal = iVal;
		Data[i] = cVal;
	}
	
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	InnerCan.CmdSendCustom(aIde, Data, Len);
}

void TSimRun::Task1000Ms()
{
	if(IsOnShow){
		if(IsRunCmd){
			RunTick++;
			if(RunTick >= TickCount){
				RunTick = 0;
				if( (SendingAddr < aAStart) || (SendingAddr > aAEnd) ){
					SendingAddr = aAStart;
				}
				InfInc(SelectedCmd, aP0, SendingAddr, SelectedType);
				ReDrawInf();
			}
		}
	}
}

int TSimRun::ExtRequst(unsigned char Prm)
{
	IsOnShow =0;
	IsRunCmd =0;
	RunState = 0;
	STextAdjust.SetText("运行",24);
	STextAdjust.Color = clFrmFace;
	STextAdjust.Show();
	return 0;
}






