Ejemplo n.º 1
0
        private void CheckConnection()
        {
            client = new TCP();

            Debug.WriteLine("Thread is running");

            while (!DroneStatus.IsConnected)
            {
                Debug.WriteLine("Checking connection");

                try
                {
                    byte[] response = client.Send(new GetServerVersion().GetCommand(), 32);
                    Debug.WriteLine(MessagePackSerializer.ConvertToJson(response));

                    if (response.Length > 0)
                    {
                        Debug.WriteLine("We're connected!");
                        DroneStatus.IsConnected = true;


                        mainPage.UpdateButton("Connected!");

                        client.Close();
                    }
                } catch (Exception e)
                {
                    Debug.WriteLine("Error: " + e.Message);
                }

                // Check connection every 3 seconds
                Thread.Sleep(3000);
            }
        }
Ejemplo n.º 2
0
        public static void GetState()
        {
            client = new TCP();

            byte[]  response = client.Send(new MultirotorState().GetCommand(), 1024);
            dynamic json     = JsonConvert.DeserializeObject(MessagePackSerializer.ConvertToJson(response));

            JToken parsed = JToken.Parse(MessagePackSerializer.ConvertToJson(response));
            JToken val    = parsed[3]["landed_state"];

            IsFlying = (bool)val;

            // 0 is landed
            // 1 is flying
            Debug.WriteLine(IsFlying);

            client.Close();
        }
Ejemplo n.º 3
0
        public void StartMissionLoop(ArrayList commands)
        {
            TCP client = new TCP();

            foreach (MessagePackCommand command in commands)
            {
                if (command.Method == "hover")
                {
                    int delay = Convert.ToInt32(command.args[0]);
                    Debug.WriteLine("Delaying for {0}", delay);
                    Thread.Sleep(delay);
                }
                else
                {
                    client.Send(command, 128);
                }

                // This may be unnecessary between commands
                Thread.Sleep(500);
            }

            client.Close();
        }