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.
wfmmodsettings.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 <QColor>
19 #include <QDebug>
20 
21 #include "dsp/dspengine.h"
22 #include "util/simpleserializer.h"
23 #include "settings/serializable.h"
24 
25 #include "wfmmodsettings.h"
26 
27 const int WFMModSettings::m_rfBW[] = {
28  12500, 25000, 40000, 60000, 75000, 80000, 100000, 125000, 140000, 160000, 180000, 200000, 220000, 250000
29 };
30 const int WFMModSettings::m_nbRfBW = 14;
31 
33  m_channelMarker(0),
34  m_cwKeyerGUI(0)
35 {
37 }
38 
40 {
42  m_rfBandwidth = 125000.0f;
43  m_afBandwidth = 15000.0f;
44  m_fmDeviation = 50000.0f;
45  m_toneFrequency = 1000.0f;
46  m_volumeFactor = 1.0f;
47  m_channelMute = false;
48  m_playLoop = false;
49  m_rgbColor = QColor(0, 0, 255).rgb();
50  m_title = "WFM Modulator";
53  m_useReverseAPI = false;
54  m_reverseAPIAddress = "127.0.0.1";
55  m_reverseAPIPort = 8888;
58 }
59 
60 QByteArray WFMModSettings::serialize() const
61 {
62  SimpleSerializer s(1);
63 
68  s.writeU32(5, m_rgbColor);
71 
72  if (m_cwKeyerGUI) {
74  }
75 
76  if (m_channelMarker) {
78  }
79 
80  s.writeString(10, m_title);
82  s.writeS32(12, (int) m_modAFInput);
88 
89  return s.final();
90 }
91 
92 bool WFMModSettings::deserialize(const QByteArray& data)
93 {
94  SimpleDeserializer d(data);
95 
96  if(!d.isValid())
97  {
99  return false;
100  }
101 
102  if(d.getVersion() == 1)
103  {
104  QByteArray bytetmp;
105  qint32 tmp;
106  uint32_t utmp;
107 
108  d.readS32(1, &tmp, 0);
110  d.readReal(2, &m_rfBandwidth, 125000.0);
111  d.readReal(3, &m_afBandwidth, 15000.0);
112  d.readReal(4, &m_fmDeviation, 50000.0);
113  d.readU32(5, &m_rgbColor);
114  d.readReal(6, &m_toneFrequency, 1000.0);
115  d.readReal(7, &m_volumeFactor, 1.0);
116 
117  if (m_cwKeyerGUI) {
118  d.readBlob(8, &bytetmp);
119  m_cwKeyerGUI->deserialize(bytetmp);
120  }
121 
122  if (m_channelMarker) {
123  d.readBlob(9, &bytetmp);
124  m_channelMarker->deserialize(bytetmp);
125  }
126 
127  d.readString(10, &m_title, "WFM Modulator");
129 
130  d.readS32(12, &tmp, 0);
131  if ((tmp < 0) || (tmp > (int) WFMModInputAF::WFMModInputTone)) {
133  } else {
134  m_modAFInput = (WFMModInputAF) tmp;
135  }
136 
137  d.readBool(13, &m_useReverseAPI, false);
138  d.readString(14, &m_reverseAPIAddress, "127.0.0.1");
139  d.readU32(15, &utmp, 0);
140 
141  if ((utmp > 1023) && (utmp < 65535)) {
142  m_reverseAPIPort = utmp;
143  } else {
144  m_reverseAPIPort = 8888;
145  }
146 
147  d.readU32(16, &utmp, 0);
148  m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp;
149  d.readU32(17, &utmp, 0);
150  m_reverseAPIChannelIndex = utmp > 99 ? 99 : utmp;
151 
152  return true;
153  }
154  else
155  {
156  qDebug() << "WFMModSettings::deserialize: ERROR";
157  resetToDefaults();
158  return false;
159  }
160 }
161 
163 {
164  if (index < 0) {
165  return m_rfBW[0];
166  } else if (index < m_nbRfBW) {
167  return m_rfBW[index];
168  } else {
169  return m_rfBW[m_nbRfBW-1];
170  }
171 }
172 
174 {
175  for (int i = 0; i < m_nbRfBW; i++)
176  {
177  if (rfbw <= m_rfBW[i])
178  {
179  return i;
180  }
181  }
182 
183  return m_nbRfBW-1;
184 }
static const QString m_defaultDeviceName
Serializable * m_cwKeyerGUI
uint16_t m_reverseAPIChannelIndex
static const int m_nbRfBW
static int getRFBW(int index)
void writeBlob(quint32 id, const QByteArray &value)
WFMModInputAF m_modAFInput
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
quint32 m_rgbColor
bool isValid() const
unsigned int uint32_t
Definition: rtptypes_win.h:46
bool deserialize(const QByteArray &data)
static const int m_rfBW[]
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
bool readBlob(quint32 id, QByteArray *result, const QByteArray &def=QByteArray()) const
int32_t i
Definition: decimators.h:244
QString m_audioDeviceName
This is the audio device you get the audio samples from.
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
virtual bool deserialize(const QByteArray &data)=0
void writeU32(quint32 id, quint32 value)
void writeReal(quint32 id, Real value)
QByteArray serialize() const
uint16_t m_reverseAPIPort
bool readReal(quint32 id, Real *result, Real def=0) const
virtual QByteArray serialize() const =0
void writeBool(quint32 id, bool value)
static int getRFBWIndex(int rfbw)
QString m_reverseAPIAddress
void writeString(quint32 id, const QString &value)
const QByteArray & final()
qint64 m_inputFrequencyOffset
uint16_t m_reverseAPIDeviceIndex
Serializable * m_channelMarker