Exemplo n.º 1
0
        public void Run()
        {
            Console.WriteLine(JournalPath);
            var journalFileName = FileUtils.GetJournalFilenames(JournalPath).OrderByDescending(x => x.StartDate).FirstOrDefault();

            if (journalFileName == null)
            {
                Console.WriteLine("Could not find a journal file to open");
                return;
            }
            Console.WriteLine($"Using journal file {journalFileName.Fullpath}");

            var journalFile = new EliteJournal(journalFileName.Fullpath);
            int i           = 0;

            while (true)
            {
                foreach (var line in journalFile.GetLines())
                {
                    Console.WriteLine(journalFile.FilePosition.ToString() + " " + line);
                }

                i++;
                if (i > 20)
                {
                    i = 0;
                    var latestJournal = FileUtils.GetLatestJournalFilename(JournalPath);
                    if (latestJournal.Fullpath != journalFileName.Fullpath)
                    {
                        journalFileName = latestJournal;
                        journalFile     = new EliteJournal(journalFileName.Fullpath);
                    }
                }

                Thread.Sleep(250);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }