///接收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();//不要自动应答 }
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(); // // } // }
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; } }