private void DisplayTrackingData()
        {
#if CALLSTACK_REALTIME
            Console.WriteLine("CALLSTACK:DisplayTrackingData");
#endif
            bool bPlaySound = false;

            bool bReinitGraphLimits = (m_PointList_Tracking_Avg.Count == 0);

            m_PointList_Tracking_Normal.Clear();
            m_GraphLine_Tracking_Normal.Clear();
            m_GraphLine_Tracking_Normal.Line.IsSmooth = menuSmoothSignals.Checked;
            m_PointList_Tracking_Avg.Clear();
            m_GraphLine_Tracking_Avg.Clear();
            m_GraphLine_Tracking_Avg.Line.IsSmooth = menuSmoothSignals.Checked;

            m_GraphTrackingGenerator.GraphPane.YAxis.MajorGrid.IsVisible = menuShowGrid.Checked;
            m_GraphTrackingGenerator.GraphPane.XAxis.MajorGrid.IsVisible = menuShowGrid.Checked;

            DisplayTrackingData_TextProgress(false);

            if (m_objRFEAnalyzer.IsTrackingNormalizing != m_TrackingStatus.IsVisible)
            {
                m_TrackingStatus.IsVisible = m_objRFEAnalyzer.IsTrackingNormalizing;
                m_GraphTrackingGenerator.Refresh();
            }

            m_MarkersSNA.HideAllMarkers();
            //draw all marker except tracking 1
            UpdateMarkerCollectionFromMenuSNA();
            //remove old text from all peak track markers and redraw
            m_MarkersSNA.CleanAllMarkerText(0);

            if (m_objRFEAnalyzer.TrackingData.Count == 0)
            {
                m_GraphTrackingGenerator.Refresh();
                return; //nothing to paint
            }

            //Use the latest data loaded
            uint nLastSample = m_objRFEAnalyzer.TrackingData.Count - 1;
            uint nAvailableAverageSamples = 1;
            uint nAverageIterations       = m_ToolGroup_RFEGenTracking.Average;
            if (nAverageIterations == 0)
            {
                nAverageIterations = 1;
            }
            if (nLastSample >= (nAverageIterations - 1))
            {
                nAvailableAverageSamples = nAverageIterations;
            }
            else
            {
                nAvailableAverageSamples = nLastSample + 1;
            }

            RFESweepData objSweep    = m_objRFEAnalyzer.TrackingData.GetData(nLastSample);
            RFESweepData objSweepAvg = m_objRFEAnalyzer.TrackingData.GetMedianAverage(nLastSample + 1 - nAvailableAverageSamples, nLastSample);
            objSweep.StepFrequencyMHZ = m_objRFEGenerator.RFGenTrackStepMHZ(); //step tracking frequency is not known by analyzer

            double dMinDB       = 100;
            double dMaxDB       = -120;
            double dMarginMinDB = 10;
            double dMarginMaxDB = 10;

            for (UInt16 nInd = 0; nInd < objSweep.TotalSteps; nInd++)
            {
                //normal realtime
                double dDB = objSweep.GetAmplitudeDBM(nInd) - m_objRFEAnalyzer.TrackingNormalizedData.GetAmplitudeDBM(nInd);
                if (dDB > dMaxDB)
                {
                    dMaxDB = dDB;
                }
                if (dDB < dMinDB)
                {
                    dMinDB = dDB;
                }
                m_PointList_Tracking_Normal.Add(objSweep.GetFrequencyMHZ(nInd), dDB, RFECommunicator.MIN_AMPLITUDE_DBM);
                //average
                if (objSweepAvg != null)
                {
                    dDB = objSweepAvg.GetAmplitudeDBM(nInd) - m_objRFEAnalyzer.TrackingNormalizedData.GetAmplitudeDBM(nInd);
                    if (dDB > dMaxDB)
                    {
                        dMaxDB = dDB;
                    }
                    if (dDB < dMinDB)
                    {
                        dMinDB = dDB;
                    }
                    m_PointList_Tracking_Avg.Add(objSweepAvg.GetFrequencyMHZ(nInd), dDB, RFECommunicator.MIN_AMPLITUDE_DBM);
                }
            }

            bool bUseVSWR = (m_ToolGroup_RFEGenTracking.ListSNAOptionsIndex == 2);

            if (bUseVSWR)
            {
                m_PointList_Tracking_Normal.ConvertToVSWR(100);
                m_PointList_Tracking_Avg.ConvertToVSWR(100);
            }

            m_GraphLine_Tracking_Normal.Points          = m_PointList_Tracking_Normal;
            m_GraphLine_Tracking_Normal.IsVisible       = true;
            m_GraphLine_Tracking_Normal.Label.IsVisible = true;

            m_GraphLine_Tracking_Avg.Points          = m_PointList_Tracking_Avg;
            m_GraphLine_Tracking_Avg.IsVisible       = true;
            m_GraphLine_Tracking_Avg.Label.IsVisible = true;

            if (!bUseVSWR)
            {
                //Limit lines are not supported in VSWR mode
                if (m_LimitLineGenerator_Max.Count > 1)
                {
                    PointPairList listCheck = null;
                    SelectSinglePointPairList(ref listCheck);
                    if (listCheck != null)
                    {
                        m_GraphLimitLineGenerator_Max.Points    = m_LimitLineGenerator_Max;
                        m_GraphLimitLineGenerator_Max.IsVisible = true;
                        if (m_LimitLineGenerator_Max.Intersect(listCheck, true))
                        {
                            bPlaySound = true;
                            m_GraphLimitLineGenerator_Max.Line.Width = 5;
                        }
                        else
                        {
                            m_GraphLimitLineGenerator_Max.Line.Width = 1;
                        }

                        int nDummy;
                        m_LimitLineGenerator_Max.GetMaxMinValues(ref dMinDB, ref dMaxDB, out nDummy, out nDummy);
                        dMarginMaxDB = 5;
                    }
                    else
                    {
                        m_GraphLimitLineGenerator_Max.IsVisible = false;
                    }
                }

                if (m_LimitLineGenerator_Min.Count > 1)
                {
                    PointPairList listCheck = null;
                    SelectSinglePointPairList(ref listCheck);
                    if (listCheck != null)
                    {
                        m_GraphLimitLineGenerator_Min.Points    = m_LimitLineGenerator_Min;
                        m_GraphLimitLineGenerator_Min.IsVisible = true;
                        if (m_LimitLineGenerator_Min.Intersect(listCheck, false))
                        {
                            bPlaySound = true;
                            m_GraphLimitLineGenerator_Min.Line.Width = 5;
                        }
                        else
                        {
                            m_GraphLimitLineGenerator_Min.Line.Width = 1;
                        }

                        int nDummy;
                        m_LimitLineGenerator_Min.GetMaxMinValues(ref dMinDB, ref dMaxDB, out nDummy, out nDummy);
                        dMarginMinDB = 5;
                    }
                    else
                    {
                        m_GraphLimitLineGenerator_Min.IsVisible = false;
                    }
                }
            }
            else
            {
                m_GraphLimitLineGenerator_Min.IsVisible = false;
                m_GraphLimitLineGenerator_Max.IsVisible = false;
            }

            m_GraphTrackingGenerator.GraphPane.XAxis.Scale.Min = objSweep.StartFrequencyMHZ;
            m_GraphTrackingGenerator.GraphPane.XAxis.Scale.Max = objSweep.EndFrequencyMHZ;
            double dGraphMin = m_GraphTrackingGenerator.GraphPane.YAxis.Scale.Min;
            if (bReinitGraphLimits)
            {
                dGraphMin = -1E6;
            }
            if (bUseVSWR || (dGraphMin < dMinDB - (dMarginMinDB * 1.5)) || (dGraphMin > dMinDB - 5))
            {
                if (bUseVSWR)
                {
                    m_GraphTrackingGenerator.GraphPane.YAxis.Scale.Min = 1;
                }
                else
                {
                    m_GraphTrackingGenerator.GraphPane.YAxis.Scale.Min = dMinDB - dMarginMinDB;
                }
            }
            double dGraphMax = m_GraphTrackingGenerator.GraphPane.YAxis.Scale.Max;
            if (bReinitGraphLimits)
            {
                dGraphMax = 1E6;
            }
            if (bUseVSWR || (dGraphMax > dMaxDB + (dMarginMaxDB * 1.5)) || (dGraphMax < dMaxDB + 5))
            {
                if (bUseVSWR)
                {
                    m_GraphTrackingGenerator.GraphPane.YAxis.Scale.Max = ConvertDB2VSWR(0.95 * dMaxDB, 105);
                }
                else
                {
                    m_GraphTrackingGenerator.GraphPane.YAxis.Scale.Max = dMaxDB + dMarginMaxDB;
                }
            }

            if (bPlaySound && menuItemSoundAlarmLimitLine.Checked)
            {
                PlayNotificationSound();
            }
            else
            {
                StopNotificationSound();
            }


            //draw marker 1
            double fTrackPeakMHZ = 0.0;
            if (m_arrMarkersEnabledMenu[0].Checked)
            {
                int nNormalIndex = -1;
                int nAvgIndex    = -1;

                if (m_ToolGroup_RFEGenTracking.ListSNAOptions.Contains("Return Loss"))
                {
                    nNormalIndex = m_PointList_Tracking_Normal.GetIndexMin();
                    nAvgIndex    = m_PointList_Tracking_Avg.GetIndexMin();
                }
                else
                {
                    nNormalIndex = m_PointList_Tracking_Normal.GetIndexMax();
                    nAvgIndex    = m_PointList_Tracking_Avg.GetIndexMax();
                }

                double fTrackDBM = RFECommunicator.MIN_AMPLITUDE_DBM;
                if (m_ToolGroup_Markers_SNA.TrackSignalPeak == RFECommunicator.RFExplorerSignalType.Realtime)
                {
                    fTrackPeakMHZ = m_PointList_Tracking_Normal[nNormalIndex].X;
                    fTrackDBM     = m_PointList_Tracking_Normal[nNormalIndex].Y;
                }
                else if (m_ToolGroup_Markers_SNA.TrackSignalPeak == RFECommunicator.RFExplorerSignalType.Average)
                {
                    fTrackPeakMHZ = m_PointList_Tracking_Avg[nAvgIndex].X;
                    fTrackDBM     = m_PointList_Tracking_Avg[nAvgIndex].Y;
                }
                else
                {
                    m_arrMarkersEnabledMenu[0].Checked = false;
                    UpdateSNAMarkerControlContents();
                }
                m_MarkersSNA.SetMarkerFrequency(0, fTrackPeakMHZ);
            }

            if (m_arrMarkersEnabledMenu[0].Checked)
            {
                double dAmplitude = m_PointList_Tracking_Normal.InterpolateX(m_MarkersSNA.GetMarkerFrequency(0));
                m_MarkersSNA.UpdateMarker(0, RFECommunicator.RFExplorerSignalType.Realtime, dAmplitude);
                if ((m_ToolGroup_Markers_SNA.TrackSignalPeak == RFECommunicator.RFExplorerSignalType.Realtime) && menuShowPeak.Checked)
                {
                    m_MarkersSNA.SetMarkerText(0, RFECommunicator.RFExplorerSignalType.Realtime, m_MarkersSNA.GetMarkerFrequency(0).ToString("0.000") + "MHZ\n" + dAmplitude.ToString("0.00") + GetCurrentAmplitudeUnitLabel());
                }

                dAmplitude = m_PointList_Tracking_Avg.InterpolateX(m_MarkersSNA.GetMarkerFrequency(0));
                m_MarkersSNA.UpdateMarker(0, RFECommunicator.RFExplorerSignalType.Average, dAmplitude);
                if ((m_ToolGroup_Markers_SNA.TrackSignalPeak == RFECommunicator.RFExplorerSignalType.Average) && menuShowPeak.Checked)
                {
                    m_MarkersSNA.SetMarkerText(0, RFECommunicator.RFExplorerSignalType.Average, m_MarkersSNA.GetMarkerFrequency(0).ToString("0.000") + "MHZ\n" + dAmplitude.ToString("0.00") + GetCurrentAmplitudeUnitLabel());
                }
            }
            UpdateMarkerCollectionFromMenuSNA();
            //remove old text from all peak track markers and redraw
            m_MarkersSNA.CleanAllMarkerText(0);

            UpdateSNAMarkerControlValues();
            m_GraphTrackingGenerator.AxisChange();
            m_GraphTrackingGenerator.Refresh();
        }
Esempio n. 2
0
        private void UpdateWaterfall()
        {
            Dictionary <double, double> RTList  = new Dictionary <double, double>();
            Dictionary <double, double> MaxList = new Dictionary <double, double>();
            Dictionary <double, double> MinList = new Dictionary <double, double>();
            Dictionary <double, double> AvgList = new Dictionary <double, double>();

            if (m_objRFE.SweepData.Count == 0)
            {
                return; //nothing to paint
            }
            UInt32 nSweepIndex = (UInt32)m_objRFE.SweepData.UpperBound;

            m_nDrawingIteration++;

            UInt32 nTotalCalculatorIterations = (UInt32)numericIterations.Value;

            if (nTotalCalculatorIterations > nSweepIndex)
            {
                nTotalCalculatorIterations = nSweepIndex;
            }

            if ((m_nDrawingIteration & 0xf) == 0)
            {
                //Update screen status every 16 drawing iterations only to reduce overhead
                toolStripMemory.Value = (int)nSweepIndex;
                if (m_objRFE.PortConnected)
                {
                    toolCOMStatus.Text = "Connected";
                }
                else
                {
                    toolCOMStatus.Text = "Disconnected";
                }

                toolStripSamples.Text = "Total Samples in buffer: " + (UInt32)numericSampleSA.Value + "/" + RFESweepDataCollection.MAX_ELEMENTS + " - " + (100 * (double)numericSampleSA.Value / RFESweepDataCollection.MAX_ELEMENTS).ToString("0.0") + "%";
            }

            double fRealtimeMax_Amp  = -200.0;
            int    fRealtimeMax_Iter = 0;
            double fAverageMax_Amp   = -200.0;
            int    fAverageMax_Iter  = 0;
            double fMaxMax_Amp       = -200.0;
            int    fMaxMax_Iter      = 0;

            m_AveragePeak.Text  = "";
            m_RealtimePeak.Text = "";
            m_MaxPeak.Text      = "";

            RFESweepData objSweep = m_objRFE.SweepData.GetData(nSweepIndex);

            for (UInt16 nSweepPointInd = 0; nSweepPointInd < m_objRFE.FreqSpectrumSteps; nSweepPointInd++)
            {
                double fVal = objSweep.GetAmplitudeDBM(nSweepPointInd);
                if (fVal > fRealtimeMax_Amp)
                {
                    fRealtimeMax_Amp  = fVal;
                    fRealtimeMax_Iter = nSweepPointInd;
                }

                double fFreq = m_objRFE.StartFrequencyMHZ + m_objRFE.StepFrequencyMHZ * nSweepPointInd;

                double fMax    = fVal;
                double fMin    = fVal;
                double fValAvg = fVal;

                for (UInt32 nSweepIterator = nSweepIndex - nTotalCalculatorIterations; nSweepIterator < nSweepIndex; nSweepIterator++)
                {
                    //Calculate average, max and min over Calculator range
                    RFESweepData objSweepIter = m_objRFE.SweepData.GetData(nSweepIterator);
                    if (objSweepIter != null)
                    {
                        double fVal2 = objSweepIter.GetAmplitudeDBM(nSweepPointInd);

                        fMax     = Math.Max(fMax, fVal2);
                        fMin     = Math.Min(fMin, fVal2);
                        fValAvg += fVal2;
                    }
                }

                if (m_bDrawRealtime)
                {
                    RTList.Add(fFreq, fVal);
                }
                if (m_bDrawMin)
                {
                    MinList.Add(fFreq, fMin);
                }

                if (m_bDrawMax)
                {
                    MaxList.Add(fFreq, fMax);
                    if (fMax > fMaxMax_Amp)
                    {
                        fMaxMax_Amp  = fMax;
                        fMaxMax_Iter = nSweepPointInd;
                    }
                }

                if (m_bDrawAverage)
                {
                    fValAvg = fValAvg / (nTotalCalculatorIterations + 1);
                    AvgList.Add(fFreq, fValAvg);
                    if (fValAvg > fAverageMax_Amp)
                    {
                        fAverageMax_Amp  = fValAvg;
                        fAverageMax_Iter = nSweepPointInd;
                    }
                }

                if (m_bDrawMax)
                {
                    controlWaterfall.DrawWaterfall(MaxList);
                }
                else if (m_bDrawAverage)
                {
                    controlWaterfall.DrawWaterfall(AvgList);
                }
                else if (m_bDrawRealtime)
                {
                    controlWaterfall.DrawWaterfall(RTList);
                }
                else if (m_bDrawMin)
                {
                    controlWaterfall.DrawWaterfall(MinList);
                }

                controlWaterfall.Invalidate();
            }
        }