1 /* -*- c++ -*- */ 2 /* 3 * Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt 4 * https://gqrx.dk/ 5 * 6 * Copyright 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 REMOTE_CONTROL_H 24 #define REMOTE_CONTROL_H 25 26 #include <QObject> 27 #include <QSettings> 28 #include <QString> 29 #include <QStringList> 30 #include <QTcpServer> 31 #include <QTcpSocket> 32 #include <QtNetwork> 33 34 /* For gain_t and gain_list_t */ 35 #include "qtgui/dockinputctl.h" 36 37 /*! \brief Simple TCP server for remote control. 38 * 39 * The TCP interface is compatible with the hamlib rigtctld so that applications 40 * gpredict can be used with gqrx without any modifications. 41 * 42 * The hamlib rigctld protocol is described in the man page 43 * http://hamlib.sourceforge.net/pdf/rigctld.8.pdf 44 * but here is a summary. 45 * 46 * client: F 144500000\n # set frequency in Hz 47 * gqrx: RPRT 0\n # 0 means no error 48 * 49 * client: f\n # get frequency 50 * gqrx: 144500000\n # gqrx replies with frequency in Hz 51 * 52 * We also have some gqrx specific commands: 53 * 54 * close: Close connection (useful for interactive telnet sessions). 55 * 56 * 57 * FIXME: The server code is very minimalistic and probably not very robust. 58 */ 59 class RemoteControl : public QObject 60 { 61 Q_OBJECT 62 public: 63 explicit RemoteControl(QObject *parent = 0); 64 ~RemoteControl(); 65 66 void start_server(void); 67 void stop_server(void); 68 69 void readSettings(QSettings *settings); 70 void saveSettings(QSettings *settings) const; 71 72 void setPort(int port); getPort(void)73 int getPort(void) const 74 { 75 return rc_port; 76 } 77 78 void setHosts(QStringList hosts); getHosts(void)79 QStringList getHosts(void) const 80 { 81 return rc_allowed_hosts; 82 } 83 void setReceiverStatus(bool enabled); 84 void setGainStages(gain_list_t &gain_list); 85 86 public slots: 87 void setNewFrequency(qint64 freq); 88 void setFilterOffset(qint64 freq); 89 void setLnbLo(double freq_mhz); 90 void setBandwidth(qint64 bw); 91 void setSignalLevel(float level); 92 void setMode(int mode); 93 void setPassband(int passband_lo, int passband_hi); 94 void setSquelchLevel(double level); 95 void startAudioRecorder(QString unused); 96 void stopAudioRecorder(); 97 bool setGain(QString name, double gain); 98 void setRDSstatus(bool enabled); 99 void rdsPI(QString program_id); 100 101 signals: 102 void newFrequency(qint64 freq); 103 void newFilterOffset(qint64 offset); 104 void newLnbLo(double freq_mhz); 105 void newMode(int mode); 106 void newPassband(int passband); 107 void newSquelchLevel(double level); 108 void startAudioRecorderEvent(); 109 void stopAudioRecorderEvent(); 110 void gainChanged(QString name, double value); 111 void dspChanged(bool value); 112 void newRDSmode(bool value); 113 114 private slots: 115 void acceptConnection(); 116 void startRead(); 117 118 private: 119 QTcpServer rc_server; /*!< The active server object. */ 120 QTcpSocket* rc_socket; /*!< The active socket object. */ 121 122 QStringList rc_allowed_hosts; /*!< Hosts where we accept connection from. */ 123 int rc_port; /*!< The port we are listening on. */ 124 125 qint64 rc_freq; 126 qint64 rc_filter_offset; 127 qint64 bw_half; 128 double rc_lnb_lo_mhz; /*!< Current LNB LO freq in MHz */ 129 130 int rc_mode; /*!< Current mode. */ 131 int rc_passband_lo; /*!< Current low cutoff. */ 132 int rc_passband_hi; /*!< Current high cutoff. */ 133 bool rds_status; /*!< RDS decoder enabled */ 134 float signal_level; /*!< Signal level in dBFS */ 135 double squelch_level; /*!< Squelch level in dBFS */ 136 QString rc_program_id; /*!< RDS Program identification */ 137 bool audio_recorder_status; /*!< Recording enabled */ 138 bool receiver_running; /*!< Whether the receiver is running or not */ 139 bool hamlib_compatible; 140 gain_list_t gains; /*!< Possible and current gain settings */ 141 142 void setNewRemoteFreq(qint64 freq); 143 int modeStrToInt(QString mode_str); 144 QString intToModeStr(int mode); 145 146 /* RC commands */ 147 QString cmd_get_freq() const; 148 QString cmd_set_freq(QStringList cmdlist); 149 QString cmd_get_mode(); 150 QString cmd_set_mode(QStringList cmdlist); 151 QString cmd_get_level(QStringList cmdlist); 152 QString cmd_set_level(QStringList cmdlist); 153 QString cmd_get_func(QStringList cmdlist); 154 QString cmd_set_func(QStringList cmdlist); 155 QString cmd_get_vfo() const; 156 QString cmd_set_vfo(QStringList cmdlist); 157 QString cmd_get_split_vfo() const; 158 QString cmd_set_split_vfo(); 159 QString cmd_get_info() const; 160 QString cmd_get_param(QStringList cmdlist); 161 QString cmd_AOS(); 162 QString cmd_LOS(); 163 QString cmd_lnb_lo(QStringList cmdlist); 164 QString cmd_dump_state() const; 165 }; 166 167 #endif // REMOTE_CONTROL_H 168