1 #ifndef RECEIVER_HH 2 #define RECEIVER_HH 3 4 #include <QObject> 5 #include <QTimer> 6 #include <QStandardItemModel> 7 #include <QSettings> 8 9 #include "sources.hh" 10 #include "portaudio.hh" 11 #include "utils.hh" 12 #include "wspr2.hh" 13 14 /** Central receiver object. */ 15 class Receiver : public QObject 16 { 17 Q_OBJECT 18 19 public: 20 /** Enumerates the possible sources. */ 21 typedef enum { 22 RTL_SOURCE, ///< A RTL2832 USB dongle. 23 AUDIO_SOURCE, ///< The sound card 24 FILE_SOURCE ///< A WAV file. 25 } SourceType; 26 27 public: 28 /** Constructor. 29 * @param type Specifies the input source to use. 30 * @param parent Specifies the QObject parent. */ 31 explicit Receiver(SourceType type, QObject *parent = 0); 32 /** Destructor. */ 33 virtual ~Receiver(); 34 35 /** Returns a weak reference to the spectrum provider. */ 36 sdr::gui::SpectrumProvider *spectrum(); 37 38 /** Wait for the WSPR decoder threads to stop. */ 39 void join(); 40 41 /** Returns the current source type. */ 42 SourceType sourceType() const; 43 /** Sets the current source type. */ 44 void setSourceType(SourceType type); 45 46 /** Creates a control view for the current source. */ 47 QWidget *createSourceControl(); 48 49 /** Returns the current frequency. */ 50 double frequency() const; 51 /** Set current frequency. If the source is tunable (i.e. RTL2832) the source frequency gets 52 * updated too. */ 53 void setFrequency(double F); 54 55 /** Returns the BFO frequency. */ 56 double bfoFrequency() const; 57 /** Sets the BFO frequency. */ 58 void setBfoFrequency(double F); 59 60 /** Returns @c true if the audio AGC is enabled. */ 61 bool audioAGCEnabled() const; 62 /** Enables/disables the audio AGC. */ 63 void enableAudioAGC(bool enabled); 64 65 /** Returns @c true if audio monitoring is enabled. */ 66 bool monitorEnabled() const; 67 /** Enables/disables audio monitoring. */ 68 void enableMonitor(bool enabled); 69 70 /** Returns the QTH locator. */ 71 QString locator() const; 72 /** Sets the QTH locator. */ 73 void setLocator(const QString &loc); 74 75 /** Returns the list model of spots. */ 76 QStandardItemModel *messages(); 77 78 signals: 79 /** Gets emitted on new spots. */ 80 void messagesReceived(); 81 82 protected: 83 /** Gets called on Queue start. This will start a timer that starts the reception on an even 84 * UTC minute. */ 85 void _onQueueStart(); 86 /** Gets called on Queue stop. */ 87 void _onQueueStop(); 88 /** Gets called once some messages are received. */ 89 void _onMessagesReceived(); 90 91 protected slots: 92 /** Gets called by on an even minute. */ 93 void _onStartRX(); 94 95 protected: 96 /** BFO frequency. */ 97 double _Fbfo; 98 /** The currently selected source. */ 99 SourceType _sourceType; 100 /** The source instance. */ 101 WSPRSource *_source; 102 /** Audio AGC instance. */ 103 sdr::AGC<int16_t> _agc; 104 /** WSPR node. */ 105 sdr::WSPR2 _wspr; 106 /** Audio sink. */ 107 sdr::PortSink _audio; 108 /** A weak reference to the queue. */ 109 sdr::Queue &_queue; 110 /** If @c true, audio monitoring is enabled. */ 111 bool _monitor; 112 /** List model of spots. */ 113 QStandardItemModel *_messages; 114 /** Timer to start reception on even minutes. */ 115 QTimer _timer; 116 117 /** Persistent settings. */ 118 QSettings _settings; 119 }; 120 121 #endif // RECEIVER_HH 122