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.
nfmdemodsettings.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 
20 #include "dsp/dspengine.h"
21 #include "util/simpleserializer.h"
22 #include "settings/serializable.h"
23 
24 #include "nfmdemodsettings.h"
25 
26 const int NFMDemodSettings::m_rfBW[] = {
27  5000, 6250, 8330, 10000, 12500, 15000, 20000, 25000, 40000
28 };
29 const int NFMDemodSettings::m_fmDev[] = { // corresponding single side FM deviations at 0.4 * BW
30  2000, 2500, 3330, 4000, 5000, 6000, 8000, 10000, 16000
31 };
32 const int NFMDemodSettings::m_nbRfBW = 9;
33 
35  m_channelMarker(0)
36 {
38 }
39 
41 {
43  m_rfBandwidth = 12500;
44  m_afBandwidth = 3000;
45  m_fmDeviation = 2000;
46  m_squelchGate = 5; // 10s of ms at 48000 Hz sample rate. Corresponds to 2400 for AGC attack
47  m_deltaSquelch = false;
48  m_squelch = -30.0;
49  m_volume = 1.0;
50  m_ctcssOn = false;
51  m_audioMute = false;
52  m_ctcssIndex = 0;
53  m_rgbColor = QColor(255, 0, 0).rgb();
54  m_title = "NFM Demodulator";
56  m_highPass = true;
57  m_useReverseAPI = false;
58  m_reverseAPIAddress = "127.0.0.1";
59  m_reverseAPIPort = 8888;
62 }
63 
64 QByteArray NFMDemodSettings::serialize() const
65 {
66  SimpleSerializer s(1);
69  s.writeS32(3, m_afBandwidth/1000.0);
70  s.writeS32(4, m_volume*10.0);
71  s.writeS32(5, static_cast<int>(m_squelch));
72  s.writeBool(6, m_highPass);
73  s.writeU32(7, m_rgbColor);
74  s.writeS32(8, m_ctcssIndex);
75  s.writeBool(9, m_ctcssOn);
76  s.writeBool(10, m_audioMute);
77  s.writeS32(11, m_squelchGate);
79 
80  if (m_channelMarker) {
82  }
83 
84  s.writeString(14, m_title);
91 
92  return s.final();
93 }
94 
95 bool NFMDemodSettings::deserialize(const QByteArray& data)
96 {
97  SimpleDeserializer d(data);
98 
99  if (!d.isValid())
100  {
101  resetToDefaults();
102  return false;
103  }
104 
105  if (d.getVersion() == 1)
106  {
107  QByteArray bytetmp;
108  qint32 tmp;
109  uint32_t utmp;
110 
111  if (m_channelMarker)
112  {
113  d.readBlob(13, &bytetmp);
114  m_channelMarker->deserialize(bytetmp);
115  }
116 
117  d.readS32(1, &tmp, 0);
119  d.readS32(2, &tmp, 4);
120  m_rfBandwidth = getRFBW(tmp);
121  m_fmDeviation = getFMDev(tmp);
122  d.readS32(3, &tmp, 3);
123  m_afBandwidth = tmp * 1000.0;
124  d.readS32(4, &tmp, 20);
125  m_volume = tmp / 10.0;
126  d.readS32(5, &tmp, -30);
127  m_squelch = (tmp < -100 ? tmp/10 : tmp) * 1.0;
128  d.readBool(6, &m_highPass, true);
129  d.readU32(7, &m_rgbColor, QColor(255, 0, 0).rgb());
130  d.readS32(8, &m_ctcssIndex, 0);
131  d.readBool(9, &m_ctcssOn, false);
132  d.readBool(10, &m_audioMute, false);
133  d.readS32(11, &m_squelchGate, 5);
134  d.readBool(12, &m_deltaSquelch, false);
135  d.readString(14, &m_title, "NFM Demodulator");
137  d.readBool(16, &m_useReverseAPI, false);
138  d.readString(17, &m_reverseAPIAddress, "127.0.0.1");
139  d.readU32(18, &utmp, 0);
140 
141  if ((utmp > 1023) && (utmp < 65535)) {
142  m_reverseAPIPort = utmp;
143  } else {
144  m_reverseAPIPort = 8888;
145  }
146 
147  d.readU32(19, &utmp, 0);
148  m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp;
149  d.readU32(20, &utmp, 0);
150  m_reverseAPIChannelIndex = utmp > 99 ? 99 : utmp;
151 
152  return true;
153  }
154  else
155  {
156  resetToDefaults();
157  return false;
158  }
159 }
160 
162 {
163  if (index < 0) {
164  return m_rfBW[0];
165  } else if (index < m_nbRfBW) {
166  return m_rfBW[index];
167  } else {
168  return m_rfBW[m_nbRfBW-1];
169  }
170 }
171 
173 {
174  if (index < 0) {
175  return m_fmDev[0];
176  } else if (index < m_nbRfBW) {
177  return m_fmDev[index];
178  } else {
179  return m_fmDev[m_nbRfBW-1];
180  }
181 }
182 
184 {
185  for (int i = 0; i < m_nbRfBW; i++)
186  {
187  if (rfbw <= m_rfBW[i])
188  {
189  return i;
190  }
191  }
192 
193  return m_nbRfBW-1;
194 }
static const QString m_defaultDeviceName
uint16_t m_reverseAPIPort
bool deserialize(const QByteArray &data)
static int getFMDev(int index)
static const int m_rfBW[]
static int getRFBW(int index)
void writeBlob(quint32 id, const QByteArray &value)
Real m_squelch
deci-Bels
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
static int getRFBWIndex(int rfbw)
bool readString(quint32 id, QString *result, const QString &def=QString::null) const
static const int m_fmDev[]
bool readBool(quint32 id, bool *result, bool def=false) const
bool isValid() const
unsigned int uint32_t
Definition: rtptypes_win.h:46
QString m_reverseAPIAddress
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
QByteArray serialize() const
bool readBlob(quint32 id, QByteArray *result, const QByteArray &def=QByteArray()) const
uint16_t m_reverseAPIChannelIndex
int32_t i
Definition: decimators.h:244
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
Serializable * m_channelMarker
virtual bool deserialize(const QByteArray &data)=0
uint16_t m_reverseAPIDeviceIndex
void writeU32(quint32 id, quint32 value)
virtual QByteArray serialize() const =0
void writeBool(quint32 id, bool value)
static const int m_nbRfBW
int32_t m_inputFrequencyOffset
void writeString(quint32 id, const QString &value)
const QByteArray & final()