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.
udpsourcesettings.cpp
Go to the documentation of this file.
1 // Copyright (C) 2017 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include "udpsourcesettings.h"
19 
20 #include <QColor>
21 
22 #include "dsp/dspengine.h"
23 #include "util/simpleserializer.h"
24 #include "settings/serializable.h"
25 
27  m_channelMarker(0),
28  m_spectrumGUI(0)
29 {
31 }
32 
34 {
36  m_inputSampleRate = 48000;
38  m_rfBandwidth = 12500;
39  m_lowCutoff = 0.0f;
40  m_fmDeviation = 2500;
41  m_amModFactor = 0.95;
42  m_channelMute = false;
43  m_gainIn = 1.0;
44  m_gainOut = 1.0;
45  m_squelch = -60.0;
46  m_squelchGate = 0.05;
47  m_autoRWBalance = true;
48  m_stereoInput = false;
49  m_squelchEnabled = true;
50  m_udpAddress = "127.0.0.1";
51  m_udpPort = 9998;
52  m_rgbColor = QColor(225, 25, 99).rgb();
53  m_title = "UDP Sample Source";
54  m_useReverseAPI = false;
55  m_reverseAPIAddress = "127.0.0.1";
56  m_reverseAPIPort = 8888;
59 }
60 
61 QByteArray UDPSourceSettings::serialize() const
62 {
63  SimpleSerializer s(1);
65  s.writeS32(3, (int) m_sampleFormat);
68 
69  if (m_channelMarker) {
71  }
72 
73  if (m_spectrumGUI) {
75  }
76 
77  s.writeS32(10, roundf(m_gainOut * 10.0));
78  s.writeS32(11, m_fmDeviation);
79  s.writeReal(12, m_amModFactor);
80  s.writeBool(13, m_stereoInput);
81  s.writeS32(14, roundf(m_squelch));
82  s.writeS32(15, roundf(m_squelchGate * 100.0));
84  s.writeS32(17, roundf(m_gainIn * 10.0));
86  s.writeU32(19, m_udpPort);
87  s.writeString(20, m_title);
93 
94  return s.final();
95 }
96 
97 bool UDPSourceSettings::deserialize(const QByteArray& data)
98 {
99  SimpleDeserializer d(data);
100 
101  if (!d.isValid())
102  {
103  resetToDefaults();
104  return false;
105  }
106 
107  if (d.getVersion() == 1)
108  {
109  QByteArray bytetmp;
110  QString strtmp;
111  qint32 s32tmp;
112  quint32 u32tmp;
113 
114  if (m_channelMarker)
115  {
116  d.readBlob(6, &bytetmp);
117  m_channelMarker->deserialize(bytetmp);
118  }
119 
120  d.readS32(2, &s32tmp, 0);
121  m_inputFrequencyOffset = s32tmp;
122 
123  d.readS32(3, &s32tmp, 0);
124 
125  if (s32tmp < (int) FormatNone) {
126  m_sampleFormat = (SampleFormat) s32tmp;
127  } else {
128  m_sampleFormat = (SampleFormat) ((int) FormatNone - 1);
129  }
130 
131  d.readReal(4, &m_inputSampleRate, 48000);
132  d.readReal(5, &m_rfBandwidth, 32000);
133 
134  if (m_spectrumGUI)
135  {
136  d.readBlob(7, &bytetmp);
137  m_spectrumGUI->deserialize(bytetmp);
138  }
139 
140  d.readS32(10, &s32tmp, 10);
141  m_gainOut = s32tmp / 10.0;
142 
143  d.readS32(11, &m_fmDeviation, 2500);
144  d.readReal(12, &m_amModFactor, 0.95);
145  d.readBool(13, &m_stereoInput, false);
146 
147  d.readS32(14, &s32tmp, -60);
148  m_squelch = s32tmp * 1.0;
149  m_squelchEnabled = (s32tmp != -100);
150 
151  d.readS32(15, &s32tmp, 5);
152  m_squelchGate = s32tmp / 100.0;
153 
154  d.readBool(16, &m_autoRWBalance, true);
155 
156  d.readS32(17, &s32tmp, 10);
157  m_gainIn = s32tmp / 10.0;
158 
159  d.readString(18, &m_udpAddress, "127.0.0.1");
160  d.readU32(19, &u32tmp, 9998);
161 
162  if ((u32tmp > 1024) & (u32tmp < 65538)) {
163  m_udpPort = u32tmp;
164  } else {
165  m_udpPort = 9998;
166  }
167 
168  d.readString(20, &m_title, "UDP Sample Sink");
169 
170  d.readBool(21, &m_useReverseAPI, false);
171  d.readString(22, &m_reverseAPIAddress, "127.0.0.1");
172  d.readU32(23, &u32tmp, 0);
173 
174  if ((u32tmp > 1023) && (u32tmp < 65535)) {
175  m_reverseAPIPort = u32tmp;
176  } else {
177  m_reverseAPIPort = 8888;
178  }
179 
180  d.readU32(24, &u32tmp, 0);
181  m_reverseAPIDeviceIndex = u32tmp > 99 ? 99 : u32tmp;
182  d.readU32(25, &u32tmp, 0);
183  m_reverseAPIChannelIndex = u32tmp > 99 ? 99 : u32tmp;
184 
185  return true;
186  }
187  else
188  {
189  resetToDefaults();
190  return false;
191  }
192 }
193 
194 
195 
196 
197 
void writeBlob(quint32 id, const QByteArray &value)
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
bool readString(quint32 id, QString *result, const QString &def=QString::null) const
bool readBool(quint32 id, bool *result, bool def=false) const
bool isValid() const
Real m_squelch
squared magnitude
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
bool readBlob(quint32 id, QByteArray *result, const QByteArray &def=QByteArray()) const
QByteArray serialize() const
bool deserialize(const QByteArray &data)
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
virtual bool deserialize(const QByteArray &data)=0
uint16_t m_reverseAPIDeviceIndex
void writeU32(quint32 id, quint32 value)
void writeReal(quint32 id, Real value)
uint16_t m_reverseAPIChannelIndex
bool readReal(quint32 id, Real *result, Real def=0) const
virtual QByteArray serialize() const =0
void writeBool(quint32 id, bool value)
Real m_squelchGate
seconds
SampleFormat m_sampleFormat
Serializable * m_spectrumGUI
Serializable * m_channelMarker
void writeString(quint32 id, const QString &value)
const QByteArray & final()