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.
testmisettings.cpp
Go to the documentation of this file.
1 // Copyright (C) 2019 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 "util/simpleserializer.h"
20 #include "testmisettings.h"
21 
23 {
25 }
26 
28 {
29  m_centerFrequency = 435000*1000;
30  m_frequencyShift = 0;
31  m_sampleRate = 768*1000;
32  m_log2Decim = 4;
35  m_amplitudeBits = 127;
38  m_modulationTone = 44; // 440 Hz
39  m_amModulation = 50; // 50%
40  m_fmDeviation = 50; // 5 kHz
41  m_dcFactor = 0.0f;
42  m_iFactor = 0.0f;
43  m_qFactor = 0.0f;
44  m_phaseImbalance = 0.0f;
45 }
46 
48 {
49  m_fileRecordName = "";
50  m_useReverseAPI = false;
51  m_reverseAPIAddress = "127.0.0.1";
52  m_reverseAPIPort = 8888;
53  m_reverseAPIDeviceIndex = 0;
54  m_streams.push_back(TestMIStreamSettings());
55  m_streams.push_back(TestMIStreamSettings());
56 }
57 
59  m_streams(other.m_streams)
60 {
66 }
67 
69 {
70  for (unsigned int i = 0; i < m_streams.size(); i++) {
71  m_streams[i].resetToDefaults();
72  }
73 }
74 
75 QByteArray TestMISettings::serialize() const
76 {
77  SimpleSerializer s(1);
78 
83 
84  for (unsigned int i = 0; i < m_streams.size(); i++)
85  {
86  s.writeS32(10 + 30*i, m_streams[i].m_frequencyShift);
87  s.writeU32(11 + 30*i, m_streams[i].m_sampleRate);
88  s.writeU32(12 + 30*i, m_streams[i].m_log2Decim);
89  s.writeS32(13 + 30*i, (int) m_streams[i].m_fcPos);
90  s.writeU32(14 + 30*i, m_streams[i].m_sampleSizeIndex);
91  s.writeS32(15 + 30*i, m_streams[i].m_amplitudeBits);
92  s.writeS32(16 + 30*i, (int) m_streams[i].m_autoCorrOptions);
93  s.writeFloat(17 + 30*i, m_streams[i].m_dcFactor);
94  s.writeFloat(18 + 30*i, m_streams[i].m_iFactor);
95  s.writeFloat(19 + 30*i, m_streams[i].m_qFactor);
96  s.writeFloat(20 + 30*i, m_streams[i].m_phaseImbalance);
97  s.writeS32(21 + 30*i, (int) m_streams[i].m_modulation);
98  s.writeS32(22 + 30*i, m_streams[i].m_modulationTone);
99  s.writeS32(23 + 30*i, m_streams[i].m_amModulation);
100  s.writeS32(24 + 30*i, m_streams[i].m_fmDeviation);
101  }
102 
103  return s.final();
104 }
105 
106 bool TestMISettings::deserialize(const QByteArray& data)
107 {
108  SimpleDeserializer d(data);
109 
110  if (!d.isValid())
111  {
112  resetToDefaults();
113  return false;
114  }
115 
116  if (d.getVersion() == 1)
117  {
118  int intval;
119  uint32_t utmp;
120 
121  d.readBool(1, &m_useReverseAPI, false);
122  d.readString(2, &m_reverseAPIAddress, "127.0.0.1");
123  d.readU32(3, &utmp, 0);
124 
125  if ((utmp > 1023) && (utmp < 65535)) {
126  m_reverseAPIPort = utmp;
127  } else {
128  m_reverseAPIPort = 8888;
129  }
130 
131  d.readU32(4, &utmp, 0);
132  m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp;
133 
134  for (unsigned int i = 0; i < m_streams.size(); i++)
135  {
136  d.readS32(10 + 30*i, &m_streams[i].m_frequencyShift, 0);
137  d.readU32(11 + 30*i, &m_streams[i].m_sampleRate, 768*1000);
138  d.readU32(12 + 30*i, &m_streams[i].m_log2Decim, 4);
139  d.readS32(13 + 30*i, &intval, 0);
140  m_streams[i].m_fcPos = (TestMIStreamSettings::fcPos_t) intval;
141  d.readU32(14 + 30*i, &m_streams[i].m_sampleSizeIndex, 0);
142  d.readS32(15 + 30*i, &m_streams[i].m_amplitudeBits, 128);
143  d.readS32(16 + 30*i, &intval, 0);
144 
145  if (intval < 0 || intval > (int) TestMIStreamSettings::AutoCorrLast) {
146  m_streams[i].m_autoCorrOptions = TestMIStreamSettings::AutoCorrNone;
147  } else {
148  m_streams[i].m_autoCorrOptions = (TestMIStreamSettings::AutoCorrOptions) intval;
149  }
150 
151  d.readFloat(17 + 30*i, &m_streams[i].m_dcFactor, 0.0f);
152  d.readFloat(18 + 30*i, &m_streams[i].m_iFactor, 0.0f);
153  d.readFloat(19 + 30*i, &m_streams[i].m_qFactor, 0.0f);
154  d.readFloat(20 + 30*i, &m_streams[i].m_phaseImbalance, 0.0f);
155  d.readS32(21 + 30*i, &intval, 0);
156 
157  if (intval < 0 || intval > (int) TestMIStreamSettings::ModulationLast) {
159  } else {
160  m_streams[i].m_modulation = (TestMIStreamSettings::Modulation) intval;
161  }
162 
163  d.readS32(22 + 30*i, &m_streams[i].m_modulationTone, 44);
164  d.readS32(23 + 30*i, &m_streams[i].m_amModulation, 50);
165  d.readS32(24 + 30*i, &m_streams[i].m_fmDeviation, 50);
166  }
167 
168  return true;
169  }
170  else
171  {
172  resetToDefaults();
173  return false;
174  }
175 }
176 
177 
178 
179 
180 
181 
QString m_reverseAPIAddress
int m_modulationTone
10&#39;Hz
QByteArray serialize() const
int m_fmDeviation
100&#39;Hz
bool readFloat(quint32 id, float *result, float def=0) const
uint16_t m_reverseAPIPort
void writeFloat(quint32 id, float value)
float m_iFactor
-1.0 < x < 1.0
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
unsigned int uint32_t
Definition: rtptypes_win.h:46
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
int32_t i
Definition: decimators.h:244
uint16_t m_reverseAPIDeviceIndex
float m_dcFactor
-1.0 < x < 1.0
std::vector< TestMIStreamSettings > m_streams
bool deserialize(const QByteArray &data)
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
float m_phaseImbalance
-1.0 < x < 1.0
void writeU32(quint32 id, quint32 value)
float m_qFactor
-1.0 < x < 1.0
void writeBool(quint32 id, bool value)
AutoCorrOptions m_autoCorrOptions
void writeString(quint32 id, const QString &value)
const QByteArray & final()
QString m_fileRecordName
int m_amModulation
percent