SoDaRadio-5.0.3-master:8901fb5
soda_band.hpp
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 #ifndef SODA_BAND_HDR
30 #define SODA_BAND_HDR
31 #include <QString>
32 #include <QObject>
33 #include <QSettings>
34 #include <QMap>
35 
36 namespace GUISoDa {
37 
38  class Band {
39  public:
40  Band() {
41  }
42 
43  void restore(QSettings * set_p) {
44  band_name = set_p->value("Name").toString();
45  band_index = set_p->value("Index").toInt();
46 
47  def_rx_ant = set_p->value("DefRXAnt").toString();
48  def_tx_ant = set_p->value("DefTXAnt").toString();
49 
50  def_mode = set_p->value("DefMode").toString();
51 
52  min_freq = set_p->value("MinFreq").toDouble();
53  max_freq = set_p->value("MaxFreq").toDouble();
54 
55  last_rx_freq = set_p->value("LastRXFreq").toDouble();
56  last_tx_freq = set_p->value("LastTXFreq").toDouble();
57 
58  tx_enabled = set_p->value("TXEna").toBool();
59 
60  tv_LO_freq = set_p->value("TVLOFreq").toDouble();
61  tv_LO_mult = set_p->value("TVLOMult").toDouble();
62  tverter_mode = set_p->value("TVMode").toBool();
63  lowside_injection = set_p->value("TVLowInjection").toBool();
64  }
65 
66  void save(QSettings * set_p) const {
67  set_p->setValue("Name", band_name);
68  set_p->setValue("Index", band_index);
69  set_p->setValue("DefRXAnt", def_rx_ant);
70  set_p->setValue("DefTXAnt", def_tx_ant);
71  set_p->setValue("DefMode", def_mode);
72  set_p->setValue("MinFreq", min_freq);
73  set_p->setValue("MaxFreq", max_freq);
74  set_p->setValue("LastRXFreq", last_rx_freq);
75  set_p->setValue("LastTXFreq", last_tx_freq);
76  set_p->setValue("TVLOFreq", tv_LO_freq);
77  set_p->setValue("TVLOMult", tv_LO_mult);
78  set_p->setValue("TXEna", tx_enabled);
79  set_p->setValue("TVMode", tverter_mode);
80  set_p->setValue("TVLowInjection", lowside_injection);
81  }
82 
83  const QString & name() const { return band_name; }
84  int index() const { return band_index; }
85  const QString & defRXAnt() const { return def_rx_ant; }
86  const QString & defTXAnt() const { return def_tx_ant; }
87  const QString & defMode() const { return def_mode; }
88  double minFreq() const { return min_freq; }
89  double maxFreq() const { return max_freq; }
90  double lastRXFreq() const { return last_rx_freq; }
91  double lastTXFreq() const { return last_tx_freq; }
92 
93  double tvLOFreq() const { return tv_LO_freq; }
94  double tvLOMult() const { return tv_LO_mult; }
95  bool txEna() const { return tx_enabled; }
96  bool tverterEna() const { return tverter_mode; }
97  bool tverterLowInjection() const { return lowside_injection; }
98 
99  void setName(const QString & v) { band_name = v; }
100  void setIndex(int v) { band_index = v; }
101  void setDefRXAnt(const QString & v) { def_rx_ant = v; }
102  void setDefTXAnt(const QString & v) { def_tx_ant = v; }
103  void setDefMode(const QString & v) { def_mode = v; }
104 
105  void setMinFreq(double v) { min_freq = v; }
106  void setMaxFreq(double v) { max_freq = v; }
107  void setLastRXFreq(double v) { last_rx_freq = v; }
108  void setLastTXFreq(double v) { last_tx_freq = v; }
109  void setTvLOFreq(double v) { tv_LO_freq = v; }
110  void setTvLOMult(double v) { tv_LO_mult = v; }
111  void setTxEna(bool v) { tx_enabled = v; }
112  void setTverterEna(bool v) { tverter_mode = v; }
114 
115 
116  bool isInBand(double freq) const {
117  double tf = freq * 1e-6;
118  bool res = (tf >= min_freq) && (tf <= max_freq);
119  return res;
120  }
121 
122 
123 
124  protected:
125  QString band_name;
127  QString def_rx_ant;
128  QString def_tx_ant;
129  double min_freq;
130  double max_freq;
131  QString def_mode;
132  bool tx_enabled;
135  double tv_LO_freq;
136  double tv_LO_mult;
137  double last_rx_freq;
138  double last_tx_freq;
139  };
140 
141  class BandMap : public QMap<QString, Band> {
142  public:
143  BandMap() { }
144 
145  typedef QMapIterator<QString, Band> BandMapIterator;
146 
147  void restoreBands(QSettings * set_p) {
148  int size = set_p->beginReadArray("Bands");
149  for(int i = 0; i < size; i++) {
150  Band b;
151  set_p->setArrayIndex(i);
152  QString dname = set_p->value("Name").toString();
153  b.restore(set_p);
154  QString bn = b.name();
155  (*this)[b.name()] = b;
156  }
157  set_p->endArray();
158  }
159 
160  void saveBands(QSettings * set_p) {
161  set_p->beginWriteArray("Bands");
162  BandMapIterator bmi(*this);
163  int i = 0;
164  while(bmi.hasNext()) {
165  bmi.next();
166  if(bmi.value().name() == "") continue;
167  set_p->setArrayIndex(i);
168  bmi.value().save(set_p);
169  i++;
170  }
171  set_p->endArray();
172  }
173 
174  QString findBand(double freq) const {
175  BandMapIterator bmi(*this);
176  while(bmi.hasNext()) {
177  bmi.next();
178  if(bmi.value().isInBand(freq)) return bmi.value().name();
179  }
180  return "";
181  }
182  };
183 }
184 #endif
QString findBand(double freq) const
Definition: soda_band.hpp:174
void setIndex(int v)
Definition: soda_band.hpp:100
const QString & name() const
Definition: soda_band.hpp:83
void setLastTXFreq(double v)
Definition: soda_band.hpp:108
double minFreq() const
Definition: soda_band.hpp:88
bool isInBand(double freq) const
Definition: soda_band.hpp:116
QString band_name
Definition: soda_band.hpp:125
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 save(QSettings *set_p) const
Definition: soda_band.hpp:66
void setTvLOFreq(double v)
Definition: soda_band.hpp:109
double tvLOFreq() const
Definition: soda_band.hpp:93
double lastRXFreq() const
Definition: soda_band.hpp:90
void setName(const QString &v)
Definition: soda_band.hpp:99
bool lowside_injection
Definition: soda_band.hpp:134
double tv_LO_mult
Definition: soda_band.hpp:136
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
double lastTXFreq() const
Definition: soda_band.hpp:91
const QString & defMode() const
Definition: soda_band.hpp:87
double maxFreq() const
Definition: soda_band.hpp:89
void restore(QSettings *set_p)
Definition: soda_band.hpp:43
QString def_tx_ant
Definition: soda_band.hpp:128
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 setLastRXFreq(double v)
Definition: soda_band.hpp:107
QString def_rx_ant
Definition: soda_band.hpp:127
void setDefRXAnt(const QString &v)
Definition: soda_band.hpp:101
void setTverterLowInjection(bool v)
Definition: soda_band.hpp:113
double last_rx_freq
Definition: soda_band.hpp:137
void setTverterEna(bool v)
Definition: soda_band.hpp:112
void setDefTXAnt(const QString &v)
Definition: soda_band.hpp:102
double last_tx_freq
Definition: soda_band.hpp:138
void setMinFreq(double v)
Definition: soda_band.hpp:105
bool tverterLowInjection() const
Definition: soda_band.hpp:97
double tv_LO_freq
Definition: soda_band.hpp:135
void setMaxFreq(double v)
Definition: soda_band.hpp:106
const QString & defRXAnt() const
Definition: soda_band.hpp:85
QString def_mode
Definition: soda_band.hpp:131
double max_freq
Definition: soda_band.hpp:130
double min_freq
Definition: soda_band.hpp:129