public CmdReader NewReader() { CmdReader reader = new CmdReader(); //reader.Register(new MockReceiver()); return(reader); }
public void TestCreate() { CmdReader r = NewReader(); Assert.IsNotNull(r); Assert.IsTrue(r.Init()); }
public CmdControlViewModel() { this.DisplayName = "CMD Window"; historyCommand = new HistoryCommand(); cmdReader = new CmdReader(); cmdReader.Register(this); Init(); }
/// <summary> /// cTor: Create all infrastructure /// Proceed with EstablishLink /// </summary> /// <param name="dat_Path">The path to my_awy.dat</param> public TrafficHandler(string dat_Path, uint stepLen_sec, bool logging) { Logger.Instance.Reset( ); Logger.Instance.Logging = logging; // user #if DEBUG // always log in DEBUG mode Logger.Instance.Logging = true; #endif // Load Database files if possible, else exit with Error Logger.Instance.Log($"TrafficHandler-Create @: {DateTime.Now.ToString( )}"); string eawy = Path.Combine(dat_Path, DBCreator.MyAwyDbName); if (!File.Exists(eawy)) { Error = $"Error: my_awy.dat does not exist: {eawy}"; Logger.Instance.Log($"TrafficHandler: {Error}"); return; // ERROR exit } string erwy = Path.Combine(dat_Path, DBCreator.MyRwyDbName); if (!File.Exists(erwy)) { Error = $"Error: my_rwy.dat does not exist: {erwy}"; Logger.Instance.Log($"TrafficHandler: {Error}"); return; // ERROR exit } string ret = awyReader.ReadDb(ref AWYDB, eawy); if (!string.IsNullOrEmpty(ret)) { Error = $"Error: my_awy.dat read failed: {ret}"; Logger.Instance.Log($"TrafficHandler: {Error}"); return; // ERROR exit } ret = rwyReader.ReadDb(ref RWYDB, erwy); if (!string.IsNullOrEmpty(ret)) { Error = $"Error: my_rwy.dat read failed: {ret}"; Logger.Instance.Log($"TrafficHandler: {Error}"); return; // ERROR exit } string escript = Path.Combine(dat_Path, DBCreator.MyVfrScriptPath); if (!Directory.Exists(escript)) { Error = $"Warning: script folder does not exist: {escript}"; Logger.Instance.Log($"TrafficHandler: {Error}"); } else { // Load Scripts CMDS = CmdReader.ReadScripts(escript); if (CMDS.Count <= 0) { Error = $"Warning: script folder does not contain valid scripts"; Logger.Instance.Log($"TrafficHandler: {Error}"); } } m_stepLen_sec = stepLen_sec; Valid = true; }
/// <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); }