1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-03 15:31:15 -05:00
sdrangel/plugins/channeltx/daemonsource/daemonsourcesettings.cpp

82 lines
2.5 KiB
C++
Raw Normal View History

2018-08-31 17:29:53 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QColor>
#include "util/simpleserializer.h"
#include "settings/serializable.h"
2018-09-11 10:50:55 -04:00
#include "daemonsourcesettings.h"
2018-08-31 17:29:53 -04:00
2018-09-11 10:32:14 -04:00
DaemonSourceSettings::DaemonSourceSettings()
2018-08-31 17:29:53 -04:00
{
resetToDefaults();
}
2018-09-11 10:32:14 -04:00
void DaemonSourceSettings::resetToDefaults()
2018-08-31 17:29:53 -04:00
{
m_dataAddress = "127.0.0.1";
m_dataPort = 9090;
2018-08-31 18:18:35 -04:00
m_rgbColor = QColor(140, 4, 4).rgb();
m_title = "Daemon source";
2018-08-31 17:29:53 -04:00
}
2018-09-11 10:32:14 -04:00
QByteArray DaemonSourceSettings::serialize() const
2018-08-31 17:29:53 -04:00
{
SimpleSerializer s(1);
s.writeString(1, m_dataAddress);
s.writeU32(2, m_dataPort);
s.writeU32(3, m_rgbColor);
s.writeString(4, m_title);
return s.final();
}
2018-09-11 10:32:14 -04:00
bool DaemonSourceSettings::deserialize(const QByteArray& data)
2018-08-31 17:29:53 -04:00
{
SimpleDeserializer d(data);
if(!d.isValid())
{
resetToDefaults();
return false;
}
if(d.getVersion() == 1)
{
uint32_t tmp;
QString strtmp;
d.readString(1, &m_dataAddress, "127.0.0.1");
d.readU32(2, &tmp, 0);
if ((tmp > 1023) && (tmp < 65535)) {
m_dataPort = tmp;
} else {
m_dataPort = 9090;
}
d.readU32(3, &m_rgbColor, QColor(0, 255, 255).rgb());
2018-09-05 02:44:14 -04:00
d.readString(4, &m_title, "Daemon source");
2018-08-31 17:29:53 -04:00
return true;
}
else
{
resetToDefaults();
return false;
}
}