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.
datvdemodsettings.cpp
Go to the documentation of this file.
1 // Copyright (C) 2019 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 #include <QDebug>
20 
21 #include "dsp/dspengine.h"
22 #include "util/simpleserializer.h"
23 #include "settings/serializable.h"
24 
25 #include "datvdemodsettings.h"
26 
28  m_channelMarker(0)
29 {
31 }
32 
34 {
35  m_rgbColor = QColor(Qt::magenta).rgb();
36  m_title = "DATV Demodulator";
37  m_rfBandwidth = 512000;
39  m_standard = DVB_S;
41  m_fec = FEC12;
42  m_symbolRate = 250000;
43  m_notchFilters = 0;
44  m_allowDrift = false;
45  m_fastLock = false;
47  m_hardMetric = false;
48  m_rollOff = 0.35;
49  m_viterbi = false;
50  m_excursion = 10;
51  m_audioMute = false;
53  m_audioVolume = 0;
54  m_videoMute = false;
55  m_udpTSAddress = "127.0.0.1";
56  m_udpTSPort = 8882;
57  m_udpTS = false;
58 }
59 
60 QByteArray DATVDemodSettings::serialize() const
61 {
62  SimpleSerializer s(1);
63  s.writeS32(2, m_rfBandwidth);
65  s.writeS32(4, (int) m_standard);
66  s.writeS32(5, (int) m_modulation);
67 
68  if (m_channelMarker) {
70  }
71 
72  s.writeU32(7, m_rgbColor);
73  s.writeString(8, m_title);
74  s.writeS32(9, (int) m_fec);
75  s.writeBool(10, m_audioMute);
76  s.writeS32(11, m_symbolRate);
77  s.writeS32(12, m_notchFilters);
78  s.writeBool(13, m_allowDrift);
79  s.writeBool(14, m_fastLock);
80  s.writeS32(15, (int) m_filter);
81  s.writeBool(16, m_hardMetric);
82  s.writeFloat(17, m_rollOff);
83  s.writeBool(18, m_viterbi);
84  s.writeS32(19, m_excursion);
86  s.writeS32(21, m_audioVolume);
87  s.writeBool(22, m_videoMute);
89  s.writeU32(24, m_udpTSPort);
90  s.writeBool(25, m_udpTS);
91 
92  return s.final();
93 }
94 
95 bool DATVDemodSettings::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  quint32 utmp;
110  QString strtmp;
111 
112  d.readS32(2, &m_rfBandwidth, 512000);
113  d.readS32(3, &m_centerFrequency, 0);
114 
115  d.readS32(4, &tmp, (int) DVB_S);
116  tmp = tmp < 0 ? 0 : tmp > (int) DVB_S2 ? (int) DVB_S2 : tmp;
117  m_standard = (dvb_version) tmp;
118 
119  d.readS32(5, &tmp, (int) BPSK);
120  tmp = tmp < 0 ? 0 : tmp >= (int) MOD_UNSET ? (int) MOD_UNSET - 1 : tmp;
122 
123  d.readBlob(6, &bytetmp);
124 
125  if (m_channelMarker) {
126  m_channelMarker->deserialize(bytetmp);
127  }
128 
129  d.readU32(7, &m_rgbColor, QColor(Qt::magenta).rgb());
130  d.readString(8, &m_title, "DATV Demodulator");
131 
132  d.readS32(9, &tmp, (int) FEC12);
133  tmp = tmp < 0 ? 0 : tmp >= (int) RATE_UNSET ? (int) RATE_UNSET - 1 : tmp;
134  m_fec = (DATVCodeRate) tmp;
135 
136  d.readBool(10, &m_audioMute, false);
137  d.readS32(11, &m_symbolRate, 250000);
138  d.readS32(12, &m_notchFilters, 0);
139  d.readBool(13, &m_allowDrift, false);
140  d.readBool(14, &m_fastLock, false);
141 
142  d.readS32(15, &tmp, (int) SAMP_LINEAR);
143  tmp = tmp < 0 ? 0 : tmp > (int) SAMP_RRC ? (int) SAMP_RRC : tmp;
144  m_filter = (dvb_sampler) tmp;
145 
146  d.readBool(16, &m_hardMetric, false);
147  d.readFloat(17, &m_rollOff, 0.35);
148  d.readBool(18, &m_viterbi, false);
149  d.readS32(19, &m_excursion, 10);
151  d.readS32(21, &m_audioVolume, 0);
152  d.readBool(22, &m_videoMute, false);
153  d.readString(23, &m_udpTSAddress, "127.0.0.1");
154  d.readU32(24, &utmp, 8882);
155  m_udpTSPort = utmp < 1024 ? 1024 : utmp > 65536 ? 65535 : utmp;
156  d.readBool(25, &m_udpTS, false);
157 
159 
160  return true;
161  }
162  else
163  {
164  resetToDefaults();
165  return false;
166  }
167 }
168 
169 void DATVDemodSettings::debug(const QString& msg) const
170 {
171  qDebug() << msg
172  << " m_standard: " << m_standard
173  << " m_allowDrift: " << m_allowDrift
174  << " m_rfBandwidth: " << m_rfBandwidth
175  << " m_centerFrequency: " << m_centerFrequency
176  << " m_fastLock: " << m_fastLock
177  << " m_hardMetric: " << m_hardMetric
178  << " m_filter: " << m_filter
179  << " m_rollOff: " << m_rollOff
180  << " m_viterbi: " << m_viterbi
181  << " m_fec: " << m_fec
182  << " m_modulation: " << m_modulation
183  << " m_standard: " << m_standard
184  << " m_notchFilters: " << m_notchFilters
185  << " m_symbolRate: " << m_symbolRate
186  << " m_excursion: " << m_excursion
187  << " m_audioMute: " << m_audioMute
188  << " m_audioDeviceName: " << m_audioDeviceName
189  << " m_audioVolume: " << m_audioVolume
190  << " m_videoMute: " << m_videoMute;
191 }
192 
194 {
195  return ((m_allowDrift != other.m_allowDrift)
196  || (m_fastLock != other.m_fastLock)
197  || (m_hardMetric != other.m_hardMetric)
198  || (m_filter != other.m_filter)
199  || (m_rollOff != other.m_rollOff)
200  || (m_viterbi != other.m_viterbi)
201  || (m_fec != other.m_fec)
202  || (m_modulation != other.m_modulation)
203  || (m_standard != other.m_standard)
204  || (m_notchFilters != other.m_notchFilters)
205  || (m_symbolRate != other.m_symbolRate)
206  || (m_excursion != other.m_excursion)
207  || (m_standard != other.m_standard));
208 }
209 
211 {
212  qDebug("DATVDemodSettings::validateSystemConfiguration: m_standard: %d m_modulation: %d m_fec: %d",
213  (int) m_standard, (int) m_modulation, (int) m_fec);
214 
215  if (m_standard == DVB_S)
216  {
217  // The ETSI standard for DVB-S specify only QPSK (EN 300 421) with a later extension to BPSK (TR 101 198)
218  // but amateur radio also use extra modes thus only the modes very specific to DVB-S2(X) are restricted
219  if ((m_modulation == APSK16) || (m_modulation == APSK32) || (m_modulation == APSK64E))
220  {
221  m_modulation = QPSK; // Fall back to QPSK
222  }
223  // Here we follow ETSI standard for DVB-S retaining only the valod code rates
224  if ((m_fec != FEC12) && (m_fec!= FEC23) && (m_fec!= FEC34) && (m_fec!= FEC56) && (m_fec!= FEC78)) {
225  m_fec = FEC12;
226  }
227  }
228  else if (m_standard == DVB_S2)
229  {
230  // Here we try to follow ETSI standard for DVB-S2 (EN 300 307 1) and DVB-S2X (EN 302 307 2) together for the available modes
231  if ((m_modulation == BPSK) || (m_modulation == QAM16) || (m_modulation == QAM64) || (m_modulation == QAM256))
232  {
233  m_modulation = QPSK; // Fall back to QPSK
234  }
235  // Here we also try to follow ETSI standard depending on the modulation (EN 300 307 1 Table 1)
236  if (m_modulation == QPSK)
237  {
238  if ((m_fec != FEC14) && (m_fec != FEC13) && (m_fec != FEC25)
239  && (m_fec != FEC12) && (m_fec != FEC35) && (m_fec != FEC23)
240  && (m_fec != FEC34) && (m_fec != FEC45) && (m_fec != FEC56)
241  && (m_fec != FEC89) && (m_fec != FEC910)) {
242  m_fec = FEC12;
243  }
244  }
245  else if (m_modulation == PSK8)
246  {
247  if ((m_fec != FEC35) && (m_fec != FEC23) && (m_fec != FEC34)
248  && (m_fec != FEC56) && (m_fec != FEC89) && (m_fec != FEC910)) {
249  m_fec = FEC34;
250  }
251  }
252  else if (m_modulation == APSK16)
253  {
254  if ((m_fec != FEC23) && (m_fec != FEC34) && (m_fec != FEC45)
255  && (m_fec != FEC56) && (m_fec != FEC89) && (m_fec != FEC910)) {
256  m_fec = FEC34;
257  }
258  }
259  else if (m_modulation == APSK32)
260  {
261  if ((m_fec != FEC34) && (m_fec != FEC45) && (m_fec != FEC56)
262  && (m_fec != FEC89) && (m_fec != FEC910)) {
263  m_fec = FEC34;
264  }
265  }
266  // DVB-S2X has many mode code rates but here we deal only with the ones available
267  else if (m_modulation == APSK64E)
268  {
269  if ((m_fec != FEC45) && (m_fec != FEC56)) {
270  m_fec = FEC45;
271  }
272  }
273  }
274 }
275 
277 {
278  if (str == "BPSK") {
279  return BPSK;
280  } else if (str == "QPSK") {
281  return QPSK;
282  } else if (str == "PSK8") {
283  return PSK8;
284  } else if (str == "APSK16") {
285  return APSK16;
286  } else if (str == "APSK32") {
287  return APSK32;
288  } else if (str == "APSK64E") {
289  return APSK64E;
290  } else if (str == "QAM16") {
291  return QAM16;
292  } else if (str == "QAM64") {
293  return QAM64;
294  } else if (str == "QAM256") {
295  return QAM256;
296  } else {
297  return MOD_UNSET;
298  }
299 
300 }
301 
303 {
304  if (str == "1/4") {
305  return FEC14;
306  } else if (str == "1/3") {
307  return FEC13;
308  } else if (str == "2/5") {
309  return FEC25;
310  } else if (str == "1/2") {
311  return FEC12;
312  } else if (str == "3/5") {
313  return FEC35;
314  } else if (str == "2/3") {
315  return FEC23;
316  } else if (str == "3/4") {
317  return FEC34;
318  } else if (str == "4/5") {
319  return FEC45;
320  } else if (str == "5/6") {
321  return FEC56;
322  } else if (str == "7/8") {
323  return FEC78;
324  } else if (str == "8/9") {
325  return FEC89;
326  } else if (str == "9/10") {
327  return FEC910;
328  } else {
329  return RATE_UNSET;
330  }
331 }
332 
334 {
335  if (modulation == BPSK) {
336  return "BPSK";
337  } else if (modulation == QPSK) {
338  return "QPSK";
339  } else if (modulation == PSK8) {
340  return "PSK8";
341  } else if (modulation == APSK16) {
342  return "APSK16";
343  } else if (modulation == APSK32) {
344  return "APSK32";
345  } else if (modulation == APSK64E) {
346  return "APSK64E";
347  } else if (modulation == QAM16) {
348  return "QAM16";
349  } else if (modulation == QAM64) {
350  return "QAM64";
351  } else if (modulation == QAM256) {
352  return "QAM256";
353  } else {
354  return "N/A";
355  }
356 }
357 
359 {
360  if (codeRate == FEC14) {
361  return "1/4";
362  } else if (codeRate == FEC13) {
363  return "1/3";
364  } else if (codeRate == FEC25) {
365  return "2/5";
366  } else if (codeRate == FEC12) {
367  return "1/2";
368  } else if (codeRate == FEC35) {
369  return "3/5";
370  } else if (codeRate == FEC23) {
371  return "2/3";
372  } else if (codeRate == FEC34) {
373  return "3/4";
374  } else if (codeRate == FEC45) {
375  return "4/5";
376  } else if (codeRate == FEC56) {
377  return "5/6";
378  } else if (codeRate == FEC78) {
379  return "7/8";
380  } else if (codeRate == FEC89) {
381  return "8/9";
382  } else if (codeRate == FEC910) {
383  return "9/10";
384  } else {
385  return "N/A";
386  }
387 }
388 
389 void DATVDemodSettings::getAvailableModulations(dvb_version dvbStandard, std::vector<DATVModulation>& modulations)
390 {
391  modulations.clear();
392 
393  if (dvbStandard == DVB_S)
394  {
395  modulations.push_back(BPSK);
396  modulations.push_back(QPSK);
397  modulations.push_back(PSK8);
398  modulations.push_back(QAM16);
399  modulations.push_back(QAM64);
400  modulations.push_back(QAM256);
401  }
402  else if (dvbStandard == DVB_S2)
403  {
404  modulations.push_back(QPSK);
405  modulations.push_back(PSK8);
406  modulations.push_back(APSK16);
407  modulations.push_back(APSK32);
408  modulations.push_back(APSK64E);
409  }
410 }
411 
412 void DATVDemodSettings::getAvailableCodeRates(dvb_version dvbStandard, DATVModulation modulation, std::vector<DATVCodeRate>& codeRates)
413 {
414  codeRates.clear();
415 
416  if (dvbStandard == DVB_S)
417  {
418  codeRates.push_back(FEC12);
419  codeRates.push_back(FEC23);
420  codeRates.push_back(FEC34);
421  codeRates.push_back(FEC56);
422  codeRates.push_back(FEC78);
423  }
424  else if (dvbStandard == DVB_S2)
425  {
426  if (modulation == QPSK)
427  {
428  codeRates.push_back(FEC14);
429  codeRates.push_back(FEC13);
430  codeRates.push_back(FEC25);
431  codeRates.push_back(FEC12);
432  }
433  if ((modulation == QPSK) || (modulation == PSK8))
434  {
435  codeRates.push_back(FEC35);
436  }
437  if ((modulation == QPSK) || (modulation == PSK8) || (modulation == APSK16))
438  {
439  codeRates.push_back(FEC23);
440  }
441  if ((modulation == QPSK) || (modulation == PSK8) || (modulation == APSK16) || (modulation == APSK32))
442  {
443  codeRates.push_back(FEC34);
444  }
445  if ((modulation == QPSK) || (modulation == APSK16) || (modulation == APSK32) || (modulation == APSK64E))
446  {
447  codeRates.push_back(FEC45);
448  }
449  if ((modulation == QPSK) || (modulation == PSK8) || (modulation == APSK16) || (modulation == APSK32) || (modulation == APSK64E))
450  {
451  codeRates.push_back(FEC56);
452  }
453  if ((modulation == QPSK) || (modulation == PSK8) || (modulation == APSK16) || (modulation == APSK32))
454  {
455  codeRates.push_back(FEC89);
456  codeRates.push_back(FEC910);
457  }
458  }
459 }
static QString getStrFromCodeRate(const DATVCodeRate codeRate)
bool isDifferent(const DATVDemodSettings &other)
static const QString m_defaultDeviceName
static DATVModulation getModulationFromStr(const QString &str)
bool readFloat(quint32 id, float *result, float def=0) const
static void getAvailableModulations(dvb_version dvbStandard, std::vector< DATVModulation > &modulations)
DATVModulation m_modulation
void writeFloat(quint32 id, float value)
void writeBlob(quint32 id, const QByteArray &value)
QByteArray serialize() const
void debug(const QString &msg) const
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
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
bool readBlob(quint32 id, QByteArray *result, const QByteArray &def=QByteArray()) const
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
virtual bool deserialize(const QByteArray &data)=0
void writeU32(quint32 id, quint32 value)
Serializable * m_channelMarker
virtual QByteArray serialize() const =0
void writeBool(quint32 id, bool value)
static DATVCodeRate getCodeRateFromStr(const QString &str)
bool deserialize(const QByteArray &data)
void writeString(quint32 id, const QString &value)
static void getAvailableCodeRates(dvb_version dvbStandard, DATVModulation modulation, std::vector< DATVCodeRate > &codeRates)
dvb_version m_standard
const QByteArray & final()
static QString getStrFromModulation(const DATVModulation modulation)