-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathApplication.cpp
More file actions
951 lines (785 loc) · 22.3 KB
/
Copy pathApplication.cpp
File metadata and controls
951 lines (785 loc) · 22.3 KB
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
//
// Application.cpp: SigDigger main class
// Copyright (C) 2019 Gonzalo José Carracedo Carballal
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>
//
#include <QApplication>
#include <Suscan/Library.h>
#include "Application.h"
#include "Scanner.h"
#include <QMessageBox>
#include <SuWidgetsHelpers.h>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDragLeaveEvent>
#include <QDropEvent>
#include <QMimeData>
#include "MainSpectrum.h"
using namespace SigDigger;
//////////////////////////// DeviceObservable //////////////////////////////////
DeviceObservable::DeviceObservable(QObject *parent) : QObject(parent)
{
}
DeviceObservable::~DeviceObservable()
{
}
void
DeviceObservable::waitForDevices()
{
std::string source;
bool result = Suscan::DeviceFacade::instance()->waitForDevices(source, 5000);
if (result)
SU_INFO("%s: changes in the device list.\n", source.c_str());
emit done();
}
////////////////////////////// Application /////////////////////////////////////
Application::Application(QWidget *parent) : QMainWindow(parent), m_ui(this)
{
Suscan::Singleton *sing = Suscan::Singleton::get_instance();
sing->init_default_plugin();
m_mediator = new UIMediator(this, &m_ui);
m_deviceObservable = new DeviceObservable();
m_deviceObservable->moveToThread(&m_deviceObservableThread);
setAcceptDrops(true);
}
Suscan::Object &&
Application::getConfig()
{
return m_mediator->getConfig()->serialize();
}
void
Application::refreshConfig()
{
m_mediator->saveUIConfig();
}
void
Application::updateRecent()
{
Suscan::Singleton *sing = Suscan::Singleton::get_instance();
m_mediator->clearRecent();
for (auto p = sing->getFirstRecent(); p != sing->getLastRecent(); ++p)
m_mediator->addRecent(*p);
m_mediator->finishRecent();
}
void
Application::run(Suscan::Object const &config)
{
m_ui.postLoadInit(m_mediator, this);
m_mediator->loadSerializedConfig(config);
m_mediator->setState(UIMediator::HALTED);
// New devices may have been discovered after config deserialization
m_mediator->refreshDevicesDone();
connectUI();
updateRecent();
m_deviceObservableThread.start();
show();
m_uiTimer.start(100);
m_cfgTimer.start();
//mediator->notifyStartupErrors();
}
void
Application::connectUI()
{
connect(
m_mediator,
SIGNAL(captureStart()),
this,
SLOT(onCaptureStart()));
connect(
m_mediator,
SIGNAL(captureEnd()),
this,
SLOT(onCaptureStop()));
connect(
m_mediator,
SIGNAL(profileChanged(bool)),
this,
SLOT(onProfileChanged(bool)));
connect(
m_mediator,
SIGNAL(frequencyChanged(qint64, qint64)),
this,
SLOT(onFrequencyChanged(qint64, qint64)));
connect(
m_mediator,
SIGNAL(seek(struct timeval)),
this,
SLOT(onSeek(struct timeval)));
connect(
m_mediator,
SIGNAL(uiQuit()),
this,
SLOT(quit()));
connect(
m_mediator,
SIGNAL(refreshDevices()),
this,
SLOT(onDeviceRefresh()));
connect(
m_mediator,
SIGNAL(recentSelected(QString)),
this,
SLOT(onRecentSelected(QString)));
connect(
m_mediator,
SIGNAL(recentCleared()),
this,
SLOT(onRecentCleared()));
connect(
m_mediator,
SIGNAL(panSpectrumStart()),
this,
SLOT(onPanSpectrumStart()));
connect(
m_mediator,
SIGNAL(panSpectrumRangeChanged(qint64, qint64, bool)),
this,
SLOT(onPanSpectrumRangeChanged(qint64, qint64, bool)));
connect(
m_mediator,
SIGNAL(panSpectrumStop()),
this,
SLOT(onPanSpectrumStop()));
connect(
m_mediator,
SIGNAL(panSpectrumSkipChanged()),
this,
SLOT(onPanSpectrumSkipChanged()));
connect(
m_mediator,
SIGNAL(panSpectrumRelBwChanged()),
this,
SLOT(onPanSpectrumRelBwChanged()));
connect(
m_mediator,
SIGNAL(panSpectrumReset()),
this,
SLOT(onPanSpectrumReset()));
connect(
m_mediator,
SIGNAL(panSpectrumStrategyChanged(QString)),
this,
SLOT(onPanSpectrumStrategyChanged(QString)));
connect(
m_mediator,
SIGNAL(panSpectrumPartitioningChanged(QString)),
this,
SLOT(onPanSpectrumPartitioningChanged(QString)));
connect(
m_mediator,
SIGNAL(panSpectrumGainChanged(QString, float)),
this,
SLOT(onPanSpectrumGainChanged(QString, float)));
connect(
&m_uiTimer,
SIGNAL(timeout()),
this,
SLOT(onTick()));
connect(
m_mediator,
SIGNAL(triggerSaveConfig()),
this,
SIGNAL(triggerSaveConfig()));
connect(
this,
SIGNAL(waitForDevices()),
m_deviceObservable,
SLOT(waitForDevices()));
connect(
m_deviceObservable,
SIGNAL(done()),
this,
SLOT(onDetectFinished()));
connect(
m_deviceObservable,
SIGNAL(destroyed()),
&m_deviceObservableThread,
SLOT(quit()));
}
void
Application::connectAnalyzer()
{
connect(
m_analyzer.get(),
SIGNAL(halted()),
this,
SLOT(onAnalyzerHalted()));
connect(
m_analyzer.get(),
SIGNAL(eos()),
this,
SLOT(onAnalyzerEos()));
connect(
m_analyzer.get(),
SIGNAL(read_error()),
this,
SLOT(onAnalyzerReadError()));
connect(
m_analyzer.get(),
SIGNAL(psd_message(const Suscan::PSDMessage &)),
this,
SLOT(onPSDMessage(const Suscan::PSDMessage &)));
connect(
m_analyzer.get(),
SIGNAL(source_info_message(const Suscan::SourceInfoMessage &)),
this,
SLOT(onSourceInfoMessage(const Suscan::SourceInfoMessage &)));
connect(
m_analyzer.get(),
SIGNAL(status_message(const Suscan::StatusMessage &)),
this,
SLOT(onStatusMessage(const Suscan::StatusMessage &)));
connect(
m_analyzer.get(),
SIGNAL(analyzer_params(const Suscan::AnalyzerParams &)),
this,
SLOT(onAnalyzerParams(const Suscan::AnalyzerParams &)));
}
void
Application::connectScanner()
{
connect(
m_scanner,
SIGNAL(spectrumUpdated()),
this,
SLOT(onScannerUpdated()));
connect(
m_scanner,
SIGNAL(stopped()),
this,
SLOT(onScannerStopped()));
}
QString
Application::getLogText(int howMany)
{
QString text = "";
std::lock_guard<Suscan::Logger> guard(*Suscan::Logger::getInstance());
QStringList msgList;
for (const auto &p : *Suscan::Logger::getInstance())
if (p.severity >= SU_LOG_SEVERITY_ERROR && p.message.find("exception") != 0)
msgList.append(p.message.c_str());
if (howMany < 0) {
text = msgList.join("");
} else {
int first = msgList.size() - howMany;
if (first < 0)
first = 0;
for (int i = first; i < msgList.size(); ++i)
text += msgList[i];
}
return text;
}
void
Application::startCapture()
{
#ifdef _WIN32
auto iface = m_mediator->getProfile()->getDeviceSpec().analyzer();
if (iface == SUSCAN_SOURCE_REMOTE_INTERFACE) {
QMessageBox::critical(
this,
"SigDigger error",
"Remote analyzers are not supported in Windows operating systems.\n\n"
"This is not a SigDigger limitation, but a Windows one. Although "
"proposals to circumvent this issue exist, they are inherently "
"non-trivial and are not expected to be implemented any time soon.\n\n"
"If you are a developer and are curious about the nature of this "
"limitation (or even feel like helping me out addressing it), please "
"feel free to e-mail me at BatchDrake@gmail.com",
QMessageBox::Ok);
m_mediator->refreshUI();
return;
}
#endif // _WIN32
try {
m_filterInstalled = false;
if (m_mediator->getState() == UIMediator::HALTED) {
Suscan::AnalyzerParams params = *m_mediator->getAnalyzerParams();
std::unique_ptr<Suscan::Analyzer> analyzer;
Suscan::Source::Config profile = *m_mediator->getProfile();
if (profile.isRealTime()) {
if (profile.getDecimatedSampleRate() > SIGDIGGER_MAX_SAMPLE_RATE) {
unsigned decimate =
static_cast<unsigned>(
std::ceil(
profile.getSampleRate()
/ static_cast<qreal>(SIGDIGGER_MAX_SAMPLE_RATE)));
unsigned proposed =
profile.getSampleRate() / decimate;
QMessageBox::StandardButton reply
= m_mediator->shouldReduceRate(
QString::fromStdString(profile.label()),
profile.getDecimatedSampleRate(),
proposed);
// TODO: Maybe ask for decimation?
if (reply == QMessageBox::Yes)
profile.setDecimation(decimate);
else if (reply == QMessageBox::Cancel) {
m_mediator->setState(UIMediator::HALTED);
return;
}
}
}
// Flush log messages from here
Suscan::Logger::getInstance()->flush();
// Allocate objects
if (profile.instance() == nullptr) {
QMessageBox::warning(
this,
"SigDigger error",
"No source defined yet. Please define a source in the settings window.",
QMessageBox::Ok);
return;
}
// Ensure we run this analyzer in channel mode.
params.mode = Suscan::AnalyzerParams::Mode::CHANNEL;
analyzer = std::make_unique<Suscan::Analyzer>(params, profile);
m_sourceInfoReceived = false;
// All set, move to application
m_analyzer = std::move(analyzer);
connectAnalyzer();
m_mediator->setState(UIMediator::RUNNING, m_analyzer.get());
}
} catch (Suscan::Exception &) {
QString fullError = getLogText(2);
if (fullError.isEmpty()) {
QMessageBox::critical(
this,
"Capture start",
"Capture failed to start. See log window for details.");
} else {
QMessageBox::critical(
this,
"Capture start",
fullError.toHtmlEscaped(),
QMessageBox::Ok);
}
m_mediator->setState(UIMediator::HALTED);
}
}
void
Application::orderedHalt()
{
m_mediator->setState(UIMediator::HALTING);
m_analyzer = nullptr;
m_mediator->setState(UIMediator::HALTED);
}
void
Application::stopCapture()
{
if (m_mediator->getState() == UIMediator::RUNNING) {
m_mediator->setState(UIMediator::HALTING);
m_analyzer.get()->halt();
}
}
void
Application::restartCapture()
{
if (m_mediator->getState() == UIMediator::RUNNING) {
m_mediator->setState(UIMediator::RESTARTING);
m_analyzer.get()->halt();
}
}
void
Application::onAnalyzerHalted()
{
bool restart = m_mediator->getState() == UIMediator::RESTARTING;
orderedHalt();
if (restart)
startCapture();
}
void
Application::onAnalyzerEos()
{
QMessageBox::information(
this,
"End of stream",
"Capture interrupted due to stream end:<p /><pre>"
+ getLogText()
+ "</pre>",
QMessageBox::Ok);
orderedHalt();
}
void
Application::onPSDMessage(const Suscan::PSDMessage &msg)
{
m_mediator->feedPSD(msg);
}
void
Application::onSourceInfoMessage(const Suscan::SourceInfoMessage &msg)
{
m_mediator->notifySourceInfo(*msg.info());
if (!m_sourceInfoReceived)
m_sourceInfoReceived = true;
}
void
Application::onStatusMessage(const Suscan::StatusMessage &message)
{
if (message.getCode() == SUSCAN_ANALYZER_INIT_FAILURE) {
QMessageBox::critical(
this,
"Analyzer initialization",
"Initialization failed: " + message.getMessage(),
QMessageBox::Ok);
} else {
m_mediator->setStatusMessage(message.getMessage());
}
}
void
Application::onAnalyzerParams(const Suscan::AnalyzerParams ¶ms)
{
m_mediator->setAnalyzerParams(params);
}
void
Application::onAnalyzerReadError()
{
QMessageBox::critical(
this,
"Source error",
"Capture stopped due to source read error. Last errors were:<p /><pre>"
+ getLogText()
+ "</pre>",
QMessageBox::Ok);
orderedHalt();
}
Application::~Application()
{
if (m_deviceObservable != nullptr)
delete m_deviceObservable;
if (m_deviceObservableThread.isRunning()) {
m_deviceObservableThread.quit();
m_deviceObservableThread.wait();
}
m_uiTimer.stop();
if (m_scanner != nullptr)
delete m_scanner;
m_analyzer = nullptr;
if (m_mediator != nullptr)
delete m_mediator;
}
/////////////////////////////// Overrides //////////////////////////////////////
void
Application::closeEvent(QCloseEvent *)
{
stopCapture();
}
void
Application::dragEnterEvent(QDragEnterEvent *event)
{
if (event->proposedAction() == Qt::CopyAction)
event->acceptProposedAction();
}
void
Application::dragMoveEvent(QDragMoveEvent *event)
{
event->acceptProposedAction();
}
void
Application::dragLeaveEvent(QDragLeaveEvent *event)
{
event->accept();
}
void
Application::dropEvent(QDropEvent *event)
{
const QMimeData* mimeData = event->mimeData();
if (mimeData->hasUrls()) {
QList<QUrl> urlList = mimeData->urls();
if (urlList.size() != 1) {
event->ignore();
return;
}
QUrl url = urlList.at(0);
if (!url.isLocalFile()) {
event->ignore();
return;
}
m_mediator->attemptReplayFile(url.toLocalFile());
}
}
//////////////////////////////// Slots /////////////////////////////////////////
void
Application::quit()
{
stopCapture();
QApplication::quit();
}
void
Application::onCaptureStart()
{
startCapture();
}
void
Application::onCaptureStop()
{
stopCapture();
}
void
Application::onProfileChanged(bool needsRestart)
{
if (m_mediator->getProfile()->label() != "") {
Suscan::Singleton *sing = Suscan::Singleton::get_instance();
sing->notifyRecent(m_mediator->getProfile()->label());
updateRecent();
}
if (needsRestart)
restartCapture();
else if (m_mediator->getState() == UIMediator::RUNNING)
hotApplyProfile(m_mediator->getProfile());
}
#define TRYSILENT(x) \
try { x; } catch (Suscan::Exception const &) { errorsOccurred = true; }
void
Application::onFrequencyChanged(qint64 freq, qint64 lnb)
{
bool errorsOccurred = false;
if (m_mediator->isLive()) {
m_mediator->getProfile()->setFreq(freq);
m_mediator->getProfile()->setLnbFreq(lnb);
}
if (m_mediator->getState() == UIMediator::RUNNING)
TRYSILENT(m_analyzer->setFrequency(freq, lnb));
if (errorsOccurred) {
}
}
void
Application::hotApplyProfile(Suscan::Source::Config const *profile)
{
bool errorsOccurred = false;
auto sourceInfo = m_analyzer->getSourceInfo();
if (sourceInfo.testPermission(SUSCAN_ANALYZER_PERM_SET_ANTENNA))
TRYSILENT(m_analyzer->setAntenna(profile->getAntenna()));
if (sourceInfo.testPermission(SUSCAN_ANALYZER_PERM_SET_BW))
TRYSILENT(m_analyzer->setBandwidth(profile->getBandwidth()));
if (sourceInfo.testPermission(SUSCAN_ANALYZER_PERM_SET_FREQ))
TRYSILENT(m_analyzer->setFrequency(profile->getFreq(), profile->getLnbFreq()));
if (sourceInfo.testPermission(SUSCAN_ANALYZER_PERM_SET_DC_REMOVE))
TRYSILENT(m_analyzer->setDCRemove(profile->getDCRemove()));
if (errorsOccurred) {
QMessageBox::warning(
this,
"Update analyzer configuration",
"Some of the settings in the profile could not be applied. See log window for details.",
QMessageBox::Ok);
}
}
void
Application::onSeek(struct timeval tv)
{
if (m_mediator->getState() == UIMediator::RUNNING) {
try {
m_analyzer->seek(tv);
} catch (Suscan::Exception &) {
QMessageBox::critical(
this,
"SigDigger error",
"Source does not allow seeking",
QMessageBox::Ok);
}
}
}
void
Application::onDeviceRefresh()
{
Suscan::DeviceFacade::instance()->discoverAll();
emit waitForDevices();
}
void
Application::onDetectFinished()
{
m_mediator->refreshDevicesDone();
}
void
Application::onRecentSelected(QString profile)
{
Suscan::Singleton *sing = Suscan::Singleton::get_instance();
Suscan::Source::Config *config = sing->getProfile(profile.toStdString());
if (config != nullptr) {
bool forceStart = m_mediator->getState() == UIMediator::HALTED;
m_mediator->setProfile(*config);
if (forceStart)
startCapture();
} else {
sing->removeRecent(profile.toStdString());
QMessageBox::warning(
this,
"Failed to load recent profile",
"Cannot load this profile. It was either renamed or deleted "
"before the history was updated. The profile has been removed from history.",
QMessageBox::Ok);
}
}
void
Application::onRecentCleared()
{
Suscan::Singleton *sing = Suscan::Singleton::get_instance();
sing->clearRecent();
}
void
Application::onPanSpectrumStart()
{
qint64 freqMin, initFreqMin;
qint64 freqMax, initFreqMax;
Suscan::DeviceProperties panDevProps;
bool noHop;
// we defer deletion of old scanner instances to here to avoid user-after-free of PSD data
// since the panoramic dialog's waterfall still uses the scanner's PSD data when stopped
if (m_scanner != nullptr) {
delete m_scanner;
m_scanner = nullptr;
}
if (m_mediator->getPanSpectrumRange(freqMin, freqMax) &&
m_mediator->getPanSpectrumZoomRange(initFreqMin, initFreqMax, noHop) &&
m_mediator->getPanSpectrumDevice(panDevProps)) {
Suscan::Source::Config config(
"soapysdr",
SUSCAN_SOURCE_FORMAT_AUTO);
Suscan::DeviceSpec spec(panDevProps);
config.setDeviceSpec(spec);
config.setAntenna(m_mediator->getPanSpectrumAntenna().toStdString());
config.setSampleRate(
static_cast<unsigned int>(
m_mediator->getPanSpectrumPreferredSampleRate()));
config.setDCRemove(true);
config.setBandwidth(m_mediator->getPanSpectrumPreferredSampleRate());
config.setLnbFreq(m_mediator->getPanSpectrumLnbOffset());
config.setFreq(.5 * (initFreqMin + initFreqMax));
// default RTL-SDR buffer size results in ~40 ms wait between chunks of data
// shorter buffer size avoids that being a bottleneck in sweep speed
if (spec.get("device") == "rtlsdr")
config.setParam("stream:bufflen", "16384");
try {
Suscan::Logger::getInstance()->flush();
m_scanner = new Scanner(this, freqMin, freqMax, initFreqMin, initFreqMax, noHop, config);
m_scanner->setRelativeBw(m_mediator->getPanSpectrumRelBw());
m_scanner->setRttMs(m_mediator->getPanSpectrumRttMs());
onPanSpectrumStrategyChanged(
m_mediator->getPanSpectrumStrategy());
onPanSpectrumPartitioningChanged(
m_mediator->getPanSpectrumPartition());
for (auto &p : panDevProps.gains())
m_scanner->setGain(
QString::fromStdString(p),
m_mediator->getPanSpectrumGain(QString::fromStdString(p)));
connectScanner();
Suscan::Logger::getInstance()->flush();
} catch (Suscan::Exception &) {
QMessageBox::critical(
this,
"SigDigger error",
"Failed to start capture due to errors:<p /><pre>"
+ getLogText()
+ "</pre>",
QMessageBox::Ok);
}
}
m_mediator->setPanSpectrumRunning(m_scanner != nullptr);
}
void
Application::onPanSpectrumStop()
{
if (m_scanner != nullptr) {
m_scanner->stop();
}
m_mediator->setPanSpectrumRunning(false);
}
void
Application::onPanSpectrumRangeChanged(qint64 min, qint64 max, bool noHop)
{
if (m_scanner != nullptr)
m_scanner->setViewRange(min, max, noHop);
}
void
Application::onPanSpectrumSkipChanged()
{
if (m_scanner != nullptr)
m_scanner->setRttMs(m_mediator->getPanSpectrumRttMs());
}
void
Application::onPanSpectrumRelBwChanged()
{
if (m_scanner != nullptr)
m_scanner->setRelativeBw(m_mediator->getPanSpectrumRelBw());
}
void
Application::onPanSpectrumReset()
{
if (m_scanner != nullptr) {
m_scanner->flip();
m_scanner->flip();
}
}
void
Application::onPanSpectrumStrategyChanged(QString strategy)
{
if (m_scanner != nullptr) {
if (strategy.toStdString() == "Stochastic")
m_scanner->setStrategy(Suscan::Analyzer::STOCHASTIC);
else if (strategy.toStdString() == "Progressive")
m_scanner->setStrategy(Suscan::Analyzer::PROGRESSIVE);
}
}
void
Application::onPanSpectrumPartitioningChanged(QString partitioning)
{
if (m_scanner != nullptr) {
if (partitioning.toStdString() == "Continuous")
m_scanner->setPartitioning(Suscan::Analyzer::CONTINUOUS);
else if (partitioning.toStdString() == "Discrete")
m_scanner->setPartitioning(Suscan::Analyzer::DISCRETE);
}
}
void
Application::onPanSpectrumGainChanged(QString name, float value)
{
if (m_scanner != nullptr)
m_scanner->setGain(name, value);
}
void
Application::onScannerStopped()
{
QString messages = getLogText();
if (messages.size() > 0) {
QMessageBox::warning(
this,
"Scanner stopped",
"Running scanner has stopped. The error log was:<p /><pre>"
+ getLogText()
+ "</pre>",
QMessageBox::Ok);
}
m_mediator->setPanSpectrumRunning(false);
}
void
Application::onScannerUpdated()
{
SpectrumView &view = m_scanner->getSpectrumView();
m_mediator->setMinPanSpectrumBw(m_scanner->getFs());
m_mediator->feedPanSpectrum(
static_cast<quint64>(view.freqMin),
static_cast<quint64>(view.freqMax),
view.psd,
view.spectrumSize);
}
void
Application::onTick()
{
if (m_mediator->getState() == UIMediator::RUNNING)
m_mediator->notifyTimeStamp(m_analyzer->getSourceTimeStamp());
if (m_cfgTimer.hasExpired(SIGDIGGER_AUTOSAVE_INTERVAL_MS)) {
m_cfgTimer.restart();
emit triggerSaveConfig();
}
}