////////////////////////////////////////////////////////////////////////////// // Sets the frequency and individual digit values ////////////////////////////////////////////////////////////////////////////// void CFreqCtrl::SetFrequency(qint64 freq) { int i; qint64 acc = 0; qint64 rem; int val; if( freq == m_Oldfreq) return; if( freq < m_MinFreq) freq = m_MinFreq; if( freq > m_MaxFreq) freq = m_MaxFreq; m_freq = freq - freq%m_MinStep; rem = m_freq; m_LeadZeroPos = m_NumDigits; for(i=m_NumDigits-1; i>=m_DigStart; i--) { val = (int)(rem/m_DigitInfo[i].weight); if(m_DigitInfo[i].val != val) { m_DigitInfo[i].val = val; m_DigitInfo[i].modified = TRUE; } rem = rem - val*m_DigitInfo[i].weight; acc += val; if( (acc==0) && ( i>m_DecPos) ) m_LeadZeroPos = i; } // signal the new frequency to world m_Oldfreq = m_freq; emit NewFrequency( m_freq ); UpdateCtrl(m_LastLeadZeroPos != m_LeadZeroPos); m_LastLeadZeroPos = m_LeadZeroPos; }
///////////////////////////////////////////////////////////////////// // Constructor/Destructor ///////////////////////////////////////////////////////////////////// MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setWindowTitle(PROGRAM_TITLE_VERSION); //create SDR interface class m_pSdrInterface = new CSdrInterface; //give GUI plotter access to the sdr interface object ui->framePlot->SetSdrInterface(m_pSdrInterface); //create the global Testbench object if(!g_pTestBench) g_pTestBench = new CTestBench(this); readSettings(); //read persistent settings ui->actionAlwaysOnTop->setChecked(m_AlwaysOnTop); AlwaysOnTop(); //create Demod setup menu for non-modal use(can leave up and still access rest of program) m_pDemodSetupDlg = new CDemodSetupDlg(this); m_pTimer = new QTimer(this); //connect a bunch of signals to the GUI objects connect(m_pTimer, SIGNAL(timeout()), this, SLOT(OnTimer())); connect(ui->frameFreqCtrl, SIGNAL(NewFrequency(qint64)), this, SLOT(OnNewCenterFrequency(qint64))); connect(ui->frameDemodFreqCtrl, SIGNAL(NewFrequency(qint64)), this, SLOT(OnNewDemodFrequency(qint64))); connect(m_pSdrInterface, SIGNAL(NewStatus(int)), this, SLOT( OnStatus(int) ) ); connect(m_pSdrInterface, SIGNAL(NewInfoData()), this, SLOT( OnNewInfoData() ) ); connect(m_pSdrInterface, SIGNAL(NewFftData()), this, SLOT( OnNewFftData() ) ); connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(OnExit())); connect(ui->actionNetwork, SIGNAL(triggered()), this, SLOT(OnNetworkDlg())); connect(ui->actionSoundCard, SIGNAL(triggered()), this, SLOT(OnSoundCardDlg())); connect(ui->actionSDR, SIGNAL(triggered()), this, SLOT(OnSdrDlg())); connect(ui->actionDisplay, SIGNAL(triggered()), this, SLOT(OnDisplayDlg())); connect(ui->actionAlwaysOnTop, SIGNAL(triggered()), this, SLOT(AlwaysOnTop())); connect(ui->actionDemod_Setup, SIGNAL(triggered()), this, SLOT(OnDemodDlg())); connect(ui->actionNoise_Processing, SIGNAL(triggered()), this, SLOT(OnNoiseProcDlg())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(OnAbout())); connect(ui->framePlot, SIGNAL(NewDemodFreq(qint64)), this, SLOT( OnNewScreenDemodFreq(qint64) ) ); connect(ui->framePlot, SIGNAL(NewCenterFreq(qint64)), this, SLOT( OnNewScreenCenterFreq(qint64) ) ); connect(ui->framePlot, SIGNAL(NewLowCutFreq(int)), this, SLOT( OnNewLowCutFreq(int) ) ); connect(ui->framePlot, SIGNAL(NewHighCutFreq(int)), this, SLOT( OnNewHighCutFreq(int) ) ); m_pTimer->start(200); //start up status timer m_pSdrInterface->SetRadioType(m_RadioType); quint32 maxspan = m_pSdrInterface->GetMaxBWFromIndex(m_BandwidthIndex); ui->framePlot->SetPercent2DScreen(m_Percent2DScreen); //initialize controls and limits qint32 tmpspan = m_SpanFrequency; //save since setting range triggers control to update ui->SpanspinBox->setMaximum(maxspan/1000); m_SpanFrequency = tmpspan; if(m_SpanFrequency>maxspan) m_SpanFrequency = maxspan; ui->SpanspinBox->setValue(m_SpanFrequency/1000); m_LastSpanKhz = m_SpanFrequency/1000; //tmp save demod freq since gets set to center freq by center freq control inititalization qint64 tmpdemod = m_DemodFrequency; ui->frameFreqCtrl->Setup(9, 100U, 500000000U, 1, UNITS_KHZ ); ui->frameFreqCtrl->SetBkColor(Qt::darkBlue); ui->frameFreqCtrl->SetDigitColor(Qt::cyan); ui->frameFreqCtrl->SetUnitsColor(Qt::lightGray); ui->frameFreqCtrl->SetHighlightColor(Qt::darkGray); ui->frameFreqCtrl->SetFrequency(m_CenterFrequency); m_DemodFrequency = tmpdemod; ui->frameDemodFreqCtrl->Setup(9, 100U, 500000000U, 1, UNITS_KHZ ); ui->frameDemodFreqCtrl->SetBkColor(Qt::darkBlue); ui->frameDemodFreqCtrl->SetDigitColor(Qt::white); ui->frameDemodFreqCtrl->SetUnitsColor(Qt::lightGray); ui->frameDemodFreqCtrl->SetHighlightColor(Qt::darkGray); //limit demod frequency to Center Frequency +/-span frequency ui->frameDemodFreqCtrl->Setup(9, m_CenterFrequency-m_SpanFrequency/2, m_CenterFrequency+m_SpanFrequency/2, 1, UNITS_KHZ ); ui->frameDemodFreqCtrl->SetFrequency(m_DemodFrequency); ui->framePlot->SetSpanFreq( m_SpanFrequency ); ui->framePlot->SetCenterFreq( m_CenterFrequency ); ui->framePlot->SetClickResolution(m_ClickResolution); m_FreqChanged = false; ui->horizontalSliderVol->setValue(m_Volume); m_pSdrInterface->SetVolume(m_Volume); ui->ScalecomboBox->addItem("10 dB/Div", 10); ui->ScalecomboBox->addItem("5 dB/Div", 5); ui->ScalecomboBox->addItem("3 dB/Div", 3); ui->ScalecomboBox->addItem("1 dB/Div", 1); m_dBStepSize = (int)ui->ScalecomboBox->itemData(m_VertScaleIndex).toInt(); ui->ScalecomboBox->setCurrentIndex(m_VertScaleIndex); ui->framePlot->SetdBStepSize(m_dBStepSize); ui->MaxdBspinBox->setValue(m_MaxdB); ui->MaxdBspinBox->setSingleStep(m_dBStepSize); ui->MaxdBspinBox->setMinimum(MIN_FFTDB+VERT_DIVS*m_dBStepSize); ui->MaxdBspinBox->setMaximum(MAX_FFTDB); ui->framePlot->SetMaxdB(m_MaxdB); m_pSdrInterface->SetFftSize( m_FftSize); m_pSdrInterface->SetFftAve( m_FftAve); m_pSdrInterface->SetMaxDisplayRate(m_MaxDisplayRate); m_pSdrInterface->SetSdrBandwidthIndex(m_BandwidthIndex); m_pSdrInterface->SetSdrRfGain( m_RfGain ); m_pSdrInterface->ManageNCOSpurOffsets(CSdrInterface::NCOSPUR_CMD_SET, &m_NCOSpurOffsetI, &m_NCOSpurOffsetQ); m_pSdrInterface->SetSoundCardSelection(m_SoundInIndex, m_SoundOutIndex, m_StereoOut); m_pSdrInterface->SetSpectrumInversion(m_InvertSpectrum); m_pSdrInterface->SetUSFmVersion(m_USFm); InitDemodSettings(); ui->framePlot->SetDemodCenterFreq( m_DemodFrequency ); SetupDemod(m_DemodMode); m_RdsDecode.DecodeReset(m_USFm); SetupNoiseProc(); UpdateInfoBox(); m_ActiveDevice = ""; m_pSdrInterface->SetupNetwork(m_IPAdr,m_Port); m_Status = CSdrInterface::NOT_CONNECTED; m_LastStatus = m_Status; m_pSdrInterface->StartIO(); m_KeepAliveTimer = 0; if(m_UseTestBench) { //make sure top of dialog is visable(0,0 doesn't include menu bar.Qt bug?) if(m_TestBenchRect.top()<30) m_TestBenchRect.setTop(30); g_pTestBench->setGeometry(m_TestBenchRect); g_pTestBench->show(); g_pTestBench->Init(); } }
MainWindow::MainWindow(const QString cfgfile, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), d_lnb_lo(0), dec_bpsk1000(0), dec_afsk1200(0) { ui->setupUi(this); /* Initialise default configuration directory */ QByteArray xdg_dir = qgetenv("XDG_CONFIG_HOME"); if (xdg_dir.isEmpty()) m_cfg_dir = QString("%1/.config/gqrx").arg(QDir::homePath()); // Qt takes care of conversion to native separators else m_cfg_dir = QString("%1/gqrx").arg(xdg_dir.data()); setWindowTitle(QString("gqrx %1 (OsmoSDR)").arg(VERSION)); /* frequency control widget */ ui->freqCtrl->Setup(10, (quint64) 0, (quint64) 9999e6, 1, UNITS_MHZ); ui->freqCtrl->SetFrequency(144500000); d_filter_shape = receiver::FILTER_SHAPE_NORMAL; /* create receiver object */ QString indev = CIoConfig::getFcdDeviceName(); //QString outdev = settings.value("output").toString(); rx = new receiver(indev.toStdString(), ""); rx->set_rf_freq(144500000.0f); rx->set_rf_sample_rate(1920000.0); // TODO variable ui->plotter->setSampleRate(1920000); /* meter timer */ meter_timer = new QTimer(this); connect(meter_timer, SIGNAL(timeout()), this, SLOT(meterTimeout())); /* FFT timer & data */ iq_fft_timer = new QTimer(this); connect(iq_fft_timer, SIGNAL(timeout()), this, SLOT(iqFftTimeout())); audio_fft_timer = new QTimer(this); connect(audio_fft_timer, SIGNAL(timeout()), this, SLOT(audioFftTimeout())); d_fftData = new std::complex<float>[MAX_FFT_SIZE]; d_realFftData = new double[MAX_FFT_SIZE]; /* timer for data decoders */ dec_timer = new QTimer(this); connect(dec_timer, SIGNAL(timeout()), this, SLOT(decoderTimeout())); /* create dock widgets */ uiDockRxOpt = new DockRxOpt(); uiDockAudio = new DockAudio(); uiDockFcdCtl = new DockFcdCtl(); //uiDockIqPlay = new DockIqPlayer(); uiDockFft = new DockFft(); /* Add dock widgets to main window. This should be done even for dock widgets that are going to be hidden, otherwise they will end up floating in their own top-level window and can not be docked to the mainwindow. */ addDockWidget(Qt::RightDockWidgetArea, uiDockFcdCtl); addDockWidget(Qt::RightDockWidgetArea, uiDockRxOpt); tabifyDockWidget(uiDockFcdCtl, uiDockRxOpt); addDockWidget(Qt::RightDockWidgetArea, uiDockAudio); addDockWidget(Qt::RightDockWidgetArea, uiDockFft); tabifyDockWidget(uiDockAudio, uiDockFft); //addDockWidget(Qt::BottomDockWidgetArea, uiDockIqPlay); /* hide docks that we don't want to show initially */ //uiDockFcdCtl->hide(); //uiDockFft->hide(); //uiDockIqPlay->hide(); /* misc configurations */ //uiDockAudio->setFftRange(0, 8000); // FM /* Add dock widget actions to View menu. By doing it this way all signal/slot connections will be established automagially. */ ui->menu_View->addAction(uiDockFcdCtl->toggleViewAction()); ui->menu_View->addAction(uiDockRxOpt->toggleViewAction()); ui->menu_View->addAction(uiDockAudio->toggleViewAction()); ui->menu_View->addAction(uiDockFft->toggleViewAction()); //ui->menu_View->addAction(uiDockIqPlay->toggleViewAction()); ui->menu_View->addSeparator(); ui->menu_View->addAction(ui->mainToolBar->toggleViewAction()); ui->menu_View->addSeparator(); ui->menu_View->addAction(ui->actionFullScreen); /* connect signals and slots */ connect(ui->freqCtrl, SIGNAL(NewFrequency(qint64)), this, SLOT(setNewFrequency(qint64))); connect(uiDockFcdCtl, SIGNAL(lnbLoChanged(double)), this, SLOT(setLnbLo(double))); connect(uiDockFcdCtl, SIGNAL(lnaGainChanged(float)), SLOT(setRfGain(float))); connect(uiDockFcdCtl, SIGNAL(lnaAutoGainChanged(int)), this, SLOT(setRfGainMode(int))); connect(uiDockFcdCtl, SIGNAL(freqCorrChanged(int)), this, SLOT(setFreqCorr(int))); connect(uiDockFcdCtl, SIGNAL(iqCorrChanged(double,double)), this, SLOT(setIqCorr(double,double))); connect(uiDockRxOpt, SIGNAL(filterOffsetChanged(qint64)), this, SLOT(setFilterOffset(qint64))); connect(uiDockRxOpt, SIGNAL(demodSelected(int)), this, SLOT(selectDemod(int))); connect(uiDockRxOpt, SIGNAL(fmMaxdevSelected(float)), this, SLOT(setFmMaxdev(float))); connect(uiDockRxOpt, SIGNAL(fmEmphSelected(double)), this, SLOT(setFmEmph(double))); connect(uiDockRxOpt, SIGNAL(agcToggled(bool)), this, SLOT(setAgcOn(bool))); connect(uiDockRxOpt, SIGNAL(agcHangToggled(bool)), this, SLOT(setAgcHang(bool))); connect(uiDockRxOpt, SIGNAL(agcThresholdChanged(int)), this, SLOT(setAgcThreshold(int))); connect(uiDockRxOpt, SIGNAL(agcSlopeChanged(int)), this, SLOT(setAgcSlope(int))); connect(uiDockRxOpt, SIGNAL(agcGainChanged(int)), this, SLOT(setAgcGain(int))); connect(uiDockRxOpt, SIGNAL(agcDecayChanged(int)), this, SLOT(setAgcDecay(int))); connect(uiDockRxOpt, SIGNAL(noiseBlankerChanged(int,bool,float)), this, SLOT(setNoiseBlanker(int,bool,float))); connect(uiDockRxOpt, SIGNAL(sqlLevelChanged(double)), this, SLOT(setSqlLevel(double))); connect(uiDockAudio, SIGNAL(audioGainChanged(float)), this, SLOT(setAudioGain(float))); connect(uiDockAudio, SIGNAL(audioRecStarted(QString)), this, SLOT(startAudioRec(QString))); connect(uiDockAudio, SIGNAL(audioRecStopped()), this, SLOT(stopAudioRec())); connect(uiDockAudio, SIGNAL(audioPlayStarted(QString)), this, SLOT(startAudioPlayback(QString))); connect(uiDockAudio, SIGNAL(audioPlayStopped()), this, SLOT(stopAudioPlayback())); connect(uiDockAudio, SIGNAL(fftRateChanged(int)), this, SLOT(setAudioFftRate(int))); connect(uiDockFft, SIGNAL(fftSizeChanged(int)), this, SLOT(setIqFftSize(int))); connect(uiDockFft, SIGNAL(fftRateChanged(int)), this, SLOT(setIqFftRate(int))); connect(uiDockFft, SIGNAL(fftSplitChanged(int)), this, SLOT(setIqFftSplit(int))); // restore last session loadConfig(cfgfile); }