SoDaRadio-5.0.3-master:8901fb5
main_setup_bandconfig.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2017 Matthew H. Reilly (kb1vc)
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #include "mainwindow.hpp"
30 #include "ui_mainwindow.h"
31 #include <iostream>
32 #include <boost/format.hpp>
33 #include "soda_comboboxes.hpp"
34 #include "soda_listener.hpp"
35 
36 // methods and such for the bandconfig panel.
37 // This includes saving the band config list to the
38 // settings object, and restoring the band config list
39 // from the settings object.
41 {
42  connect(ui->bandSel_cb, SIGNAL(currentTextChanged(const QString &)),
43  this, SLOT(changeBand(const QString &)));
44 
45  connect(ui->BCOK_btn, SIGNAL(clicked(bool)),
46  this, SLOT(writeBandMapEntry(bool)));
47  connect(ui->BCCancel_btn, &QPushButton::clicked,
48  [=](bool v){ fillBandMapEntry(ui->BCBandSel_cb->currentText()); });
49  connect(ui->BCBandSel_cb, SIGNAL(currentTextChanged(const QString &)),
50  this, SLOT(fillBandMapEntry(const QString &)));
51 
52  // setup validators.
53  ui->BCMinFreq_le->setValidator(new QDoubleValidator(this));
54  ui->BCMaxFreq_le->setValidator(new QDoubleValidator(this));
55  ui->BCLOFreq_le->setValidator(new QDoubleValidator(this));
56 
58  [this](const QString & v){
59  ui->BCRXAnt_cb->addItem(v); });
61  [this](const QString & v){
62  ui->BCTXAnt_cb->addItem(v); });
63 
64  connect(listener, SIGNAL(addModulation(QString, int)),
65  ui->BCDefMode_cb, SLOT(addValue(QString, int)));
66 
67 
68 }
69 
71 {
72  if(band_map.count(current_band_selector) > 0) {
73  double rxfreq = ui->RXFreq_lab->getFreq() * 1.0e-6;
74  double txfreq = ui->TXFreq_lab->getFreq() * 1.0e-6;
76  if((rxfreq >= bp->minFreq()) && (rxfreq <= bp->maxFreq())) {
77  band_map[current_band_selector].setLastRXFreq(1e-6 * ui->RXFreq_lab->getFreq());
78  }
79  if((txfreq >= bp->minFreq()) && (txfreq <= bp->maxFreq())) {
80  band_map[current_band_selector].setLastTXFreq(1e-6 * ui->TXFreq_lab->getFreq());
81  }
82  }
83 }
84 
86 {
87  if(save) {
89  bmap.saveBands(settings_p);
90  }
91  else {
93  // now load the comboboxes
95  // clear the two band selectors.
96  ui->BCBandSel_cb->clear();
97  ui->bandSel_cb->clear();
98  while(bmi.hasNext()) {
99  bmi.next();
100  ui->BCBandSel_cb->addItem(bmi.key());
101  ui->bandSel_cb->addItem(bmi.key());
102  }
103  // add a new band at the end of the band config selector
104  ui->BCBandSel_cb->addItem("Create Band");
105  }
106 }
107 
108 // called when we change the band selector in the band setup box.
109 // or hit cancel.
110 void MainWindow::fillBandMapEntry(const QString & band)
111 {
112  ui->BCStatus_lbl->setText("");
113  if(band_map.count(band)) {
114  GUISoDa::Band b = band_map[band];
115  ui->BCBandName_le->setText("");
116 
117  ui->BCBandSel_cb->setCurrentText(band);
118 
119  ui->BCIndex_sb->setValue(b.index());;
120  ui->BCRXAnt_cb->setCurrentText(b.defRXAnt());
121  ui->BCTXAnt_cb->setCurrentText(b.defTXAnt());
122 
123  ui->BCMinFreq_le->setText(QString("%1").arg(b.minFreq(), 14, 'f', 6));
124  ui->BCMaxFreq_le->setText(QString("%1").arg(b.maxFreq(), 14, 'f', 6));
125 
126  ui->BCDefMode_cb->setCurrentText(b.defMode());
127 
128  ui->BCLOFreq_le->setText(QString("%1").arg(b.tvLOFreq(), 14, 'f', 6));
129  ui->BCLOMult_sb->setValue((int) b.tvLOMult());
130 
131  ui->BCEnableTX_cb->setChecked(b.txEna());
132  ui->BCTransMode_cb->setChecked(b.tverterEna());
133  ui->BCLowInj_cb->setChecked(b.tverterLowInjection());
134  }
135 }
136 
137 // called when we hit the OK button in the band setup box.
139 {
140  GUISoDa::Band b;
141  (void) v;
142 
143  ui->BCStatus_lbl->setText("");
144  QString bname = ui->BCBandName_le->text();
145  if(bname == "") {
146  bname = ui->BCBandSel_cb->currentText();
147  }
148 
149  if(bname == "Create Band") {
150  // there's a problem here... we need a band name.
151  // launch an error message
152  ui->BCStatus_lbl->setText("<font color='red'>Please supply a band name to create a new band.</font>");
153  return;
154  }
155 
156  // if we get to here, it is time to create a new band or modify an old one
157  b.setName(bname);
158  b.setIndex(ui->BCIndex_sb->value());
159  b.setDefRXAnt(ui->BCRXAnt_cb->currentText());
160  b.setDefTXAnt(ui->BCTXAnt_cb->currentText());
161 
162  b.setDefMode(ui->BCDefMode_cb->currentText());
163 
164  double min_freq = ui->BCMinFreq_le->text().toDouble();
165  double max_freq = ui->BCMaxFreq_le->text().toDouble();
166  b.setMinFreq(min_freq);
167  b.setMaxFreq(max_freq);
168 
169  b.setTvLOFreq(ui->BCLOFreq_le->text().toDouble());
170  b.setTvLOMult(ui->BCLOMult_sb->value());
171  b.setTxEna(ui->BCEnableTX_cb->isChecked());
172  b.setTverterEna(ui->BCTransMode_cb->isChecked());
173  b.setTverterLowInjection(ui->BCLowInj_cb->isChecked());
174 
175  b.setLastRXFreq((min_freq + max_freq) * 0.5);
176  b.setLastTXFreq((min_freq + max_freq) * 0.5);
177 
178  band_map[bname] = b;
179 
180  // now add the name to the rolling list.
181  if(ui->BCBandSel_cb->findText(bname) < 0) {
182  ui->BCBandSel_cb->addItem(bname);
183  }
184  if(ui->bandSel_cb->findText(bname) < 0) {
185  ui->bandSel_cb->addItem(bname);
186  }
187 }
188 
189 // called when the selection changes in the band selector
190 void MainWindow::changeBand(const QString & band)
191 {
192  // first save the current frequency in the current band, if and only
193  // if it is "in range" and if the band exists.
195 
196  // now find the new band.
197  if(band_map.count(band)) {
198  // and set the UI widgets.
199  if((band != auto_bandswitch_target)) {
200  // but only change these if this was the result of user band input.
201  if (auto_bandswitch_target != "") {
202  ui->Mode_cb->setValue(band_map[band].defMode());
203  }
204  double rx_freq = band_map[band].lastRXFreq() * 1e6;
205  setRXFreq(rx_freq);
206  setTXFreq(band_map[band].lastTXFreq() * 1e6);
207  listener->setSpectrumCenter(rx_freq);
208  }
209  else {
211  }
212 
213  ui->RXAnt_sel->setCurrentText(band_map[band].defRXAnt());
214  ui->TXAnt_sel->setCurrentText(band_map[band].defTXAnt());
215 
216  current_band_selector = band;
217  }
218 }
void setIndex(int v)
Definition: soda_band.hpp:100
void setLastTXFreq(double v)
Definition: soda_band.hpp:108
GUISoDa::Listener * listener
Definition: mainwindow.hpp:151
double minFreq() const
Definition: soda_band.hpp:88
Ui::MainWindow * ui
Definition: mainwindow.hpp:149
void changeBand(const QString &band)
const QString & defTXAnt() const
Definition: soda_band.hpp:86
void restoreBands(QSettings *set_p)
Definition: soda_band.hpp:147
void saveBands(QSettings *set_p)
Definition: soda_band.hpp:160
void addTXAntName(const QString &ant_name)
void setTvLOFreq(double v)
Definition: soda_band.hpp:109
QString auto_bandswitch_target
Definition: mainwindow.hpp:144
double tvLOFreq() const
Definition: soda_band.hpp:93
void setName(const QString &v)
Definition: soda_band.hpp:99
QSettings * settings_p
Definition: mainwindow.hpp:137
double tvLOMult() const
Definition: soda_band.hpp:94
void setTxEna(bool v)
Definition: soda_band.hpp:111
void setTvLOMult(double v)
Definition: soda_band.hpp:110
bool tverterEna() const
Definition: soda_band.hpp:96
const QString & defMode() const
Definition: soda_band.hpp:87
void fillBandMapEntry(const QString &band)
double maxFreq() const
Definition: soda_band.hpp:89
QMapIterator< QString, Band > BandMapIterator
Definition: soda_band.hpp:145
bool txEna() const
Definition: soda_band.hpp:95
void setDefMode(const QString &v)
Definition: soda_band.hpp:103
int index() const
Definition: soda_band.hpp:84
void setSpectrumCenter(double freq)
void setLastRXFreq(double v)
Definition: soda_band.hpp:107
void writeBandMapEntry(bool)
void setDefRXAnt(const QString &v)
Definition: soda_band.hpp:101
void setTverterLowInjection(bool v)
Definition: soda_band.hpp:113
void setTverterEna(bool v)
Definition: soda_band.hpp:112
void setDefTXAnt(const QString &v)
Definition: soda_band.hpp:102
void setMinFreq(double v)
Definition: soda_band.hpp:105
GUISoDa::BandMap band_map
Definition: mainwindow.hpp:141
void bandMapSaveRestore(GUISoDa::BandMap &bmap, bool save)
bool tverterLowInjection() const
Definition: soda_band.hpp:97
void addRXAntName(const QString &ant_name)
void setTXFreq(double freq)
set the TX frequency label to freq, and send the requested frequency to the SDR radio server...
void setMaxFreq(double v)
Definition: soda_band.hpp:106
const QString & defRXAnt() const
Definition: soda_band.hpp:85
QString current_band_selector
Definition: mainwindow.hpp:143
void setRXFreq(double freq)
set the RX frequency label to freq, and send the requested frequency to the SDR radio server...