Exemplo n.º 1
0
        public void Start()
        {
            if (!tcpClient.Connected)
            {
                Console.WriteLine("Error: Server is disconnected");
                ErrorInfo = "Error: Server is disconnected";
                Disconnect();
                return;
            }

            new Thread(delegate()
            {
                stop = false;
                string tmpLongitude, tmpLatitude;
                while (!stop)
                {
                    try
                    {
                        //Heading
                        Heading = SendCommand(HEADING, false);

                        //VerticalSpeed
                        VerticalSpeed = SendCommand(VERTICAL_SPEED, false);

                        //GroundSpeed
                        GroundSpeed = SendCommand(GROUND_SPEED, false);

                        //AirSpeed
                        AirSpeed = SendCommand(AIR_SPEED, false);

                        //Altitude
                        Altitude = SendCommand(ALTITUDE, false);

                        //Roll
                        Roll = SendCommand(ROLL, false);

                        //Pitch
                        Pitch = SendCommand(PITCH, false);

                        //Altimeter
                        Altimeter = SendCommand(ALTIMETER, false);


                        ///get location info
                        tmpLatitude = "0"; tmpLongitude = "0";
                        prevLat     = originalLat; prevLong = originalLong;

                        //Latitude
                        Latitude    = SendCommand(LATITUDE, false);
                        tmpLatitude = Latitude;
                        if (!Latitude.Contains("ERR"))
                        {
                            originalLat = Double.Parse(Latitude);
                        }

                        //Longitude
                        Longitude    = SendCommand(LONGITUDE, false);
                        tmpLongitude = Longitude;
                        if (!Longitude.Contains("ERR"))
                        {
                            originalLong = Double.Parse(Longitude);
                        }

                        //Location
                        if (originalLat > 90)
                        {
                            originalLat = 90;
                            tmpLatitude = "90";
                        }
                        else if (originalLat < -90)
                        {
                            originalLat = -90;
                            tmpLatitude = "-90";
                        }
                        if (originalLong > 180)
                        {
                            originalLong = 180;
                            tmpLongitude = "180";
                        }
                        else if (originalLong < -180)
                        {
                            originalLong = -180;
                            tmpLongitude = "-180";
                        }
                        Location = tmpLatitude + "," + tmpLongitude;

                        //Angle
                        if (calcAngle)
                        {
                            Angle = AngleFromCoordinate(prevLat, prevLong, originalLat, originalLong).ToString();
                        }


                        Thread.Sleep(250); //read the data in 4Hz
                    }
                    catch (ArgumentNullException e)
                    {
                        Console.WriteLine("ArgumentNullException: {0}", e);
                        ErrorInfo = e.Message;
                    }
                    catch (SocketException e)
                    {
                        Console.WriteLine("SocketException: {0}", e);
                        ErrorInfo = e.Message;
                    }
                }
                System.Diagnostics.Debug.WriteLine("Client thread has been Stopped!");
            }).Start();
        }