public void ValidSet(string source, string variable) { string var = ""; switch (variable) { case "Throttle": var = "/controls/engines/engine[0]/throttle"; break; case "Aileron": var = "/controls/flight/aileron"; break; case "Elevator": var = "/controls/flight/elevator"; break; case "Rudder": var = "/controls/flight/rudder"; break; } mutex.WaitOne(); telnetClient.Write("get " + var + "\n"); string current = telnetClient.Read(); if (source != current) { // Error Console.WriteLine("error post" + variable); } mutex.ReleaseMutex(); }
// 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"; } }