예제 #1
0
            public void Read(Telnet TC)
            {
                string read = TC.Read();

                log.Append(read);
                PendingText += read;

                System.Diagnostics.Debug.Write(read);

                int index;

                while ((index = PendingText.IndexOfAny(endLines)) >= 0)
                {
                    string line = PendingText.Substring(0, index);
                    PendingText = PendingText.Substring(index + 1);

                    if (line.Length > 0)
                    {
                        Lines.Enqueue(line);
                    }
                }
            }
예제 #2
0
        public static bool GetData(DateTime Date)
        {
            string startDate = Date.ToString("yyyy-MMM-dd HH:mm:ss.ffff");
            string endDate   = Date.AddDays(1).ToString("yyyy-MMM-dd HH:mm:ss.ffff");

            StringBuilder sbEphemeris = new StringBuilder();

            Telnet tc = new Telnet("ssd.jpl.nasa.gov", 6775);

            Queue <string> commandQueue = new Queue <string>();

            commandQueue.Enqueue("tty 80 240");

            bool ready = false;
            int  triesLeft;

            System.Threading.Thread.Sleep(500);

            bool      isFirst     = true;
            const int TRY_COUNT   = 200;
            Buffer    inputBuffer = new Buffer();

            foreach (var o in orbiterCodes.Where(oc => oc.Item3 <Date && oc.Item4> Date))
            {
                if (tc.IsConnected)
                {
                    triesLeft = TRY_COUNT;
                    bool gotData     = false;
                    bool readingData = false;
                    queueCommands(startDate, endDate, commandQueue, ref isFirst, o.Item2);

                    while (tc.IsConnected && (commandQueue.Count > 0 || !gotData))
                    {
                        if (--triesLeft < 0)
                        {
                            throw new Exception("Horizons Time Out");
                        }

                        inputBuffer.Read(tc);

                        if (inputBuffer.HasPendingText)
                        {
                            var nrtl = inputBuffer.PendingText.Trim().ToLower();

                            if (nrtl.EndsWith("return to continue -->"))
                            {
                                tc.WriteLine();
                            }
                            else if (nrtl.Contains("scroll & page: space, <cr>"))
                            {
                                tc.Write(" ");
                            }

                            ready |= nrtl.EndsWith("horizons>") || nrtl.EndsWith(":");
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(3000 / TRY_COUNT);
                        }

                        while (inputBuffer.HasLine)
                        {
                            triesLeft = TRY_COUNT;

                            string line = inputBuffer.Dequeue();

                            if (line.StartsWith(END_MARKER))
                            {
                                readingData = false;
                                gotData     = true;
                            }
                            if (readingData)
                            {
                                sbEphemeris.AppendLine(o.Item1 + "," + line);
                            }

                            if (line.StartsWith(START_MARKER))
                            {
                                readingData = true;
                            }
                        }
                        if (ready && commandQueue.Count > 0)
                        {
                            string cmd = commandQueue.Dequeue();

                            tc.WriteLine(cmd);

                            inputBuffer.WriteToLog("{{Command Sent: " + cmd + "}}");
                            triesLeft = TRY_COUNT;
                            ready     = false;
                        }
                    }
                }
            }

            tc.WriteLine("quit");

            IO.WriteFile("all_horizons_output.txt", DirectoryLocation.Data, inputBuffer.Log);

            if (sbEphemeris.Length == 0)
            {
                return(false);
            }

            StringBuilder eph = new StringBuilder();

            eph.AppendLine("// Improperly altering this file can cause SolarMax to malfunction");
            eph.AppendLine();
            eph.AppendLine("// Original Ephemeris: Version is Zero");
            eph.AppendLine("0");
            eph.AppendLine();
            eph.AppendLine("// Baseline Date");
            eph.AppendLine(Date.ToString(Physics.DATE_FORMAT_1));
            eph.AppendLine();
            eph.AppendLine("// Name, X, Y, Z, VX, VY, VZ");

            foreach (string s in sbEphemeris.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
            {
                eph.AppendLine(stripColsTwoAndThree(s));
            }

            IO.WriteFile("ephemeris_" + Date.ToString(Ephemeris.DATE_FORMAT_FOR_FILE_NAME) + ".txt", DirectoryLocation.Data, eph.ToString());

            return(true);
        }