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.
freedvmodsettings.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 <QColor>
19 
20 #include "dsp/dspengine.h"
21 #include "util/simpleserializer.h"
22 #include "settings/serializable.h"
23 #include "freedvmodsettings.h"
24 
26  m_channelMarker(0),
27  m_spectrumGUI(0),
28  m_cwKeyerGUI(0)
29 {
31 }
32 
34 {
36  m_toneFrequency = 1000.0;
37  m_volumeFactor = 1.0;
38  m_spanLog2 = 3;
39  m_audioMute = false;
40  m_playLoop = false;
41  m_rgbColor = QColor(0, 255, 204).rgb();
42  m_title = "FreeDV Modulator";
43  m_modAFInput = FreeDVModInputAF::FreeDVModInputNone;
45  m_freeDVMode = FreeDVMode::FreeDVMode2400A;
46  m_gaugeInputElseModem = false;
47  m_useReverseAPI = false;
48  m_reverseAPIAddress = "127.0.0.1";
49  m_reverseAPIPort = 8888;
52 }
53 
54 QByteArray FreeDVModSettings::serialize() const
55 {
56  SimpleSerializer s(1);
57 
59  s.writeS32(3, roundf(m_toneFrequency / 10.0));
60 
61  if (m_spectrumGUI) {
63  }
64 
65  s.writeU32(5, m_rgbColor);
66 
67  if (m_cwKeyerGUI) {
69  }
70 
72  s.writeS32(8, m_spanLog2);
73  s.writeS32(10, (int) m_freeDVMode);
74 
75  if (m_channelMarker) {
77  }
78 
79  s.writeString(19, m_title);
81  s.writeS32(21, (int) m_modAFInput);
87 
88  return s.final();
89 }
90 
91 bool FreeDVModSettings::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 
107  d.readS32(1, &tmp, 0);
109 
110  d.readS32(3, &tmp, 100);
111  m_toneFrequency = tmp * 10.0;
112 
113  if (m_spectrumGUI)
114  {
115  d.readBlob(4, &bytetmp);
116  m_spectrumGUI->deserialize(bytetmp);
117  }
118 
119  d.readU32(5, &m_rgbColor);
120 
121  if (m_cwKeyerGUI) {
122  d.readBlob(6, &bytetmp);
123  m_cwKeyerGUI->deserialize(bytetmp);
124  }
125 
126  d.readBool(7, &m_gaugeInputElseModem, false);
127  d.readS32(8, &m_spanLog2, 3);
128 
129  d.readS32(10, &tmp, 0);
130  if ((tmp < 0) || (tmp > (int) FreeDVMode::FreeDVMode700D)) {
131  m_freeDVMode = FreeDVMode::FreeDVMode2400A;
132  } else {
133  m_freeDVMode = (FreeDVMode) tmp;
134  }
135 
136  if (m_channelMarker) {
137  d.readBlob(18, &bytetmp);
138  m_channelMarker->deserialize(bytetmp);
139  }
140 
141  d.readString(19, &m_title, "FreeDV Modulator");
143 
144  d.readS32(21, &tmp, 0);
145  if ((tmp < 0) || (tmp > (int) FreeDVModInputAF::FreeDVModInputTone)) {
147  } else {
149  }
150 
151  d.readBool(22, &m_useReverseAPI, false);
152  d.readString(23, &m_reverseAPIAddress, "127.0.0.1");
153  d.readU32(24, &utmp, 0);
154 
155  if ((utmp > 1023) && (utmp < 65535)) {
156  m_reverseAPIPort = utmp;
157  } else {
158  m_reverseAPIPort = 8888;
159  }
160 
161  d.readU32(25, &utmp, 0);
162  m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp;
163  d.readU32(26, &utmp, 0);
164  m_reverseAPIChannelIndex = utmp > 99 ? 99 : utmp;
165 
166  return true;
167  }
168  else
169  {
170  resetToDefaults();
171  return false;
172  }
173 }
174 
176 {
177  switch(freeDVMode)
178  {
179  case FreeDVModSettings::FreeDVMode800XA: // C4FM NB
183  return 2400.0;
184  break;
185  case FreeDVModSettings::FreeDVMode2400A: // C4FM WB
186  default:
187  return 6000.0;
188  break;
189  }
190 }
191 
193 {
194  switch(freeDVMode)
195  {
196  case FreeDVModSettings::FreeDVMode800XA: // C4FM NB
197  return 400.0;
198  break;
202  return 600.0;
203  break;
204  case FreeDVModSettings::FreeDVMode2400A: // C4FM WB
205  default:
206  return 0.0;
207  break;
208  }
209 }
210 
212 {
213  if (freeDVMode == FreeDVModSettings::FreeDVMode2400A) {
214  return 48000;
215  } else {
216  return 8000;
217  }
218 }
static const QString m_defaultDeviceName
uint16_t m_reverseAPIDeviceIndex
Serializable * m_spectrumGUI
QByteArray serialize() const
static int getLowCutoff(FreeDVMode freeDVMode)
void writeBlob(quint32 id, const QByteArray &value)
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
Serializable * m_cwKeyerGUI
Serializable * m_channelMarker
bool m_gaugeInputElseModem
Volume gauge shows speech input level else modem level.
bool readString(quint32 id, QString *result, const QString &def=QString::null) const
bool readBool(quint32 id, bool *result, bool def=false) const
static int getHiCutoff(FreeDVMode freeDVMode)
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
static int getModSampleRate(FreeDVMode freeDVMode)
FreeDVModInputAF m_modAFInput
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
virtual bool deserialize(const QByteArray &data)=0
void writeU32(quint32 id, quint32 value)
bool deserialize(const QByteArray &data)
virtual QByteArray serialize() const =0
void writeBool(quint32 id, bool value)
uint16_t m_reverseAPIChannelIndex
void writeString(quint32 id, const QString &value)
const QByteArray & final()