";
135 |
136 | status = status.toHtmlEscaped();
137 |
138 | double startFreqHz = inf.data.values.begin()->first;
139 | double stopFreqHz = inf.data.values.rbegin()->first;
140 | status = "" + status
141 | + qs(ssprintf(256, "\n %8.3f MHz - %8.3f MHz, %d points
",
142 | startFreqHz*1e-6, stopFreqHz*1e-6, (int)inf.data.values.size()));
143 | return status;
144 | }
145 |
--------------------------------------------------------------------------------
/vna_qt/calkitsettingsdialog.H:
--------------------------------------------------------------------------------
1 | #ifndef CALKITSETTINGSDIALOG_H
2 | #define CALKITSETTINGSDIALOG_H
3 |
4 | #include
5 | #include "calkitsettings.H"
6 | #include "ui_calkitsettingswidget.h"
7 | namespace Ui {
8 | class CalKitSettingsDialog;
9 | }
10 |
11 | class CalKitSettingsDialog : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | struct calKitInfo {
16 | Ui::CalKitSettingsWidget ui;
17 | string fileName;
18 | SParamSeries data;
19 | bool useIdeal;
20 | };
21 | public:
22 | explicit CalKitSettingsDialog(QWidget *parent = 0);
23 | ~CalKitSettingsDialog();
24 |
25 | void fromSettings(const CalKitSettings& settings);
26 | void toSettings(CalKitSettings& settings);
27 |
28 | QString generateLabel(const calKitInfo& inf);
29 | map info;
30 | private:
31 | Ui::CalKitSettingsDialog *ui;
32 | };
33 |
34 | #endif // CALKITSETTINGSDIALOG_H
35 |
--------------------------------------------------------------------------------
/vna_qt/calkitsettingsdialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | CalKitSettingsDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 772
10 | 511
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 | -
18 |
19 |
20 |
21 | 0
22 | 0
23 |
24 |
25 |
26 |
27 | 12
28 |
29 |
30 |
31 | Calibration kit parameters
32 |
33 |
34 |
35 | -
36 |
37 |
38 | 1
39 |
40 |
41 | true
42 |
43 |
44 |
45 |
46 | 0
47 | 0
48 | 752
49 | 16
50 |
51 |
52 |
53 |
54 | 0
55 | 0
56 |
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 | Qt::Horizontal
65 |
66 |
67 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | buttonBox
77 | accepted()
78 | CalKitSettingsDialog
79 | accept()
80 |
81 |
82 | 248
83 | 254
84 |
85 |
86 | 157
87 | 274
88 |
89 |
90 |
91 |
92 | buttonBox
93 | rejected()
94 | CalKitSettingsDialog
95 | reject()
96 |
97 |
98 | 316
99 | 260
100 |
101 |
102 | 286
103 | 274
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/vna_qt/calkitsettingswidget.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | CalKitSettingsWidget
4 |
5 |
6 |
7 | 0
8 | 0
9 | 611
10 | 45
11 |
12 |
13 |
14 |
15 | 0
16 | 0
17 |
18 |
19 |
20 |
21 | 0
22 | 45
23 |
24 |
25 |
26 | Form
27 |
28 |
29 |
30 | 0
31 |
32 |
33 | 0
34 |
35 |
36 | 0
37 |
38 |
39 | 0
40 |
41 | -
42 |
43 |
44 |
45 | 0
46 | 0
47 |
48 |
49 |
50 |
51 | 130
52 | 0
53 |
54 |
55 |
56 | Open (port 1)
57 |
58 |
59 | 5
60 |
61 |
62 |
63 | -
64 |
65 |
66 |
67 | 0
68 | 0
69 |
70 |
71 |
72 | Ideal
73 |
74 |
75 | true
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 | 0
84 | 0
85 |
86 |
87 |
88 | S-Parameter
89 |
90 |
91 |
92 | -
93 |
94 |
95 | color: #0066aa; font-family: Monospace
96 |
97 |
98 | aaaaa<br />sssss
99 |
100 |
101 | Qt::RichText
102 |
103 |
104 | 8
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/vna_qt/configureviewdialog.C:
--------------------------------------------------------------------------------
1 | #include "configureviewdialog.H"
2 | #include "ui_configureviewdialog.h"
3 |
4 | ConfigureViewDialog::ConfigureViewDialog(QWidget *parent) :
5 | QDialog(parent),
6 | ui(new Ui::ConfigureViewDialog)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | ConfigureViewDialog::~ConfigureViewDialog()
12 | {
13 | delete ui;
14 | }
15 |
--------------------------------------------------------------------------------
/vna_qt/configureviewdialog.H:
--------------------------------------------------------------------------------
1 | #ifndef CONFIGUREVIEWDIALOG_H
2 | #define CONFIGUREVIEWDIALOG_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class ConfigureViewDialog;
8 | }
9 |
10 | class ConfigureViewDialog : public QDialog
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit ConfigureViewDialog(QWidget *parent = 0);
16 | ~ConfigureViewDialog();
17 |
18 | private:
19 | Ui::ConfigureViewDialog *ui;
20 | };
21 |
22 | #endif // CONFIGUREVIEWDIALOG_H
23 |
--------------------------------------------------------------------------------
/vna_qt/dtfwindow.C:
--------------------------------------------------------------------------------
1 | #define _USE_MATH_DEFINES
2 | #include "dtfwindow.H"
3 | #include "ui_dtfwindow.h"
4 | #include "graphpanel.H"
5 | #include "utility.H"
6 | #include
7 | #include
8 | #include
9 |
10 | DTFWindow::DTFWindow(QWidget *parent) :
11 | QMainWindow(parent),
12 | ui(new Ui::DTFWindow)
13 | {
14 | ui->setupUi(this);
15 | nv.init(ui->w_bottom->layout());
16 | nv.xAxisValueStr = [](double val) {
17 | return ssprintf(32, "%.3lf ns", val);
18 | };
19 |
20 | GraphPanel* gp = nv.createGraphView(false, false);
21 | gp->maximizeButton()->hide();
22 | ui->w_graph->layout()->addWidget(gp);
23 |
24 | nv.addMarker(false);
25 | }
26 |
27 | DTFWindow::~DTFWindow()
28 | {
29 | delete ui;
30 | }
31 |
32 | inline double gauss(double x, double m, double s) {
33 | static const double inv_sqrt_2pi = 0.3989422804014327;
34 | double a = (x - m) / s;
35 | return inv_sqrt_2pi / s * std::exp(-0.5 * a * a);
36 | }
37 |
38 | void DTFWindow::initFFT(int sz) {
39 | fft_in = (complex*) fftw_malloc(sizeof(complex) * sz);
40 | fft_out = (complex*) fftw_malloc(sizeof(complex) * sz);
41 | fft_window = (complex*) fftw_malloc(sizeof(complex) * sz);
42 | p = fftw_plan_dft_1d(sz, (fftw_complex*)fft_in, (fftw_complex*)fft_out, FFTW_BACKWARD, 0);
43 |
44 | /*double raisedCosineWidth = 0.1;
45 | for(int i=0; i 0.5) x = 1. - x;
48 | if(x > raisedCosineWidth) fft_window[i] = 1.;
49 | else {
50 | double tmp = -cos(x*M_PI/raisedCosineWidth);
51 | fft_window[i] = (tmp + 1) * 0.5;
52 | }
53 | }*/
54 | for(int i=0;i &freqDomainValues) {
84 | int sz = (int)freqDomainValues.size();
85 | assert(sz == (int)nv.values.size());
86 | for(int row=0;row<2;row++)
87 | for(int col=0;col<2;col++) {
88 | for(int i=0;i
5 | #include
6 | #include "networkview.H"
7 |
8 | namespace Ui {
9 | class DTFWindow;
10 | }
11 |
12 | class DTFWindow : public QMainWindow
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | NetworkView nv;
18 | fftw_plan p;
19 | complex* fft_in = nullptr;
20 | complex* fft_out = nullptr;
21 | complex* fft_window = nullptr;
22 |
23 | double timeScale = 1e9;
24 | explicit DTFWindow(QWidget *parent = 0);
25 | ~DTFWindow();
26 |
27 | void initFFT(int sz);
28 | void deinitFFT();
29 | void updateSweepParams(double stepFreqHz, int nPoints);
30 | void updateValues(const vector& freqDomainValues);
31 | signals:
32 | void hidden();
33 | protected:
34 | void closeEvent(QCloseEvent *event);
35 | private:
36 | Ui::DTFWindow *ui;
37 | };
38 |
39 | #endif // DTFWINDOW_H
40 |
--------------------------------------------------------------------------------
/vna_qt/dtfwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | DTFWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 600
10 | 400
11 |
12 |
13 |
14 | Time to fault
15 |
16 |
17 |
18 | -
19 |
20 |
21 |
22 | 0
23 | 0
24 |
25 |
26 |
27 |
28 | 0
29 |
30 |
31 | 0
32 |
33 |
34 | 0
35 |
36 |
37 | 0
38 |
39 |
40 |
41 |
42 | -
43 |
44 |
45 |
46 | 0
47 | 0
48 |
49 |
50 |
51 |
52 | 0
53 | 10
54 |
55 |
56 |
57 |
58 | 0
59 |
60 |
61 | 0
62 |
63 |
64 | 0
65 |
66 |
67 | 0
68 |
69 |
70 | 0
71 |
72 |
73 |
74 |
75 |
76 |
77 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/vna_qt/edit-redo-symbolic.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
33 |
--------------------------------------------------------------------------------
/vna_qt/emblem-ok-symbolic.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
32 |
--------------------------------------------------------------------------------
/vna_qt/firmwareupdatedialog.C:
--------------------------------------------------------------------------------
1 | #include "firmwareupdatedialog.H"
2 | #include "ui_firmwareupdatedialog.h"
3 | #include "firmwareupdater.H"
4 | #include "utility.H"
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | FirmwareUpdateDialog::FirmwareUpdateDialog(QWidget *parent) :
12 | QDialog(parent),
13 | ui(new Ui::FirmwareUpdateDialog)
14 | {
15 | ui->setupUi(this);
16 | }
17 |
18 | FirmwareUpdateDialog::~FirmwareUpdateDialog()
19 | {
20 | delete ui;
21 | }
22 |
23 | void FirmwareUpdateDialog::beginUploadFirmware(string dev, string file) {
24 | ui->buttonBox->setDisabled(true);
25 |
26 | /*_fd = ::open(file.c_str(), O_RDONLY);
27 | if(_fd < 0)
28 | throw runtime_error(strerror(errno));*/
29 |
30 | filePtr = fopen(file.c_str(), "rb");
31 | if(filePtr == nullptr)
32 | throw runtime_error(strerror(errno));
33 |
34 |
35 | updater = new FirmwareUpdater();
36 | updater->open(dev.c_str());
37 | updater->beginUploadFirmware(0x08004000, [this](uint8_t* buf, int len) {
38 | //return int(::read(_fd, buf, size_t(len)));
39 | return int(fread(buf, 1, size_t(len), this->filePtr));
40 | },
41 | [this](int progress){
42 | QMetaObject::invokeMethod(this, "updateProgress", Qt::QueuedConnection, Q_ARG(int, progress));
43 | });
44 | }
45 |
46 | void FirmwareUpdateDialog::updateProgress(int progress) {
47 | if(progress == -1) {
48 | auto ex = updater->endUploadFirmware();
49 | if(ex == nullptr)
50 | updater->reboot();
51 |
52 | updater->close();
53 | delete updater;
54 | updater = nullptr;
55 |
56 | fclose(filePtr);
57 |
58 | if(ex != nullptr) {
59 | QString msg = "An error occurred during firmware update:\n\n";
60 | msg += ex->what();
61 | msg += "\n\nPlease retry the update.\nYou can re-enter DFU mode by holding down the JOG LEFT button and power cycling the device.";
62 | QMessageBox::critical(this, "Error", msg);
63 | this->accept();
64 | } else {
65 | ui->l_progress->setText("Done\n" + ui->l_progress->text());
66 | ui->buttonBox->setDisabled(false);
67 | }
68 | return;
69 | }
70 | string msg;
71 | if(progress < 1024)
72 | msg = ssprintf(128, "%d bytes", progress);
73 | else msg = ssprintf(128, "%d KiB", progress/1024);
74 | ui->l_progress->setText(qs(msg));
75 | }
76 |
--------------------------------------------------------------------------------
/vna_qt/firmwareupdatedialog.H:
--------------------------------------------------------------------------------
1 | #ifndef FIRMWAREUPDATEDIALOG_H
2 | #define FIRMWAREUPDATEDIALOG_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | using namespace std;
9 | namespace Ui {
10 | class FirmwareUpdateDialog;
11 | }
12 | class FirmwareUpdater;
13 | class FirmwareUpdateDialog : public QDialog
14 | {
15 | Q_OBJECT
16 |
17 | public:
18 | explicit FirmwareUpdateDialog(QWidget *parent = nullptr);
19 | ~FirmwareUpdateDialog();
20 |
21 | void beginUploadFirmware(string dev, string file);
22 |
23 | public slots:
24 | void updateProgress(int progress);
25 |
26 | private:
27 | Ui::FirmwareUpdateDialog *ui;
28 | FirmwareUpdater* updater = nullptr;
29 | //int _fd = -1;
30 | FILE* filePtr = nullptr;
31 | };
32 |
33 | #endif // FIRMWAREUPDATEDIALOG_H
34 |
--------------------------------------------------------------------------------
/vna_qt/firmwareupdatedialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | FirmwareUpdateDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 388
10 | 186
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 | -
18 |
19 |
20 | Qt::Horizontal
21 |
22 |
23 | QDialogButtonBox::Ok
24 |
25 |
26 |
27 | -
28 |
29 |
30 | 0 KiB
31 |
32 |
33 |
34 | -
35 |
36 |
37 | Uploading firmware...
38 |
39 |
40 |
41 | -
42 |
43 |
44 | If the firmware update is interrupted, you can re-enter DFU mode by holding down the JOG LEFT button while power cycling the device.
45 |
46 |
47 | true
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | buttonBox
57 | accepted()
58 | FirmwareUpdateDialog
59 | accept()
60 |
61 |
62 | 248
63 | 254
64 |
65 |
66 | 157
67 | 274
68 |
69 |
70 |
71 |
72 | buttonBox
73 | rejected()
74 | FirmwareUpdateDialog
75 | reject()
76 |
77 |
78 | 316
79 | 260
80 |
81 |
82 | 286
83 | 274
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/vna_qt/firmwareupdater.C:
--------------------------------------------------------------------------------
1 | #include "firmwareupdater.H"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | // this dependency can be removed if you provide implementations
9 | // of qToLittleEndian() and qFromLittleEndian()
10 | #include
11 |
12 | static int writeAll(int fd, const void* buf, int len) {
13 | const uint8_t* buf1 = static_cast (buf);
14 | int off = 0;
15 | while(off& reader,
62 | const function& cb) {
63 | // set flash write address
64 | checkError(writeRegister32(0xe0, dstAddr));
65 |
66 | this->_cb = cb;
67 | this->_reader = reader;
68 | checkError(pthread_create(&_pth, nullptr, &_flashThread, this));
69 | }
70 |
71 | exception* FirmwareUpdater::endUploadFirmware() {
72 | if(!_reader)
73 | throw logic_error("endUploadFirmware called without a prior beginUploadFirmware");
74 | _reader = nullptr;
75 | void* ret;
76 | checkError(pthread_join(_pth, &ret));
77 | return static_cast(ret);
78 | }
79 |
80 | void FirmwareUpdater::setUserArgument(uint32_t arg) {
81 | checkError(writeRegister32(0xe8, arg));
82 | }
83 |
84 | void FirmwareUpdater::reboot() {
85 | checkError(writeRegister(0xef, 0x5e));
86 | }
87 |
88 | int FirmwareUpdater::readRegister(uint8_t addr) {
89 | uint8_t buf[] = {
90 | 0x10, addr
91 | };
92 | if(writeAll(ttyFD,buf,sizeof(buf)) != int(sizeof(buf)))
93 | return -1;
94 |
95 | uint8_t rBuf[1];
96 | if(read(ttyFD, rBuf, 1) != 1)
97 | return -1;
98 | return rBuf[0];
99 | }
100 |
101 | int FirmwareUpdater::writeRegister(uint8_t addr, uint8_t val) {
102 | uint8_t buf[] = {
103 | 0x20, addr, val
104 | };
105 | return (writeAll(ttyFD,buf,sizeof(buf)) == int(sizeof(buf))) ? 0 : -1;
106 | }
107 |
108 | int FirmwareUpdater::writeRegister32(uint8_t addr, uint32_t val) {
109 | uint8_t buf[] = {
110 | 0x22, addr, 0,0,0,0
111 | };
112 | qToLittleEndian(val, buf + 2);
113 | return (writeAll(ttyFD,buf,sizeof(buf)) == int(sizeof(buf))) ? 0 : -1;
114 | }
115 |
116 | int FirmwareUpdater::_sendBytes(const uint8_t* data, int len) {
117 | if(len > 255)
118 | throw out_of_range("FirmwareUpdater::_sendBytes can not send > 255 bytes");
119 |
120 | // cmd: write FIFO 0xe4
121 | string cmd = "\x28\xe4";
122 | cmd += char(uint8_t(len));
123 | cmd.append(reinterpret_cast(data), size_t(len));
124 | // cmd: echo version
125 | cmd += 0x0d;
126 | int totalLen = int(cmd.length());
127 | if(writeAll(ttyFD, cmd.data(), totalLen) != totalLen)
128 | return -1;
129 | return 0;
130 | }
131 |
132 | int FirmwareUpdater::_waitSend() {
133 | uint8_t buf;
134 | auto tmp = read(ttyFD, &buf, 1);
135 | if(tmp == 0)
136 | errno = EPIPE;
137 | if(tmp <= 0)
138 | return -1;
139 | return 0;
140 | }
141 |
142 | void* FirmwareUpdater::_flashThread(void* v) {
143 | FirmwareUpdater* t = static_cast(v);
144 | return t->flashThread();
145 | }
146 |
147 |
148 | void* FirmwareUpdater::flashThread() {
149 | constexpr int bufSize = 255;
150 | uint8_t buf[bufSize];
151 | int outstanding = 0;
152 | int progress = 0;
153 | auto lastNotify = time(nullptr);
154 |
155 | while(true) {
156 | auto br = _reader(buf, bufSize);
157 | if(br < 0)
158 | goto fail;
159 | if(br == 0) {
160 | if(progress < 1024) {
161 | auto ex = new runtime_error("EOF reading from file at " + to_string(progress) + " bytes");
162 | _cb(-1);
163 | return ex;
164 | }
165 | break;
166 | }
167 | progress += br;
168 |
169 | int res = _sendBytes(buf, int(br));
170 | if(res < 0)
171 | goto fail;
172 |
173 | auto t = time(nullptr);
174 | if(t - lastNotify >= 1) {
175 | lastNotify = t;
176 | _cb(progress);
177 | }
178 |
179 | outstanding++;
180 | if(outstanding > 5) {
181 | if(_waitSend() < 0)
182 | goto fail;
183 | outstanding--;
184 | }
185 | }
186 | if(progress == 0) {
187 | auto ex = new runtime_error("Read 0 bytes from file!");
188 | _cb(-1);
189 | return ex;
190 | }
191 | _cb(progress);
192 | while(outstanding > 0) {
193 | if(_waitSend() < 0)
194 | goto fail;
195 | outstanding--;
196 | }
197 | _cb(-1);
198 | return nullptr;
199 | fail:
200 | auto ex = new runtime_error(strerror(errno));
201 | _cb(-1);
202 | return ex;
203 | }
204 |
--------------------------------------------------------------------------------
/vna_qt/firmwareupdater.H:
--------------------------------------------------------------------------------
1 | #ifndef FIRMWAREUPDATER_H
2 | #define FIRMWAREUPDATER_H
3 | #include
4 | #include
5 | #include
6 | using namespace std;
7 |
8 | class FirmwareUpdater
9 | {
10 | public:
11 | FirmwareUpdater();
12 | ~FirmwareUpdater();
13 |
14 | // open a tty device. Throws logic_error if device is not in DFU mode.
15 | void open(const char *dev);
16 | void close();
17 |
18 | // upload firmware asynchronously.
19 | // reader is a function that will read up to len bytes into buf, similar to read(2).
20 | // cb is called at a set interval to indicate progress.
21 | // progress is bytes sent. When cb is called with progress = -1, the operation is complete,
22 | // and you can call endUploadFirmware() from another thread to check for errors.
23 | void beginUploadFirmware(uint32_t dstAddr,
24 | const function& reader,
25 | const function& cb);
26 |
27 | // returns the first exception encountered during firmware upload, if any.
28 | // if return value is non-null, the user must call delete on it.
29 | exception* endUploadFirmware();
30 |
31 | // sets the argument passed to the user application upon reboot
32 | void setUserArgument(uint32_t arg);
33 |
34 | // reboot the device
35 | void reboot();
36 |
37 | // returns -1 on error
38 | int readRegister(uint8_t addr);
39 | int writeRegister(uint8_t addr, uint8_t val);
40 | int writeRegister32(uint8_t addr, uint32_t val);
41 |
42 |
43 | // internal functions
44 | int ttyFD = -1;
45 | int _sendBytes(const uint8_t* data, int len);
46 | int _waitSend();
47 |
48 | private:
49 | function _cb;
50 | function _reader;
51 | pthread_t _pth;
52 | static void* _flashThread(void* v);
53 | void* flashThread();
54 | };
55 |
56 | #endif // FIRMWAREUPDATER_H
57 |
--------------------------------------------------------------------------------
/vna_qt/frequencydialog.C:
--------------------------------------------------------------------------------
1 | #include "utility.H"
2 | #include "frequencydialog.H"
3 | #include "ui_frequencydialog.h"
4 | #include
5 | #include
6 |
7 | using namespace xaxaxa;
8 | FrequencyDialog::FrequencyDialog(QWidget *parent) :
9 | QDialog(parent),
10 | ui(new Ui::FrequencyDialog)
11 | {
12 | ui->setupUi(this);
13 | ui->w_advanced->setVisible(false);
14 | this->resize(this->width(),0);
15 | this->setWindowTitle("Sweep Parameters");
16 | }
17 |
18 | FrequencyDialog::~FrequencyDialog()
19 | {
20 | delete ui;
21 | }
22 |
23 | void FrequencyDialog::fromVNA(const VNADevice &dev) {
24 | ui->t_start->setValue(dev.startFreqHz*1e-6);
25 | ui->t_stop->setValue(dev.startFreqHz*1e-6 + dev.stepFreqHz*1e-6 *(dev.nPoints - 1));
26 | ui->t_points->setValue(dev.nPoints);
27 | ui->slider_power->setRange(dev.maxPower()-40, dev.maxPower());
28 | ui->slider_power->setValue(dev.maxPower() - dev.attenuation1);
29 | ui->t_nValues->setText(qs(ssprintf(32, "%d", dev.nValues)));
30 | ui->t_nWait->setText(qs(ssprintf(32, "%d", dev.nWait)));
31 | emit on_slider_power_valueChanged(ui->slider_power->value());
32 | }
33 |
34 | bool floatEq(double a, double b, double maxError=1e-9) {
35 | double err = abs(a/b - 1.);
36 | return err <= maxError;
37 | }
38 | bool FrequencyDialog::toVNA(VNADevice &dev) {
39 | double oldStartFreq = dev.startFreqHz;
40 | double oldStepFreq = dev.stepFreqHz;
41 | int oldNPoints = dev.nPoints;
42 | dev.startFreqHz = ui->t_start->value()*1e6;
43 | double stopFreqHz = ui->t_stop->value()*1e6;
44 |
45 | if(stopFreqHz <= dev.startFreqHz){ //sanity check
46 | stopFreqHz=dev.startFreqHz + 1e6;
47 | QMessageBox::critical(this, "Error","Invalid Stop Frequency");
48 | }
49 |
50 | dev.nPoints = ui->t_points->value();
51 | dev.stepFreqHz=(stopFreqHz - dev.startFreqHz)/(dev.nPoints - 1); //-1 to not skip the last step
52 |
53 | dev.attenuation1 = dev.attenuation2 = dev.maxPower() - ui->slider_power->value();
54 | dev.nValues = atoi(ui->t_nValues->text().toUtf8().data());
55 | dev.nWait = atoi(ui->t_nWait->text().toUtf8().data());
56 | if(!floatEq(dev.startFreqHz, oldStartFreq))
57 | return true;
58 | if(!floatEq(dev.stepFreqHz, oldStepFreq))
59 | return true;
60 | if(dev.nPoints != oldNPoints)
61 | return true;
62 | return false;
63 | }
64 |
65 | void FrequencyDialog::updateLabels() {
66 | double stepSize = ( ui->t_stop->value() - ui->t_start->value()) / ui->t_points->value();
67 |
68 | if(!std::isnan(stepSize) && stepSize>0)
69 | ui->l_end->setText(qs(ssprintf(32, "%.6f", stepSize)));
70 | }
71 |
72 | void FrequencyDialog::on_slider_power_valueChanged(int value) {
73 | ui->l_power->setText(qs(ssprintf(32, "%d dBm", value)));
74 | }
75 |
76 | void FrequencyDialog::on_t_start_valueChanged(const QString &) {
77 | updateLabels();
78 | }
79 |
80 | void FrequencyDialog::on_t_stop_valueChanged(const QString &) {
81 | updateLabels();
82 | }
83 |
84 | void FrequencyDialog::on_t_points_valueChanged(const QString &) {
85 | updateLabels();
86 | }
87 |
88 | void FrequencyDialog::on_c_advanced_stateChanged(int) {
89 | ui->w_advanced->setVisible(ui->c_advanced->isChecked());
90 | }
91 |
--------------------------------------------------------------------------------
/vna_qt/frequencydialog.H:
--------------------------------------------------------------------------------
1 | #ifndef FREQUENCYDIALOG_H
2 | #define FREQUENCYDIALOG_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class FrequencyDialog;
9 | }
10 | namespace xaxaxa {
11 | class VNADevice;
12 | }
13 | using namespace xaxaxa;
14 | class FrequencyDialog : public QDialog
15 | {
16 | Q_OBJECT
17 |
18 | public:
19 | explicit FrequencyDialog(QWidget *parent = 0);
20 | ~FrequencyDialog();
21 |
22 | // populate the UI with parameters from dev
23 | void fromVNA(const VNADevice& dev);
24 |
25 | // update dev with parameters from the UI
26 | // returns true if frequency parameters were changed, false otherwise
27 | bool toVNA(VNADevice& dev);
28 |
29 | void updateLabels();
30 |
31 | private slots:
32 | void on_slider_power_valueChanged(int value);
33 | void on_t_start_valueChanged(const QString &arg1);
34 | void on_t_stop_valueChanged(const QString &arg1);
35 | void on_t_points_valueChanged(const QString &arg1);
36 |
37 | void on_c_advanced_stateChanged(int);
38 |
39 | private:
40 | Ui::FrequencyDialog *ui;
41 | };
42 |
43 | #endif // FREQUENCYDIALOG_H
44 |
--------------------------------------------------------------------------------
/vna_qt/graphlimitsdialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | GraphLimitsDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 273
10 | 181
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 | -
18 |
19 |