Example #1
0
        // Asynch processing from receiving actual user position (Triggered by TCPclient)
        private void LTLink_LTEvent(object sender, LTEventArgs e)
        {
            long secSinceLastPing = (long)(DateTime.Now - m_lastUpdate).TotalSeconds;

            OnTraffic(secSinceLastPing);

            if (!Valid)
            {
                return;     // catch out of bounds messages
            }
            m_userAcft.NewPos(e.LatLon);
            if (POOL == null)
            {
                // create the first subset with our AcftPos
                POOL = new VAcftPool(m_radius_nm, m_stepLen_sec)
                {
                    NumAcft     = m_numAcft,
                    NumVFRcraft = m_numVFR
                };
                POOL.CreateAwySelection(AWYDB.GetTable( ), RWYDB.GetTable( ), m_userAcft.LatLon);
                POOL.UpdateVFRscripts(CMDS);
                Logger.Instance.Log($"TrafficHandler: Create POOL with {m_numAcft} aircrafts where {m_numVFR} are VFR, one sim step is >= {m_stepLen_sec} seconds");
            }
            // push an update only after 'StepLen_sec' secs
            if (secSinceLastPing >= POOL.StepLen_sec)
            {
                m_lastUpdate = DateTime.Now;                      // reset timer

                LT_Weather.SendMsg(RealTraffic.WeatherString( )); // send a 'generic' weather string
                // do POOL maintenance
                POOL.ReGenerate( );
                POOL.Update( );
                // send updates to LiveTraffic - TODO need to pace it ??
                foreach (var vac in POOL.AircraftPoolRef)
                {
                    string msg = RealTraffic.AITrafficString(vac);
                    LT_Traffic.SendMsg(msg);
                }
                // recreates the airway selection if needed
                POOL.UpdateAwySelection(AWYDB.GetTable( ), RWYDB.GetTable( ), m_userAcft.LatLon);
            }
        }
Example #2
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);
        }