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.
bfmdemodsettings.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 "bfmdemodsettings.h"
25 
26 const int BFMDemodSettings::m_nbRFBW = 9;
27 const int BFMDemodSettings::m_rfBW[] = {
28  80000, 100000, 120000, 140000, 160000, 180000, 200000, 220000, 250000
29 };
30 
32  m_channelMarker(0),
33  m_spectrumGUI(0)
34 {
36 }
37 
39 {
42  m_afBandwidth = 15000;
43  m_volume = 2.0;
44  m_squelch = -60.0;
45  m_audioStereo = false;
46  m_lsbStereo = false;
47  m_showPilot = false;
48  m_rdsActive = false;
49  m_rgbColor = QColor(80, 120, 228).rgb();
50  m_title = "Broadcast FM Demod";
52  m_useReverseAPI = false;
53  m_reverseAPIAddress = "127.0.0.1";
54  m_reverseAPIPort = 8888;
57 }
58 
59 QByteArray BFMDemodSettings::serialize() const
60 {
61  SimpleSerializer s(1);
64  s.writeS32(3, m_afBandwidth/1000.0);
65  s.writeS32(4, m_volume*10.0);
66  s.writeS32(5, m_squelch);
67  s.writeU32(7, m_rgbColor);
68 
69  if (m_spectrumGUI) {
71  }
72 
74  s.writeBool(10, m_lsbStereo);
75 
76  if (m_channelMarker) {
78  }
79 
80  s.writeString(12, m_title);
87 
88  return s.final();
89 }
90 
91 bool BFMDemodSettings::deserialize(const QByteArray& data)
92 {
93  SimpleDeserializer d(data);
94 
95  if(!d.isValid())
96  {
98  return false;
99  }
100 
101  if(d.getVersion() == 1)
102  {
103  QByteArray bytetmp;
104  qint32 tmp;
105  uint32_t utmp;
106  QString strtmp;
107 
108  d.readS32(1, &tmp, 0);
110  d.readS32(2, &tmp, 4);
111  m_rfBandwidth = getRFBW(tmp);
112  d.readS32(3, &tmp, 3);
113  m_afBandwidth = tmp * 1000.0;
114  d.readS32(4, &tmp, 20);
115  m_volume = tmp * 0.1;
116  d.readS32(5, &tmp, -60);
117  m_squelch = tmp;
118  d.readU32(7, &m_rgbColor);
119 
120  d.readBlob(8, &bytetmp);
121 
122  if (m_spectrumGUI) {
123  m_spectrumGUI->deserialize(bytetmp);
124  }
125 
126  d.readBool(9, &m_audioStereo, false);
127  d.readBool(10, &m_lsbStereo, false);
128 
129  d.readBlob(11, &bytetmp);
130 
131  if (m_channelMarker) {
132  m_channelMarker->deserialize(bytetmp);
133  }
134 
135  d.readString(12, &m_title, "Broadcast FM Demod");
137  d.readBool(14, &m_useReverseAPI, false);
138  d.readString(15, &m_reverseAPIAddress, "127.0.0.1");
139  d.readU32(16, &utmp, 0);
140 
141  if ((utmp > 1023) && (utmp < 65535)) {
142  m_reverseAPIPort = utmp;
143  } else {
144  m_reverseAPIPort = 8888;
145  }
146 
147  d.readU32(17, &utmp, 0);
148  m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp;
149  d.readU32(18, &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  for (int i = 0; i < m_nbRFBW; i++)
175  {
176  if (rfbw <= m_rfBW[i])
177  {
178  return i;
179  }
180  }
181 
182  return m_nbRFBW-1;
183 }
static const QString m_defaultDeviceName
QString m_reverseAPIAddress
bool deserialize(const QByteArray &data)
uint16_t m_reverseAPIChannelIndex
qint64 m_inputFrequencyOffset
static int getRFBWIndex(int rfbw)
void writeBlob(quint32 id, const QByteArray &value)
Serializable * m_channelMarker
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
bool readString(quint32 id, QString *result, const QString &def=QString::null) const
uint16_t m_reverseAPIDeviceIndex
bool readBool(quint32 id, bool *result, bool def=false) const
bool isValid() const
unsigned int uint32_t
Definition: rtptypes_win.h:46
static int getRFBW(int index)
QByteArray serialize() const
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
bool readBlob(quint32 id, QByteArray *result, const QByteArray &def=QByteArray()) const
static const int m_nbRFBW
uint16_t m_reverseAPIPort
int32_t i
Definition: decimators.h:244
static const int m_rfBW[]
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
virtual bool deserialize(const QByteArray &data)=0
void writeU32(quint32 id, quint32 value)
Serializable * m_spectrumGUI
virtual QByteArray serialize() const =0
void writeBool(quint32 id, bool value)
void writeString(quint32 id, const QString &value)
const QByteArray & final()