public void SetThrottle(string s)
 {
     try
     {
         mutex.WaitOne();
         string toSend = "set " + "/controls/engines/current-engine/throttle " + s + "\n";
         telnetClient.Write(toSend);
         ValidSet(s, "Throttle");
         mutex.ReleaseMutex();
     }
     catch (Exception e)
     {
         Error = e.Message + "\n";
     }
 }
        // Constructor.
        public MySimulatorModel(IConfiguration config)
        {
            mutex        = new Mutex();
            telnetClient = new MyTelnetClient();
            string ip          = config.GetConnectionString("IP");
            string socket_port = config.GetConnectionString("socket_port");

            this.Connect(ip, socket_port);
            telnetClient.Write("data\n");
        }
Exemple #3
0
        // Get the values from the simulator.
        public void Start()
        {
            try
            {
                new Thread(delegate()
                {
                    while (telnetClient.isConnect)
                    {
                        // Update dashboard variables.
                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /instrumentation/heading-indicator/indicated-heading-deg\n");
                            Indicated_heading_deg = telnetClient.Read();
                            // Console.WriteLine(Indicated_heading_deg);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }

                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /instrumentation/gps/indicated-vertical-speed\n");
                            Gps_indicated_vertical_speed = telnetClient.Read();
                            // Console.WriteLine(Gps_indicated_vertical_speed);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }

                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /instrumentation/gps/indicated-ground-speed-kt\n");
                            Gps_indicated_ground_speed_kt = telnetClient.Read();
                            // Console.WriteLine(gps_indicated_ground_speed_kt);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }

                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /instrumentation/airspeed-indicator/indicated-speed-kt\n");
                            Airspeed_indicator_indicated_speed_kt = telnetClient.Read();
                            // Console.WriteLine(Airspeed_indicator_indicated_speed_kt);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }
                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /instrumentation/gps/indicated-altitude-ft\n");
                            Gps_indicated_altitude_ft = telnetClient.Read();
                            // Console.WriteLine(Gps_indicated_altitude_ft);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }
                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /instrumentation/attitude-indicator/internal-roll-deg\n");
                            Attitude_indicator_internal_roll_deg = telnetClient.Read();
                            // Console.WriteLine(Attitude_indicator_internal_roll_deg);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }
                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /instrumentation/attitude-indicator/internal-pitch-deg\n");
                            Attitude_indicator_internal_pitch_deg = telnetClient.Read();
                            // Console.WriteLine(Attitude_indicator_internal_pitch_deg);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }
                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /instrumentation/altimeter/indicated-altitude-ft\n");
                            Altimeter_indicated_altitude_ft = telnetClient.Read();
                            // Console.WriteLine(Altimeter_indicated_altitude_ft);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }
                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /position/latitude-deg\n");
                            Latitude_deg = telnetClient.Read();
                            // Console.WriteLine(Latitude_deg);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }
                        try
                        {
                            mutex.WaitOne();
                            telnetClient.Write("get /position/longitude-deg\n");
                            Longitude_deg = telnetClient.Read();
                            // Console.WriteLine(Longitude_deg);
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }
                        try
                        {
                            mutex.WaitOne();
                            double Latitude  = Convert.ToDouble(this.Latitude_deg);
                            double Longitude = Convert.ToDouble(this.Longitude_deg);
                            if (Longitude > 180 || Longitude < -180 || Latitude > 90 || Latitude < -90)
                            {
                                throw new Exception("Invalid coordinate values");
                            }
                            Location = Latitude + "," + Longitude;
                            mutex.ReleaseMutex();
                        }
                        catch (Exception e)
                        {
                            Error = e.Message + "\n";
                        }
                        // Read the data in 4HZ
                        Thread.Sleep(250);
                    }
                }).Start();
            }
            catch (Exception e)
            {
                Error = e.Message + "\n";
            }
        }