Exemplo n.º 1
0
 public FlightSimulatorModel(ITelnetClient telnetC)
 {
     initializeModel();
     telnetClient = telnetC;
     status       = "Disconnected";
     initializeDashboard();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DummyServerTCPHandler"/> class.
 /// </summary>
 /// <param name="client">The client.</param>
 private DummyServerTCPHandler(ITelnetClient client)
 {
     this.client       = new DummyTelnetClient();
     this.threadsList  = new List <Thread>();
     this.parsingQueue = new Queue <string>();
     this.initializeParametersMap();
 }
Exemplo n.º 3
0
        /// <summary>
        /// connecting the telnet client to a server.
        /// </summary>
        /// <param name="ip">the ip address of the server.</param>
        /// <param name="port">the port number of the server.</param>
        public void connect(string ip, int port)
        {
            StrException = "trying to connect...\npleast wait";

            bool tryToConnect = false;

            for (int i = 0; i < 2; i++)
            {
                try
                {
                    this.stopRunning = false;
                    this.telnetClient.connect(ip, port);
                    StrException = "connected to the server succesfuly";
                    this.start();
                    tryToConnect = true;
                    break;
                }
                catch
                {
                    StrException = "trying to connect...\npleast wait";
                    Console.WriteLine("can't connect to the serverXXX");
                }
            }
            if (!tryToConnect)
            {
                StrException      = "can't connect to the server";
                stopRunning       = true;
                this.telnetClient = new MyTelnetClient();
            }
        }
Exemplo n.º 4
0
        /**
         * FlyModel constructor update variables.
         * get ITelnetClient.
         */
        public FlyModel(ITelnetClient telClient)
        {
            //Read value
            valueMap = new Dictionary <string, FlyData>();
            valueMap.Add("longitude", new FlyData("/position/longitude-deg", 34.888781));
            valueMap.Add("latitude", new FlyData("/position/latitude-deg", 32.002644));
            valueMap.Add("indicatedSpeed", new FlyData("/instrumentation/airspeed-indicator/indicated-speed-kt", 0.0));
            valueMap.Add("gpsAltitude", new FlyData("/instrumentation/gps/indicated-altitude-ft", 0.0));
            valueMap.Add("internalRoll", new FlyData("/instrumentation/attitude-indicator/internal-roll-deg", 0.0));
            valueMap.Add("internalPitch", new FlyData("/instrumentation/attitude-indicator/internal-pitch-deg", 0.0));
            valueMap.Add("altimeterAltitude", new FlyData("/instrumentation/altimeter/indicated-altitude-ft", 0.0));
            valueMap.Add("headingDeg", new FlyData("/instrumentation/heading-indicator/indicated-heading-deg", 0.0));
            valueMap.Add("groundSpeed", new FlyData("/instrumentation/gps/indicated-ground-speed-kt", 0.0));
            valueMap.Add("verticalSpeed", new FlyData("/instrumentation/gps/indicated-vertical-speed", 0.0));
            // Write value
            valueMap.Add("throttle", new FlyData("/controls/engines/current-engine/throttle", 0.0));
            valueMap.Add("aileron", new FlyData("/controls/flight/aileron", 0.0));
            valueMap.Add("elevator", new FlyData("/controls/flight/elevator", 0.0));
            valueMap.Add("rudder", new FlyData("/controls/flight/rudder", 0.0));
            this.dashBoardError = new List <string>();
            this.stop           = false;
            this.telnetClient   = telClient;
            sendToSimQueue      = new Queue <string>();

            this.generalErrList = new List <string>();
        }
Exemplo n.º 5
0
 /// <summary>
 /// disconnecting from the server.
 /// </summary>
 public void disconnect()
 {
     this.stopRunning = true;
     this.telnetClient.disconnect();
     this.telnetClient = new MyTelnetClient();
     StrException      = "disconnected";
 }
 //constroctor.
 public CommandManager(ITelnetClient telnetClient, IConfiguration configuration)
 {
     this.telnetClient  = telnetClient;
     this.configuration = configuration;
     this.queue         = new BlockingCollection <AsyncCommand>();
     stop = true;
     Start();
 }
 // Initialize the model class
 private void initialize(ITelnetClient client)
 {
     this.client        = client;
     this.playing       = false;
     this.PlaybackSpeed = 1;
     this.Time          = DateTime.MinValue;
     this.currentLine   = 0;
 }
Exemplo n.º 8
0
 /// <summary>
 /// a static functoin that creates an object of FGModelImp
 /// </summary>
 /// <param name="telnetClient">telnet client to initialize</param>
 public static void CreateModel(ITelnetClient telnetClient)
 {
     if (fgModel != null)
     {
         throw new Exception("FGModel was created");
     }
     fgModel = new FGModelImp(telnetClient);
 }
Exemplo n.º 9
0
        public void createClient(string ip, int port)
        {
            ITelnetClient telnetClient = new MyTelnetClient();

            this.telnetClient = telnetClient;

            telnetClient.connect(ip, port);
        }
Exemplo n.º 10
0
 // CTOR
 public ConnectionManager(CommandManager commandManager)
 {
     this.ip   = commandManager.IP;
     this.port = commandManager.PORT;
     _queue    = new BlockingCollection <AsyncCommand>();
     this.telnetClientHandler = new MyTelnetClient();
     this.isConnected         = false;
     this.Start();
 }
 public void Run(string ip, int port)
 {
     // Set ip and port.
     this.telnetClient = new Telnet(ip, port);
     // Connect to the simulator.
     this.Connect();
     // Set time out to 10 seconds.
     this.telnetClient.SetTimeOutRead(10000);
 }
Exemplo n.º 12
0
 //A setter for telnet client.
 public IFlightSimulatorModel SetTelnetClient(ITelnetClient telnet)
 {
     //set it only once because this is a singleton.
     if (!isTelnetSet)
     {
         tc = telnet;
     }
     return(this);
 }
Exemplo n.º 13
0
        /// <summary>
        /// connecting to the simulator (client and server) and starting to read from the server
        /// </summary>
        public void Connect()
        {
            ISettingsModel settings = ApplicationSettingsModel.Instance;
            ITelnetServer  server   = DataReaderServer.Instance;
            ITelnetClient  client   = FlightTelnetClient.Instance;

            server.Connect(settings.FlightServerIP, settings.FlightInfoPort);
            client.connect(settings.FlightServerIP, settings.FlightCommandPort);
            FlightBoardModel.Instance.ReadFromServer();
        }
Exemplo n.º 14
0
 /// <summary>
 /// this is the constructor of this class.
 /// </summary>
 /// <param name="_planeLocations"></param>
 /// <param name="_plotter"></param>
 public FlightBoardModel(ObservableDataSource <Point> _planeLocations, ChartPlotter _plotter)
 {
     planeLocations = _planeLocations;
     plotter        = _plotter;
     ts             = new TelnetServer(planeLocations, plotter);
     mtc            = new MyTelnetClient();
     ip             = (string)Settings.Default["IP"];
     clientPort     = Int32.Parse((string)Settings.Default["PortClient"]);
     serverPort     = Int32.Parse((string)Settings.Default["PortServer"]);
 }
Exemplo n.º 15
0
        public ConnectionViewModel(ITelnetClient model)
        {
            IP   = System.Configuration.ConfigurationManager.AppSettings["ip"];
            Port = System.Configuration.ConfigurationManager.AppSettings["port"];

            this.model             = model;
            model.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                NotifyPropertyChanged("Vm" + e.PropertyName);
            };
        }
Exemplo n.º 16
0
 public CommandManager(ITelnetClient telnetClient)
 {
     this.telnetClient = telnetClient;
     try
     {
         telnetClient.connect("127.0.0.1", 5402);
     }
     catch
     {
     }
 }
Exemplo n.º 17
0
 public static void CheckTelnetClient(ITelnetClient telnet)
 {
     if (telnet == null)
     {
         throw new NullReferenceException();
     }
     if (!telnet.Connected)
     {
         throw new System.Net.Sockets.SocketException((int)System.Net.Sockets.SocketError.NotConnected);
     }
 }
Exemplo n.º 18
0
 // MyMapModel Ctor
 public MyMapModel(ITelnetClient tc)
 {
     this.tc            = tc;
     Latitude           = System.Configuration.ConfigurationManager.AppSettings["startLatitude"];
     Longitude          = System.Configuration.ConfigurationManager.AppSettings["startLongitude"];
     LatitudeError      = "";
     LongitudeError     = "";
     this.oldLatitude   = Latitude;
     this.oldLongtitude = Longitude;
     StartReadingFlightData();
 }
Exemplo n.º 19
0
        public static void SendTime(ITelnetClient telnet, TimeInfo timeInfo)
        {
            TelnetException.CheckTelnetClient(telnet);

            var minute = Math.Ceiling(timeInfo.Minute * 16.666666666666666666666666666667);
            //16.66666666667 ≒ 50.0f ÷ 3.0f
            var stTime = (timeInfo.Day - 1) * 24000 + (timeInfo.Hour * 1000) + (int)minute;

            //(Day - 1) * 24000 + (Hour * 1000) + (Minute * 16.666666666666666666666666666667)
            telnet.WriteLine("st " + stTime.ToString());
        }
Exemplo n.º 20
0
        public MyFlight(ITelnetClient tc)
        {
            this.myTelnetClient = tc;
            stop = false;

            timer           = new System.Timers.Timer(10000);
            timer.Elapsed  += HandleTimer;
            timer.AutoReset = false;
            timer.Enabled   = true;

            InitializeObjects();
        }
Exemplo n.º 21
0
        public static TimeInfo GetTimeFromTelnet(ITelnetClient telnet)
        {
            TelnetException.CheckTelnetClient(telnet);

            telnet.DestructionEvent = true;
            telnet.WriteLine("gt");
            System.Threading.Thread.Sleep(200);
            var log = telnet.Read().TrimEnd('\0');

            telnet.DestructionEvent = false;
            return(ConvertTime(log));
        }
Exemplo n.º 22
0
        private string getValuesFromServer(string ip, int port, List <string> vars)
        {
            IModel model = MyModel.Instance;

            model.connectClient(ip, port);
            ICollection <string> elemetsWithGet = addGetAndNewLineToStrings(vars);

            ITelnetClient c       = model.getClient();
            string        strings = c.read(elemetsWithGet);

            model.disconnectClient();
            return(strings);
        }
Exemplo n.º 23
0
 public MyFlightGearModel(ITelnetClient telnetClient)
 {
     this.telnetClient   = telnetClient;
     this.isStopped      = true;
     this.isPaused       = false;
     this.simulatorspeed = 1.00;
     createProperties();
     SetUpGraphOfCurrent();
     SetUpGraphOfCorrelated();
     SetUpGraphOfRegression();
     this.currerntChoice   = null;
     this.correlatedChoice = null;
     this.assembly         = null;
 }
Exemplo n.º 24
0
 public void addClient(Tuple <String, int> key)
 {
     mutex.WaitOne();
     try
     {
         ITelnetClient client = clientsFactory.New();
         client.Connect(key.Item1, key.Item2);
         clients[key] = new ManagableClient(client, Timeout);
     }
     finally
     {
         mutex.ReleaseMutex();
     }
 }
        /// <summary>
        /// this function disconnect the socket.
        /// </summary>
        private void disconnectSockets()
        {
            Connector     connector = Connector.getInstance();
            ITelnetClient tc        = connector.getClient();
            TelnetServer  ts        = connector.getServer();

            if (tc != null)
            {
                tc.disconnect();
            }
            if (ts != null)
            {
                ts.closeServer();
            }
        }
        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);
        }
Exemplo n.º 27
0
 //Connection to server.
 public void Connect(string ip, int port)
 {
     client = new MyTelnetClient();
     try
     {
         client.Connect(ip, port);
         MessageInd = true;
         Message    = "Connected to server.";
         Connected  = true;
     } catch (Exception)
     {
         MessageInd = true;
         Connected  = false;
         Message    = "Unable to connect to server.";
     }
 }
Exemplo n.º 28
0
 // Constructor
 public MyAirplaneModel()
 {
     this.client    = new MyTelnetClient();
     this.stop      = false;
     this.simVars   = this.CreateSimVarsArr();
     this.commands  = new Queue <string>();
     this.syncLock  = new object();
     this.stopWatch = new Stopwatch();
     this.timer     = new DispatcherTimer();
     // Set the timer to perform the function repeatedly within 2 seconds.
     this.timer.Interval = TimeSpan.FromSeconds(2);
     this.timer.Tick    += TimerTick;
     // Default IP and port.
     Ip   = ConfigurationManager.AppSettings["ip"];
     Port = ConfigurationManager.AppSettings["port"];
 }
Exemplo n.º 29
0
        public static List <PlayerInfo> SetPlayerInfo(ITelnetClient telnet)
        {
            TelnetException.CheckTelnetClient(telnet);

            telnet.DestructionEvent = true;
            var players = new List <PlayerInfo>();

            telnet.WriteLine("lp");
            System.Threading.Thread.Sleep(200);
            string log = telnet.Read().TrimEnd('\0');

            telnet.DestructionEvent = false;
            players.Add(log);

            return(players);
        }
        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");
            }
        }