/// <summary> /// Processing incoming command /// </summary> private void ProcessCommands() { //NetworkStream stream = _client.GetStream(); foreach (AsyncCommand command in _queue.GetConsumingEnumerable()) { Result res; try { //Sending data to the simulator _tcp.write("set /controls/engines/current-engine/throttle " + String.Format("{0:0.##}", command.Command.throttle) + "\r\n"); _tcp.write("set /controls/flight/rudder " + String.Format("{0:0.##}", command.Command.rudder) + "\r\n"); _tcp.write("set /controls/flight/aileron " + String.Format("{0:0.##}", command.Command.aileron) + "\r\n"); _tcp.write("set /controls/flight/elevator " + String.Format("{0:0.##}", command.Command.elevator) + "\r\n"); //check validation res = ValidateData(command.Command); } catch { res = Result.NotOk; } //Check is value defined and then set Result command.Completion.SetResult(res); } }
public void start() { new Thread(delegate() { while (!stop) { //push the message to the server. pushMassege(); while (queue.Count > 0) { str = queue.Dequeue(); telnetClient.write(str); var task = Task.Run(() => (value = telnetClient.read())); //check for timeout of 10 seconds. if (task.Wait(TimeSpan.FromSeconds(10))) { property = checkProperty(str); initializeProperty(property, value); } //shoe the right message of timeout. else { ErrorMessage = "Theres no information from the\nserver for over 10 seconds."; } } Thread.Sleep(250); //read the data in 4Hz } }).Start(); }
/** * start func - where everything is happen! * reading from the server, set theam in there properties. * if the server is crushed or disconnected put the plan in Ben Gurion Air Port * and notify that. */ public void start() { new Thread(delegate() { while (!stop) { try { mutex.WaitOne(); String data = ""; // reading from the server. telnetClient.write("get /instrumentation/attitude-indicator/internal-roll-deg\r\n " + "get /instrumentation/attitude-indicator/internal-pitch-deg\r\n " + "get /instrumentation/gps/indicated-vertical-speed\r\n" + "get /instrumentation/gps/indicated-ground-speed-kt\r\n" + "get /instrumentation/airspeed-indicator/indicated-speed-kt\r\n" + "get /instrumentation/heading-indicator/indicated-heading-deg\r\n" + "get /instrumentation/gps/indicated-altitude-ft\r\n" + "get /instrumentation/altimeter/indicated-altitude-ft\r\n" + "get /position/latitude-deg\r\n" + "get /position/longitude-deg\r\n" + "get /controls/flight/aileron\r\n" + "get /controls/engines/current-engine/throttle\r\n" + "get /controls/flight/elevator\r\n" + "get /controls/flight/rudder\r\n"); // reading 4 time in a secoend. Thread.Sleep(250); data = telnetClient.read(); mutex.ReleaseMutex(); setEverything(data); Debug.WriteLine(longtitude + " , " + Latitude); // check if the plan is in earth if ((longtitude <= 180 && longtitude >= -180) && (latitude <= 90 && latitude >= -90)) { Location = latitude + "," + longtitude; } else { ErrorString = "go back!! this is the end of the world!"; } // read the data in 4Hz } // notify there is timeout catch (IOException e) { ErrorString = "timeout! lets wait some more!"; } // if the server crushed or disconnected. catch (Exception e) { ErrorString = "cannot use the server!"; mutex.WaitOne(); latitude = 32.005; longtitude = 34.887; Location = latitude + "," + longtitude; mutex.ReleaseMutex(); } } }).Start(); }
public void setValue(ITelnetClient myTelnetClient, string property, double value) { ITelnetClient telnetClient = myTelnetClient; string set = null; if (property.Equals("throttle")) { set = "set /controls/engines/current-engine/" + property + " " + value + "\r\n"; } else { set = "set /controls/flight/" + property + " " + value + "\r\n"; } telnetClient.write(set); }
public void startSetThread() { new Thread(delegate() { while (isConnected) { //execute the commands while (this.myQueue.Count != 0) { string cmd = this.myQueue.Dequeue(); telnetClient.write(cmd); } } }).Start(); }
public string checkSet(ITelnetClient myTelnetClient, string property, double value) { ITelnetClient telnetClient = myTelnetClient; string get = null; if (property.Equals("throttle")) { get = "get /controls/engines/current-engine/" + property + "\r\n"; } else { get = "get /controls/flight/" + property + "\r\n"; } telnetClient.write(get); string retValue = telnetClient.read(); Console.WriteLine(retValue); string s; double newRet = Convert.ToDouble(retValue); if (retValue.ToString().Length > 7) { s = retValue.ToString().Substring(0, 7); newRet = Convert.ToDouble(s); } double newVal = value; if (value.ToString().Length > 7) { s = value.ToString().Substring(0, 7); newVal = Convert.ToDouble(s); } if (newRet == newVal) { return("Ok"); } else { return("NotOk"); } }
public void start() { // testing xmlParser XmlNodeList parsedXML = parseXML("playback_small.xml"); List <int> indexList = new List <int>(); PointsSelectedFeature = new List <DataPoint>(); PointsCorrelatedFeature = new List <DataPoint>(); PointsSelectedAndCorrelated = new List <DataPoint>(); RegressionLinePoints = new List <DataPoint>(); Last30SecPoints = new List <DataPoint>(); // open client connection telnetClient.connect("localhost", 5400); // lastSelectedFeatureIndex to clean the plot int lastSelectedFeatureIndex = -1; int lastSelectedAnomaly = -1; int startOfPlotIndex = 0; new Thread(delegate() { while ((!stop) && (currentRow < rowsList.getNumOfRows())) { while (pause) { continue; } telnetClient.write(rowsList.printRow(currentRow)); Thread.Sleep(playbackSpeed); string[] parsedLine = parseLine(rowsList.printRow(currentRow)); if (parsedLine.Length > 1) { Rudder = float.Parse(parsedLine[getAttributeIdx("rudder", parsedXML, 1)]); Throttle1 = float.Parse(parsedLine[getAttributeIdx("throttle", parsedXML, 1)]); Throttle2 = float.Parse(parsedLine[getAttributeIdx("throttle", parsedXML, 2)]); Aileron = 125 + (75 * float.Parse(parsedLine[getAttributeIdx("aileron", parsedXML, 1)])); Elevator = 125 + (75 * float.Parse(parsedLine[getAttributeIdx("elevator", parsedXML, 1)])); Altitude = float.Parse(parsedLine[getAttributeIdx("altitude-ft", parsedXML, 1)]); Airspeed = float.Parse(parsedLine[getAttributeIdx("airspeed-kt", parsedXML, 1)]); HeadingDeg = float.Parse(parsedLine[getAttributeIdx("heading-deg", parsedXML, 1)]); Pitch = float.Parse(parsedLine[getAttributeIdx("pitch-deg", parsedXML, 1)]); Roll = float.Parse(parsedLine[getAttributeIdx("roll-deg", parsedXML, 1)]); Yaw = float.Parse(parsedLine[getAttributeIdx("side-slip-deg", parsedXML, 1)]); } // identify change in selected feature if (lastSelectedFeatureIndex != selectedFeatureIndex) { startOfPlotIndex = currentRow; PointsSelectedFeature = new List <DataPoint>(); PointsCorrelatedFeature = new List <DataPoint>(); AnomalyPoints = new List <DataPoint>(); AnomalyIdxList = new List <string>(); // Add Scatter Plot PointsSelectedAndCorrelated = rowsList.getDataPointSeries(selectedFeatureIndex, rowsList.highestCorrelationInds[selectedFeatureIndex]); OnPropertyChanged("PointsSelectedAndCorrelated"); RegressionLinePoints = rowsList.getRegressionLine(selectedFeatureIndex, rowsList.highestCorrelationInds[selectedFeatureIndex]); OnPropertyChanged("RegressionLinePoints"); //Last30SecPoints = new List<DataPoint>(); //TODO: init with last 30 sec or from the beginning Last30SecPoints = PointsSelectedAndCorrelated.GetRange(0, currentRow); lastSelectedFeatureIndex = selectedFeatureIndex; if (dllDynamic != null) { dllDynamic.Update(selectedFeatureIndex, rowsList.highestCorrelationInds[selectedFeatureIndex], csvFile.FileName, csvFileDetect.FileName); indexList = dllDynamic.getModel().getAnomalyList(); foreach (int index in indexList) { AnomalyPoints.Add(PointsSelectedAndCorrelated[index]); AnomalyIdxList.Add(String.Format("{0}:\t ({1},{2})", index, PointsSelectedAndCorrelated[index].X, PointsSelectedAndCorrelated[index].Y)); } OnPropertyChanged("AnomalyPoints"); OnPropertyChanged("AnomalyIdxList"); } } PointsSelectedFeature.Add(new DataPoint(currentRow, float.Parse(parsedLine[selectedFeatureIndex]))); PointsCorrelatedFeature.Add(new DataPoint(currentRow, float.Parse(parsedLine[rowsList.highestCorrelationInds[selectedFeatureIndex]]))); OnPropertyChanged("PointsSelectedFeature"); OnPropertyChanged("PointsCorrelatedFeature"); // Add to Last30SecPoints Last30SecPoints.Add(new DataPoint(float.Parse(parsedLine[selectedFeatureIndex]), float.Parse(parsedLine[rowsList.highestCorrelationInds[selectedFeatureIndex]]))); while (Last30SecPoints.Count > 30 * (1000 / playbackSpeed)) { Last30SecPoints.RemoveAt(0); } OnPropertyChanged("Last30SecPoints"); // read new line CurrentRow++; if (indexList.Count > 0) { if (lastSelectedAnomaly != selectedAnomaly) { CurrentRow = indexList[selectedAnomaly]; lastSelectedAnomaly = selectedAnomaly; lastSelectedFeatureIndex = -1; } } } }).Start(); }
public void start() { if (isConnected) { isStarted = true; this.PlaybackSpeed = 10; new Thread(delegate() { bool playbackSpeedZero = false; while (!stop) { float playbackSpeedRational = 10; if (this.playbackSpeed == 0.0) { playbackSpeedZero = true; } else { playbackSpeedZero = false; playbackSpeedRational = 1000 / this.playbackSpeed; } // Keeping the animation running if (this.currentLineIndex < this.csvLinesNumber && !playbackSpeedZero && !isPaused) { telnetClient.write(this.csvLines[this.currentLineIndex]); // Joystick AileronCurrentValue = (float)Convert.ToDouble(this.csvDict[0][this.currentLineIndex]); ElevatorCurrentValue = (float)Convert.ToDouble(this.csvDict[1][this.currentLineIndex]); ThrottleCurrentValue = (float)Convert.ToDouble(this.csvDict[6][this.currentLineIndex]); RudderCurrentValue = (float)Convert.ToDouble(this.csvDict[2][this.currentLineIndex]); // Data Display CurrentAltimeter = (float)Convert.ToDouble(this.csvDict[24][this.currentLineIndex]); CurrentAirSpeed = (float)Convert.ToDouble(this.csvDict[20][this.currentLineIndex]); CurrentHeading = (float)Convert.ToDouble(this.csvDict[18][this.currentLineIndex]); CurrentPitch = (float)Convert.ToDouble(this.csvDict[17][this.currentLineIndex]); CurrentRoll = (float)Convert.ToDouble(this.csvDict[16][this.currentLineIndex]); CurrentYaw = (float)Convert.ToDouble(this.csvDict[19][this.currentLineIndex]); this.CurrentLineIndex += 1; float nTime = this.currentLineIndex / 10; Time = TimeSpan.FromSeconds(nTime).ToString(); } DataPointsList = RenderDataPointsList(this.CurrentAttribute); if (findCorrelativeAttribute(this.currentAttribute) == "") { DataPointsListToCorrelative = this.regressionDataPointsList.GetRange(0, 0); } else { DataPointsListToCorrelative = RenderDataPointsList(this.CurrentCorrelativeAttribute); } // Last 30 seconds. if (this.isPressed) { if (findCorrelativeAttribute(this.currentAttribute) == "") { LastRecordsPointsList = this.regressionDataPointsList.GetRange(0, 0); } else if (this.currentLineIndex < 300) { LastRecordsPointsList = this.regressionDataPointsList.GetRange(0, this.currentLineIndex); } else { LastRecordsPointsList = this.regressionDataPointsList.GetRange( this.currentLineIndex - 300, 300); } } Thread.Sleep((int)playbackSpeedRational); } }).Start(); } }
public void sendStringCommand(string command) { client.write(command); }
/*public void connect(string ip, int port) * { * telnet.connect(ip, port); * }*/ /*public void disconnect() * { * //stop = true; * telnet.disconnect(); * }*/ public void write(string data, string ip, int port) { telnet.write(data, ip, port); }
public void Start() { //getting the dashboard information new Thread(delegate() { Console.WriteLine("entered new thread"); if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = "RequestPropsThread"; } while (!stop) { try { mut.WaitOne(); telnetClient.write("get /instrumentation/heading-indicator/indicated-heading-deg\n"); Degree = Math.Round(double.Parse(telnetClient.read()), 4); telnetClient.write("get /instrumentation/gps/indicated-vertical-speed\n"); VerticalSpeed = Math.Round(double.Parse(telnetClient.read()), 4); telnetClient.write("get /instrumentation/gps/indicated-ground-speed-kt\n"); GroundSpeed = Math.Round(double.Parse(telnetClient.read()), 4); telnetClient.write("get /instrumentation/airspeed-indicator/indicated-speed-kt\n"); AirSpeed = Math.Round(double.Parse(telnetClient.read()), 4); telnetClient.write("get /instrumentation/gps/indicated-altitude-ft\n"); GpsAltitude = Math.Round(double.Parse(telnetClient.read()), 4); telnetClient.write("get /instrumentation/attitude-indicator/internal-roll-deg\n"); RollDegree = Math.Round(double.Parse(telnetClient.read()), 4); telnetClient.write("get /instrumentation/attitude-indicator/internal-pitch-deg\n"); PitchDegree = Math.Round(double.Parse(telnetClient.read()), 4); telnetClient.write("get /instrumentation/altimeter/indicated-altitude-ft\n"); AltimeterAltitude = Math.Round(double.Parse(telnetClient.read()), 4); for (int i = 0; i < 5; i++) { if (!stop) { telnetClient.write("get /position/longitude-deg\n"); Longitude = Math.Round(double.Parse(telnetClient.read()), 4); } if (!stop) { telnetClient.write("get /position/latitude-deg\n"); Latitude = Math.Round(double.Parse(telnetClient.read()), 4); } Thread.Sleep(50); } }catch (IOException e) { Got_IO_Error(); Thread.Sleep(5000); Err_Server_IO = Visibility.Collapsed; disconnect(); Err_visiblity_Not_Connected = Visibility.Visible; } catch (FormatException e) { Got_Format_Error(); } mut.ReleaseMutex(); } }).Start(); }
public void write(string command) { telnetClient.write(command); }
public void start() { new Thread(delegate () { Location lastKnownCoordinates = new Location(0,0); List<String> getMessages = new List<String>(); getMessages.Add("get /instrumentation/heading-indicator/indicated-heading-deg\r\n"); getMessages.Add("get /instrumentation/gps/indicated-vertical-speed\r\n"); getMessages.Add("get /instrumentation/gps/indicated-ground-speed-kt\r\n"); getMessages.Add("get /instrumentation/airspeed-indicator/indicated-speed-kt\r\n"); getMessages.Add("get /instrumentation/gps/indicated-altitude-ft\r\n"); getMessages.Add("get /instrumentation/attitude-indicator/internal-roll-deg\r\n"); getMessages.Add("get /instrumentation/attitude-indicator/internal-pitch-deg\r\n"); getMessages.Add("get /instrumentation/altimeter/indicated-altitude-ft\r\n"); getMessages.Add("get /position/latitude-deg\r\n"); getMessages.Add("get /position/longitude-deg\r\n"); while (!m_stop) { bool everythingsFine = true; //for dashbord for (int i = 0; i < 10; i++) { try { m_telnetClient.write(getMessages[i]); } catch (Exception) { //cant write get message, server closed ErrorMessage = connectionError; m_stop = true; break; } try { switch (i) { case 0: HeadingDeg = Double.Parse(m_telnetClient.read()); break; case 1: VerticalSpeed = Double.Parse(m_telnetClient.read()); break; case 2: GroundSpeed = Double.Parse(m_telnetClient.read()); break; case 3: Airspeed = Double.Parse(m_telnetClient.read()); break; case 4: Alttitude = Double.Parse(m_telnetClient.read()); break; case 5: RollDeg = Double.Parse(m_telnetClient.read()); break; case 6: PitchDeg = Double.Parse(m_telnetClient.read()); break; case 7: Altimeter = Double.Parse(m_telnetClient.read()); break; case 8: Latitude = Double.Parse(m_telnetClient.read()); if (Latitude >= 90) { Latitude = 90; everythingsFine = false; ErrorMessage = "Latitude out of range"; } else if (Latitude <= -90) { Latitude = 90; everythingsFine = false; ErrorMessage = "Latitude out of range"; } break; case 9: Longitude = Double.Parse(m_telnetClient.read()); if (Longitude >= 180) { Longitude = 180; everythingsFine = false; ErrorMessage = "Longitude out of range"; } else if (Longitude <= -180) { Longitude = -180; everythingsFine = false; ErrorMessage = "Longitude out of range"; } break; default: ErrorMessage = "shit pavel im sorry dont ruin my grade, something unexcepted happened :("; break; } } catch (FormatException) { //incorrect values switch (i) { case 0: ErrorMessage = "HeadingDeg value is incorrect\n"; break; case 1: ErrorMessage = "verticalSpeed value is incorrect\n"; break; case 2: ErrorMessage = "GroundSpeed value is incorrect\n"; break; case 3: ErrorMessage = "Airspeed value is incorrect\n"; break; case 4: ErrorMessage = "Alttitude value is incorrect\n"; break; case 5: ErrorMessage = "RollDeg value is incorrect\n"; break; case 6: ErrorMessage = "PitchDeg value is incorrect\n"; break; case 7: ErrorMessage = "Altimeter value is incorrect\n"; break; case 8: ErrorMessage = "Latitude value is incorrect\n"; everythingsFine = false; break; case 9: ErrorMessage = "Longitude value is incorrect\n"; everythingsFine = false; break; default: ErrorMessage = "shit\n"; break; } } catch (Exception) { // cant read values, server closed. ErrorMessage = connectionError; m_stop = true; break; } } if (everythingsFine) { lastKnownCoordinates = Cordinates; //Cordinates = Longitude.ToString() + "," + Latitude.ToString(); Cordinates = new Location(Latitude, Longitude); } else { Cordinates = lastKnownCoordinates; } while (commandsForServer.Count() > 0) { { try { m_telnetClient.write(commandsForServer.Peek()); m_telnetClient.read(); } catch (Exception) { ErrorMessage = connectionError; m_stop = true; break; } } commandsForServer.Dequeue(); } Thread.Sleep(250); } Console.WriteLine("finished get and set thread"); }).Start(); }
public void stop() { isStopped = true; telnetClient.write(detectionFlight[detectionFlight.Count - 1].ToString()); telnetClient.disconnect(); }
public void start() { new Thread(delegate() { while (!stopRunning) { try { string tempStr; try { telnetClient.write("get /instrumentation/heading-indicator/indicated-heading-deg\n"); //1 //HeadingDeg = Double.Parse(telnetClient.read()); tempStr = telnetClient.read(); //Console.WriteLine("\nheading value="+ telnetClient.read()); HeadingDeg = Double.Parse(tempStr); //Console.WriteLine("1, " + a); } catch { StrException = "error - can't update the current value of heading"; //Console.WriteLine("heading, " + telnetClient.read()); errorCounter++; } try { telnetClient.write("get /instrumentation/gps/indicated-vertical-speed\n");//2 tempStr = telnetClient.read(); GpsVerticalSpeed = Double.Parse(tempStr); //errorCounter = 0; } catch { StrException = "error - can't update the current value of vertical speed"; errorCounter++; } try { telnetClient.write("get /instrumentation/gps/indicated-ground-speed-kt\n");//3 tempStr = telnetClient.read(); GpsGroundSpeed = Double.Parse(tempStr); //errorCounter = 0; } catch { StrException = "error - can't update the current value of GpsGroundSpeed"; //Console.WriteLine("GpsGroundSpeed, " + telnetClient.read()); errorCounter++; } try { telnetClient.write("get /instrumentation/airspeed-indicator/indicated-speed-kt\n");//4 tempStr = telnetClient.read(); AirSpeed = Double.Parse(tempStr); } catch { StrException = "error - can't update the current value of AirSpeed"; //Console.WriteLine("AirSpeed, " + telnetClient.read()); errorCounter++; } try { telnetClient.write("get /instrumentation/gps/indicated-altitude-ft\n");//5 tempStr = telnetClient.read(); GpsAltitude = Double.Parse(tempStr); } catch { StrException = "error - can't update the current value of GpsAltitude"; //Console.WriteLine("GpsAltitude, " + telnetClient.read()); errorCounter++; } try { telnetClient.write("get /instrumentation/attitude-indicator/internal-roll-deg\n");//6 tempStr = telnetClient.read(); InternalRollDeg = Double.Parse(tempStr); } catch { StrException = "error - can't update the current value of InternalRollDeg"; //Console.WriteLine("InternalRollDeg, " + telnetClient.read()); errorCounter++; } try { telnetClient.write("get /instrumentation/attitude-indicator/internal-pitch-deg\n");//7 tempStr = telnetClient.read(); InternalPitchDeg = Double.Parse(tempStr); } catch { StrException = "error - can't update the current value of InternalPitchDeg"; } try { telnetClient.write("get /instrumentation/altimeter/indicated-altitude-ft\n");//8 tempStr = telnetClient.read(); AltimeterAltitude = Double.Parse(tempStr); } catch { StrException = "error - can't update the current value of AltimeterAltitude"; } // update Latitude try { telnetClient.write("get /position/latitude-deg\n"); // x value of the pin. (x,y) tempStr = telnetClient.read(); tempLatitude = Double.Parse(tempStr); } catch { StrException = "error - can't update the current value of Latitude"; } if ((tempLatitude >= -90) && (tempLatitude <= 90)) { Latitude = tempLatitude; //Console.WriteLine("latitude = " + Latitude); } else { StrException = "altitude is not in the range"; } // update Longtitude try { telnetClient.write("get /position/longitude-deg\n"); // y value of the pin. (x,y) tempStr = telnetClient.read(); tempLongitude = Double.Parse(tempStr); } catch { StrException = "error - can't update the current value of Longtitude"; } if ((tempLongitude >= -180) && (tempLongitude <= 180)) { Longtitude = tempLongitude; } else { StrException = "longitude is not in the range"; } Location = new Location(latitude, longitude); // reads 5 times per second. Thread.Sleep(200); } catch (System.IO.IOException e) { if (!stopRunning) { this.disconnect(); this.StrException = "problem with connecting the server\nplease try to connect again\n"; break; } else { break; } } //Console.WriteLine("counter is: " + this.errorCounter); //if(this.errorCounter==10) //{ // //this.telnetClient.disconnect(); // this.disconnect(); // this.StrException = "problem with connecting the server\nplease try to connect again\n"; //} } }).Start(); }
/* * The method set the all values by the command values it gets and by using the telnet * client, and if there is any kind of prolbem in the command sending, the method return 1. * for evrey single value that we need to set, we send to the server "set" command and * then "get" command, reed the feedback from the server and check if the values are equals */ public int SetAllValues(Command command) { try { if (telnetClientHandler.isConnected()) { string tmp = ""; telnetClientHandler.write("set /controls/flight/aileron " + String.Format("{0:0.##}", command.Aileron) + "\r\n"); telnetClientHandler.write("get /controls/flight/aileron" + "\r\n"); tmp = telnetClientHandler.read(); if (tryToConvert(tmp) == true) { if (command.Aileron != double.Parse(tmp)) { return(1); //notOk } } telnetClientHandler.write("set /controls/engines/current-engine/throttle " + String.Format("{0:0.##}", command.Throttle) + "\r\n"); telnetClientHandler.write("get /controls/engines/current-engine/throttle" + "\r\n"); tmp = this.telnetClientHandler.read(); if (tryToConvert(tmp) == true) { if (command.Throttle != double.Parse(tmp)) { return(1); //notOk } } telnetClientHandler.write("set /controls/flight/elevator " + String.Format("{0:0.##}", command.Elevator) + "\r\n"); telnetClientHandler.write("get /controls/flight/elevator" + "\r\n"); tmp = this.telnetClientHandler.read(); if (tryToConvert(tmp) == true) { if (command.Elevator != double.Parse(tmp)) { return(1); //notOk } } telnetClientHandler.write("set /controls/flight/rudder " + String.Format("{0:0.##}", command.Rudder) + "\r\n"); telnetClientHandler.write("get /controls/flight/rudder" + "\r\n"); tmp = this.telnetClientHandler.read(); if (tryToConvert(tmp) == true) { if (command.Rudder != double.Parse(tmp)) { return(1); //notOk } } } return(0); //Ok } catch { throw new Exception("Could not read / write"); //notOk } }
public void Start() { new Thread(delegate() { while (IsConnected) { try { mutex.WaitOne(); // Roll try { Client.write("get /instrumentation/attitude-indicator/internal-roll-deg\r\n"); Roll = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "Roll"; Console.WriteLine(e1); } // Pitch try { Client.write("get /instrumentation/attitude-indicator/internal-pitch-deg\r\n"); Pitch = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "Pitch"; Console.WriteLine(e1); } // VerticalSpeed try { Client.write("get /instrumentation/gps/indicated-vertical-speed\r\n"); VerticalSpeed = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "VerticalSpeed"; Console.WriteLine(e1); } // GroundSpeed try { Client.write("get /instrumentation/gps/indicated-ground-speed-kt\r\n"); GroundSpeed = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "GroundSpeed"; Console.WriteLine(e1); } // AirSpeed try { Client.write("get /instrumentation/airspeed-indicator/indicated-speed-kt\r\n"); AirSpeed = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "AirSpeed"; Console.WriteLine(e1); } // Heading try { Client.write("get /instrumentation/heading-indicator/indicated-heading-deg\r\n"); Heading = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "Heading"; Console.WriteLine(e1); } // Altitude try { Client.write("get /instrumentation/gps/indicated-altitude-ft\r\n"); Altitude = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "Altitude"; Console.WriteLine(e1); } // Altimeter try{ Client.write("get /instrumentation/altimeter/indicated-altitude-ft\r\n"); Altimeter = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "Altimeter"; Console.WriteLine(e1); } // Latitude try { Client.write("get /position/latitude-deg\r\n"); Latitude = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "Latitude"; Console.WriteLine(e1); } // Longitude try { Client.write("get /position/longitude-deg\r\n"); Longitude = Convert.ToDouble(Client.read()); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } catch (Exception e1) { ErrorString = "Longitude"; Console.WriteLine(e1); } // Location if ((longitude <= 180 && longitude >= -180) && (latitude <= 90 && latitude >= -90)) { Location = latitude + "," + longitude; } else { ErrorString = "plain is out of bounds"; } mutex.ReleaseMutex(); Thread.Sleep(250); } catch (System.IO.IOException Err) { ErrorString = "Timeout exception"; Console.WriteLine(Err); } } }).Start(); }
ITelnetClient client = FlightTelnetClient.Instance; //calling a client instance. /// <summary> /// sending commands to the simulator. /// </summary> /// <param name="msg">the massage sent</param> public void sendCommands(string msg) { client.write(msg); }
public void SendCommand(Command command) { string messageFromSimulator; telnetClient.write("set /controls/flight/aileron " + command.Aileron.ToString() + "\r\n"); try { telnetClient.write("get /controls/flight/aileron\r\n"); try { messageFromSimulator = telnetClient.read(); if (messageFromSimulator.Contains("ERR") || Double.Parse(messageFromSimulator) != command.Aileron) { } } catch { } } catch { } telnetClient.write("set /controls/engines/current-engine/throttle " + command.Throttle.ToString() + "\r\n"); try { telnetClient.write("get /controls/engines/current-engine/throttle\r\n"); try { messageFromSimulator = telnetClient.read(); if (messageFromSimulator.Contains("ERR") || Double.Parse(messageFromSimulator) != command.Throttle) { } } catch { } } catch { } telnetClient.write("set /controls/flight/rudder " + command.Rudder.ToString() + "\r\n"); try { telnetClient.write("get /controls/flight/rudder\r\n"); try { messageFromSimulator = telnetClient.read(); if (messageFromSimulator.Contains("ERR") || Double.Parse(messageFromSimulator) != command.Rudder) { } } catch { } } catch { } telnetClient.write("set /controls/flight/elevator " + command.Elevator.ToString() + "\r\n"); try { telnetClient.write("get /controls/flight/elevator\r\n"); try { messageFromSimulator = telnetClient.read(); if (messageFromSimulator.Contains("ERR") || Double.Parse(messageFromSimulator) != command.Elevator) { } } catch { } } catch { } }