Beispiel #1
0
        /// <summary>
        /// Initialize the Link with LiveTraffic
        ///  this will init the receiver and pace outbound messages every 10 sec
        ///  Connects to default ports
        /// </summary>
        /// <param name="hostIP">The LiveTraffic plugin host</param>
        /// <returns>True if successfull (else see Error content)</returns>
        public bool EstablishLink(string hostIP, uint numAcft, uint numVFR)
        {
            Logger.Instance.Log($"TrafficHandler-EstablishLink to: {hostIP}");
            if (!Valid)
            {
                return(false);
            }

            m_numAcft = numAcft;
            m_numVFR  = numVFR;

            m_userAcft = new UserAcft( );
            // setup Comm
            m_host = hostIP;
            try {
                LT_Traffic      = new UDPsender(m_host, RealTraffic.PortTrafficUDP);
                LT_Weather      = new UDPsender(m_host, RealTraffic.PortWeatherUDP);
                LTLink          = new TCPclient(m_host, RealTraffic.PortLinkTCP);
                LTLink.LTEvent += LTLink_LTEvent;
            }
            catch (Exception e) {
                Error = $"Error: {e.Message}";
                Logger.Instance.Log($"TrafficHandler: {Error}");
                return(false);
            }
            //
            Valid = LTLink.Connect( ); // if successful this triggers the reception of messages;
            if (!Valid)
            {
                Error = $"Error: {LTLink.Error}";
            }

            Logger.Instance.Log($"TrafficHandler: {Error}");
            return(Valid);
        }
Beispiel #2
0
 /// <summary>
 /// Shut Link to LiveTraffic down
 /// </summary>
 public void RemoveLink()
 {
     Logger.Instance.Log($"TrafficHandler-RemoveLink");
     Valid = false;
     Error = "";
     try {
         LTLink.LTEvent -= LTLink_LTEvent;
         LT_Traffic      = null;
         LT_Weather      = null;
         LTLink.Disconnect( );
         m_userAcft = null;
         POOL       = null;
     }
     catch (Exception e) {
         Error = $"Error: {e.Message}";
         Logger.Instance.Log($"TrafficHandler: {Error}");
     }
 }
Beispiel #3
0
        /// <summary>
        /// Simulate the Model file given and write a kmlfile of the path
        /// same folder as the model file with the extension .kml
        /// </summary>
        /// <param name="vfrModelFile">The VFR Model File</param>
        /// <returns>True if successfull (else see Error content)</returns>
        public bool RunSimulation(string vfrModelFile, string fallBackRwy)
        {
            Error = "";
            Logger.Instance.Log($"VFRSimulation-SetupSimulation for: {vfrModelFile}");
            if (!Valid)
            {
                return(false);
            }

            var route = CmdReader.ReadCmdScript(vfrModelFile);

            if (!route.IsValid)
            {
                Valid = false;
                Error = "File not found or invalid content";
                Logger.Instance.Log(Error);
                return(false);
            }

            if (route.Descriptor.FlightType == CmdA.FlightT.Runway)
            {
                string rwID = route.Descriptor.RunwayPreference; // preferred one
                if (string.IsNullOrEmpty(rwID))
                {
                    rwID = fallBackRwy;
                }
                var rwy = RWYDB.GetSubtable(rwID); // search RWY
                if (rwy.Count < 1)
                {
                    Valid = false;
                    Error = $"Runway: {route.Descriptor.Start_IcaoID} not found in Runway database, cannot continue";
                    Logger.Instance.Log(Error);
                    return(false);
                }
                // actually my position
                m_userAcft = new UserAcft( );
                m_userAcft.NewPos(rwy.ElementAt(0).Value.start_latlon);
                // the simulated aircraft
                route.Descriptor.InitFromRunway(1, rwy.ElementAt(0).Value); // Complete the script
            }
            else if (route.Descriptor.FlightType == CmdA.FlightT.Airway)
            {
                return(false); // not supported - use the one above...
            }
            else if (route.Descriptor.FlightType == CmdA.FlightT.MsgRelative)
            {
                string rwID = route.Descriptor.RunwayPreference; // preferred one
                if (string.IsNullOrEmpty(rwID))
                {
                    rwID = fallBackRwy;
                }
                var rwy = RWYDB.GetSubtable(rwID); // search RWY
                if (rwy.Count < 1)
                {
                    Valid = false;
                    Error = $"Runway: {route.Descriptor.Start_IcaoID} not found in Runway database, cannot continue";
                    Logger.Instance.Log(Error);
                    return(false);
                }
                // actually my position
                m_userAcft = new UserAcft( );
                m_userAcft.NewPos(rwy.ElementAt(0).Value.start_latlon);
                // the simulated aircraft
                route.Descriptor.InitFromMsgRelative(1, rwy.ElementAt(0).Value, "SIM"); // Complete the script
            }

            else if (route.Descriptor.FlightType == CmdA.FlightT.MsgAbsolute)
            {
                // actually my position
                m_userAcft = new UserAcft( );
                m_userAcft.NewPos(route.Descriptor.StartPos_latlon);
                // the simulated aircraft
                route.Descriptor.InitFromMsgAbsolute(1, "SIM"); // Complete the script
            }

            var virtAcft = new VFRvAcft(route); // use the GA model
            var kmlFile  = new KmlFile( );
            var kmlLine  = new line {
                Name      = Path.GetFileNameWithoutExtension(vfrModelFile),
                LineColor = LineStyle.LT_Yellow
            };

            do
            {
                virtAcft.StepModel(m_stepLen_sec); // step the model at 2 sec until finished

                kmlLine.Add(new point {
                    Position    = new LatLon(virtAcft.LatLon),
                    Altitude_ft = virtAcft.Alt_ft,
                    Heading     = (int)virtAcft.TRK
                });
            } while (!virtAcft.Out);
            // setup Comm
            kmlFile.Lines.Add(kmlLine);
            kmlFile.WriteKML(vfrModelFile + ".kml");
            return(Valid);
        }