forked from gqrx-sdr/gqrx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
1311 lines (1104 loc) · 38.3 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- c++ -*- */
/*
* Copyright 2011-2012 Alexandru Csete OZ9AEC.
* Copyright 2012 Mathis Schmieder <[email protected]>
*
* Gqrx is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* Gqrx is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Gqrx; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include <QSettings>
#include <QByteArray>
#include <QDateTime>
#include <QDesktopServices>
#include <QDebug>
#include "qtgui/ioconfig.h"
#include "mainwindow.h"
/* Qt Designer files */
#include "ui_mainwindow.h"
/* DSP */
#include "receiver.h"
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(), "pulse");
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);
}
MainWindow::~MainWindow()
{
/* stop and delete timers */
dec_timer->stop();
delete dec_timer;
meter_timer->stop();
delete meter_timer;
iq_fft_timer->stop();
delete iq_fft_timer;
audio_fft_timer->stop();
delete audio_fft_timer;
if (m_settings)
{
m_settings->setValue("configversion", 2);
// save session
m_settings->setValue("input/frequency", ui->freqCtrl->GetFrequency());
if (d_lnb_lo)
m_settings->setValue("input/lnb_lo", d_lnb_lo);
else
m_settings->remove("input/lnb_lo");
double dblval = uiDockFcdCtl->lnaGain();
m_settings->setValue("input/gain", dblval);
m_settings->setValue("input/corr_freq", uiDockFcdCtl->freqCorr());
dblval = uiDockFcdCtl->iqGain();
if (dblval < 1.0)
m_settings->setValue("input/corr_iq_gain", dblval);
else
m_settings->remove("input/corr_iq_gain");
dblval = uiDockFcdCtl->iqPhase();
if (dblval != 0.0)
m_settings->setValue("input/corr_iq_phase", dblval);
else
m_settings->remove("input/corr_iq_phase");
m_settings->sync();
delete m_settings;
}
delete ui;
delete uiDockRxOpt;
delete uiDockAudio;
delete uiDockFft;
//delete uiDockIqPlay;
delete uiDockFcdCtl;
delete rx;
delete [] d_fftData;
delete [] d_realFftData;
}
/*! \brief Load new configuration.
* \param cfgfile
* \returns Always true.
*
* If cfgfile is an absolute path it will be used as is, otherwise it is assumed to be the
* name of a file under m_cfg_dir.
*
* If cfgfile does not exist it will be created.
*/
bool MainWindow::loadConfig(const QString cfgfile)
{
qDebug() << "Loading configuration from:" << cfgfile;
if (m_settings)
delete m_settings;
if (QDir::isAbsolutePath(cfgfile))
m_settings = new QSettings(cfgfile, QSettings::IniFormat);
else
m_settings = new QSettings(QString("%1/%2").arg(m_cfg_dir).arg(cfgfile), QSettings::IniFormat);
qDebug() << "Configuration file:" << m_settings->fileName();
emit configChanged(m_settings);
// manual reconf (FIXME: check status)
bool cok = false;
uiDockFcdCtl->setFreqCorr(m_settings->value("input/corr_freq", -115).toInt(&cok));
d_lnb_lo = m_settings->value("input/lnb_lo", 0).toLongLong(&cok);
uiDockFcdCtl->setLnbLo((double)d_lnb_lo/1.0e6);
ui->freqCtrl->SetFrequency(m_settings->value("input/frequency", 144500000).toLongLong(&cok));
uiDockFcdCtl->setLnaGain(m_settings->value("input/gain", 20).toFloat(&cok));
setRfGain(m_settings->value("input/gain", 20).toFloat(&cok));
uiDockFcdCtl->setIqGain(m_settings->value("input/corr_iq_gain", 1.0).toDouble(&cok));
uiDockFcdCtl->setIqPhase(m_settings->value("input/corr_iq_phase", 0.0).toDouble(&cok));
return true;
}
/*! \brief Save current configuration to a file.
* \param cfgfile
* \returns True if the operation was successful.
*
* If cfgfile is an absolute path it will be used as is, otherwise it is assumed to be the
* name of a file under m_cfg_dir.
*
* If cfgfile already exists it will be overwritten (we assume that a file selection dialog
* has already asked for confirmation of overwrite.
*
* Since QSettings does not support "save as" we do this by copying the current
* settings to a new file.
*/
bool MainWindow::saveConfig(const QString cfgfile)
{
QString oldfile = m_settings->fileName();
QString newfile;
qDebug() << "Saving configuration to:" << cfgfile;
m_settings->sync();
if (QDir::isAbsolutePath(cfgfile))
newfile = cfgfile;
else
newfile = QString("%1/%2").arg(m_cfg_dir).arg(cfgfile);
if (QFile::copy(oldfile, newfile))
{
loadConfig(cfgfile);
return true;
}
else
{
qDebug() << "Error saving configuration to" << newfile;
return false;
}
}
/*! \brief Slot for receiving frequency change signals.
* \param[in] freq The new frequency.
*
* This slot is connected to the CFreqCtrl::NewFrequency() signal and is used
* to set new RF frequency.
*/
void MainWindow::setNewFrequency(qint64 freq)
{
/* set receiver frequency */
rx->set_rf_freq((double) (freq-d_lnb_lo));
/* update pandapter */
ui->plotter->SetCenterFreq(freq);
/* update RX frequncy label in rxopts */
uiDockRxOpt->setRfFreq(freq);
}
/*! \brief Set new LNB LO frequency.
* \param freq_mhz The new frequency in MHz.
*/
void MainWindow::setLnbLo(double freq_mhz)
{
// calculate current RF frequency
qint64 rf_freq = ui->freqCtrl->GetFrequency() - d_lnb_lo;
d_lnb_lo = qint64(freq_mhz*1e6);
qDebug() << "New LNB LO:" << d_lnb_lo << "Hz";
// Show updated frequency in display
ui->freqCtrl->SetFrequency(d_lnb_lo + rf_freq);
}
/*! \brief Set new channel filter offset.
* \param freq_hs The new filter offset in Hz.
*/
void MainWindow::setFilterOffset(qint64 freq_hz)
{
rx->set_filter_offset((double) freq_hz);
ui->plotter->SetFilterOffset(freq_hz);
}
/*! \brief Set RF gain.
* \param gain The new RF gain.
*
* Valid range depends on hardware.
*/
void MainWindow::setRfGain(float gain)
{
rx->set_rf_gain(gain);
}
/*! \brief Set RF gain mode.
* \param gain_mode Automatic or manual gain..
*/
void MainWindow::setRfGainMode(int gain_mode)
{
rx->set_rf_gain_mode(gain_mode);
}
/*! \brief Set new frequency offset value.
* \param ppm Frequency correction.
*
* The valid range is between -200 and 200, though this is not checked.
*/
void MainWindow::setFreqCorr(int ppm)
{
qDebug() << "PPM:" << ppm;
rx->set_freq_corr(ppm);
}
/*! \brief Set new DC offset values.
* \param dci I correction.
* \param dcq Q correction.
*
* The valid range is between -1.0 and 1.0, though hthis is not checked.
*/
void MainWindow::setDcCorr(double dci, double dcq)
{
qDebug() << "DCI:" << dci << " DCQ:" << dcq;
rx->set_dc_corr(dci, dcq);
}
/*! \brief Set new IQ correction values.
* \param gain IQ gain correction.
* \param phase IQ phase correction.
*
* The valid range is between -1.0 and 1.0, though hthis is not checked.
*/
void MainWindow::setIqCorr(double gain, double phase)
{
qDebug() << "Gain:" << gain << " Phase:" << phase;
rx->set_iq_corr(gain, phase);
}
/*! \brief Select new demodulator.
* \param demod New demodulator index.
*
* This slot basically maps the index of the mode selector to receiver::demod
* and configures the default channel filter.
*
*/
void MainWindow::selectDemod(int index)
{
float maxdev;
int filter_preset = uiDockRxOpt->currentFilter();
int flo, fhi;
switch (index) {
case 0:
/* Raw I/Q */
qDebug() << "RAW I/Q mode not implemented!";
break;
/* AM */
case 1:
rx->set_demod(receiver::DEMOD_AM);
ui->plotter->SetDemodRanges(-20000, -100, 100, 20000, true);
uiDockAudio->setFftRange(0,15000);
switch (filter_preset) {
case 0: //wide
flo = -10000;
fhi = 10000;
break;
case 2: // narrow
flo = -2500;
fhi = 2500;
break;
default: // normal
flo = -5000;
fhi = 5000;
break;
}
break;
/* FM */
case 2:
rx->set_demod(receiver::DEMOD_FM);
maxdev = uiDockRxOpt->currentMaxdev();
if (maxdev < 20000.0) {
ui->plotter->SetDemodRanges(-25000, -100, 100, 25000, true);
uiDockAudio->setFftRange(0,12000);
switch (filter_preset) {
case 0: //wide
flo = -10000;
fhi = 10000;
break;
case 2: // narrow
flo = -2500;
fhi = 2500;
break;
default: // normal
flo = -5000;
fhi = 5000;
break;
}
}
else {
ui->plotter->SetDemodRanges(-45000, -10000, 10000, 45000, true);
uiDockAudio->setFftRange(0,24000);
switch (filter_preset) {
/** FIXME: not sure about these **/
case 0: //wide
flo = -45000;
fhi = 45000;
break;
case 2: // narrow
flo = -10000;
fhi = 10000;
break;
default: // normal
flo = -35000;
fhi = 35000;
break;
}
}
break;
/* LSB */
case 3:
rx->set_demod(receiver::DEMOD_SSB);
ui->plotter->SetDemodRanges(-10000, -100, -5000, 0, false);
uiDockAudio->setFftRange(0,3500);
switch (filter_preset) {
case 0: //wide
flo = -4100;
fhi = -100;
break;
case 2: // narrow
flo = -1600;
fhi = -200;
break;
default: // normal
flo = -3000;
fhi = -200;
break;
}
break;
/* USB */
case 4:
rx->set_demod(receiver::DEMOD_SSB);
ui->plotter->SetDemodRanges(0, 5000, 100, 10000, false);
uiDockAudio->setFftRange(0,3500);
switch (filter_preset) {
case 0: //wide
flo = 100;
fhi = 4100;
break;
case 2: // narrow
flo = 200;
fhi = 1600;
break;
default: // normal
flo = 200;
fhi = 3000;
break;
}
break;
/* CWL */
case 5:
rx->set_demod(receiver::DEMOD_SSB);
ui->plotter->SetDemodRanges(-10000, -100, -5000, 0, false);
uiDockAudio->setFftRange(0,1500);
switch (filter_preset) {
case 0: //wide
flo = -2300;
fhi = -200;
break;
case 2: // narrow
flo = -900;
fhi = -400;
break;
default: // normal
flo = -1200;
fhi = -200;
break;
}
break;
/* CWU */
case 6:
rx->set_demod(receiver::DEMOD_SSB);
ui->plotter->SetDemodRanges(0, 5000, 100, 10000, false);
uiDockAudio->setFftRange(0,1500);
switch (filter_preset) {
case 0: //wide
flo = 200;
fhi = 2300;
break;
case 2: // narrow
flo = 400;
fhi = 900;
break;
default: // normal
flo = 200;
fhi = 1200;
break;
}
break;
default:
qDebug() << "Invalid mode selection: " << index;
flo = -5000;
fhi = 5000;
break;
}
qDebug() << "Filter preset for mode" << index << "LO:" << flo << "HI:" << fhi;
ui->plotter->SetHiLowCutFrequencies(flo, fhi);
rx->set_filter((double)flo, (double)fhi, receiver::FILTER_SHAPE_NORMAL);
}
/*! \brief New FM deviation selected.
* \param max_dev The enw FM deviation.
*/
void MainWindow::setFmMaxdev(float max_dev)
{
qDebug() << "FM MAX_DEV: " << max_dev;
/* receiver will check range */
rx->set_fm_maxdev(max_dev);
/* update filter */
if (max_dev < 20000.0) {
ui->plotter->SetDemodRanges(-25000, -1000, 1000, 25000, true);
ui->plotter->SetHiLowCutFrequencies(-5000, 5000);
rx->set_filter(-5000.0, 5000.0, receiver::FILTER_SHAPE_NORMAL);
}
else {
ui->plotter->SetDemodRanges(-45000, -10000, 10000, 45000, true);
ui->plotter->SetHiLowCutFrequencies(-35000, 35000);
rx->set_filter(-35000.0, 35000.0, receiver::FILTER_SHAPE_NORMAL);
}
}
/*! \brief New FM de-emphasis time consant selected.
* \param tau The new time constant
*/
void MainWindow::setFmEmph(double tau)
{
qDebug() << "FM TAU: " << tau;
/* receiver will check range */
rx->set_fm_deemph(tau);
}
/*! \brief AM DCR status changed (slot).
* \param enabled Whether DCR is enabled or not.
*/
void MainWindow::setAmDcrStatus(bool enabled)
{
rx->set_am_dcr(enabled);
}
/*! \brief Audio gain changed.
* \param value The new audio gain in dB.
*/
void MainWindow::setAudioGain(float value)
{
rx->set_af_gain(value);
}
/*! \brief Set AGC ON/OFF.
* \param agc_on Whether AGC is ON (true) or OFF (false).
*/
void MainWindow::setAgcOn(bool agc_on)
{
rx->set_agc_on(agc_on);
}
/*! \brief AGC hang ON/OFF.
* \param use_hang Whether to use hang.
*/
void MainWindow::setAgcHang(bool use_hang)
{
rx->set_agc_hang(use_hang);
}
/*! \brief AGC threshold changed.
* \param threshold The new threshold.
*/
void MainWindow::setAgcThreshold(int threshold)
{
rx->set_agc_threshold(threshold);
}
/*! \brief AGC slope factor changed.
* \param factor The new slope factor.
*/
void MainWindow::setAgcSlope(int factor)
{
rx->set_agc_slope(factor);
}
/*! \brief AGC manual gain changed.
* \param gain The new manual gain in dB.
*/
void MainWindow::setAgcGain(int gain)
{
rx->set_agc_manual_gain(gain);
}
/*! \brief AGC decay changed.
* \param factor The new AGC decay.
*/
void MainWindow::setAgcDecay(int msec)
{
rx->set_agc_decay(msec);
}
/*! \brief Noide blanker configuration changed.
* \param nb1 Noise blanker 1 ON/OFF.
* \param nb2 Noise blanker 2 ON/OFF.
* \param threshold Noise blanker threshold.
*/
void MainWindow::setNoiseBlanker(int nbid, bool on, float threshold)
{
qDebug() << "Noise blanker NB:" << nbid << " ON:" << on << "THLD:" << threshold;
rx->set_nb_on(nbid, on);
rx->set_nb_threshold(nbid, threshold);
}
/*! \brief Squelch level changed.
* \param level_db The new squelch level in dBFS.
*/
void MainWindow::setSqlLevel(double level_db)
{
rx->set_sql_level(level_db);
}
/*! \brief Signal strength meter timeout */
void MainWindow::meterTimeout()
{
float level;
level = rx->get_signal_pwr(true);
ui->sMeter->setLevel(level);
}
/*! \brief Baseband FFT plot timeout. */
void MainWindow::iqFftTimeout()
{
int fftsize;
int i;
std::complex<float> pt; /* a single FFT point used in calculations */
std::complex<float> scaleFactor; /* normalizing factor (fftsize cast to complex) */
double min=0.0,max=-120.0,avg=0.0;
rx->get_iq_fft_data(d_fftData, fftsize);
if (fftsize == 0) {
/* nothing to do, wait until next activation. */
return;
}
scaleFactor = std::complex<float>((float)fftsize);
/** FIXME: move post processing to rx_fft_c **/
/* Normalize, calculcate power and shift the FFT */
for (i = 0; i < fftsize; i++) {
/* normalize and shift */
if (i < fftsize/2) {
pt = d_fftData[fftsize/2+i] / scaleFactor;
}
else {
pt = d_fftData[i-fftsize/2] / scaleFactor;
}
/* calculate power in dBFS */
d_realFftData[i] = 10.0 * log10(pt.imag()*pt.imag() + pt.real()*pt.real() + 1.0e-20);
/*
if (d_realFftData[i] < min)
min = d_realFftData[i];
if (d_realFftData[i] > max)
max = d_realFftData[i];
avg = (avg+d_realFftData[i]) / 2.0;
*/
}
ui->plotter->SetNewFttData(d_realFftData, fftsize);
//qDebug() << "FFT size: " << fftsize;
//qDebug() << "FFT[0]=" << d_realFftData[0] << " FFT[MID]=" << d_realFftData[fftsize/2];
//qDebug() << "MIN:" << min << " AVG:" << avg << " MAX:" << max;
}
/*! \brief Audio FFT plot timeout. */
void MainWindow::audioFftTimeout()
{
int fftsize;
int i;
std::complex<float> pt; /* a single FFT point used in calculations */
std::complex<float> scaleFactor; /* normalizing factor (fftsize cast to complex) */
double min=0.0,max=-120.0,avg=0.0;
rx->get_audio_fft_data(d_fftData, fftsize);
if (fftsize == 0) {
/* nothing to do, wait until next activation. */
qDebug() << "No audio FFT data.";
return;
}
scaleFactor = std::complex<float>((float)fftsize);
/** FIXME: move post processing to rx_fft_f **/
/* Normalize, calculcate power and shift the FFT */
for (i = 0; i < fftsize; i++) {
/* normalize and shift */
if (i < fftsize/2) {
pt = d_fftData[fftsize/2+i] / scaleFactor;
}
else {
pt = d_fftData[i-fftsize/2] / scaleFactor;
}
/* calculate power in dBFS */
d_realFftData[i] = 10.0 * log10(pt.imag()*pt.imag() + pt.real()*pt.real() + 1.0e-20);
}
uiDockAudio->setNewFttData(d_realFftData, fftsize);
}
/*! \brief Start audio recorder.
* \param filename The file name into which audio should be recorded.
*/
void MainWindow::startAudioRec(const QString filename)
{
if (rx->start_audio_recording(filename.toStdString())) {
ui->statusBar->showMessage(tr("Error starting audio recorder"));
/* reset state of record button */
uiDockAudio->setAudioRecButtonState(false);
}
else {
ui->statusBar->showMessage(tr("Recording audio to %1").arg(filename));
}
}
/*! \brief Stop audio recorder. */
void MainWindow::stopAudioRec()
{
if (rx->stop_audio_recording()) {
/* okay, this one would be weird if it really happened */
ui->statusBar->showMessage(tr("Error stopping audio recorder"));
uiDockAudio->setAudioRecButtonState(true);
}
else {
ui->statusBar->showMessage(tr("Audio recorder stopped"), 5000);
}
}
/*! \brief Start playback of audio file. */
void MainWindow::startAudioPlayback(const QString filename)
{
if (rx->start_audio_playback(filename.toStdString())) {
ui->statusBar->showMessage(tr("Error trying to play %1").arg(filename));
/* reset state of record button */
uiDockAudio->setAudioPlayButtonState(false);
}
else {
ui->statusBar->showMessage(tr("Playing %1").arg(filename));
}
}
/*! \brief Stop playback of audio file. */
void MainWindow::stopAudioPlayback()
{
if (rx->stop_audio_playback()) {
/* okay, this one would be weird if it really happened */
ui->statusBar->showMessage(tr("Error stopping audio playback"));
uiDockAudio->setAudioPlayButtonState(true);
}
else {
ui->statusBar->showMessage(tr("Audio playback stopped"), 5000);
}
}
/*! \brief Start/stop I/Q data playback.
* \param play True if playback is started, false if it is stopped.
* \param filename Full path of the I/Q data file.
*/
void MainWindow::toggleIqPlayback(bool play, const QString filename)
{
if (play) {
/* starting playback */
if (rx->start_iq_playback(filename.toStdString(), 1920000.0)) {
ui->statusBar->showMessage(tr("Error trying to play %1").arg(filename));
}
else {
ui->statusBar->showMessage(tr("Playing %1").arg(filename));
/* disable REC button */
ui->actionIqRec->setEnabled(false);
}
}
else {
/* stopping playback */
if (rx->stop_iq_playback()) {
/* okay, this one would be weird if it really happened */
ui->statusBar->showMessage(tr("Error stopping I/Q playback"));
}
else {
ui->statusBar->showMessage(tr("I/Q playback stopped"), 5000);
}
/* enable REC button */
ui->actionIqRec->setEnabled(true);
}
}
/*! \brief FFT size has changed. */
void MainWindow::setIqFftSize(int size)
{
qDebug() << "Changing baseband FFT size TBD...";
}
/*! \brief Baseband FFT rate has changed. */
void MainWindow::setIqFftRate(int fps)
{
int interval = 1000 / fps;
if (interval < 10)
return;
if (iq_fft_timer->isActive())
iq_fft_timer->setInterval(interval);
}
/*! \brief Vertical split between waterfall and pandapter changed.
* \param pct_pand The percentage of the waterfall.
*/
void MainWindow::setIqFftSplit(int pct_wf)
{
if ((pct_wf >= 20) && (pct_wf <= 80)) {
ui->plotter->SetPercent2DScreen(pct_wf);
}
}
/*! \brief Audio FFT rate has changed. */
void MainWindow::setAudioFftRate(int fps)
{
int interval = 1000 / fps;
if (interval < 10)
return;
if (audio_fft_timer->isActive())
audio_fft_timer->setInterval(interval);
}
/*! \brief Start/Stop DSP processing.
* \param checked Flag indicating whether DSP processing should be ON or OFF.
*
* This slot is executed when the actionDSP is toggled by the user. This can either be
* via the menu bar or the "power on" button in the main toolbar.
*/
void MainWindow::on_actionDSP_triggered(bool checked)
{
if (checked) {
/* start receiver */
rx->start();
/* start GUI timers */
meter_timer->start(100);
iq_fft_timer->start(1000/uiDockFft->fftRate());
audio_fft_timer->start(1000/uiDockAudio->fftRate());
/* update menu text and button tooltip */
ui->actionDSP->setToolTip(tr("Stop DSP processing"));
ui->actionDSP->setText(tr("Stop DSP"));
}
else {
/* stop GUI timers */
meter_timer->stop();
iq_fft_timer->stop();
audio_fft_timer->stop();
/* stop receiver */
rx->stop();
/* update menu text and button tooltip */
ui->actionDSP->setToolTip(tr("Start DSP processing"));
ui->actionDSP->setText(tr("Start DSP"));
}
}
/*! \brief Load configuration activated by user. */
void MainWindow::on_actionLoadSettings_triggered()
{
QString cfgfile = QFileDialog::getOpenFileName(this,
tr("Load settings"),
m_last_dir.isEmpty() ? m_cfg_dir : m_last_dir,
tr("Settings (*.conf)"));
qDebug() << "File to open:" << cfgfile;
if (cfgfile.isEmpty())
return;
if (!cfgfile.endsWith(".conf", Qt::CaseSensitive))
cfgfile.append(".conf");
loadConfig(cfgfile);
// store last dir
QFileInfo fi(cfgfile);
if (m_cfg_dir != fi.absolutePath())
m_last_dir = fi.absolutePath();
}