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.
soapysdroutputsettings.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 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 <QtGlobal>
19 #include <QDataStream>
20 
21 #include "util/simpleserializer.h"
22 
23 #include "soapysdroutputsettings.h"
24 
26 {
28 }
29 
31 {
32  m_centerFrequency = 435000*1000;
33  m_LOppmTenths = 0;
34  m_devSampleRate = 1024000;
35  m_log2Interp = 0;
36  m_transverterMode = false;
38  m_antenna = "NONE";
39  m_bandwidth = 1000000;
40  m_globalGain = 0;
41  m_autoGain = false;
42  m_autoDCCorrection = false;
43  m_autoIQCorrection = false;
44  m_dcCorrection = std::complex<double>{0,0};
45  m_iqCorrection = std::complex<double>{0,0};
46  m_useReverseAPI = false;
47  m_reverseAPIAddress = "127.0.0.1";
48  m_reverseAPIPort = 8888;
50 }
51 
53 {
54  SimpleSerializer s(1);
55 
57  s.writeS32(2, m_LOppmTenths);
58  s.writeU32(3, m_log2Interp);
61  s.writeString(6, m_antenna);
62  s.writeU32(7, m_bandwidth);
64  s.writeS32(12, m_globalGain);
66  s.writeBool(14, m_autoGain);
69  s.writeDouble(17, m_dcCorrection.real());
70  s.writeDouble(18, m_dcCorrection.imag());
71  s.writeDouble(19, m_iqCorrection.real());
72  s.writeDouble(20, m_iqCorrection.imag());
79 
80  return s.final();
81 }
82 
83 bool SoapySDROutputSettings::deserialize(const QByteArray& data)
84 {
85  SimpleDeserializer d(data);
86 
87  if (!d.isValid())
88  {
90  return false;
91  }
92 
93  if (d.getVersion() == 1)
94  {
95  QByteArray blob;
96  double realval, imagval;
97  uint32_t uintval;
98 
99  d.readS32(1, &m_devSampleRate, 1024000);
100  d.readS32(2, &m_LOppmTenths, 0);
101  d.readU32(3, &m_log2Interp, 0);
102  d.readBool(4, &m_transverterMode, false);
104  d.readString(6, &m_antenna, "NONE");
105  d.readU32(7, &m_bandwidth, 1000000);
106  d.readBlob(8, &blob);
108  d.readS32(12, &m_globalGain, 0);
109  d.readBlob(13, &blob);
111  d.readBool(14, &m_autoGain, false);
112  d.readBool(15, &m_autoDCCorrection, false);
113  d.readBool(16, &m_autoIQCorrection, false);
114  d.readDouble(17, &realval, 0);
115  d.readDouble(18, &imagval, 0);
116  m_dcCorrection = std::complex<double>{realval, imagval};
117  d.readDouble(19, &realval, 0);
118  d.readDouble(20, &imagval, 0);
119  m_iqCorrection = std::complex<double>{realval, imagval};
120  d.readBlob(21, &blob);
122  d.readBlob(22, &blob);
124  d.readBool(23, &m_useReverseAPI, false);
125  d.readString(24, &m_reverseAPIAddress, "127.0.0.1");
126  d.readU32(25, &uintval, 0);
127 
128  if ((uintval > 1023) && (uintval < 65535)) {
129  m_reverseAPIPort = uintval;
130  } else {
131  m_reverseAPIPort = 8888;
132  }
133 
134  d.readU32(26, &uintval, 0);
135  m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
136 
137  return true;
138  }
139  else
140  {
141  resetToDefaults();
142  return false;
143  }
144 }
145 
146 QByteArray SoapySDROutputSettings::serializeNamedElementMap(const QMap<QString, double>& map) const
147 {
148  QByteArray data;
149  QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
150  (*stream) << map;
151  delete stream;
152 
153  return data;
154 }
155 
156 void SoapySDROutputSettings::deserializeNamedElementMap(const QByteArray& data, QMap<QString, double>& map)
157 {
158  QDataStream *stream = new QDataStream(data);
159  (*stream) >> map;
160  delete stream;
161 }
162 
163 QByteArray SoapySDROutputSettings::serializeArgumentMap(const QMap<QString, QVariant>& map) const
164 {
165  QByteArray data;
166  QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
167  (*stream) << map;
168  delete stream;
169 
170  return data;
171 }
172 
173 void SoapySDROutputSettings::deserializeArgumentMap(const QByteArray& data, QMap<QString, QVariant>& map)
174 {
175  QDataStream *stream = new QDataStream(data);
176  (*stream) >> map;
177  delete stream;
178 }
179 
void deserializeArgumentMap(const QByteArray &data, QMap< QString, QVariant > &map)
QMap< QString, double > m_tunableElements
void writeDouble(quint32 id, double value)
bool readS64(quint32 id, qint64 *result, qint64 def=0) const
void writeBlob(quint32 id, const QByteArray &value)
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
bool readDouble(quint32 id, double *result, double def=0) const
QByteArray serializeArgumentMap(const QMap< QString, QVariant > &map) const
bool readString(quint32 id, QString *result, const QString &def=QString::null) const
bool readBool(quint32 id, bool *result, bool def=false) const
QMap< QString, QVariant > m_streamArgSettings
bool isValid() const
unsigned int uint32_t
Definition: rtptypes_win.h:46
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
bool readBlob(quint32 id, QByteArray *result, const QByteArray &def=QByteArray()) const
QMap< QString, double > m_individualGains
void deserializeNamedElementMap(const QByteArray &data, QMap< QString, double > &map)
QByteArray serializeNamedElementMap(const QMap< QString, double > &map) const
std::complex< double > m_iqCorrection
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
void writeU32(quint32 id, quint32 value)
std::complex< double > m_dcCorrection
void writeBool(quint32 id, bool value)
void writeS64(quint32 id, qint64 value)
void writeString(quint32 id, const QString &value)
bool deserialize(const QByteArray &data)
const QByteArray & final()
QMap< QString, QVariant > m_deviceArgSettings