Exemplo n.º 1
0
//WIFI模块数据,非协议
void DeErrEvent(UartEvent e)
{
	u8 buf[50]={0};
u8 bufip[15]={0};
u8 *bufipp;
u8 bufp[4]={0};
	char *buf1;
	char *buf2;
u8 i;
u8 f;
	if(getid==1)
	{
		getid=0;
		memset(meDev.ID,0,12);
		memset(meDev.IP,0,4);
		e->ReadBuff(buf,packlen);
		
		buf1 = strstr((char *)buf,"id:");
		if(buf1==NULL) return ;
		buf1+=3;
		i=0;
		while((*buf1) != ' ')
		{
			meDev.ID[i++] = *buf1;
			buf1++;
		}
		
		buf2 = strstr((char *)buf1,"ip:");
		if(buf2==NULL) return;
		buf2+=3;
		i=0;
		while((*buf2) != ' ')
		{
			bufip[i++]=*buf2;
			buf2++;
		}
		
		bufipp=(u8 *)bufip;
		for(f=0;f<3;f++)
		{
			i=0;
			bufp[0]=bufp[1]=bufp[2]=0;
			while(*bufipp!='.')
			{
				bufp[i] = *bufipp;
				bufipp++;
				i++;
			}
			bufipp++;
			bufp[i]='\0';
			meDev.IP[f]=atoi((char *)bufp);
		}
		i=0;
		bufp[0]=bufp[1]=bufp[2]=0;
		while(*bufipp!='\0')
		{
			bufp[i] = *bufipp;
			bufipp++;
			i++;
		}
		bufp[i]='\0';
		meDev.IP[3] = atoi((char *)bufp);
		
		
		if(meDev.IP[0]!=0&&meDev.IP[1]!=0&&meDev.IP[2]!=0&&meDev.IP[3]!=0)
		Timer.Stop(getIPIDid);
		
//		LCD_Fill(30,20,200,60,WHITE);
//		LCD_ShowString(30,20,200,16,16,meDev.ID);	
//		LCD_ShowString(30,40,200,16,16,bufip);	
	}
	
	
}
Exemplo n.º 2
0
void SetDataEvent(UartEvent e)
{
	u8 id;
	id=e->ReadByte();
	if(lastCodeID==id)return;
	lastCodeID=id;
	switch(e->ReadByte())
	{
		case 0:
			RightSpeed.P=LeftSpeed.P=e->ReadByte();
			RightSpeed.I=LeftSpeed.I=e->ReadByte();
			RightSpeed.D=LeftSpeed.D=e->ReadByte();			
			break;
		case 1:
			//e->ReadBuff((u8*)StatsCode,9);
			break;
		case 2:
			//fmaxlen= e->ReadByte();
			break;
		case 3:
			PathPos=e->ReadWord();
			PathLen=e->ReadByte();
			e->ReadBuff(&pathbuff[PathPos],PathLen);
			PathLen+=PathPos;
			PathPos=0;
			savecount=PathLen;
			break;
		case 4:
			switch(e->ReadByte())
			{
				case 0:PathSelect|=PathType.Forward; DetectionLogic.Control->ActionRun(Forward,1);lastAction=Forward; 
				EnableTime=1;
				lastTick=TimerTick;
				lastTime=0;
				if(PathPos<PathLen&&PathLen!=0xffff){
					PathPos++;
				}
				RecvCode++;
				break;
				case 1:PathSelect|=PathType.Left; DetectionLogic.Control->ActionRun(Left,1000);lastAction=Left;break;
				case 2:PathSelect|=PathType.Right; DetectionLogic.Control->ActionRun(Right,1000);lastAction=Right;break;
				case 3: DetectionLogic.Control->ActionRun(Back,1000);lastAction=Back;break;
			}
			break;
		case 5:
			DetectionLogic.Control->StopRun();
			PathSelect=PathType.Forward;
			DetectionLogic.Control->ActionRun(Forward,1);
			PathLen=0xffff;
			PathPos=0;
			lastAction=Forward;
			DetectionLogic.Control->StopRun();
			lastTick=TimerTick;
			lastTime=0;
			EnableTime=0;
//			lastCodeID=255;
			break;
		case 6:
			AveSpeedL=e->ReadByte();
			AveSpeedR=e->ReadByte();
			break;
		case 7:
			statusRL = e->ReadByte();
			switch(statusRL)
		{
				case 0:
					Motor.Speed(0,MotorLeftSpeed=0);
					Motor.Speed(1,MotorRightSpeed=0);
					break;
				case 1:
					Motor.Speed(0,MotorLeftSpeed=AveSpeedL);
					Motor.Speed(1,MotorRightSpeed=AveSpeedR);
					break;
				case 2:
					Motor.Speed(0,MotorLeftSpeed=-AveSpeedL);
					Motor.Speed(1,MotorRightSpeed=-AveSpeedR);
					break;
				case 3:
					Motor.Speed(0,MotorLeftSpeed=-AveSpeedL);
					Motor.Speed(1,MotorRightSpeed=AveSpeedR);
					break;
				case 4:
					Motor.Speed(0,MotorLeftSpeed=AveSpeedL);
					Motor.Speed(1,MotorRightSpeed=-AveSpeedR);
					break;
		}
			break;
	}
}