SoDaRadio-5.0.3-master:8901fb5
soda_hamlib_handler.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_HAMLIB_HANDLER_HEADER
30 #define SODA_HAMLIB_HANDLER_HEADER
31 #include <QObject>
32 #include <QString>
33 #include <QTextStream>
34 #include <QtNetwork/QtNetwork>
35 #include <iostream>
36 #include <boost/format.hpp>
37 #include <errno.h>
38 
39 #include "../src/Command.hxx"
40 
41 namespace GUISoDa {
42 
43  class HamlibHandler : public QObject {
44  Q_OBJECT
45 
46  public:
47  HamlibHandler(QObject * parent = 0);
48 
50 
51  void processCommand(const QString & cmd, QTcpSocket * socket_p);
52 
53  public slots:
54  void reportRXFreq(double f);
55  void reportTXFreq(double f);
56  void reportModulation(int mod_id);
57  void reportTXOn(bool tx_on);
58 
59  signals:
60  void setRXFreq(double f);
61  void setTXFreq(double f);
63  void setTXOn(bool tx_on);
64 
65  protected:
66  double rx_freq;
67  double tx_freq;
68  bool tx_on;
70 
71  protected:
72 
73  // command handlers
74  typedef bool(HamlibHandler::*cmdHandler_t)(QTextStream &, QTextStream &, bool);
75  std::map<QString, cmdHandler_t> set_command_map;
76  std::map<QString, cmdHandler_t> get_command_map;
77  void registerCommand(const char * shortname,
78  const char * longname,
79  cmdHandler_t handler,
80  bool is_get);
81 
82  std::map<SoDa::Command::ModulationType, QString> soda2hl_modmap;
83  std::map<QString, SoDa::Command::ModulationType> hl2soda_modmap;
84 
85  bool cmdDumpState(QTextStream & out, QTextStream & in, bool getval);
86  bool cmdVFO(QTextStream & out, QTextStream & in, bool getval);
87  bool cmdFreq(QTextStream & out, QTextStream & in, bool getval);
88  bool cmdSplitFreq(QTextStream & out, QTextStream & in, bool getval);
89  bool cmdMode(QTextStream & out, QTextStream & in, bool getval);
90  bool cmdPTT(QTextStream & out, QTextStream & in, bool getval);
91  bool cmdSplitVFO(QTextStream & out, QTextStream & in, bool getval);
92  bool cmdQuit(QTextStream & out, QTextStream & in, bool getval);
93 
94  // state of the radio
95  QString current_VFO, tx_VFO;
97  double current_rx_freq;
98  double current_tx_freq;
101 
102  private:
103  void initModTables();
104  void initCommandTables();
105  };
106 }
107 #endif
void setTXOn(bool tx_on)
bool cmdMode(QTextStream &out, QTextStream &in, bool getval)
void setModulation(SoDa::Command::ModulationType mod)
void processCommand(const QString &cmd, QTcpSocket *socket_p)
bool cmdPTT(QTextStream &out, QTextStream &in, bool getval)
std::map< QString, SoDa::Command::ModulationType > hl2soda_modmap
bool cmdSplitVFO(QTextStream &out, QTextStream &in, bool getval)
ModulationType
modulation selector targets take one of these values
Definition: Command.hxx:478
std::map< QString, cmdHandler_t > set_command_map
bool cmdQuit(QTextStream &out, QTextStream &in, bool getval)
bool(HamlibHandler::* cmdHandler_t)(QTextStream &, QTextStream &, bool)
bool cmdVFO(QTextStream &out, QTextStream &in, bool getval)
void registerCommand(const char *shortname, const char *longname, cmdHandler_t handler, bool is_get)
std::map< QString, cmdHandler_t > get_command_map
void reportModulation(int mod_id)
void setTXFreq(double f)
bool cmdDumpState(QTextStream &out, QTextStream &in, bool getval)
bool cmdSplitFreq(QTextStream &out, QTextStream &in, bool getval)
HamlibHandler(QObject *parent=0)
SoDa::Command::ModulationType current_modtype
SoDa::Command::ModulationType modulation
std::map< SoDa::Command::ModulationType, QString > soda2hl_modmap
void setRXFreq(double f)
bool cmdFreq(QTextStream &out, QTextStream &in, bool getval)