SoDaRadio-5.0.3-master:8901fb5
soda_listener.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_LISTENER_HEADER
30 #define SODA_LISTENER_HEADER
31 #include <QObject>
32 #include <QString>
33 #include <QtNetwork/QtNetwork>
34 #include <iostream>
35 #include <errno.h>
36 #include "../src/Command.hxx"
37 
38 namespace GUISoDa {
39 
40  class Listener : public QObject {
41  Q_OBJECT
42 
43  public:
44  Listener(QObject * parent = 0, const QString & socket_basename = "tmp");
46  }
47 
53  bool init();
54 
55 
59  void start();
60 
61 
62  signals:
63  // when new spectrum data arrives
64  void updateData(double cfreq, float * y);
65 
66  void configureSpectrum(double cfreq, double span, long buckets);
67 
68  void addModulation(QString modtype, int mod_id);
69  void addFilterWidth(double lo, double hi);
70  void addFilterName(QString filter_name, int filt_id);
71  void repMarkerOffset(double lo, double hi);
72 
73  void addRXAntName(const QString & ant_name);
74  void addTXAntName(const QString & ant_name);
75 
76  void repFilterEdges(double lo, double hi);
77 
78  void repGPSLatLon(double lat, double lon);
79  void repGPSTime(int hh, int mm, int ss);
80 
81  void repGPSLock(bool is_locked);
82 
83  void repSDRVersion(const QString & version);
84  void repHWMBVersion(const QString & version);
85 
86  void repPTT(bool on);
87 
88  void initSetupComplete();
89 
90  void fatalError(const QString & error_string);
91 
92  public slots:
93  void setRXFreq(double freq);
94  void setTXFreq(double freq);
95 
96  void setModulation(int mod_id);
97 
98  void setAFFilter(int id);
99 
100  void setRXGain(int gain);
101  void setTXGain(int gain);
102  void setAFGain(int gain);
103  void setAFSidetoneGain(int gain);
104 
105  void setRXAnt(const QString & antname);
106  void setTXAnt(const QString & antname);
107 
108  double getRXFreq() { return current_rx_freq; }
109  double getTXFreq() { return current_tx_freq; }
110 
111  void setSpectrumCenter(double freq);
112  void setSpectrumAvgWindow(int window);
113  void setSpectrumUpdateRate(int rate);
114 
115  void setCWSpeed(int speed);
116  void setSidetoneVolume(int vol);
117  void setTXPower(int vol);
118 
119  void setPTT(bool on);
120 
121  void sendCW(const QString & txt);
122  void clearCWBuffer();
123 
124  void closeRadio();
125 
126 
127  protected:
130  int get(char* buf, int maxlen);
131  bool get(SoDa::Command & cmd);
132  int put(const char * buf, int len);
133  bool put(const SoDa::Command & cmd);
134 
135  bool handleREP(const SoDa::Command & cmd);
136  bool handleSET(const SoDa::Command & cmd);
137  bool handleGET(const SoDa::Command & cmd);
138 
139  private:
140  void setupSpectrumBuffer(double cfreq, double span, long buflen);
142  float * spect_buffer;
144 
145  protected slots:
146  void processCmd();
147  void cmdErrorHandler(QLocalSocket::LocalSocketError err) {
148  std::cerr << "Error [" << err << "]\n";
149  }
150 
151  void processSpectrum();
152 
153  private:
154  QString socket_basename;
155  QLocalSocket * cmd_socket;
156  QLocalSocket * spect_socket;
157  bool quit;
158  };
159 }
160 #endif
void repMarkerOffset(double lo, double hi)
void addFilterName(QString filter_name, int filt_id)
void sendCW(const QString &txt)
void repPTT(bool on)
void repFilterEdges(double lo, double hi)
void addTXAntName(const QString &ant_name)
int put(const char *buf, int len)
void setTXAnt(const QString &antname)
void setSidetoneVolume(int vol)
void updateData(double cfreq, float *y)
void setModulation(int mod_id)
void initSetupComplete()
void setRXFreq(double freq)
void setSpectrumAvgWindow(int window)
void setCWSpeed(int speed)
void repSDRVersion(const QString &version)
void setPTT(bool on)
void setAFSidetoneGain(int gain)
void setSpectrumUpdateRate(int rate)
This is a list of all the commands that can "do something" to one or more components in the SoDa radi...
Definition: Command.hxx:47
void setAFFilter(int id)
void repGPSTime(int hh, int mm, int ss)
void setTXPower(int vol)
void addModulation(QString modtype, int mod_id)
QLocalSocket * spect_socket
void repGPSLock(bool is_locked)
bool init()
connect to radio server sockets and initialize listener state
void addFilterWidth(double lo, double hi)
void setRXGain(int gain)
bool handleREP(const SoDa::Command &cmd)
void repHWMBVersion(const QString &version)
void setSpectrumCenter(double freq)
bool handleSET(const SoDa::Command &cmd)
void cmdErrorHandler(QLocalSocket::LocalSocketError err)
void setupSpectrumBuffer(double cfreq, double span, long buflen)
void start()
initiate transfers on the socket.
void configureSpectrum(double cfreq, double span, long buckets)
Listener(QObject *parent=0, const QString &socket_basename="tmp")
void setTXFreq(double freq)
void setRXAnt(const QString &antname)
QLocalSocket * cmd_socket
bool handleGET(const SoDa::Command &cmd)
void addRXAntName(const QString &ant_name)
void setTXGain(int gain)
void setAFGain(int gain)
void fatalError(const QString &error_string)
void repGPSLatLon(double lat, double lon)