1 /* -*- c++ -*- */
2 /*
3  * Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
4  *           https://gqrx.dk/
5  *
6  * Copyright 2011-2013 Alexandru Csete OZ9AEC.
7  *
8  * Gqrx is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3, or (at your option)
11  * any later version.
12  *
13  * Gqrx is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Gqrx; see the file COPYING.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street,
21  * Boston, MA 02110-1301, USA.
22  */
23 #ifndef DOCKRXOPT_H
24 #define DOCKRXOPT_H
25 
26 #include <QDockWidget>
27 #include <QSettings>
28 #include "qtgui/agc_options.h"
29 #include "qtgui/demod_options.h"
30 #include "qtgui/nb_options.h"
31 
32 #define FILTER_PRESET_WIDE      0
33 #define FILTER_PRESET_NORMAL    1
34 #define FILTER_PRESET_NARROW    2
35 #define FILTER_PRESET_USER      3
36 
37 namespace Ui {
38     class DockRxOpt;
39 }
40 
41 
42 /**
43  * @brief Dock window with receiver options.
44  * @ingroup UI
45  *
46  * This dock widget encapsulates the receiver options. The controls
47  * are grouped in a tool box that allows packing many controls in little space.
48  * The UI itself is in the dockrxopt.ui file.
49  *
50  * This class also provides the signal/slot API necessary to connect
51  * the encapsulated widgets to the rest of the application.
52  */
53 class DockRxOpt : public QDockWidget
54 {
55     Q_OBJECT
56 
57 public:
58 
59     /**
60      * Mode selector entries.
61      *
62      * @note If you change this enum, remember to update the TCP interface.
63      * @note Keep in same order as the Strings in ModulationStrings, see
64      *       DockRxOpt.cpp constructor.
65      */
66     enum rxopt_mode_idx {
67         MODE_OFF        = 0, /*!< Demodulator completely off. */
68         MODE_RAW        = 1, /*!< Raw I/Q passthrough. */
69         MODE_AM         = 2, /*!< Amplitude modulation. */
70         MODE_AM_SYNC    = 3, /*!< Amplitude modulation (synchronous demod). */
71         MODE_LSB        = 4, /*!< Lower side band. */
72         MODE_USB        = 5, /*!< Upper side band. */
73         MODE_CWL        = 6, /*!< CW using LSB filter. */
74         MODE_CWU        = 7, /*!< CW using USB filter. */
75         MODE_NFM        = 8, /*!< Narrow band FM. */
76         MODE_WFM_MONO   = 9, /*!< Broadcast FM (mono). */
77         MODE_WFM_STEREO = 10, /*!< Broadcast FM (stereo). */
78         MODE_WFM_STEREO_OIRT = 11, /*!< Broadcast FM (stereo oirt). */
79         MODE_LAST       = 12
80     };
81 
82     explicit DockRxOpt(qint64 filterOffsetRange = 90000, QWidget *parent = 0);
83     ~DockRxOpt();
84 
85     void readSettings(QSettings *settings);
86     void saveSettings(QSettings *settings);
87 
88     void setFilterOffsetRange(qint64 range_hz);
89 
90     void setFilterParam(int lo, int hi);
91     void setCurrentFilter(int index);
92     int  currentFilter() const;
93 
94     void setCurrentFilterShape(int index);
95     int  currentFilterShape() const;
96 
97     void setHwFreq(qint64 freq_hz);
98     void setRxFreqRange(qint64 min_hz, qint64 max_hz);
99 
100     void setResetLowerDigits(bool enabled);
101     void setInvertScrolling(bool enabled);
102 
103     int  currentDemod() const;
104     QString currentDemodAsString();
105 
106     float currentMaxdev() const;
107     double currentEmph() const;
108     double currentSquelchLevel() const;
109 
110     void    getFilterPreset(int mode, int preset, int * lo, int * hi) const;
111     int     getCwOffset() const;
112 
113     double  getSqlLevel(void) const;
114 
115     static QStringList ModulationStrings;
116     static QString GetStringForModulationIndex(int iModulationIndex);
117     static int GetEnumForModulationString(QString param);
118     static bool IsModulationValid(QString strModulation);
119 
120 public slots:
121     void setRxFreq(qint64 freq_hz);
122     void setCurrentDemod(int demod);
123     void setFilterOffset(qint64 freq_hz);
124     void setSquelchLevel(double level);
125 
126 private:
127     void updateHwFreq();
128     void updateDemodOptPage(int demod);
129     unsigned int filterIdxFromLoHi(int lo, int hi) const;
130 
131     void modeOffShortcut();
132     void modeRawShortcut();
133     void modeAMShortcut();
134     void modeNFMShortcut();
135     void modeWFMmonoShortcut();
136     void modeWFMstereoShortcut();
137     void modeLSBShortcut();
138     void modeUSBShortcut();
139     void modeCWLShortcut();
140     void modeCWUShortcut();
141     void modeWFMoirtShortcut();
142     void modeAMsyncShortcut();
143     void filterNarrowShortcut();
144     void filterNormalShortcut();
145     void filterWideShortcut();
146 
147 signals:
148     /** Signal emitted when receiver frequency has changed */
149     void rxFreqChanged(qint64 freq_hz);
150 
151     /** Signal emitted when the channel filter frequency has changed. */
152     void filterOffsetChanged(qint64 freq_hz);
153 
154     /** Signal emitted when new demodulator is selected. */
155     void demodSelected(int demod);
156 
157     /** Signal emitted when new FM deviation is selected. */
158     void fmMaxdevSelected(float max_dev);
159 
160     /** Signal emitted when new FM de-emphasis constant is selected. */
161     void fmEmphSelected(double tau);
162 
163     /** Signal emitted when AM DCR status is toggled. */
164     void amDcrToggled(bool enabled);
165 
166     /** Signal emitted when AM-Sync DCR status is toggled. */
167     void amSyncDcrToggled(bool enabled);
168 
169     /** Signal emitted when new AM-Sync PLL BW is selected. */
170     void amSyncPllBwSelected(float pll_bw);
171 
172     /** Signal emitted when baseband gain has changed. Gain is in dB. */
173     //void bbGainChanged(float gain);
174 
175     /** Signal emitted when squelch level has changed. Level is in dBFS. */
176     void sqlLevelChanged(double level);
177 
178     /**
179      * Signal emitted when auto squelch level is clicked.
180      *
181      * @note Need current signal/noise level returned
182      */
183     double sqlAutoClicked();
184 
185     /** Signal emitted when AGC is togglen ON/OFF. */
186     void agcToggled(bool agc_on);
187 
188     /** Signal emitted when AGC hang is toggled. */
189     void agcHangToggled(bool use_hang);
190 
191     /** Signal emitted when AGC threshold has changed. Threshold in dB. */
192     void agcThresholdChanged(int value);
193 
194     /** Signal emitted when AGC slope has changed. Slope is in dB.*/
195     void agcSlopeChanged(int slope);
196 
197     /** Signal emitted when AGC decay has changed. Decay is in millisec.*/
198     void agcDecayChanged(int decay);
199 
200     /** Signal emitted when AGC manual gain has changed. Gain is in dB.*/
201     void agcGainChanged(int gain);
202 
203     /** Signal emitted when noise blanker status has changed. */
204     void noiseBlankerChanged(int nbid, bool on, float threshold);
205 
206     void cwOffsetChanged(int offset);
207 
208 private slots:
209     void on_freqSpinBox_valueChanged(double freq);
210     void on_filterFreq_newFrequency(qint64 freq);
211     void on_filterCombo_activated(int index);
212     void on_modeSelector_activated(int index);
213     void on_modeButton_clicked();
214     void on_agcButton_clicked();
215     void on_autoSquelchButton_clicked();
216     void on_resetSquelchButton_clicked();
217     //void on_agcPresetCombo_activated(int index);
218     void on_agcPresetCombo_currentIndexChanged(int index);
219     void on_sqlSpinBox_valueChanged(double value);
220     void on_nb1Button_toggled(bool checked);
221     void on_nb2Button_toggled(bool checked);
222     void on_nbOptButton_clicked();
223 
224     // Signals coming from noise blanker pop-up
225     void nbOpt_thresholdChanged(int nbid, double value);
226 
227     // Signals coming from demod options pop-up
228     void demodOpt_fmMaxdevSelected(float max_dev);
229     void demodOpt_fmEmphSelected(double tau);
230     void demodOpt_amDcrToggled(bool enabled);
231     void demodOpt_cwOffsetChanged(int offset);
232     void demodOpt_amSyncDcrToggled(bool enabled);
233     void demodOpt_amSyncPllBwSelected(float pll_bw);
234 
235     // Signals coming from AGC options popup
236     void agcOpt_hangToggled(bool checked);
237     void agcOpt_gainChanged(int value);
238     void agcOpt_thresholdChanged(int value);
239     void agcOpt_slopeChanged(int value);
240     void agcOpt_decayChanged(int value);
241 
242 private:
243     Ui::DockRxOpt *ui;        /** The Qt designer UI file. */
244     CDemodOptions *demodOpt;  /** Demodulator options. */
245     CAgcOptions   *agcOpt;    /** AGC options. */
246     CNbOptions    *nbOpt;     /** Noise blanker options. */
247 
248     bool agc_is_on;
249 
250     qint64 hw_freq_hz;   /** Current PLL frequency in Hz. */
251 };
252 
253 #endif // DOCKRXOPT_H
254