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.
nfmmodsettings.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 #include "nfmmodsettings.h"
25 
26 const int NFMModSettings::m_rfBW[] = {
27  3000, 4000, 5000, 6250, 8330, 10000, 12500, 15000, 20000, 25000, 40000
28 };
29 const int NFMModSettings::m_nbRfBW = 11;
30 
31 const float NFMModSettings::m_ctcssFreqs[] = {
32  67.0, 71.9, 74.4, 77.0, 79.7, 82.5, 85.4, 88.5, 91.5, 94.8,
33  97.4, 100.0, 103.5, 107.2, 110.9, 114.8, 118.8, 123.0, 127.3, 131.8,
34  136.5, 141.3, 146.2, 151.4, 156.7, 162.2, 167.9, 173.8, 179.9, 186.2,
35  192.8, 203.5
36 };
37 const int NFMModSettings::m_nbCTCSSFreqs = 32;
38 
39 
41  m_channelMarker(0),
42  m_cwKeyerGUI(0)
43 {
45 }
46 
48 {
49  m_afBandwidth = 3000;
51  m_rfBandwidth = 12500.0f;
52  m_fmDeviation = 5000.0f;
53  m_toneFrequency = 1000.0f;
54  m_volumeFactor = 1.0f;
55  m_channelMute = false;
56  m_playLoop = false;
57  m_ctcssOn = false;
58  m_ctcssIndex = 0;
59  m_rgbColor = QColor(255, 0, 0).rgb();
60  m_title = "NFM Modulator";
61  m_modAFInput = NFMModInputAF::NFMModInputNone;
65  m_feedbackAudioEnable = false;
66  m_useReverseAPI = false;
67  m_reverseAPIAddress = "127.0.0.1";
68  m_reverseAPIPort = 8888;
71 }
72 
73 QByteArray NFMModSettings::serialize() const
74 {
75  SimpleSerializer s(1);
76 
81  s.writeU32(5, m_rgbColor);
84 
85  if (m_cwKeyerGUI) {
87  }
88 
89  if (m_channelMarker) {
91  }
92 
93  s.writeBool(9, m_ctcssOn);
94  s.writeS32(10, m_ctcssIndex);
95  s.writeString(12, m_title);
96  s.writeS32(13, (int) m_modAFInput);
100  s.writeU32(17, m_reverseAPIPort);
106 
107  return s.final();
108 }
109 
110 bool NFMModSettings::deserialize(const QByteArray& data)
111 {
112  SimpleDeserializer d(data);
113 
114  if(!d.isValid())
115  {
116  resetToDefaults();
117  return false;
118  }
119 
120  if(d.getVersion() == 1)
121  {
122  QByteArray bytetmp;
123  qint32 tmp;
124  uint32_t utmp;
125 
126  d.readS32(1, &tmp, 0);
128  d.readReal(2, &m_rfBandwidth, 12500.0);
129  d.readReal(3, &m_afBandwidth, 1000.0);
130  d.readReal(4, &m_fmDeviation, 5000.0);
131  d.readU32(5, &m_rgbColor);
132  d.readReal(6, &m_toneFrequency, 1000.0);
133  d.readReal(7, &m_volumeFactor, 1.0);
134 
135  if (m_cwKeyerGUI) {
136  d.readBlob(8, &bytetmp);
137  m_cwKeyerGUI->deserialize(bytetmp);
138  }
139 
140  d.readBool(9, &m_ctcssOn, false);
141  d.readS32(10, &m_ctcssIndex, 0);
142 
143  if (m_channelMarker) {
144  d.readBlob(11, &bytetmp);
145  m_channelMarker->deserialize(bytetmp);
146  }
147 
148  d.readString(12, &m_title, "NFM Modulator");
149 
150  d.readS32(13, &tmp, 0);
151  if ((tmp < 0) || (tmp > (int) NFMModInputAF::NFMModInputTone)) {
153  } else {
154  m_modAFInput = (NFMModInputAF) tmp;
155  }
156 
158 
159  d.readBool(15, &m_useReverseAPI, false);
160  d.readString(16, &m_reverseAPIAddress, "127.0.0.1");
161  d.readU32(17, &utmp, 0);
162 
163  if ((utmp > 1023) && (utmp < 65535)) {
164  m_reverseAPIPort = utmp;
165  } else {
166  m_reverseAPIPort = 8888;
167  }
168 
169  d.readU32(18, &utmp, 0);
170  m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp;
171  d.readU32(19, &utmp, 0);
172  m_reverseAPIChannelIndex = utmp > 99 ? 99 : utmp;
174  d.readReal(21, &m_feedbackVolumeFactor, 1.0);
175  d.readBool(22, &m_feedbackAudioEnable, false);
176 
177  return true;
178  }
179  else
180  {
181  qDebug() << "NFMModSettings::deserialize: ERROR";
182  resetToDefaults();
183  return false;
184  }
185 }
186 
188 {
189  if (index < 0) {
190  return m_rfBW[0];
191  } else if (index < m_nbRfBW) {
192  return m_rfBW[index];
193  } else {
194  return m_rfBW[m_nbRfBW-1];
195  }
196 }
197 
199 {
200  for (int i = 0; i < m_nbRfBW; i++)
201  {
202  if (rfbw <= m_rfBW[i])
203  {
204  return i;
205  }
206  }
207 
208  return m_nbRfBW-1;
209 }
210 
212 {
213  if (index < 0) {
214  return m_ctcssFreqs[0];
215  } else if (index < m_nbCTCSSFreqs) {
216  return m_ctcssFreqs[index];
217  } else {
218  return m_ctcssFreqs[m_nbCTCSSFreqs-1];
219  }
220 }
221 
223 {
224  for (int i = 0; i < m_nbCTCSSFreqs; i++)
225  {
226  if (ctcssFreq <= m_ctcssFreqs[i])
227  {
228  return i;
229  }
230  }
231 
232  return m_nbCTCSSFreqs-1;
233 }
234 
static const QString m_defaultDeviceName
bool deserialize(const QByteArray &data)
static const int m_nbRfBW
bool m_feedbackAudioEnable
static const int m_nbCTCSSFreqs
void writeBlob(quint32 id, const QByteArray &value)
static float getCTCSSFreq(int index)
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
quint32 m_rgbColor
unsigned int uint32_t
Definition: rtptypes_win.h:46
static const int m_rfBW[]
static int getCTCSSFreqIndex(float ctcssFreq)
qint64 m_inputFrequencyOffset
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
Serializable * m_cwKeyerGUI
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
virtual bool deserialize(const QByteArray &data)=0
uint16_t m_reverseAPIDeviceIndex
static const float m_ctcssFreqs[]
void writeU32(quint32 id, quint32 value)
float m_feedbackVolumeFactor
void writeReal(quint32 id, Real value)
bool readReal(quint32 id, Real *result, Real def=0) const
virtual QByteArray serialize() const =0
QByteArray serialize() const
void writeBool(quint32 id, bool value)
NFMModInputAF m_modAFInput
Serializable * m_channelMarker
QString m_audioDeviceName
This is the audio device you get the audio samples from.
static int getRFBW(int index)
QString m_reverseAPIAddress
void writeString(quint32 id, const QString &value)
static int getRFBWIndex(int rfbw)
uint16_t m_reverseAPIPort
QString m_feedbackAudioDeviceName
This is the audio device you send the audio samples to for audio feedback.
const QByteArray & final()
uint16_t m_reverseAPIChannelIndex