-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtek492.cpp
1393 lines (1255 loc) · 41.8 KB
/
tek492.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
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <dl8dtl@s09.sax.de> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Joerg Wunsch
* ----------------------------------------------------------------------------
*/
/*
* As this application uses Qt, any redistribution is bound to the
* terms of either the GNU Lesser General Public License v. 3 ("LGPL"),
* or to any commercial Qt license.
*/
/*
* This application uses the Qwt extensions to Qt, which are also
* provided under the terms of LGPL v2.1. However, the Qwt license
* explicitly disclaims many common use cases as not constituting a
* "derived work" (in the LGPL sense), so it is generally less
* demanding about the redistribution policy than Qt itself.
*/
/* $Id$ */
#include <QMessageBox>
#include <QFileDialog>
#include <QInputDialog>
#include <QTime>
#include <QPrinter>
#include <QPrintDialog>
#include <QtXml/qdom.h>
#include <qwt_plot_renderer.h>
#include <stdio.h>
#include "tek492.h"
#include "ui_tek492.h"
#include "usb_492/usb492.hpp"
using namespace std;
static USB_Device *dev = 0;
static const QString spanNames[] =
{
"FULL",
"200 MHz", "100 MHz", "50 MHz", "20 MHz", "10 MHz",
"5 MHz", "2 MHz", "1 MHz", "500 kHz", "200 kHz", "100 kHz",
"50 kHz", "20 kHz", "10 kHz", "5 kHz", "2 kHz", "1 kHz",
"500 Hz"
};
static const double spanValues[] =
{
0, // Full
200E6, 100E6, 50E6, 20E6, 10E6,
5E6, 2E6, 1E6, 500E3, 200E3, 100E3,
50E3, 20E3, 10E3, 5E3, 2E3, 1E3,
500
};
static const int autoBW[] =
{
1000000, // Full
1000000, 1000000, 1000000, 1000000, 1000000,
1000000, 100000, 100000, 100000, 10000, 10000,
10000, 10000, 1000, 1000, 1000, 100,
100
};
static const int autoAtten[] =
{
0, // -120 dBm
0, // -110 dBm
0, // -100 dBm
0, // -90 dBm
0, // -80 dBm
0, // -70 dBm
0, // -60 dBm
0, // -50 dBm
0, // -40 dBm
0, // -30 dBm
10, // -20 dBm
20, // -10 dBm
30, // 0 dBm
40, // +10 dBm
50, // +20 dBm
60, // +30 dBm
};
static USB492 *logger_open(void)
{
vector<USB_Device *> devs;
USB_Device::find_all(devs, 0x3141, 0x0005);
if (devs.empty())
{
throw("USB492 device not found\n");
return NULL;
}
int n = 0;
dev = devs[n];
if (!dev->open())
{
throw("Can't open\n");
return NULL;
}
if (!dev->set_default())
{
throw("Can't set default config\n");
return NULL;
}
USB492 *usb492 = new USB492(dev);
return usb492;
}
Tek492::Tek492(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Tek492)
{
ui->setupUi(this);
QApplication::setWindowIcon(QIcon(":/resource/images/icon"));
try
{
usb492 = logger_open();
ui->actionConnect->setEnabled(true);
}
catch (const char *e)
{
QMessageBox::warning(this, "USB error", e);
usb492 = 0;
}
ui->fBand->addItem("1: 100 kHz … 1.8 GHz", 1);
ui->fBand->addItem("2: 1.7 … 5.5 GHz", 2);
ui->fBand->addItem("3: 3.0 … 7.1 GHz", 3);
ui->fBand->addItem("4: 5.4 … 18.0 GHz", 4);
ui->fBand->addItem("5: 15.0 … 21.0 GHz", 5);
// File menu
connect(ui->actionConnect, SIGNAL(triggered()), SLOT(connectToDevice()));
connect(ui->actionSave, SIGNAL(triggered()), SLOT(saveAs()));
connect(ui->actionOpen, SIGNAL(triggered()), SLOT(loadFile()));
connect(ui->actionPrint, SIGNAL(triggered()), SLOT(print()));
// Help menu
connect(ui->actionAbout, SIGNAL(triggered()), SLOT(about()));
connect(ui->actionUsage, SIGNAL(triggered()), SLOT(info()));
// Main widgeet
connect(ui->acquire, SIGNAL(pressed()), SLOT(acquire()));
connect(ui->frequencyDial, SIGNAL(valueChanged(int)), SLOT(frequencyDial(int)));
connect(ui->spanWheel, SIGNAL(valueChanged(double)), SLOT(spanWheelChanged(double)));
connect(ui->refLevelWheel, SIGNAL(valueChanged(double)), SLOT(refLevelChanged(double)));
connect(ui->fBand, SIGNAL(currentIndexChanged(int)), SLOT(bandChanged(int)));
connect(ui->atten0, SIGNAL(toggled(bool)), SLOT(attenChanged(bool)));
connect(ui->atten10, SIGNAL(toggled(bool)), SLOT(attenChanged(bool)));
connect(ui->atten20, SIGNAL(toggled(bool)), SLOT(attenChanged(bool)));
connect(ui->atten30, SIGNAL(toggled(bool)), SLOT(attenChanged(bool)));
connect(ui->atten40, SIGNAL(toggled(bool)), SLOT(attenChanged(bool)));
connect(ui->atten50, SIGNAL(toggled(bool)), SLOT(attenChanged(bool)));
connect(ui->atten60, SIGNAL(toggled(bool)), SLOT(attenChanged(bool)));
connect(ui->rbw100, SIGNAL(toggled(bool)), SLOT(bwChanged(bool)));
connect(ui->rbw1k, SIGNAL(toggled(bool)), SLOT(bwChanged(bool)));
connect(ui->rbw10k, SIGNAL(toggled(bool)), SLOT(bwChanged(bool)));
connect(ui->rbw100k, SIGNAL(toggled(bool)), SLOT(bwChanged(bool)));
connect(ui->rbw1M, SIGNAL(toggled(bool)), SLOT(bwChanged(bool)));
connect(ui->vfNone, SIGNAL(toggled(bool)), SLOT(bwChanged(bool)));
connect(ui->vfWide, SIGNAL(toggled(bool)), SLOT(bwChanged(bool)));
connect(ui->vfNarrow, SIGNAL(toggled(bool)), SLOT(bwChanged(bool)));
connect(ui->mAEnabled, SIGNAL(toggled(bool)), SLOT(markerAchecked(bool)));
connect(ui->mAWheel, SIGNAL(valueChanged(double)), SLOT(markerAmoved(double)));
connect(ui->mBEnabled, SIGNAL(toggled(bool)), SLOT(markerBchecked(bool)));
connect(ui->mBWheel, SIGNAL(valueChanged(double)), SLOT(markerBmoved(double)));
grid = new QwtPlotGrid();
grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine));
grid->enableX(true);
grid->enableXMin(true);
grid->enableY(true);
grid->enableYMin(false);
grid->attach(ui->plotArea);
data = new QVector<QPointF>();
for (int i = 0; i < 1015; i++)
{
data->append(QPointF(i, 1000 - i));
}
curve = new TekPlotCurve();
curve->setStyle(QwtPlotCurve::Lines);
curve->setPen(QPen(Qt::green, 0.0, Qt::SolidLine));
curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
curve->setSamples(*data);
curve->attach(ui->plotArea);
titleText = new QwtText("Tek492");
titleText->setRenderFlags(Qt::AlignLeft | Qt::AlignTop);
titleText->setColor("yellow");
bLeftText = new QwtText("BL");
bLeftText->setRenderFlags(Qt::AlignLeft | Qt::AlignBottom);
bLeftText->setColor("yellow");
bCenterText = new QwtText("BC");
bCenterText->setRenderFlags(Qt::AlignHCenter | Qt::AlignBottom);
bCenterText->setColor("yellow");
bRightText = new QwtText("BR");
bRightText->setRenderFlags(Qt::AlignRight | Qt::AlignBottom);
bRightText->setColor("yellow");
QFont font;
font.setBold(true);
titleText->setFont(font);
title = new QwtPlotTextLabel();
title->setText(*titleText);
title->attach(ui->plotArea);
marker = new QwtPlotTextLabel();
marker->attach(ui->plotArea);
bLeft = new QwtPlotTextLabel();
bLeft->setText(*bLeftText);
bLeft->attach(ui->plotArea);
bCenter = new QwtPlotTextLabel();
bCenter->setText(*bCenterText);
bCenter->attach(ui->plotArea);
bRight = new QwtPlotTextLabel();
bRight->setText(*bRightText);
bRight->attach(ui->plotArea);
mAvalue = new QString();
QColor markerColor("yellow");
mASymbol = new QwtSymbol(QwtSymbol::DTriangle, QBrush(), QPen(markerColor), QSize(10,10));
markerA = new QwtPlotMarker();
markerA->setSymbol(mASymbol);
mAText = new QwtText("A");
mAText->setColor("yellow");
markerA->setLabelAlignment(Qt::AlignHCenter | Qt::AlignTop);
markerA->setLabel(*mAText);
mBvalue = new QString();
mBSymbol = new QwtSymbol(QwtSymbol::Diamond, QBrush(), QPen(markerColor), QSize(10,10));
markerB = new QwtPlotMarker();
markerB->setSymbol(mBSymbol);
mBText = new QwtText("B");
mBText->setColor("yellow");
markerB->setLabelAlignment(Qt::AlignHCenter | Qt::AlignTop);
markerB->setLabel(*mBText);
ui->plotArea->replot();
refLevelChanged(ui->refLevelWheel->value());
bandChanged(0);
attenChanged(true);
bwChanged(true);
spanWheelChanged(ui->spanWheel->value());
}
Tek492::~Tek492()
{
delete markerA;
//delete mASymbol; // this crashes; is the marker symbol deleted when deleting marker?
delete mAvalue;
delete markerB;
delete mBvalue;
delete mAText;
delete mBText;
delete titleText;
delete bLeftText;
delete bCenterText;
delete bRightText;
delete title;
delete marker;
delete bLeft;
delete bCenter;
delete bRight;
delete ui;
if (usb492)
delete usb492;
delete grid;
delete data;
delete curve;
}
static void delay(int milliseconds)
{
QTime endTime = QTime::currentTime().addMSecs(milliseconds);
while (QTime::currentTime() < endTime)
{
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
}
static uint8_t memConfig(Ui::Tek492 *ui)
{
uint8_t confval = 0x60; // unknown meaning, always set
if (ui->maxHold->isChecked())
confval |= 0x10;
if (ui->viewB_minus_saveA->isChecked())
confval |= 0x08;
if (ui->viewB->isChecked())
confval |= 0x04;
if (ui->viewA->isChecked())
confval |= 0x02;
if (ui->saveA->isChecked())
confval |= 0x01;
return confval;
}
#define XML_ROOT "tek492"
/* root attributes */
#define XMLNS "http://uriah.heep.sax.de/tek492/xml"
#define XSI "http://www.w3.org/2001/XMLSchema-instance"
#define SCHEMALOC "http://uriah.heep.sax.de/tek492/xml http://uriah.heep.sax.de/tek492/xml/tek492.xsd"
#define VERSION "0.1"
void Tek492::readFile(const QString fName)
{
QDomDocument doc;
QFile file(fName);
if (!file.open(QIODevice::ReadOnly))
{
QMessageBox::critical(this, "File error", "Error opening file");
return;
}
if (!doc.setContent(&file))
{
QMessageBox::information(this, "File error", "File has no contents");
file.close();
return;
}
file.close();
QDomElement docElem = doc.documentElement();
for (QDomNode node = docElem.firstChild();
!node.isNull();
node = node.nextSibling())
{
QDomElement ele = node.toElement();
if (!ele.isNull())
{
if (ele.tagName() == "header")
{
for (QDomNode hnode = node.firstChild();
!hnode.isNull();
hnode = hnode.nextSibling())
{
QDomElement hele = hnode.toElement();
if (!hele.isNull())
{
// parse header tags
if (hele.tagName() == "comment")
{
QString text = hele.text();
if (text != QString())
QMessageBox::information(this, "File comment",
QString("File comment is: ") + text);
}
else if (hele.tagName() == "band")
{
int index = hele.text().toInt();
ui->fBand->setCurrentIndex(index);
// triggers
//bandChanged(index);
}
else if (hele.tagName() == "centerFrequency")
{
ui->frequencySpinBox->setValue(hele.text().toDouble());
}
else if (hele.tagName() == "memoryConfiguration")
{
uint8_t confval = hele.text().toInt();
ui->maxHold->setChecked((confval & 0x10) != 0);
ui->viewB_minus_saveA->setChecked((confval & 0x08) != 0);
ui->viewB->setChecked((confval & 0x04) != 0);
ui->viewA->setChecked((confval & 0x02) != 0);
ui->saveA->setChecked((confval & 0x01) != 0);
}
else if (hele.tagName() == "videoFilter")
{
int vf = hele.text().toInt();
switch (vf)
{
case 0:
ui->vfNone->setChecked(true);
break;
case 1:
ui->vfWide->setChecked(true);
break;
case 2:
ui->vfNarrow->setChecked(true);
break;
}
}
else if (hele.tagName() == "spanIdx")
{
double val = hele.text().toDouble();
ui->spanWheel->setValue(18 - val);
// triggers
//spanWheelChanged(val);
}
else if (hele.tagName() == "rbw")
{
int rbw = hele.text().toInt();
switch (rbw)
{
case 100:
ui->rbw100->setChecked(true);
break;
case 1000:
ui->rbw1k->setChecked(true);
break;
case 10000:
ui->rbw10k->setChecked(true);
break;
case 100000:
ui->rbw100k->setChecked(true);
break;
case 1000000:
ui->rbw1M->setChecked(true);
break;
}
}
else if (hele.tagName() == "referenceLevel")
{
double val = hele.text().toDouble();
ui->refLevelWheel->setValue(val);
// triggers.
// refLevelChanged(val);
}
else if (hele.tagName() == "attenuation")
{
int atten = hele.text().toInt();
switch (atten)
{
case 0:
ui->atten0->setChecked(true);
break;
case 10:
ui->atten10->setChecked(true);
break;
case 20:
ui->atten20->setChecked(true);
break;
case 30:
ui->atten30->setChecked(true);
break;
case 40:
ui->atten40->setChecked(true);
break;
case 50:
ui->atten50->setChecked(true);
break;
case 60:
ui->atten60->setChecked(true);
break;
}
}
else
{
qDebug() << "Unknown header tag:" << hele.tagName();
}
}
}
}
else if (ele.tagName() == "data")
{
int idx = 0;
for (QDomNode dnode = node.firstChild();
!dnode.isNull() && idx < 1024;
dnode = dnode.nextSibling(), idx++)
{
QDomElement dele = dnode.toElement();
if (!dele.isNull())
{
if (dele.tagName() == "ele")
{
rawData[idx] = dele.text().toInt();
}
}
}
}
else
{
qDebug() << "Unknown tag:" << ele.tagName();
}
}
plotData();
}
}
void Tek492::writeFile(const QString fName, const QString comment)
{
QDomDocument doc;
doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
QDomElement root = doc.createElement(XML_ROOT);
doc.appendChild(root);
root.setAttribute("xmlns", XMLNS);
root.setAttribute("xmlns:xsi", XSI);
root.setAttribute("xsi:schemaLocation", SCHEMALOC);
root.setAttribute("version", VERSION);
QDomElement rootChildHeader = doc.createElement("header");
root.appendChild(rootChildHeader);
QDomElement headerComment = doc.createElement("comment");
if (comment != QString())
{
QDomText txtComment = doc.createTextNode(comment);
headerComment.appendChild(txtComment);
}
rootChildHeader.appendChild(headerComment);
QDomElement headerBand = doc.createElement("band");
QDomText txtBand = doc.createTextNode(QString::number(ui->fBand->currentIndex()));
headerBand.appendChild(txtBand);
rootChildHeader.appendChild(headerBand);
QDomElement headerCF = doc.createElement("centerFrequency");
QDomText txtCF = doc.createTextNode(QString::number(ui->frequencySpinBox->value()));
headerCF.appendChild(txtCF);
rootChildHeader.appendChild(headerCF);
QDomElement memConf = doc.createElement("memoryConfiguration");
QDomText txtMemConf = doc.createTextNode(QString::number(memConfig(ui), 10));
memConf.appendChild(txtMemConf);
rootChildHeader.appendChild(memConf);
QDomElement videoFilter = doc.createElement("videoFilter");
int vf = 0;
if (ui->vfWide->isChecked())
vf = 1;
else if (ui->vfNarrow->isChecked())
vf = 2;
QDomText txtVF = doc.createTextNode(QString::number(vf));
videoFilter.appendChild(txtVF);
rootChildHeader.appendChild(videoFilter);
QDomElement span = doc.createElement("spanIdx");
QDomText txtSpan = doc.createTextNode(QString::number(spanIdx));
span.appendChild(txtSpan);
rootChildHeader.appendChild(span);
QDomElement rbwEle = doc.createElement("rbw");
uint rbw = 1000000;
if (ui->rbw100->isChecked())
rbw = 100;
else if (ui->rbw1k->isChecked())
rbw = 1000;
else if (ui->rbw10k->isChecked())
rbw = 10000;
else if (ui->rbw100k->isChecked())
rbw = 100000;
QDomText txtRbw = doc.createTextNode(QString::number(rbw));
rbwEle.appendChild(txtRbw);
rootChildHeader.appendChild(rbwEle);
QDomElement refLev = doc.createElement("referenceLevel");
QDomText txtRef = doc.createTextNode(QString::number(refLevel));
refLev.appendChild(txtRef);
rootChildHeader.appendChild(refLev);
QDomElement attenEle = doc.createElement("attenuation");
int atten = 0;
if (ui->atten10->isChecked())
atten = 10;
else if (ui->atten20->isChecked())
atten = 20;
else if (ui->atten30->isChecked())
atten = 30;
else if (ui->atten40->isChecked())
atten = 40;
else if (ui->atten50->isChecked())
atten = 50;
else if (ui->atten60->isChecked())
atten = 60;
QDomText txtAtten = doc.createTextNode(QString::number(atten));
attenEle.appendChild(txtAtten);
rootChildHeader.appendChild(attenEle);
QDomElement data = doc.createElement("data");
for (int i = 0; i < 1024; i++)
{
QDomElement dataEle = doc.createElement("ele");
QDomText txtEle = doc.createTextNode(QString::number(rawData[i]));
dataEle.appendChild(txtEle);
data.appendChild(dataEle);
}
root.appendChild(data);
QString fname = fName;
if(fname.right(4) != ".xml") {fname += ".xml";}
QFile file(fname);
if(QFile::exists(fname)) {QFile::remove(fname);}
if(file.open(QFile::WriteOnly))
{
file.write(QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n").toUtf8());
file.write(doc.toByteArray());
file.close();
}
}
void Tek492::plotData(void)
{
qreal cf, span;
// full span
if (spanIdx == 0)
{
// f in MHz
if (lowBound == 0)
// band 1 is actually 0 ... 4.2 GHz
span = 4200;
else
span = highBound - lowBound;
cf = span / 2 + lowBound;
}
else
{
cf = ui->frequencySpinBox->value();
span = 10 * spanValues[spanIdx];
span /= 1E6; // in MHz
}
data->clear();
// Discard bogus samples at the beginning and end
qreal rl = refLevel;
for (int i = 4; i <= 1018; ++i)
{
qreal f = cf + ((i - 507) / 1015.0) * span;
qreal v = (static_cast<qreal>(rawData[i]) - 24) / 220.0;
if (v > 1)
v = 1;
else if (v < 0)
v = 0;
qreal val = rl + 80 * (v - 1);
data->append(QPointF(f, val));
}
curve->setBoundingRect(cf - 0.5 * span, rl - 80, span, 80.0);
curve->setSamples(*data);
ui->plotArea->replot();
ui->mAEnabled->setCheckable(true);
ui->mAEnabled->setToolTip("");
ui->mBEnabled->setCheckable(true);
ui->mBEnabled->setToolTip("");
ui->actionSave->setEnabled(true);
ui->actionPrint->setEnabled(true);}
// SLOTs
void Tek492::connectToDevice(void)
{
ui->acquire->setEnabled(true);
}
void Tek492::saveAs(void)
{
QString fName = QFileDialog::getSaveFileName(this, "Save file to");
if (fName != QString())
{
QString comment = QInputDialog::getText(this, "File comment", "Enter an optional file comment");
writeFile(fName, comment);
}
}
void Tek492::loadFile(void)
{
QString fName = QFileDialog::getOpenFileName(this, "Load file from");
if (fName != QString())
{
readFile(fName);
}
}
void Tek492::acquire(void)
{
uint8_t crt_control;
// full span
if (spanIdx == 0)
{
crt_control = 0x08; // maxspan dot
}
else
{
crt_control = 0;
}
// Halt acquisition, turn off readout
uint8_t confval = memConfig(ui);
usb492->write_reg(USB492::CRT_Control, crt_control);
usb492->write_reg(USB492::Storage_Control, confval);
delay(50);
for (int i = 0; i < 1024; i += 64)
dev->control(USB_Device::Control_In | USB_Device::Control_Vendor,
0x01, 0, USB492::Storage_Data,
rawData + i, 64);
// Resume acquisition, re-enable readout
usb492->write_reg(USB492::Storage_Control, confval | 0x80);
usb492->write_reg(USB492::CRT_Control, crt_control | 0x01);
plotData();
}
void Tek492::frequencyDial(int value)
{
static int oldValue;
double cf = ui->frequencySpinBox->value();
int delta = value - oldValue;
oldValue = value;
if (delta > 50)
// wrap counterclockwise, e.g. 1 to 99 = 98; means -1
delta -= 99;
else if (delta < -50)
// wrap clockwise, e.g. 99 to 1 = -98; means +1
delta += 99;
cf += delta;
if (cf >= lowBound && cf <= highBound)
{
ui->frequencySpinBox->setValue(cf);
qreal span;
if (spanIdx == 0)
{
if (lowBound == 0)
{
// band 1 is actually 0 ... 4.2 GHz
span = 4200;
cf = span / 2;
}
else
span = highBound - lowBound;
}
else
{
span = 10 * spanValues[spanIdx];
span /= 1E6; // in MHz
}
ui->mAWheel->setMinimum(cf - span / 2);
ui->mAWheel->setMaximum(cf + span / 2);
ui->mAWheel->setSingleStep(span / 1015.0);
if (ui->mAWheel->value() > cf + span / 2)
{
ui->mAWheel->setValue(cf + span / 2);
markerAmoved(cf + span / 2);
}
else if (ui->mAWheel->value() < cf - span / 2)
{
ui->mAWheel->setValue(cf - span / 2);
markerAmoved(cf - span / 2);
}
ui->mBWheel->setMinimum(cf - span / 2);
ui->mBWheel->setMaximum(cf + span / 2);
ui->mBWheel->setSingleStep(span / 1015.0);
if (ui->mBWheel->value() > cf + span / 2)
{
ui->mBWheel->setValue(cf + span / 2);
markerAmoved(cf + span / 2);
}
else if (ui->mBWheel->value() < cf - span / 2)
{
ui->mBWheel->setValue(cf - span / 2);
markerAmoved(cf - span / 2);
}
ui->plotArea->replot();
}
}
void Tek492::spanWheelChanged(double value)
{
spanIdx = 18 - int(value);
const QString &curspan = spanNames[spanIdx];
ui->spanValue->setText(curspan);
switch (autoBW[spanIdx])
{
case 1000000:
ui->rbw1M->setChecked(true);
break;
case 100000:
ui->rbw100k->setChecked(true);
break;
case 10000:
ui->rbw10k->setChecked(true);
break;
case 1000:
ui->rbw1k->setChecked(true);
break;
case 100:
ui->rbw100->setChecked(true);
break;
}
qreal cf = ui->frequencySpinBox->value();
qreal span;
if (spanIdx == 0)
{
if (lowBound == 0)
{
// band 1 is actually 0 ... 4.2 GHz
span = 4200;
cf = span / 2;
}
else
span = highBound - lowBound;
}
else
{
span = 10 * spanValues[spanIdx];
span /= 1E6; // in MHz
}
ui->mAWheel->setMinimum(cf - span / 2);
ui->mAWheel->setMaximum(cf + span / 2);
ui->mAWheel->setSingleStep(span / 1015.0);
if (ui->mAWheel->value() > cf + span / 2)
{
ui->mAWheel->setValue(cf + span / 2);
markerAmoved(cf + span / 2);
}
else if (ui->mAWheel->value() < cf - span / 2)
{
ui->mAWheel->setValue(cf - span / 2);
markerAmoved(cf - span / 2);
}
ui->mBWheel->setMinimum(cf - span / 2);
ui->mBWheel->setMaximum(cf + span / 2);
ui->mBWheel->setSingleStep(span / 1015.0);
if (ui->mBWheel->value() > cf + span / 2)
{
ui->mBWheel->setValue(cf + span / 2);
markerAmoved(cf + span / 2);
}
else if (ui->mBWheel->value() < cf - span / 2)
{
ui->mBWheel->setValue(cf - span / 2);
markerAmoved(cf - span / 2);
}
ui->plotArea->replot();
}
void Tek492::refLevelChanged(double value)
{
refLevel = int(value);
char buf[20];
sprintf(buf, "%+3d dBm", refLevel);
ui->refLevValue->setText(buf);
int idx = (value + 120) / 10; // -120 dBm => index 0
switch (autoAtten[idx])
{
case 0:
ui->atten0->setChecked(true);
break;
case 10:
ui->atten10->setChecked(true);
break;
case 20:
ui->atten20->setChecked(true);
break;
case 30:
ui->atten30->setChecked(true);
break;
case 40:
ui->atten40->setChecked(true);
break;
case 50:
ui->atten50->setChecked(true);
break;
case 60:
ui->atten60->setChecked(true);
break;
}
}
void Tek492::bandChanged(int index)
{
switch (index)
{
case 0: // 1: 100 kHz ... 1.8 GHz (actually 4.2)
lowBound = 0;
highBound = 1800;
bCenterText->setText("0 … 1.8");
break;
case 1: // 2: 1.7 ... 5.5 GHz
lowBound = 1700;
highBound = 5500;
bCenterText->setText("1.7 … 5.5");
break;
case 2: // 3: 3.0 ... 7.1 GHz
lowBound = 3000;
highBound = 7100;
bCenterText->setText("3.0 … 7.1");
break;
case 3: // 4: 5.4 ... 18.0 GHz
lowBound = 5400;
highBound = 18000;
bCenterText->setText("5.4 … 18.0");
break;
case 4: // 5: 15.0 ... 21.0 GHz
lowBound = 15E3;
highBound = 21E3;
bCenterText->setText("15 … 21");
break;
}
bCenter->setText(*bCenterText);
ui->plotArea->replot();
ui->frequencySpinBox->setMinimum(lowBound);
ui->frequencySpinBox->setMaximum(highBound);
if (ui->frequencySpinBox->value() < lowBound)
ui->frequencySpinBox->setValue(lowBound);
else if (ui->frequencySpinBox->value() > highBound)
ui->frequencySpinBox->setValue(highBound);
qreal span;
qreal cf = ui->frequencySpinBox->value();
if (spanIdx == 0)
{
if (lowBound == 0)
{
// band 1 is actually 0 ... 4.2 GHz
span = 4200;
cf = span / 2;
}
else
span = highBound - lowBound;
}
else
{
span = 10 * spanValues[spanIdx];
span /= 1E6; // in MHz
}
ui->mAWheel->setMinimum(cf - span / 2);
ui->mAWheel->setMaximum(cf + span / 2);
ui->mAWheel->setSingleStep(span / 1015.0);
if (ui->mAWheel->value() > cf + span / 2)
{
ui->mAWheel->setValue(cf + span / 2);
markerAmoved(cf + span / 2);
}
else if (ui->mAWheel->value() < cf - span / 2)
{
ui->mAWheel->setValue(cf - span / 2);
markerAmoved(cf - span / 2);
}
ui->mBWheel->setMinimum(cf - span / 2);
ui->mBWheel->setMaximum(cf + span / 2);
ui->mBWheel->setSingleStep(span / 1015.0);
if (ui->mBWheel->value() > cf + span / 2)
{
ui->mBWheel->setValue(cf + span / 2);
markerAmoved(cf + span / 2);
}
else if (ui->mBWheel->value() < cf - span / 2)
{
ui->mBWheel->setValue(cf - span / 2);
markerAmoved(cf - span / 2);
}
ui->plotArea->replot();
}