public MainForm(string sFile) { #if CALLSTACK Console.WriteLine("CALLSTACK:MainForm"); #endif try { if (!String.IsNullOrEmpty(sFile)) m_sStartFile = sFile; SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); InitializeComponent(); InitializeRFGenTab(); m_GraphSpectrumAnalyzer = new ZedGraph.ZedGraphControl(); m_WaterfallSweepMaxHold = new RFESweepDataCollection(100, false); m_Markers = new MarkerCollection(); m_Markers.Initialize(); CreateMarkerMenu(); m_objRFEAnalyzer = new RFECommunicator(); m_objRFEAnalyzer.PortClosedEvent += new EventHandler(OnAnalyzerPortClosed); m_objRFEAnalyzer.PortConnectedEvent += new EventHandler(OnAnalyzerPortConnected); m_objRFEAnalyzer.ReportInfoAddedEvent += new EventHandler(OnAnalyzerReportLog); m_objRFEAnalyzer.ReceivedConfigurationDataEvent += new EventHandler(OnAnalyzerReceivedConfigData); m_objRFEAnalyzer.UpdateDataEvent += new EventHandler(OnAnalyzerUpdateData); m_objRFEAnalyzer.UpdateRemoteScreenEvent += new EventHandler(OnAnalyzerUpdateRemoteScreen); m_objRFEAnalyzer.ReceivedDeviceModelEvent += new EventHandler(OnAnalyzerReceivedDeviceModel); m_objRFEAnalyzer.UpdateDataTrakingNormalizationEvent += new EventHandler(OnAnalyzerUpdateDataTrakingNormalization); m_objRFEAnalyzer.UpdateDataTrakingEvent += new EventHandler(OnAnalyzerUpdateTrackingData); m_objRFEAnalyzer.ShowDetailedCOMPortInfo = false; m_groupCOMPortAnalyzer = new ToolGroupCOMPort(); m_groupCOMPortAnalyzer.RFExplorer = m_objRFEAnalyzer; m_groupCOMPortAnalyzer.PortClosed += new EventHandler(OnAnalyzerButtons_PortClosed); m_groupCOMPortAnalyzer.PortConnected += new EventHandler(OnAnalyzerButtons_PortConnected); m_groupCOMPortAnalyzer.GroupBoxTitle = "COM Port Spectrum Analyzer"; m_objRFEGenerator = new RFECommunicator(); m_objRFEGenerator.PortClosedEvent += new EventHandler(OnGeneratorPortClosed); m_objRFEGenerator.PortConnectedEvent += new EventHandler(OnGeneratorPortConnected); m_objRFEGenerator.ReportInfoAddedEvent += new EventHandler(OnGeneratorReportLog); m_objRFEGenerator.ReceivedConfigurationDataEvent += new EventHandler(OnGeneratorReceivedConfigData); //m_objRFEGen.UpdateData += new EventHandler(OnRFE_UpdateData); m_objRFEGenerator.UpdateRemoteScreenEvent += new EventHandler(OnAnalyzerUpdateRemoteScreen); m_objRFEGenerator.ReceivedDeviceModelEvent += new EventHandler(OnGeneratorReceivedDeviceModel); m_objRFEGenerator.ShowDetailedCOMPortInfo = false; m_groupCOMPortGenerator = new ToolGroupCOMPort(); m_groupCOMPortGenerator.RFExplorer = m_objRFEGenerator; //m_groupCOMPortGenerator.PortClosed += new EventHandler(OnGeneratorButtons_PortClosed); //m_groupCOMPortGenerator.PortConnected += new EventHandler(OnGeneratorButtons_PortConnected); m_groupCOMPortGenerator.GroupBoxTitle = "COM Port Signal Generator"; printMainDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument_PrintPage); printMainDocument.DocumentName = "RF Explorer"; } catch (Exception obEx) { string sReportFile = Environment.GetEnvironmentVariable("APPDATA") + "\\rfexplorer_crash.log"; using (StreamWriter sr = new StreamWriter(sReportFile, true)) { sr.WriteLine(Environment.NewLine + Environment.NewLine + "------------------------------------------------------------" + Environment.NewLine + "Report log date " + DateTime.Now.ToString() + Environment.NewLine); sr.WriteLine("Exception: " + obEx.ToString()); sr.Flush(); } } }
public RFECommunicator() { InitializeModels(); m_LastCaptureTime = new DateTime(2000, 1, 1); m_SweepDataContainer = new RFESweepDataCollection(100 * 1024, true); m_TrackingDataContainer = new RFESweepDataCollection(1024, true); m_ScreenDataContainer = new RFEScreenDataCollection(); m_nScreenIndex = 0; m_arrReceivedData = new Queue(); m_bRunReceiveThread = true; ThreadStart threadDelegate = new ThreadStart(this.ReceiveThreadfunc); m_ReceiveThread = new Thread(threadDelegate); m_ReceiveThread.Start(); ReportLog("RFECommunicator library started."); for (int nInd = 0; nInd < m_arrFLASH.Length; nInd++) { m_arrFLASH[nInd] = new RFEMemoryBlock(); m_arrFLASH[nInd].Address = (UInt32)(nInd * RFEMemoryBlock.MAX_BLOCK_SIZE); } try { m_serialPortObj = new SerialPort(); } catch (Exception obEx) { ReportLog("Error in RFECommunicator constructor: " + obEx.ToString()); } }
/// <summary> /// removes any prior loaeded normalization data /// </summary> public void ResetTrackingNormalizedData() { m_SweepTrackingNormalized = null; m_SweepTrackingNormalizedContainer = null; }
/// <summary> /// load a normalization SNA file and reconfigures m_SweepTrackingNormalized based on that /// </summary> /// <param name="sFilename"></param> /// <returns></returns> private bool LoadFileSNANormalization(string sFilename) { RFESweepDataCollection objCollection = new RFESweepDataCollection(1, true); string sModel, sConfig; if (objCollection.LoadFile(sFilename, out sModel, out sConfig)) { if (!sModel.Contains(_RFEGEN_FILE_MODEL_Mark)) return false; int nIndRFEGen = sModel.IndexOf(_RFEGEN_FILE_MODEL_Mark); string sModelRFEGen = sModel.Substring(nIndRFEGen + 1 + _RFEGEN_FILE_MODEL_Mark.Length); nIndRFEGen = sConfig.IndexOf(_RFEGEN_FILE_MODEL_Mark); string sConfigRFEGen = sConfig.Substring(nIndRFEGen + 1 + _RFEGEN_FILE_MODEL_Mark.Length); m_SweepTrackingNormalized = objCollection.GetData(0); return UpdateOfflineConfigurationParameters_Generator(sConfigRFEGen, sModelRFEGen); } else return false; }
public bool SaveFileSNANormalization(string sFilename) { if (!IsTrackingNormalized()) return false; RFESweepDataCollection objCollection = new RFESweepDataCollection(1, true); objCollection.Add(TrackingNormalizedData); objCollection.SaveFile(sFilename, FullModelText + " - " + _RFEGEN_FILE_MODEL_Mark + " " + m_objRFEGen.FullModelText, ConfigurationText + " - " + _RFEGEN_FILE_MODEL_Mark + " " + m_objRFEGen.ConfigurationText, null); return true; }
public bool ProcessReceivedString(bool bProcessAllEvents, out string sReceivedString) { bool bDraw = false; sReceivedString = ""; try { do { bool bWrongFormat = false; object objNew = null; long nCount = 0; try { Monitor.Enter(m_arrReceivedData); nCount = m_arrReceivedData.Count; if (nCount == 0) break; objNew = m_arrReceivedData.Dequeue(); } catch (Exception obEx) { ReportLog("m_arrReceivedStrings processing: " + obEx.ToString()); } finally { Monitor.Exit(m_arrReceivedData); } if (objNew.GetType() == typeof(RFEConfiguration)) { RFEConfiguration objConfiguration = (RFEConfiguration)objNew; ReportLog("Received configuration: " + objConfiguration.sLineString); if (m_arrSpectrumAnalyzerEmbeddedCalibrationOffsetDB == null) { //request internal calibration data, if available SendCommand("Cq"); } if (IsGenerator()) { //signal generator RFGenStartFrequencyMHZ = objConfiguration.fStartMHZ; RFGenStepFrequencyMHZ = objConfiguration.fStepMHZ; RFGenCWFrequencyMHZ = objConfiguration.fRFEGenCWFreqMHZ; RFGenSweepSteps = objConfiguration.nFreqSpectrumSteps; RFGenStopFrequencyMHZ = RFGenStartFrequencyMHZ + RFGenSweepSteps * RFGenStepFrequencyMHZ; RFGenPowerON = objConfiguration.bRFEGenPowerON; RFGenPowerLevel = objConfiguration.nRFEGenPowerLevel; RFGenHighPowerSwitch = objConfiguration.bRFEGenHighPowerSwitch; MaxFreqMHZ = 6000; MinFreqMHZ = 23.438; RFGenStepWaitMS = objConfiguration.nRFEGenSweepWaitMS; OnReceivedConfigurationData(new EventArgs()); } else { //spectrum analyzer if ((Math.Abs(StartFrequencyMHZ - objConfiguration.fStartMHZ) >= 0.001) || (Math.Abs(StepFrequencyMHZ - objConfiguration.fStepMHZ) >= 0.001)) { StartFrequencyMHZ = objConfiguration.fStartMHZ; StepFrequencyMHZ = objConfiguration.fStepMHZ; ReportLog("New Freq range - buffer cleared."); } AmplitudeTopDBM = objConfiguration.fAmplitudeTopDBM; AmplitudeBottomDBM = objConfiguration.fAmplitudeBottomDBM; FreqSpectrumSteps = objConfiguration.nFreqSpectrumSteps; m_bExpansionBoardActive = objConfiguration.bExpansionBoardActive; if (m_bExpansionBoardActive) { m_eActiveModel = m_eExpansionBoardModel; if (ExpansionBoardModel == RFECommunicator.eModel.MODEL_WSUB3G) { //If it is a MODEL_WSUB3G, make sure we use the MAX HOLD mode to account for proper DSP Thread.Sleep(500); if (m_bUseMaxHold) { ReportLog("Updated remote mode to Max Hold for reliable DSP calculations with fast signals"); SendCommand_SetMaxHold(); } else { ReportLog("Remote mode is not Max Hold, some fast signals may not be detected"); SendCommand_Realtime(); } } } else { m_eActiveModel = m_eMainBoardModel; } m_eMode = objConfiguration.eMode; MinFreqMHZ = objConfiguration.fMinFreqMHZ; MaxFreqMHZ = objConfiguration.fMaxFreqMHZ; MaxSpanMHZ = objConfiguration.fMaxSpanMHZ; m_fRBWKHZ = objConfiguration.fRBWKHZ; m_fOffset_dB = objConfiguration.fOffset_dB; if ((m_eActiveModel == eModel.MODEL_2400) || (m_eActiveModel == eModel.MODEL_6G)) { MinSpanMHZ = 2.0; } else { MinSpanMHZ = 0.112; } if (objConfiguration.nFreqSpectrumSteps == 13) { m_eMode = RFECommunicator.eMode.MODE_WIFI_ANALYZER; } else { m_eMode = RFECommunicator.eMode.MODE_SPECTRUM_ANALYZER; } OnReceivedConfigurationData(new EventArgs()); } } else if (objNew.GetType() == typeof(RFESweepData)) { if (m_eMode == eMode.MODE_TRACKING) { if (m_bTrackingNormalizing) { if (m_SweepTrackingNormalizedContainer == null) m_SweepTrackingNormalizedContainer = new RFESweepDataCollection(3,true); RFESweepData objSweep=(RFESweepData)objNew; m_SweepTrackingNormalizedContainer.Add(objSweep); bool bWrongData=objSweep.GetAmplitudeDBM(objSweep.GetMinStep())<=MIN_AMPLITUDE_TRACKING_NORMALIZE; if (bWrongData || ((m_nAutoStopSNATrackingCounter != 0) && (m_SweepTrackingNormalizedContainer.Count >= m_nAutoStopSNATrackingCounter))) { StopTracking(); if (bWrongData) //invalid data, end so it can be restarted m_SweepTrackingNormalized = objSweep; else //if all samples collected, end and get average among them m_SweepTrackingNormalized = m_SweepTrackingNormalizedContainer.GetAverage(0, m_SweepTrackingNormalizedContainer.Count - 1); OnUpdateDataTrakingNormalization(new EventArgs()); } } else { RFESweepData objSweep = (RFESweepData)objNew; m_TrackingDataContainer.Add(objSweep); bDraw = true; OnUpdateDataTraking(new EventArgs()); if ((m_nAutoStopSNATrackingCounter != 0) && (m_nTrackingPass > m_nAutoStopSNATrackingCounter)) { StopTracking(); } } } else { if (!HoldMode) { RFESweepData objSweep = (RFESweepData)objNew; m_SweepDataContainer.Add(objSweep); bDraw = true; if (m_SweepDataContainer.IsFull()) { HoldMode = true; OnUpdateFeedMode(new EventArgs()); ReportLog("RAM Buffer is full."); } m_sSweepInfoText = "Captured:" + objSweep.CaptureTime.ToString("yyyy-MM-dd HH:mm:ss\\.fff"); TimeSpan objSpan = new TimeSpan(); objSpan = objSweep.CaptureTime - m_LastCaptureTime; if (objSpan.TotalSeconds < 60) { //if time between captures is less than 60 seconds, we can assume we are getting realtime data //and therefore can provide average sweep/seconds information, otherwise we were in hold or something //and data could not be used for these calculations. m_nAverageSweepSpeedIterator++; m_spanAverageSpeedAcumulator += (objSweep.CaptureTime - m_LastCaptureTime); if (m_fAverageSweepTime > 0.0) { m_sSweepInfoText += "\nSweep time: " + m_fAverageSweepTime.ToString("0.000") + " seconds - Avg Sweeps/second: " + (1.0 / m_fAverageSweepTime).ToString("0.0"); } if (m_nAverageSweepSpeedIterator >= 10) { m_fAverageSweepTime = m_spanAverageSpeedAcumulator.TotalSeconds / m_nAverageSweepSpeedIterator; m_nAverageSweepSpeedIterator = 0; m_spanAverageSpeedAcumulator = m_LastCaptureTime - m_LastCaptureTime; //set it to zero and start average all over again } } m_LastCaptureTime = objSweep.CaptureTime; OnUpdateData(new EventArgs()); } else { //if in hold mode, we just record last time came here to make sure we start from most reliable point in time m_LastCaptureTime = DateTime.Now; } } } else if (objNew.GetType() == typeof(RFEScreenData)) { if ((CaptureRemoteScreen) && (m_ScreenDataContainer.IsFull() == false)) { RFEScreenData objScreen = (RFEScreenData)objNew; objScreen.Model = ActiveModel; m_ScreenDataContainer.Add(objScreen); ScreenIndex = (UInt16)m_ScreenDataContainer.UpperBound; OnUpdateRemoteScreen(new EventArgs()); } else { //receiving Screen Dump data but it was intended to be disabled, resend a disable command now SendCommand("D0"); } } else { //received a string, so use it along to parse parameters string sLine = (string)objNew; sReceivedString = sLine; if ((sLine.Length > 3) && (sLine.Substring(0, 4) == _Acknowldedge)) { m_bAcknowledge = true; } else if ((sLine.Length > 16) && (sLine.Substring(0, 3) == "#Sn")) { m_sSerialNumber = sLine.Substring(3, 16); ReportLog("Device serial number: " + SerialNumber); } else if((sLine.Length > 2) && (sLine.Substring(0, 2) == "$q")) { //calibration data UInt16 nSize=Convert.ToUInt16(sLine[2]); if (IsGenerator()) { //signal generator uses a different approach for storing absolute amplitude value offset over an ideal -30dBm response if ((m_arrSignalGeneratorEmbeddedCalibrationActual30DBM == null) || (m_arrSignalGeneratorEmbeddedCalibrationActual30DBM.Length != nSize)) { m_arrSignalGeneratorEmbeddedCalibrationActual30DBM = new double[nSize]; for (int nInd = 0; nInd < nSize; nInd++) { m_arrSignalGeneratorEmbeddedCalibrationActual30DBM[nInd] = -30.0; } //Values using 10*delta from the value delivered when compared with 30dBm. //For instance if value delivered for a frequency is -28.5dBm, that is a +1.5dB difference //therefore a 1.5*10=15 value. If the value delivered is -33.2 that is a -3.2dB difference //therefore a -32 value. string sData = "Embedded calibration Signal Generator data received:"; for (int nInd = 0; nInd < nSize; nInd++) { m_arrSignalGeneratorEmbeddedCalibrationActual30DBM[nInd] = -30.0 + Convert.ToInt16(sLine[nInd + 3]) / 10.0; sData += m_arrSignalGeneratorEmbeddedCalibrationActual30DBM[nInd].ToString(); if (nInd < nSize - 1) sData += ","; } ReportLog(sData); } } else { if ((m_arrSpectrumAnalyzerEmbeddedCalibrationOffsetDB == null) || (m_arrSpectrumAnalyzerEmbeddedCalibrationOffsetDB.Length != nSize)) { m_arrSpectrumAnalyzerEmbeddedCalibrationOffsetDB = new float[nSize]; for (int nInd = 0; nInd < nSize; nInd++) { m_arrSpectrumAnalyzerEmbeddedCalibrationOffsetDB[nInd] = 0.0f; } } if (m_eActiveModel == eModel.MODEL_6G) { string sData = "Embedded calibration Spectrum Analyzer data received:"; for (int nInd = POS_EMBEDDED_CALIBRATED_6G; nInd < nSize; nInd++) { int nVal = Convert.ToInt32(sLine[nInd + 3]); if (nVal > 127) nVal = -(256 - nVal); //get the right sign m_arrSpectrumAnalyzerEmbeddedCalibrationOffsetDB[nInd] = nVal / 2.0f; //split by two to get dB sData += m_arrSpectrumAnalyzerEmbeddedCalibrationOffsetDB[nInd].ToString(); if (nInd < nSize - 1) sData += ","; } ReportLog(sData); } } } else if ((sLine.Length > 18) && (sLine.Substring(0, 18) == _ResetString)) { //RF Explorer device was reset for some reason, reconfigure client based on new configuration OnDeviceResetEvent(new EventArgs()); } else if ((sLine.Length > 5) && sLine.Substring(0, 6) == "#C2-M:") { ReportLog("Received RF Explorer device model info:" + sLine); m_eMainBoardModel = (eModel)Convert.ToUInt16(sLine.Substring(6, 3)); m_eExpansionBoardModel = (eModel)Convert.ToUInt16(sLine.Substring(10, 3)); m_sRFExplorerFirmware = (sLine.Substring(14, 5)); OnReceivedDeviceModel(new EventArgs()); } else if ((sLine.Length > 5) && sLine.Substring(0, 6) == "#C3-M:") { ReportLog("Received RF Explorer Generator device info:" + sLine); m_eMainBoardModel = (eModel)Convert.ToUInt16(sLine.Substring(6, 3)); m_eExpansionBoardModel = (eModel)Convert.ToUInt16(sLine.Substring(10, 3)); m_sRFExplorerFirmware = (sLine.Substring(14, 5)); OnReceivedDeviceModel(new EventArgs()); } else if ((sLine.Length > 2) && sLine.Substring(0, 3) == "#K1") { ReportLog("RF Explorer is now in TRACKING mode."); m_eMode = eMode.MODE_TRACKING; } else if ((sLine.Length > 2) && sLine.Substring(0, 3) == "#K0") { ReportLog("RF Explorer is now in ANALYZER mode."); m_eMode = eMode.MODE_SPECTRUM_ANALYZER; } else if ((sLine.Length > 2) && (sLine.Substring(0, 2) == "$S") && (StartFrequencyMHZ > 0.1)) { bWrongFormat = true; } #if SUPPORT_EXPERIMENTAL else if ((sLine.Length > 2) && sLine.Substring(0, 2) == "$R") { if (!HoldMode && m_nRAWSnifferIndex < m_nTotalBufferSize) { if (m_arrRAWSnifferData == null) { //don't allocate memory for this object before actually required as most users may not need this m_arrRAWSnifferData = new string[m_nTotalBufferSize]; } m_nRAWSnifferIndex++; if (m_nRAWSnifferIndex >= m_nTotalBufferSize) { m_nRAWSnifferIndex = m_nTotalBufferSize; HoldMode = true; UpdateFeedMode(); ReportLog("Buffer is full."); } else { m_arrRAWSnifferData[m_nRAWSnifferIndex] = sLine; } m_nMaxRAWSnifferIndex = m_nRAWSnifferIndex; DrawRAWDecoder(); } } #endif else if ((sLine.Length > 5) && (sLine.Substring(0, 6) == "#C2-F:")) { bWrongFormat = true; //parsed on the thread } else if ((sLine.Length > 5) && (sLine.Substring(0, 6) == "#C1-F:")) { bWrongFormat = true; //obsolete firmware } else { ReportLog(sLine); //report any line we don't understand - it is likely a human readable message } if (bWrongFormat) { ReportLog("Received unexpected data from RFExplorer device:" + sLine); ReportLog("Please update your RF Explorer to a recent firmware version and"); ReportLog("make sure you are using the latest version of RF Explorer for Windows."); ReportLog("Visit http://www.rf-explorer/download for latest firmware updates."); OnWrongFormatData(new EventArgs()); } } } while (bProcessAllEvents && (m_arrReceivedData.Count > 0)); } catch (Exception obEx) { ReportLog("ProcessReceivedString: " + sReceivedString + Environment.NewLine + obEx.ToString()); } return bDraw; }