forked from JvanKatwijk/sdr-j-fm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio.cpp
2218 lines (1954 loc) · 65.7 KB
/
radio.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
#
/*
* Copyright (C) 2014
* Jan van Katwijk (J.vanKatwijk@gmail.com)
* Lazy Chair Computing
*
* This file is part of the fm software
*
* fm software 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 2 of the License, or
* (at your option) any later version.
*
* fm software 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <QDateTime>
#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QTabWidget>
#include <QHeaderView>
#include <QSettings>
#include <Qt>
#include <fstream>
#include <iostream>
#include <array>
#include "radio.h"
#include "hs-scope.h"
#include "ls-scope.h"
#include "audiosink.h"
#include "fm-constants.h"
#include "fm-demodulator.h"
#include "rds-decoder.h"
#include "themechoser.h"
#include "program-list.h"
#include "device-handler.h"
#include "filereader.h"
#ifdef HAVE_SDRPLAY
#include "sdrplay-handler.h"
#endif
#ifdef HAVE_SDRPLAY_V3
#include "sdrplay-handler-v3.h"
#endif
#ifdef HAVE_AIRSPY
#include "airspy-handler.h"
#endif
#ifdef HAVE_DABSTICK
#include "rtlsdr-handler.h"
#endif
#ifdef HAVE_EXTIO
#include "extio-handler.h"
#endif
#ifdef HAVE_HACKRF
#include "hackrf-handler.h"
#endif
#ifdef HAVE_LIME
#include "lime-handler.h"
#endif
#ifdef HAVE_PLUTO
#include "pluto-handler.h"
#endif
#ifdef HAVE_ELAD_S1
#include "elad-s1.h"
#endif
#ifdef __MINGW32__
#include <iostream>
#include <windows.h>
#endif
#define FM_RATE 192000
#ifdef __MINGW32__
__int64 FileTimeToInt64 (FILETIME & ft) {
ULARGE_INTEGER foo;
foo.LowPart = ft.dwLowDateTime;
foo.HighPart = ft.dwHighDateTime;
return (foo.QuadPart);
}
bool get_cpu_times (size_t &idle_time, size_t &total_time) {
FILETIME IdleTime, KernelTime, UserTime;
size_t thisIdle, thisKernel, thisUser;
GetSystemTimes (&IdleTime, &KernelTime, &UserTime);
thisIdle = FileTimeToInt64 (IdleTime);
thisKernel = FileTimeToInt64 (KernelTime);
thisUser = FileTimeToInt64 (UserTime);
idle_time = (size_t) thisIdle;
total_time = (size_t)(thisKernel + thisUser);
return true;
}
#else
std::vector<size_t> get_cpu_times() {
std::ifstream proc_stat ("/proc/stat");
proc_stat. ignore (5, ' '); // Skip the 'cpu' prefix.
std::vector<size_t> times;
for (size_t time; proc_stat >> time; times. push_back (time));
return times;
}
bool get_cpu_times (size_t &idle_time, size_t &total_time) {
const std::vector <size_t> cpu_times = get_cpu_times();
if (cpu_times. size() < 4)
return false;
idle_time = cpu_times [3];
total_time = std::accumulate (cpu_times. begin(), cpu_times. end(), 0);
return true;
}
#endif
#include "deviceselect.h"
#define D_SDRPLAY "sdrplay"
#define D_SDRPLAY_V3 "sdrplay-v3"
#define D_RTL_TCP "rtl_tcp"
#define D_HACKRF "hackrf"
#define D_LIME "lime"
#define D_COLIBRI "colibri"
#define D_AIRSPY "airspy"
#define D_RTLSDR "dabstick"
#define D_PLUTO "pluto"
#define D_ELAD_S1 "elad-s1"
#define D_EXTIO "extio"
#define D_PMSDR "pmsdr"
#define D_FILEREADER "filereader"
static
const char *deviceTable [] = {
#ifdef HAVE_SDRPLAY
D_SDRPLAY,
#endif
#ifdef HAVE_SDRPLAY_V3
D_SDRPLAY_V3,
#endif
#ifdef HAVE_PLUTO
D_PLUTO,
#endif
#ifdef HAVE_AIRSPY
D_AIRSPY,
#endif
#ifdef HAVE_HACKRF
D_HACKRF,
#endif
#ifdef HAVE_LIME
D_LIME,
#endif
#ifdef HAVE_DABSTICK
D_RTLSDR,
#endif
#ifdef HAVE_RTL_TCP
D_RTL_TCP,
#endif
D_FILEREADER,
nullptr
};
static int startKnop;
static QTimer *starter;
constexpr int16_t delayTable [] = { 1, 3, 5, 7, 9, 10, 15 };
constexpr int16_t delayTableSize = ((int)(sizeof(delayTable) / sizeof(int16_t)));
/**
* @file gui.cpp
* @brief gui.cpp : Defines the functions for the GUI of the FM software
* @author Jan van Katwijk
* @version 0.98
* @date 2015-01-07
*/
RadioInterface::RadioInterface (QSettings *Si,
QString saveName,
ThemeChoser *themeChooser,
int32_t outputRate,
QWidget *parent):
QDialog (parent),
iqBuffer (
IQ_SCOPE_SIZE),
hfBuffer (8 * 32768),
lfBuffer (32768),
theDemodulator (
FM_RATE),
configDisplay (nullptr),
mykeyPad () {
int16_t i;
QString h;
int k;
setupUi (this);
fmSettings = Si;
this -> themeChooser = themeChooser;
configWidget. setupUi (&configDisplay);
runMode. store (ERunStates::IDLE);
squelchMode = false;
//
// Added: cannot compile on Ubuntu 16, the system where
// I build the appImage
//
// with QT 5.15.2 and Ubuntu 22.04.1 LTS it works
// so, feel free to uncomment, but leave it commented out for me
// setWindowFlag (Qt::WindowContextHelpButtonHint, false);
// setWindowFlag (Qt::WindowMinMaxButtonsHint, true);
thermoPeakLevelLeft -> setFillBrush (Qt::darkBlue);
thermoPeakLevelRight -> setFillBrush (Qt::darkBlue);
thermoPeakLevelLeft -> setAlarmBrush (Qt::red);
thermoPeakLevelRight -> setAlarmBrush (Qt::red);
thermoPeakLevelLeft -> setAlarmEnabled (true);
thermoPeakLevelRight -> setAlarmEnabled(true);
reset_afc ();
//
// added inits for various class variables
afcActive = false;
afcAlpha = 1;
afcCurrOffFreq = 0;
peakLeftDamped = -100;
peakRightDamped = -100;
// end added
//
this -> inputRate = INPUT_RATE;
this -> fmRate = FM_RATE;
this -> workingRate = 48000;
/**
* We allow the user to set the displaysize
* (as long as it is reasonable)
*/
this -> displaySize =
fmSettings -> value ("displaySize", 512).toInt();
if ((displaySize & (displaySize - 1)) != 0)
displaySize = 1024;
this -> spectrumSize = 4 * displaySize;
this -> rasterSize =
fmSettings -> value ("rasterSize", 50). toInt ();
this -> repeatRate =
fmSettings -> value ("repeatRate", 10). toInt ();
this -> averageCount =
fmSettings -> value ("averageCount", 5). toInt ();
this -> audioRate =
fmSettings -> value ("audioRate",
outputRate). toInt ();
//
// fill the decoder selector
QStringList names = theDemodulator. listNameofDecoder ();
for (QString decoderName: names)
configWidget. fmDecoderSelector -> addItem (decoderName);
h = fmSettings -> value ("fmDecoder", "PLL Decoder"). toString ();
k = configWidget. fmDecoderSelector -> findText (h);
if (k != -1) {
configWidget. fmDecoderSelector -> setCurrentIndex (k);
handle_fmDecoderSelector (configWidget. fmDecoderSelector -> currentText ());
}
h = fmSettings -> value ("rdsSelector", "RDS 1"). toString ();
k = fmRdsSelector -> findText (h);
if (k != -1)
fmRdsSelector -> setCurrentIndex (k);
//
myFMprocessor = nullptr;
our_audioSink = new audioSink (this -> audioRate, 16384);
outTable. resize (our_audioSink -> numberofDevices () + 1);
for (i = 0; i < our_audioSink -> numberofDevices (); i++)
outTable [i] = -1;
if (!setupSoundOut (configWidget. streamOutSelector,
our_audioSink,
this -> audioRate,
outTable)) {
fprintf(stderr, "Cannot open any output device\n");
abortSystem (33);
}
/**
* Use, if possible, the outputstream the user had previous time
*/
h = fmSettings -> value ("streamOutSelector",
"default"). toString ();
k = configWidget. streamOutSelector -> findText (h);
if (k != -1) {
configWidget. streamOutSelector -> setCurrentIndex (k);
handle_StreamOutSelector (k);
}
setup_HFScope ();
setup_LFScope ();
//added
setup_IQPlot ();
//end added
//
// Set relevant sliders etc to the value they had last time
restoreGUIsettings (fmSettings);
//
int weCloseDirect = fmSettings -> value ("closeDirect", 0). toInt ();
if (weCloseDirect != 0)
configWidget. closeDirect -> setChecked (true);
configWidget. incrementFlag ->
setStyleSheet ("QLabel {background-color:blue}");
configWidget. incrementFlag -> setText(" ");
incrementIndex = 0;
// settings for the auto tuner
incrementIndex =
fmSettings -> value ("incrementIndex", 0). toInt ();
fmIncrement =
fmSettings -> value ("fm_increment", 100). toInt ();
minLoopFrequency =
fmSettings -> value ("min_loop_frequency", 86500). toInt ();
if (minLoopFrequency == 0)
minLoopFrequency = 86500;
maxLoopFrequency =
fmSettings -> value ("max_loop_frequency", 110000). toInt ();
if (maxLoopFrequency == 0)
maxLoopFrequency = 110000;
configWidget. fm_increment -> setValue (fmIncrement); //
configWidget. minimumSelect -> setValue (KHz (minLoopFrequency) / MHz(1));
configWidget. maximumSelect -> setValue (KHz (maxLoopFrequency) / MHz(1));
// he does the connections from the gui buttons, sliders etc
localConnects ();
// Create a timer for autoincrement/decrement of the tuning
autoIncrementTimer. setSingleShot (true);
autoIncrementTimer. setInterval (5000);
connect (&autoIncrementTimer, SIGNAL (timeout()),
this, SLOT (autoIncrement_timeout ()));
// create a timer for displaying the "real" time
displayTimer. setInterval (1000);
connect (&displayTimer,
SIGNAL (timeout ()),
this,
SLOT (updateTimeDisplay ()));
//
// Display the version
QString v = "sdrJ-FM -V" + QString (CURRENT_VERSION);
systemindicator -> setText (v);
copyrightLabel -> setToolTip (footText ());
ExtioLock = false;
logFile = nullptr;
pauseButton -> setText (QString ("Pause"));
sourceDumping = false;
audioDumping = false;
dumpfilePointer = nullptr;
audiofilePointer = nullptr;
configWidget. dumpButton -> setText ("inputDump");
configWidget. audioDumpButton -> setText ("audioDump");
currentPIcode = 0;
frequencyforPICode = 0;
theSelector -> hide ();
theDevice = new deviceHandler ();
currentFreq = setTuner (Khz (94700));
inputRate = theDevice -> getRate ();
hfScope -> setBitDepth (theDevice -> bitDepth ());
lfScope -> setBitDepth (theDevice -> bitDepth ());
//
connect (configWidget. fm_increment, SIGNAL (valueChanged (int)),
this, SLOT (handle_fm_increment (int)));
connect (configWidget. minimumSelect, SIGNAL (valueChanged (int)),
this, SLOT (handle_minimumSelect (int)));
connect (configWidget. maximumSelect, SIGNAL (valueChanged (int)),
this, SLOT (handle_maximumSelect (int)));
displayTimer. start (1000);
scrollStationList -> setWidgetResizable (true);
myProgramList = new programList (this, saveName, scrollStationList);
//
connect (freqSave, SIGNAL (clicked ()),
this, SLOT (handle_freqSaveButton ()));
connect (cbAfc, SIGNAL (stateChanged (int)),
this, SLOT (handle_afcSelector (int)));
QString country =
fmSettings -> value ("ptyLocale", "Europe"). toString ();
if ((country == "Europe") || (country == "USA")) {
k = configWidget. countrySelector -> findText (country);
if (k != -1)
configWidget. countrySelector -> setCurrentIndex (k);
}
connect (configWidget. countrySelector,
SIGNAL (activated (const QString &)),
this, SLOT (handle_countrySelector (const QString &)));
QString device =
fmSettings -> value ("device", "no device").toString ();
k = -1;
for (int i = 0; deviceTable [i] != nullptr; i ++)
if (deviceTable [i] == device) {
k = i;
break;
}
if (k != -1) {
starter = new QTimer;
startKnop = k;
starter -> setSingleShot (true);
starter -> setInterval (500);
connect (starter, SIGNAL (timeout()),
this, SLOT (quickStart ()));
starter -> start (500);
}
else {
// deviceSelector -> setCurrentIndex (0);
startKnop = 0;
if (setDevice (fmSettings) == nullptr)
TerminateProcess ();
}
for (auto name : themeChooser -> get_style_sheet_names ())
configWidget. cbThemes -> addItem (name);
configWidget. cbThemes -> setCurrentIndex (themeChooser -> get_curr_style_sheet_idx());
}
QString RadioInterface::footText () {
QString versionText = "sdr-j-FM version: " + QString(CURRENT_VERSION) + "\n";
versionText += "Built on " + QString(__TIMESTAMP__) + QString (", Commit ") + QString (GITHASH) + "\n";
versionText += "Copyright Jan van Katwijk, mailto:J.vanKatwijk@gmail.com\n";
versionText += "with significant input from Tomneda\n";
versionText += "Rights of Qt, fftw, portaudio, libfaad, libsamplerate and libsndfile gratefully acknowledged\n";
versionText += "Rights of developers of RTLSDR library, SDRplay libraries, AIRspy library and others gratefully acknowledged\n";
versionText += "Rights of other contributors gratefully acknowledged";
return versionText;
}
void RadioInterface::quickStart () {
disconnect (starter, SIGNAL (timeout ()),
this, SLOT (quickStart ()));
fprintf (stderr, "going for quickStart\n");
delete starter;
if (getDevice (deviceTable [startKnop]) == nullptr)
if (setDevice (fmSettings) == nullptr)
TerminateProcess ();
}
//
// The end of all
RadioInterface::~RadioInterface () {
}
//
// Function used to "dump" settings into the ini file
// pointed to by s
void RadioInterface::dumpControlState (QSettings *s) {
if (s == nullptr)
return;
// s -> setValue ("device", deviceSelector -> currentText ());
s -> setValue ("fm_increment",
configWidget. fm_increment -> value ());
s -> setValue ("spectrumAmplitudeSlider_hf",
spectrumAmplitudeSlider_hf -> value ());
s -> setValue ("spectrumAmplitudeSlider_lf",
spectrumAmplitudeSlider_lf -> value ());
s -> setValue ("IQbalanceSlider",
IQbalanceSlider -> value());
s -> setValue ("afc",
cbAfc -> checkState ());
s -> setValue ("dcRemove",
cbDCRemove -> checkState ());
s -> setValue ("autoMono",
cbAutoMono -> checkState ());
s -> setValue ("pss",
cbPSS -> checkState ());
// now setting the parameters for the fm decoder
s -> setValue ("fmFilterSelect",
configWidget. fmFilterSelect -> currentText ());
s -> setValue ("fmMode",
fmModeSelector -> currentText ());
s -> setValue ("fmDecoder",
configWidget. fmDecoderSelector -> currentText ());
s -> setValue ("volumeHalfDb",
volumeSlider -> value ());
s -> setValue ("fmRdsSelector",
fmRdsSelector -> currentText ());
s -> setValue ("fmChannelSelect",
fmChannelSelect -> currentText ());
s -> setValue ("fmDeemphasisSelector",
configWidget. fmDeemphasisSelector -> currentText ());
s -> setValue ("fmStereoPanoramaSlider",
fmStereoPanoramaSlider -> value ());
s -> setValue ("fmStereoBalanceSlider",
fmStereoBalanceSlider -> value ());
s -> setValue ("fmLFcutoff",
fmLFcutoff -> currentText ());
s -> setValue ("logging",
configWidget. loggingButton -> currentText ());
s -> setValue ("streamOutSelector",
configWidget. streamOutSelector -> currentText ());
s -> setValue ("currentFreq",
currentFreq);
s -> setValue ("min_loop_frequency",
minLoopFrequency);
s -> setValue ("max_loop_frequency",
maxLoopFrequency);
s -> setValue ("peakLevelDelaySteps",
configWidget. sbDispDelay -> value ());
s -> setValue ("styleSheet", configWidget. cbThemes -> currentText ());
s -> sync ();
}
// On start, we ensure that the streams are stopped so
// that they can be restarted again.
void RadioInterface::setStart () {
bool r = false;
// someone presses while running, ignore
if (runMode. load () == ERunStates::RUNNING) {
return;
}
r = theDevice -> restartReader ();
// qDebug ("Starting %d\n", r);
if (!r) {
QMessageBox::warning(this, tr("sdr"),
tr("Opening input stream failed\n"));
return;
}
if (myFMprocessor == nullptr)
make_newProcessor ();
myFMprocessor -> start ();
our_audioSink ->restart ();
// and finally: recall that starting overrules pausing
pauseButton -> setText (QString ("Pause"));
//
// New stuff:
handle_squelchSelector ("NSQ"); // toggle sequelch on
// toggle sequelch off (TODO: make this nicer)
handle_squelchSelector ("SQ OFF");
int k = fmSettings -> value ("dcRemove", Qt::CheckState::Checked).toInt ();
cbDCRemove -> setCheckState (k ? Qt::CheckState::Checked :
Qt::CheckState::Unchecked);
k = fmSettings -> value ("autoMono", Qt::CheckState::Checked).toInt ();
cbAutoMono -> setCheckState (k ? Qt::CheckState::Checked :
Qt::CheckState::Unchecked);
k = fmSettings -> value ("pss", Qt::CheckState::Checked).toInt ();
cbPSS-> setCheckState (k ? Qt::CheckState::Checked :
Qt::CheckState::Unchecked);
myFMprocessor -> setDCRemove (cbDCRemove -> checkState());
myFMprocessor -> setAutoMonoMode (cbAutoMono -> checkState());
myFMprocessor -> setPSSMode (cbPSS -> checkState());
int vol = fmSettings -> value ("volumeHalfDb", -12).toInt();
volumeSlider -> setValue (vol);
handle_AudioGainSlider (vol);
connect (cbAutoMono, &QCheckBox::clicked,
this, [this](bool isChecked){myFMprocessor -> setAutoMonoMode(isChecked); });
connect (cbPSS, &QCheckBox::clicked,
this, [this](bool isChecked){myFMprocessor -> setPSSMode(isChecked); });
connect (cbDCRemove, &QCheckBox::clicked,
this, [this](bool isChecked){ myFMprocessor->setDCRemove(isChecked); });
connect (volumeSlider, SIGNAL (valueChanged (int)),
this, SLOT (handle_AudioGainSlider (int)));
connect (configWidget. cbTestTone, SIGNAL (stateChanged (int)),
this, SLOT (handle_cbTestTone (int)));
connect (configWidget. sbDispDelay, SIGNAL (valueChanged (int)),
this, SLOT (handle_sbDispDelay (int)));
connect (btnRestartPSS, &QAbstractButton::clicked,
this, [this](){myFMprocessor -> restartPssAnalyzer(); });
runMode. store (ERunStates::RUNNING);
}
//
// always tricky to kill tasks
void RadioInterface::TerminateProcess () {
runMode. store (ERunStates::STOPPING);
if (myFMprocessor == nullptr)
exit (1);
if (sourceDumping && (myFMprocessor != nullptr)) {
myFMprocessor -> stopDumping ();
sf_close (dumpfilePointer);
}
if (audioDumping) {
our_audioSink -> stopDumping();
sf_close (audiofilePointer);
}
if (myProgramList != nullptr)
myProgramList -> saveTable ();
stopIncrementing ();
dumpControlState (fmSettings);
fmSettings -> sync ();
configDisplay. hide ();
// It is pretty important that no one is attempting to
// set things within the FMprocessor when it is
// being deleted
theDevice -> stopReader ();
myFMprocessor -> stop ();
//
// fmProcessor and device are stopped
if (myFMprocessor != nullptr)
delete myFMprocessor;
// setDevice (QString ("dummy")); // will select a virtualinput
accept();
qDebug () << "Termination started";
delete theDevice;
delete our_audioSink;
delete myProgramList;
delete hfScope;
delete lfScope;
}
void RadioInterface::abortSystem (int d) {
qDebug ("aborting for reason %d\n", d);
accept ();
}
//
// The following signals originate from the Winrad Extio interface
//
// Note: the extio interface provides two signals
// one ExtLO signals that the external LO is set
// to a different value,
// the other one, ExtFreq, requests the client program
// to adapt its (local) tuning settings to a new frequency
void RadioInterface::set_ExtFrequency (int f) {
int32_t vfo = theDevice -> getVFOFrequency ();
(void)f;
currentFreq = vfo + inputRate / 4;
loFrequency = inputRate / 4;
displayFrequency (currentFreq);
if (myFMprocessor != nullptr) {
myFMprocessor -> set_localOscillator (loFrequency);
myFMprocessor -> triggerFrequencyChange ();
}
}
//
// From our perspective, the external device only provides us
// with a vfo
void RadioInterface::set_ExtLO (int f) {
set_ExtFrequency (f);
}
void RadioInterface::set_lockLO () {
// fprintf (stderr, "ExtioLock is true\n");
ExtioLock = true;
}
void RadioInterface::set_unlockLO () {
// fprintf (stderr, "ExtioLock is false\n");
ExtioLock = false;
}
void RadioInterface::set_stopHW () {
theDevice -> stopReader ();
}
void RadioInterface::set_startHW () {
if (runMode. load () == ERunStates::RUNNING)
theDevice -> restartReader();
}
//
//// This is a difficult one, everything should go down first
//// and then restart with the new samplerate
//void RadioInterface::set_changeRate (int r) {
// if (r == inputRate)
// return;
// fprintf (stderr, "request for changerate\n");
// theDevice -> stopReader ();
// if (myFMprocessor != nullptr) {
// myFMprocessor -> stop();
// delete myFMprocessor;
// myFMprocessor = nullptr;
// }
//
// runMode. store (ERunStates::IDLE);
////
//// Now we need to rebuild the prerequisites for the "new" processor
// inputRate = r;
// if (inputRate < Khz (176)) { // rather arbitrarily
// QMessageBox::warning (this, tr("sdr"),
// tr("Sorry, rate low\n"));
// delete theDevice;
// theDevice = new deviceHandler ();
// inputRate = theDevice -> getRate ();
// }
////
//// compute the new fmRate
//// fmRate = mapRates (inputRate);
//// ask the new for the frequency
// currentFreq = theDevice -> getVFOFrequency () + fmRate / 4;
//// and show everything
// Display (currentFreq);
// lcd_fmRate -> display ((int)this -> fmRate);
// lcd_inputRate -> display ((int)this -> inputRate);
// lcd_OutputRate -> display ((int)this -> audioRate);
////
//// The device is still the same, so now we wait for a start
//}
//
// @brief setDevice is called upon pressing the device button
// @params: the name (string) on the button
deviceHandler *RadioInterface::getDevice (const QString &s) {
QString file;
bool success;
// The fm processor is a client of the rig, so the
// fm processor has to go first
if (theDevice != nullptr) {
theDevice -> stopReader ();
delete theDevice;
theDevice = nullptr;
}
if (myFMprocessor != nullptr) {
myFMprocessor ->stop ();
delete myFMprocessor;
myFMprocessor = nullptr;
}
runMode. store (ERunStates::IDLE);
ExtioLock = false;
success = true; // default for now
#ifdef HAVE_SDRPLAY
if (s == D_SDRPLAY) {
try {
theDevice = new sdrplayHandler (fmSettings);
} catch (int e) {
success = false;
}
}
else
#endif
#ifdef HAVE_SDRPLAY_V3
if (s == D_SDRPLAY_V3) {
try {
theDevice = new sdrplayHandler_v3 (fmSettings);
} catch (int e) {
success = false;
}
}
else
#endif
#ifdef HAVE_AIRSPY
if (s == D_AIRSPY) {
try {
theDevice = new airspyHandler (fmSettings);
} catch (int e) {
success = false;
}
}
else
#endif
#ifdef HAVE_HACKRF
if (s == D_HACKRF) {
try {
theDevice = new hackrfHandler (fmSettings);
} catch (int e) {
success = false;
}
}
else
#endif
#ifdef HAVE_LIME
if (s == D_LIME) {
try {
theDevice = new limeHandler (fmSettings);
} catch (int e) {
success = false;
}
}
else
#endif
#ifdef HAVE_PLUTO
if (s == D_PLUTO) {
try {
theDevice = new plutoHandler (fmSettings);
} catch (int e) {
success = false;
}
}
else
#endif
#ifdef HAVE_ELAD_S1
if (s == D_ELAD_S1) {
try {
theDevice = new eladHandler (fmSettings, true, &success);
} catch (int e) {
success = false;
}
}
else
#endif
#ifdef HAVE_DABSTICK
if (s == D_RTLSDR) {
try {
theDevice = new rtlsdrHandler (fmSettings);
} catch (int e) {
success = false;
}
}
else
#endif
#ifdef HAVE_EXTIO
if (s == D_EXTIO) {
try {
theDevice = new ExtioHandler (fmSettings, theSelector, &success);
} catch (int e) {
success = false;
}
else
#endif
if (s == "filereader") {
try {
theDevice = new fileReader (fmSettings);
} catch (int e) {
success = false;
}
}
else
theDevice = new deviceHandler ();
if (!success) {
QMessageBox::warning (this, tr ("sdr"),
tr ("loading device failed"));
if (theDevice == nullptr)
theDevice = new deviceHandler (); // the empty one
return nullptr;
}
inputRate = theDevice -> getRate ();
if (inputRate < Khz (176)) { // rather arbitrarily
QMessageBox::warning (this, tr ("sdr"),
tr ("Sorry, rate low\n"));
delete theDevice;
theDevice = new deviceHandler ();
inputRate = theDevice -> getRate ();
}
//
// ask the new rig for the frequency
// fmRate = mapRates (inputRate);
currentFreq = theDevice -> defaultFrequency () + fmRate / 4;
currentFreq = fmSettings -> value ("currentFreq",
currentFreq). toInt ();
displayFrequency (currentFreq);
lcd_fmRate -> display ((int)this -> fmRate);
lcd_inputRate -> display ((int)this -> inputRate);
lcd_OutputRate -> display ((int)this -> audioRate);
// connect (theDevice, SIGNAL (set_changeRate (int)),
// this, SLOT (set_changeRate (int)));
#ifdef __MINGW32__
// communication from the dll to the main program is through signals
if (s == D_EXTIO) {
// and for the extio:
// The following signals originate from the Winrad Extio interface
connect (theDevice, SIGNAL (set_ExtFrequency (int)),
this, SLOT (set_ExtFrequency (int)));
connect (theDevice, SIGNAL (set_ExtLO (int)),
this, SLOT (set_ExtLO (int)));
connect (theDevice, SIGNAL (set_lockLO ()),
this, SLOT (set_lockLO ()));
connect (theDevice, SIGNAL (set_unlockLO ()),
this, SLOT (set_unlockLO ()));
connect (theDevice, SIGNAL (set_stopHW ()),
this, SLOT (set_stopHW ()));
connect (theDevice, SIGNAL (set_startHW ()),
this, SLOT (set_startHW ()));
}
#endif
theDevice -> setVFOFrequency (currentFreq);
setStart ();
fmSettings -> setValue ("device", s);
return theDevice;
}
//
//
deviceHandler *RadioInterface::setDevice (QSettings *fmSettings) {
(void)fmSettings;
deviceSelect deviceSelect;
deviceHandler *theDevice = nullptr;
QStringList devices;
for (int i = 0; deviceTable [i] != nullptr; i ++)
devices += deviceTable [i];
devices += "quit";
deviceSelect. addList (devices);
int theIndex = -1;
while (theDevice == nullptr) {
theIndex = deviceSelect. QDialog::exec ();
if (theIndex < 0)
continue;
QString s = devices. at (theIndex);
if (s == "quit")
return nullptr;
theDevice = getDevice (s);
}
return theDevice;
}
//
// Just for convenience packed as a function
void RadioInterface::make_newProcessor () {
QString area
= fmSettings -> value ("ptyLocale", "Europe"). toString ();
int ptyLocale = area == "Europe" ? 0 : 1;
int thresHold
= fmSettings -> value ("threshold", 20). toInt ();
myFMprocessor = new fmProcessor (theDevice,
this,
our_audioSink,
&theDemodulator,
inputRate,
fmRate,
workingRate,
this -> audioRate,
displaySize,
spectrumSize,
repeatRate,
ptyLocale,
&hfBuffer,
&lfBuffer,
&iqBuffer,
thresHold);
lcd_fmRate -> display ((int)this -> fmRate);
lcd_inputRate -> display ((int)this -> inputRate);
lcd_OutputRate -> display ((int)this -> audioRate);
hfScope -> setBitDepth (theDevice -> bitDepth ());
handle_fmFilterSelect (configWidget. fmFilterSelect -> currentText ());
handle_fmModeSelector (fmModeSelector -> currentText ());
handle_fmRdsSelector (fmRdsSelector -> currentText ());
handle_fmChannelSelector (fmChannelSelect -> currentText ());
handle_fmDeemphasis (configWidget. fmDeemphasisSelector -> currentText ());
handle_squelchSlider (squelchSlider -> value ());
handle_fmLFcutoff (fmLFcutoff -> currentText ());
handle_loggingButton (configWidget. loggingButton -> currentText ());
hfScope ->setBitDepth (theDevice -> bitDepth ());
handle_sbDispDelay (configWidget. sbDispDelay -> value ());
handle_fmStereoBalanceSlider (fmStereoBalanceSlider -> value ());
handle_fmStereoPanoramaSlider (fmStereoPanoramaSlider -> value ());
}
void RadioInterface::handle_fmChannelSelector (const QString &s) {
if (s == "L | R")
channelSelector = fmProcessor::S_STEREO;
else
if (s == "R | L")
channelSelector = fmProcessor::S_STEREO_SWAPPED;
else
if (s == "L | L")
channelSelector = fmProcessor::S_LEFT;
else
if (s == "R | R")
channelSelector = fmProcessor::S_RIGHT;
else
if (s == "M | M")
channelSelector = fmProcessor::S_LEFTplusRIGHT;
else
if (s == "S | S")
channelSelector = fmProcessor::S_LEFTminusRIGHT;
else
if (s == "T | T")
channelSelector = fmProcessor::S_LEFTminusRIGHT_Test;
else // the default
channelSelector = fmProcessor::S_STEREO;
if (myFMprocessor != nullptr)
myFMprocessor -> setSoundMode (channelSelector);
}