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.
filesourcesettings.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 "filesourcesettings.h"
19 
20 #include <QColor>
21 
22 #include "util/simpleserializer.h"
23 #include "settings/serializable.h"
24 
25 
27 {
29 }
30 
32 {
33  m_fileName = "test.sdriq";
34  m_loop = false;
35  m_log2Interp = 0;
37  m_gainDB = 0;
38  m_rgbColor = QColor(140, 4, 4).rgb();
39  m_title = "File source";
40  m_channelMarker = nullptr;
41  m_useReverseAPI = false;
42  m_reverseAPIAddress = "127.0.0.1";
43  m_reverseAPIPort = 8888;
46 }
47 
49 {
50  SimpleSerializer s(1);
51  s.writeString(1, m_fileName);
52  s.writeBool(2, m_loop);
53  s.writeU32(3, m_log2Interp);
55  s.writeS32(5, m_gainDB);
56  s.writeU32(6, m_rgbColor);
57  s.writeString(7, m_title);
63 
64  return s.final();
65 }
66 
67 bool FileSourceSettings::deserialize(const QByteArray& data)
68 {
69  SimpleDeserializer d(data);
70 
71  if(!d.isValid())
72  {
74  return false;
75  }
76 
77  if(d.getVersion() == 1)
78  {
79  uint32_t tmp;
80  int itmp;
81  QString strtmp;
82 
83  d.readString(1, &m_fileName, "test.sdriq");
84  d.readBool(2, &m_loop, false);
85  d.readU32(3, &tmp, 0);
86  m_log2Interp = tmp > 6 ? 6 : tmp;
87  d.readU32(4, &m_filterChainHash, 0);
88  d.readS32(5, &itmp, 20);
89  m_gainDB = itmp < -10 ? -10 : itmp > 50 ? 50 : itmp;
90  d.readU32(5, &m_rgbColor, QColor(140, 4, 4).rgb());
91  d.readString(6, &m_title, "File source");
92  d.readBool(7, &m_useReverseAPI, false);
93  d.readString(8, &m_reverseAPIAddress, "127.0.0.1");
94  d.readU32(9, &tmp, 0);
95 
96  if ((tmp > 1023) && (tmp < 65535)) {
97  m_reverseAPIPort = tmp;
98  } else {
99  m_reverseAPIPort = 8888;
100  }
101 
102  d.readU32(10, &tmp, 0);
103  m_reverseAPIDeviceIndex = tmp > 99 ? 99 : tmp;
104  d.readU32(11, &tmp, 0);
105  m_reverseAPIChannelIndex = tmp > 99 ? 99 : tmp;
106 
107  return true;
108  }
109  else
110  {
111  resetToDefaults();
112  return false;
113  }
114 }
bool deserialize(const QByteArray &data)
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
QByteArray serialize() const
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
void writeS32(quint32 id, qint32 value)
uint16_t m_reverseAPIChannelIndex
quint32 getVersion() const
uint16_t m_reverseAPIDeviceIndex
void writeU32(quint32 id, quint32 value)
void writeBool(quint32 id, bool value)
Serializable * m_channelMarker
void writeString(quint32 id, const QString &value)
const QByteArray & final()