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.
remotesourcesettings.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018-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 "remotesourcesettings.h"
19 
20 #include <QColor>
21 
22 #include "util/simpleserializer.h"
23 #include "settings/serializable.h"
24 
25 
27 {
29 }
30 
32 {
33  m_dataAddress = "127.0.0.1";
34  m_dataPort = 9090;
35  m_rgbColor = QColor(140, 4, 4).rgb();
36  m_title = "Remote source";
37  m_channelMarker = nullptr;
38  m_useReverseAPI = false;
39  m_reverseAPIAddress = "127.0.0.1";
40  m_reverseAPIPort = 8888;
43 }
44 
46 {
47  SimpleSerializer s(1);
49  s.writeU32(2, m_dataPort);
50  s.writeU32(3, m_rgbColor);
51  s.writeString(4, m_title);
57 
58  return s.final();
59 }
60 
61 bool RemoteSourceSettings::deserialize(const QByteArray& data)
62 {
63  SimpleDeserializer d(data);
64 
65  if(!d.isValid())
66  {
68  return false;
69  }
70 
71  if(d.getVersion() == 1)
72  {
73  uint32_t tmp;
74  QString strtmp;
75 
76  d.readString(1, &m_dataAddress, "127.0.0.1");
77  d.readU32(2, &tmp, 0);
78 
79  if ((tmp > 1023) && (tmp < 65535)) {
80  m_dataPort = tmp;
81  } else {
82  m_dataPort = 9090;
83  }
84 
85  d.readU32(3, &m_rgbColor, QColor(0, 255, 255).rgb());
86  d.readString(4, &m_title, "Remote source");
87  d.readBool(5, &m_useReverseAPI, false);
88  d.readString(6, &m_reverseAPIAddress, "127.0.0.1");
89  d.readU32(7, &tmp, 0);
90 
91  if ((tmp > 1023) && (tmp < 65535)) {
92  m_reverseAPIPort = tmp;
93  } else {
94  m_reverseAPIPort = 8888;
95  }
96 
97  d.readU32(8, &tmp, 0);
98  m_reverseAPIDeviceIndex = tmp > 99 ? 99 : tmp;
99  d.readU32(9, &tmp, 0);
100  m_reverseAPIChannelIndex = tmp > 99 ? 99 : tmp;
101  return true;
102  }
103  else
104  {
105  resetToDefaults();
106  return false;
107  }
108 }
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
uint16_t m_dataPort
Listening data port.
QString m_dataAddress
Listening (local) data address.
quint32 getVersion() const
QByteArray serialize() const
void writeU32(quint32 id, quint32 value)
void writeBool(quint32 id, bool value)
void writeString(quint32 id, const QString &value)
const QByteArray & final()
Serializable * m_channelMarker