public static async Task ConnectAsync(string hostName = HOST_NAME, string port = REMOTE_PORT) { if (!StubMode) { #if WINDOWS_APP || WINDOWS_PHONE_APP // Set up the UDP connection. var droneIP = new HostName(hostName); udpSocket = new DatagramSocket(); await udpSocket.BindServiceNameAsync(port); await udpSocket.ConnectAsync(droneIP, port); udpWriter = new DataWriter(udpSocket.OutputStream); udpWriter.WriteByte(1); await udpWriter.StoreAsync(); #else udpSocket = new UdpClient(); udpSocket.Connect(hostName, int.Parse(port)); byte[] datagram = new byte[1] { 1 }; await udpSocket.SendAsync(datagram, datagram.Length); #endif } var loop = Task.Run(() => DroneLoop()); }
// Send a command to the drone private static async Task SendCommandAsync(string command) { var message = string.Format("Command: {0}", command); #if WINDOWS_APP || WINDOWS_PHONE_APP Debug.WriteLine(message); #else Trace.WriteLine(message); #endif if (!StubMode) { #if WINDOWS_APP || WINDOWS_PHONE_APP udpWriter.WriteString(command); await udpWriter.StoreAsync(); #else byte[] datagram = Encoding.ASCII.GetBytes(command); await udpSocket.SendAsync(datagram, datagram.Length); #endif } }