Example #1
0
        static GuideStats accum_get_stats(Accum ra, Accum dec)
        {
            GuideStats stats = new GuideStats();

            stats.rms_ra   = ra.Stdev();
            stats.rms_dec  = dec.Stdev();
            stats.peak_ra  = ra.Peak();
            stats.peak_dec = dec.Peak();
            return(stats);
        }
Example #2
0
        private void handle_event(JObject ev)
        {
            string e = (string)ev["Event"];

            if (e == "AppState")
            {
                lock (m_sync)
                {
                    AppState = (string)ev["State"];
                    if (is_guiding(AppState))
                    {
                        AvgDist = 0.0;   // until we get a GuideStep event
                    }
                }
            }
            else if (e == "Version")
            {
                lock (m_sync)
                {
                    Version   = (string)ev["PHDVersion"];
                    PHDSubver = (string)ev["PHDSubver"];
                }
            }
            else if (e == "StartGuiding")
            {
                accum_active = true;
                accum_ra.Reset();
                accum_dec.Reset();

                GuideStats stats = accum_get_stats(accum_ra, accum_dec);

                lock (m_sync)
                {
                    Stats = stats;
                }
            }
            else if (e == "GuideStep")
            {
                GuideStats stats = null;
                if (accum_active)
                {
                    accum_ra.Add((double)ev["RADistanceRaw"]);
                    accum_dec.Add((double)ev["DECDistanceRaw"]);
                    stats = accum_get_stats(accum_ra, accum_dec);
                }

                lock (m_sync)
                {
                    AppState = "Guiding";
                    AvgDist  = (double)ev["AvgDist"];
                    if (accum_active)
                    {
                        Stats = stats;
                    }
                }
            }
            else if (e == "SettleBegin")
            {
                accum_active = false;  // exclude GuideStep messages from stats while settling
            }
            else if (e == "Settling")
            {
                SettleProgress s = new SettleProgress();
                s.Done       = false;
                s.Distance   = (double)ev["Distance"];
                s.SettlePx   = settle_px;
                s.Time       = (double)ev["Time"];
                s.SettleTime = (double)ev["SettleTime"];
                s.Status     = 0;
                lock (m_sync)
                {
                    mSettle = s;
                }
            }
            else if (e == "SettleDone")
            {
                accum_active = true;
                accum_ra.Reset();
                accum_dec.Reset();

                GuideStats stats = accum_get_stats(accum_ra, accum_dec);

                SettleProgress s = new SettleProgress();
                s.Done   = true;
                s.Status = (int)ev["Status"];
                s.Error  = (string)ev["Error"];

                lock (m_sync)
                {
                    mSettle = s;
                    Stats   = stats;
                }
            }
            else if (e == "Paused")
            {
                lock (m_sync)
                {
                    AppState = "Paused";
                }
            }
            else if (e == "StartCalibration")
            {
                lock (m_sync)
                {
                    AppState = "Calibrating";
                }
            }
            else if (e == "LoopingExposures")
            {
                lock (m_sync)
                {
                    AppState = "Looping";
                }
            }
            else if (e == "LoopingExposuresStopped" || e == "GuidingStopped")
            {
                lock (m_sync)
                {
                    AppState = "Stopped";
                }
            }
            else if (e == "StarLost")
            {
                lock (m_sync)
                {
                    AppState = "LostLock";
                    AvgDist  = (double)ev["AvgDist"];
                }
            }
            else
            {
                Debug.WriteLine(String.Format("todo: handle event {0}", e));
            }
        }