private void clientdata(IAsyncResult ar) { var client = ((UdpClient)ar.AsyncState); if (client == null || client.Client == null) { return; } try { var port = ((IPEndPoint)client.Client.LocalEndPoint).Port; var udpclient = new UdpSerial(client); var mav = new MAVLinkInterface(); mav.BaseStream = udpclient; MainV2.comPort = mav; MainV2.Comports.Add(mav); //MainV2.instance.doConnect(mav, "preset", port.ToString()); Log.Warning("", "mav init " + mav.ToString()); var hb = mav.getHeartBeat(); Log.Warning("", "getHeartBeat " + hb.ToString()); mav.setAPType(mav.MAV.sysid, mav.MAV.compid); Log.Warning("", "setAPType " + mav.MAV.ToJSON()); Forms.Device.BeginInvokeOnMainThread(() => { }); Task.Run(() => { while (true) { try { while (mav.BaseStream.BytesToRead < 10 || mav.giveComport == true) { Thread.Sleep(20); } var packet = mav.readPacket(); mav.MAV.cs.UpdateCurrentSettings(null); } catch (Exception ex) { Log.Warning("", ex.ToString()); Thread.Sleep(10); } } }); } catch (Exception ex) { Log.Warning("", ex.ToString()); } }
public void UpdateIcon(MAVLinkInterface mav, float x, float y, float z, bool movable) { foreach (var icon in icons) { if (icon.interf == mav) { icon.Movable = movable; if (!movable) { icon.x = 0; icon.y = 0; icon.z = 0; icon.Color = Color.Blue; } else { icon.x = x; icon.y = y; icon.z = z; icon.Color = Color.Red; } this.Invalidate(); return; } } Console.WriteLine("ADD MAV {0} {1} {2}", x, y, z); icons.Add(new icon() { interf = mav, y = y, z = z, x = x, Movable = movable, Name = mav.ToString() }); }