SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Slots | Signals | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
KiwiSDRWorker Class Reference

#include <kiwisdrworker.h>

Inherits QObject.

+ Collaboration diagram for KiwiSDRWorker:

Public Slots

void onCenterFrequencyChanged (quint64 centerFrequency)
 
void onServerAddressChanged (QString serverAddress)
 
void onGainChanged (quint32 gain, bool useAGC)
 

Signals

void updateStatus (int status)
 

Public Member Functions

 KiwiSDRWorker (SampleSinkFifo *sampleFifo)
 
int getStatus () const
 

Private Slots

void onConnected ()
 
void onDisconnected ()
 
void onBinaryMessageReceived (const QByteArray &message)
 
void onSocketError (QAbstractSocket::SocketError error)
 
void tick ()
 

Private Member Functions

void sendCenterFrequency ()
 
void sendGain ()
 

Private Attributes

QTimer m_timer
 
QWebSocket m_webSocket
 
SampleVector m_samplesBuf
 
SampleSinkFifom_sampleFifo
 
QString m_serverAddress
 
uint64_t m_centerFrequency
 
uint32_t m_gain
 
bool m_useAGC
 
int m_status
 See GUI for status number detail. More...
 

Detailed Description

Definition at line 26 of file kiwisdrworker.h.

Constructor & Destructor Documentation

◆ KiwiSDRWorker()

KiwiSDRWorker::KiwiSDRWorker ( SampleSinkFifo sampleFifo)

Definition at line 21 of file kiwisdrworker.cpp.

References m_timer, m_webSocket, onBinaryMessageReceived(), onConnected(), onDisconnected(), onSocketError(), and tick().

22  : QObject(),
23  m_timer(this),
24  m_sampleFifo(sampleFifo),
25  m_samplesBuf(),
26  m_centerFrequency(1450000),
27  m_gain(20),
28  m_useAGC(true),
29  m_status(0)
30 {
31  connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
32 
33  m_webSocket.setParent(this);
34  connect(&m_webSocket, &QWebSocket::connected,
36  connect(&m_webSocket, &QWebSocket::binaryMessageReceived,
38  connect(&m_webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
40  connect(&m_webSocket, &QWebSocket::disconnected,
42 }
SampleVector m_samplesBuf
Definition: kiwisdrworker.h:37
QWebSocket m_webSocket
Definition: kiwisdrworker.h:35
uint32_t m_gain
Definition: kiwisdrworker.h:43
void onDisconnected()
uint64_t m_centerFrequency
Definition: kiwisdrworker.h:41
SampleSinkFifo * m_sampleFifo
Definition: kiwisdrworker.h:38
void onBinaryMessageReceived(const QByteArray &message)
void onSocketError(QAbstractSocket::SocketError error)
int m_status
See GUI for status number detail.
Definition: kiwisdrworker.h:46
+ Here is the call graph for this function:

Member Function Documentation

◆ getStatus()

int KiwiSDRWorker::getStatus ( ) const
inline

Definition at line 31 of file kiwisdrworker.h.

References m_status.

Referenced by KiwiSDRInput::getStatus().

31 { return m_status; }
int m_status
See GUI for status number detail.
Definition: kiwisdrworker.h:46
+ Here is the caller graph for this function:

◆ onBinaryMessageReceived

void KiwiSDRWorker::onBinaryMessageReceived ( const QByteArray &  message)
privateslot

Definition at line 84 of file kiwisdrworker.cpp.

References i, m_sampleFifo, m_samplesBuf, m_status, m_timer, m_webSocket, SDR_RX_SAMP_SZ, sendCenterFrequency(), sendGain(), updateStatus(), and SampleSinkFifo::write().

Referenced by KiwiSDRWorker().

85 {
86  if (message[0] == 'M' && message[1] == 'S' && message[2] == 'G')
87  {
88  QStringList al = QString::fromUtf8(message).split(' ');
89  if (al[1] == "audio_init=0" &&
90  al[2] == "audio_rate=12000")
91  {
92  m_webSocket.sendTextMessage("SET AR OK in=12000 out=48000");
93  m_webSocket.sendTextMessage("SERVER DE CLIENT KiwiAngel SND");
94  sendGain();
96  m_timer.start(5000);
97  m_status = 2;
98  emit updateStatus(2);
99  }
100  }
101  else if (message[0] == 'S' && message[1] == 'N' && message[2] == 'D')
102  {
103  int dataOffset = 20;
104  int sampleCount = 512;
105  const int16_t* messageSamples = (const int16_t*)(message.constData() + dataOffset);
106 
107  m_samplesBuf.clear();
108  for (int i = 0; i < sampleCount; i++)
109  {
110  m_samplesBuf.push_back(Sample(
111  boost::endian::endian_reverse(messageSamples[i * 2]) << (SDR_RX_SAMP_SZ - 16),
112  boost::endian::endian_reverse(messageSamples[i * 2 + 1]) << (SDR_RX_SAMP_SZ - 16)
113  ));
114  }
115 
116  m_sampleFifo->write(m_samplesBuf.begin(), m_samplesBuf.end());
117  }
118 }
short int16_t
Definition: rtptypes_win.h:43
SampleVector m_samplesBuf
Definition: kiwisdrworker.h:37
void sendCenterFrequency()
uint write(const quint8 *data, uint count)
QWebSocket m_webSocket
Definition: kiwisdrworker.h:35
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
SampleSinkFifo * m_sampleFifo
Definition: kiwisdrworker.h:38
void updateStatus(int status)
int32_t i
Definition: decimators.h:244
int m_status
See GUI for status number detail.
Definition: kiwisdrworker.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onCenterFrequencyChanged

void KiwiSDRWorker::onCenterFrequencyChanged ( quint64  centerFrequency)
slot

Definition at line 120 of file kiwisdrworker.cpp.

References m_centerFrequency, and sendCenterFrequency().

Referenced by KiwiSDRInput::start().

121 {
122  if (m_centerFrequency == centerFrequency)
123  return;
124 
125  m_centerFrequency = centerFrequency;
127 }
void sendCenterFrequency()
uint64_t m_centerFrequency
Definition: kiwisdrworker.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onConnected

void KiwiSDRWorker::onConnected ( )
privateslot

Definition at line 44 of file kiwisdrworker.cpp.

References m_webSocket.

Referenced by KiwiSDRWorker().

45 {
46  m_webSocket.sendTextMessage("SET auth t=kiwi p=#");
47 }
QWebSocket m_webSocket
Definition: kiwisdrworker.h:35
+ Here is the caller graph for this function:

◆ onDisconnected

void KiwiSDRWorker::onDisconnected ( )
privateslot

Definition at line 49 of file kiwisdrworker.cpp.

References m_status, and updateStatus().

Referenced by KiwiSDRWorker().

50 {
51  qDebug("KiwiSDRWorker::onDisconnected");
52  m_status = 4;
53  emit updateStatus(4);
54 }
void updateStatus(int status)
int m_status
See GUI for status number detail.
Definition: kiwisdrworker.h:46
+ Here is the caller graph for this function:

◆ onGainChanged

void KiwiSDRWorker::onGainChanged ( quint32  gain,
bool  useAGC 
)
slot

Definition at line 129 of file kiwisdrworker.cpp.

References m_gain, m_useAGC, and sendGain().

Referenced by KiwiSDRInput::start().

130 {
131  if (m_gain == gain && m_useAGC == useAGC)
132  return;
133 
134  m_gain = gain;
135  m_useAGC = useAGC;
136 
137  sendGain();
138 }
uint32_t m_gain
Definition: kiwisdrworker.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onServerAddressChanged

void KiwiSDRWorker::onServerAddressChanged ( QString  serverAddress)
slot

Definition at line 140 of file kiwisdrworker.cpp.

References m_serverAddress, m_status, m_webSocket, and updateStatus().

Referenced by KiwiSDRInput::start().

141 {
142  if (m_serverAddress == serverAddress)
143  return;
144  m_serverAddress = serverAddress;
145 
146  m_status = 1;
147  emit updateStatus(1);
148 
149  QString url("ws://");
150  url.append(m_serverAddress);
151  url.append("/kiwi/");
152  url.append(QString::number(QDateTime::currentMSecsSinceEpoch()));
153  url.append("/SND");
154  m_webSocket.open(QUrl(url));
155 }
QString m_serverAddress
Definition: kiwisdrworker.h:40
QWebSocket m_webSocket
Definition: kiwisdrworker.h:35
void updateStatus(int status)
int m_status
See GUI for status number detail.
Definition: kiwisdrworker.h:46
+ Here is the caller graph for this function:

◆ onSocketError

void KiwiSDRWorker::onSocketError ( QAbstractSocket::SocketError  error)
privateslot

Definition at line 56 of file kiwisdrworker.cpp.

References m_status, and updateStatus().

Referenced by KiwiSDRWorker().

57 {
58  m_status = 3;
59  emit updateStatus(3);
60 }
void updateStatus(int status)
int m_status
See GUI for status number detail.
Definition: kiwisdrworker.h:46
+ Here is the caller graph for this function:

◆ sendCenterFrequency()

void KiwiSDRWorker::sendCenterFrequency ( )
private

Definition at line 62 of file kiwisdrworker.cpp.

References m_centerFrequency, and m_webSocket.

Referenced by onBinaryMessageReceived(), and onCenterFrequencyChanged().

63 {
64  if (!m_webSocket.isValid())
65  return;
66 
67  QString freq = QString::number(m_centerFrequency / 1000.0, 'f', 3);
68  QString msg = "SET mod=iq low_cut=-5980 high_cut=5980 freq=" + freq;
69  m_webSocket.sendTextMessage(msg);
70 }
QWebSocket m_webSocket
Definition: kiwisdrworker.h:35
uint64_t m_centerFrequency
Definition: kiwisdrworker.h:41
+ Here is the caller graph for this function:

◆ sendGain()

void KiwiSDRWorker::sendGain ( )
private

Definition at line 72 of file kiwisdrworker.cpp.

References m_gain, m_useAGC, and m_webSocket.

Referenced by onBinaryMessageReceived(), and onGainChanged().

73 {
74  if (!m_webSocket.isValid())
75  return;
76 
77  QString msg("SET agc=");
78  msg.append(m_useAGC ? "1" : "0");
79  msg.append(" hang=0 thresh=-130 slope=6 decay=1000 manGain=");
80  msg.append(QString::number(m_gain));
81  m_webSocket.sendTextMessage(msg);
82 }
QWebSocket m_webSocket
Definition: kiwisdrworker.h:35
uint32_t m_gain
Definition: kiwisdrworker.h:43
+ Here is the caller graph for this function:

◆ tick

void KiwiSDRWorker::tick ( )
privateslot

Definition at line 157 of file kiwisdrworker.cpp.

References m_webSocket.

Referenced by KiwiSDRWorker().

158 {
159  m_webSocket.sendTextMessage("SET keepalive");
160 }
QWebSocket m_webSocket
Definition: kiwisdrworker.h:35
+ Here is the caller graph for this function:

◆ updateStatus

void KiwiSDRWorker::updateStatus ( int  status)
signal

Referenced by onBinaryMessageReceived(), onDisconnected(), onServerAddressChanged(), onSocketError(), and KiwiSDRInput::start().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_centerFrequency

uint64_t KiwiSDRWorker::m_centerFrequency
private

Definition at line 41 of file kiwisdrworker.h.

Referenced by onCenterFrequencyChanged(), and sendCenterFrequency().

◆ m_gain

uint32_t KiwiSDRWorker::m_gain
private

Definition at line 43 of file kiwisdrworker.h.

Referenced by onGainChanged(), and sendGain().

◆ m_sampleFifo

SampleSinkFifo* KiwiSDRWorker::m_sampleFifo
private

Definition at line 38 of file kiwisdrworker.h.

Referenced by onBinaryMessageReceived().

◆ m_samplesBuf

SampleVector KiwiSDRWorker::m_samplesBuf
private

Definition at line 37 of file kiwisdrworker.h.

Referenced by onBinaryMessageReceived().

◆ m_serverAddress

QString KiwiSDRWorker::m_serverAddress
private

Definition at line 40 of file kiwisdrworker.h.

Referenced by onServerAddressChanged().

◆ m_status

int KiwiSDRWorker::m_status
private

See GUI for status number detail.

Definition at line 46 of file kiwisdrworker.h.

Referenced by getStatus(), onBinaryMessageReceived(), onDisconnected(), onServerAddressChanged(), and onSocketError().

◆ m_timer

QTimer KiwiSDRWorker::m_timer
private

Definition at line 34 of file kiwisdrworker.h.

Referenced by KiwiSDRWorker(), and onBinaryMessageReceived().

◆ m_useAGC

bool KiwiSDRWorker::m_useAGC
private

Definition at line 44 of file kiwisdrworker.h.

Referenced by onGainChanged(), and sendGain().

◆ m_webSocket

QWebSocket KiwiSDRWorker::m_webSocket
private

The documentation for this class was generated from the following files: