示例#1
0
文件: wifi.c 项目: xinshaochen/WIFI
///接收IP,发送自己的IP
void SendMeIPEvent(UartEvent e)
{
	sendIP[0]=192;
	sendIP[1]=168;
	sendIP[2]=1;
	sendIP[3]=e->ReadByte();
	
	sprintf((char *)sendIPstr,"%d.%d.%d.%d\0",sendIP[0],sendIP[1],sendIP[2],sendIP[3]);
	ConnectSendCode(sendIPstr,2333,0,&meDev.IP[3],1);
	e->noack();//不要自动应答
}
示例#2
0
文件: wifi.c 项目: xinshaochen/WIFI
void AliveEvent(UartEvent e)
{
	u8 i;
	u8 l;
	u8 s=0;
	u8 buf[4];
	
	buf[0]=192;
	buf[1]=168;
	buf[2]=1;
	buf[3]=e->ReadByte();
	
	if (remoteDevCount >= 15) return;

	if(remoteDevCount>0)
	{
		for(i=0;i<remoteDevCount;i++)
		{
			for(l=0;l<4;l++)
			{
				if(buf[l]== remoteDev[i].IP[l])
				{
					s++;
				}
			}
			if(s>=4)
			{
				break;
			}else
			s=0;
		}
		if(i==remoteDevCount)//列表没有相同IP
		{
			
			for(l=0;l<4;l++)
			{
				remoteDev[remoteDevCount].IP[l] =buf[l];
			}
			sprintf((char *)remoteDev[remoteDevCount].IPstr,"%d.%d.%d.%d\0",remoteDev[remoteDevCount].IP[0],remoteDev[remoteDevCount].IP[1],
			remoteDev[remoteDevCount].IP[2],remoteDev[remoteDevCount].IP[3]);
			
			remoteDevCount++;
		}
		
	}else
	{
		for(l=0;l<4;l++)
		{
			remoteDev[0].IP[l]=buf[l];
		}
		sprintf((char *)remoteDev[remoteDevCount].IPstr,"%d.%d.%d.%d\0",remoteDev[remoteDevCount].IP[0],remoteDev[remoteDevCount].IP[1],
			remoteDev[remoteDevCount].IP[2],remoteDev[remoteDevCount].IP[3]);
		remoteDevCount++;

	}
	
//	e->ReadBuff(type,4);
//	if(strstr((const char*)type,"Tx0")!=NULL)
//	{
//		e->WriteString("useIP()");
//		e->WriteString((u8 *)"Rx0");//设备类型
//		e->SendAckPacket();
//	
//	}
//	
}
示例#3
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;
	}
}
示例#4
0
文件: wifi.c 项目: xinshaochen/WIFI
//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);	
	}
	
	
}
示例#5
0
void GetDataEvent(UartEvent e)
{
	u8 i;
	s16 yawvalue;
	SensorStatus val=Sensor.Read();
  //mpu_dmp_get_data(&pitch,&roll,&yaw);
	yawvalue=yaw;
	e->WriteDWord(0);
	e->WriteDWord(val&0xffffffff);
	e->WriteWord(flen);
	e->WriteWord(blen);
	e->WriteByte(MotorLeftSpeed);//lspeed
	e->WriteByte(MotorRightSpeed);//rspeed
  e->WriteWord(yawvalue);
	e->WriteByte(lastBatteryValue);
	e->WriteWord(PathPos);
	e->WriteByte(lastAction);
	e->WriteByte(PathSelect);
	e->WriteByte(lastCodeID);
	e->WriteByte(RecvCode);
	if(EnableTime)lastTime=TimerTick-lastTick;
	e->WriteWord(lastTime);
	e->WriteDWord(lastIDCard);
	for(i=0;i<MaxSensor;i++)
	{
		e->WriteWord(Sensor.GetCHValue(i));		
	}
	e->SendAckPacket();
}