private void Apply(string s)
        {
            var header = JsonConvert.DeserializeObject <JournalHeader>(s);

            header._InputLine = s;

            journalParser.Parse(header, ship);
        }
Esempio n. 2
0
 private static void Validate(string line, JournalParser parser)
 {
     Log.Debug(line);
     try
     {
         var _ = parser.Parse(line);
     }
     catch (Exception ex) when(ex is UnrecognizedJournalException || ex is JournalParseException)
     {
         Log.Warn(line);
         Log.Warn(ex.Message);
     }
 }
        public void Run()
        {
            // tell panel to start up
            controlPanel.SendCommand(new StartupCommand());
            Thread.Sleep(100);


            // TODO: exit condition
            while (true)
            {
                InitJournalReader();
                InitStatusReader();

                ship.JournalFileName = journalFile.Filename;

                var items = new List <IEliteEventHeader>();

                if (journalFile != null)
                {
                    items.AddRange(journalFile.GetLines().Select(s => { var a = JsonConvert.DeserializeObject <JournalHeader>(s); a._InputLine = s; return(a); }));
                }

                var status = statusFile?.GetStatus()?.FirstOrDefault();
                if (status != null)
                {
                    items.Add(status);
                }

                bool update = false;
                bool clear  = true;
                foreach (var item in items.OrderBy(i => i.Timestamp))
                {
                    if (parser.Parse(item, ship))
                    {
                        if (!item.EventName.Equals("status", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (clear)
                            {
                                ship.LastJournalLines.Clear();
                            }
                            clear = false;
                            ship.LastJournalLines.Add(item._InputLine);
                        }

                        update = true;
                    }
                }


                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();

                    if (key.Key == ConsoleKey.Escape)
                    {
                        Thread.Sleep(100);
                        controlPanel.SendCommand(new ShutdownCommand());
                        Thread.Sleep(500);
                        break;
                    }
                    if (key.Key == ConsoleKey.U)
                    {
                        update = true;
                    }
                }

                if (update)
                {
                    ship.RenderToConsole();

                    controlPanel.SendCommand(new LED7SegCommand(0, ship.Cargo));

                    int tempFuel = ship.TotalFuelKg;
                    controlPanel.SendCommand(new LED7SegIntCommand(1, tempFuel));


                    controlPanel.SendCommand(new LCDLineCommand(0, $"@ {ship.Location}"));

                    controlPanel.SendCommand(new LCDLineCommand(1, $"{ship.RemainingJumpsInRoute}> {ship.FSDTarget} ({ship.FSDTargetStarClass})"));

                    controlPanel.SendCommand(new LCDLineCommand(2, $"* {ship.TargetName}"));

                    if (!ship.TargetLocked)
                    {
                        controlPanel.SendCommand(new LCDLineCommand(3, $"?"));
                    }
                    if (ship.TargetLocked && ship.TargetScanStage < 3)
                    {
                        string scantext = "***";
                        controlPanel.SendCommand(new LCDLineCommand(3, $"! {ship.TargetName} {scantext.Substring(0, ship.TargetScanStage + 1)}"));
                    }
                    if (ship.TargetLocked && ship.TargetScanStage == 3)
                    {
                        controlPanel.SendCommand(new LCDLineCommand(3, $"! {ship.TargetName} {((ship.TargetWanted ?? false) ? "W!" : "C")}"));
                    }

                    controlPanel.SendCommand(new ShiftRegisterCommand(ship));
                }



                Thread.Sleep(100);
            }
        }