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.
soapysdrinputsettings.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 <QDataStream>
19 
20 #include "util/simpleserializer.h"
21 
22 #include "soapysdrinputsettings.h"
23 
25 {
27 }
28 
30 {
31  m_centerFrequency = 435000*1000;
32  m_LOppmTenths = 0;
33  m_devSampleRate = 1024000;
34  m_log2Decim = 0;
36  m_softDCCorrection = false;
37  m_softIQCorrection = false;
38  m_transverterMode = false;
40  m_fileRecordName = "";
41  m_antenna = "NONE";
42  m_bandwidth = 1000000;
43  m_globalGain = 0;
44  m_autoGain = false;
45  m_autoDCCorrection = false;
46  m_autoIQCorrection = false;
47  m_dcCorrection = std::complex<double>{0,0};
48  m_iqCorrection = std::complex<double>{0,0};
49  m_useReverseAPI = false;
50  m_reverseAPIAddress = "127.0.0.1";
51  m_reverseAPIPort = 8888;
53 }
54 
56 {
57  SimpleSerializer s(1);
58 
60  s.writeU32(2, m_log2Decim);
61  s.writeS32(3, (int) m_fcPos);
64  s.writeS32(6, m_LOppmTenths);
67  s.writeString(9, m_antenna);
68  s.writeU32(10, m_bandwidth);
70  s.writeS32(12, m_globalGain);
72  s.writeBool(14, m_autoGain);
75  s.writeDouble(17, m_dcCorrection.real());
76  s.writeDouble(18, m_dcCorrection.imag());
77  s.writeDouble(19, m_iqCorrection.real());
78  s.writeDouble(20, m_iqCorrection.imag());
85 
86  return s.final();
87 }
88 
89 bool SoapySDRInputSettings::deserialize(const QByteArray& data)
90 {
91  SimpleDeserializer d(data);
92 
93  if (!d.isValid())
94  {
96  return false;
97  }
98 
99  if (d.getVersion() == 1)
100  {
101  int intval;
102  uint32_t uintval;
103  QByteArray blob;
104  double realval, imagval;
105 
106  d.readS32(1, &m_devSampleRate, 1024000);
107  d.readU32(2, &m_log2Decim, 0);
108  d.readS32(3, &intval, (int) FC_POS_CENTER);
109  m_fcPos = (fcPos_t) intval;
110  d.readBool(4, &m_softDCCorrection, false);
111  d.readBool(5, &m_softIQCorrection, false);
112  d.readS32(6, &m_LOppmTenths, 0);
113  d.readBool(7, &m_transverterMode, false);
115  d.readString(9, &m_antenna, "NONE");
116  d.readU32(10, &m_bandwidth, 1000000);
117  d.readBlob(11, &blob);
119  d.readS32(12, &m_globalGain, 0);
120  d.readBlob(13, &blob);
122  d.readBool(14, &m_autoGain, false);
123  d.readBool(15, &m_autoDCCorrection, false);
124  d.readBool(16, &m_autoIQCorrection, false);
125  d.readDouble(17, &realval, 0);
126  d.readDouble(18, &imagval, 0);
127  m_dcCorrection = std::complex<double>{realval, imagval};
128  d.readDouble(19, &realval, 0);
129  d.readDouble(20, &imagval, 0);
130  m_iqCorrection = std::complex<double>{realval, imagval};
131  d.readBlob(21, &blob);
133  d.readBlob(22, &blob);
135  d.readBool(23, &m_useReverseAPI, false);
136  d.readString(24, &m_reverseAPIAddress, "127.0.0.1");
137  d.readU32(25, &uintval, 0);
138 
139  if ((uintval > 1023) && (uintval < 65535)) {
140  m_reverseAPIPort = uintval;
141  } else {
142  m_reverseAPIPort = 8888;
143  }
144 
145  d.readU32(26, &uintval, 0);
146  m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
147 
148  return true;
149  }
150  else
151  {
152  resetToDefaults();
153  return false;
154  }
155 }
156 
157 QByteArray SoapySDRInputSettings::serializeNamedElementMap(const QMap<QString, double>& map) const
158 {
159  QByteArray data;
160  QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
161  (*stream) << map;
162  delete stream;
163 
164  return data;
165 }
166 
167 void SoapySDRInputSettings::deserializeNamedElementMap(const QByteArray& data, QMap<QString, double>& map)
168 {
169  QDataStream *stream = new QDataStream(data);
170  (*stream) >> map;
171  delete stream;
172 }
173 
174 QByteArray SoapySDRInputSettings::serializeArgumentMap(const QMap<QString, QVariant>& map) const
175 {
176  QByteArray data;
177  QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
178  (*stream) << map;
179  delete stream;
180 
181  return data;
182 }
183 
184 void SoapySDRInputSettings::deserializeArgumentMap(const QByteArray& data, QMap<QString, QVariant>& map)
185 {
186  QDataStream *stream = new QDataStream(data);
187  (*stream) >> map;
188  delete stream;
189 }
190 
QMap< QString, QVariant > m_streamArgSettings
void writeDouble(quint32 id, double value)
bool readS64(quint32 id, qint64 *result, qint64 def=0) const
void deserializeNamedElementMap(const QByteArray &data, QMap< QString, double > &map)
void writeBlob(quint32 id, const QByteArray &value)
std::complex< double > m_iqCorrection
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
bool readDouble(quint32 id, double *result, double 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
unsigned int uint32_t
Definition: rtptypes_win.h:46
QByteArray serializeNamedElementMap(const QMap< QString, double > &map) const
QMap< QString, QVariant > m_deviceArgSettings
void deserializeArgumentMap(const QByteArray &data, QMap< QString, QVariant > &map)
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
QMap< QString, double > m_tunableElements
bool readBlob(quint32 id, QByteArray *result, const QByteArray &def=QByteArray()) const
bool deserialize(const QByteArray &data)
std::complex< double > m_dcCorrection
QMap< QString, double > m_individualGains
QByteArray serialize() const
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
QByteArray serializeArgumentMap(const QMap< QString, QVariant > &map) const
void writeU32(quint32 id, quint32 value)
void writeBool(quint32 id, bool value)
void writeS64(quint32 id, qint64 value)
void writeString(quint32 id, const QString &value)
const QByteArray & final()