sdrangel/sdrbase/device/deviceuserargs.cpp

84 wiersze
2.6 KiB
C++
Czysty Zwykły widok Historia

2019-06-12 06:39:25 +00:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019 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 //
// (at your option) any later version. //
// //
// 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 <QDataStream>
#include "util/simpleserializer.h"
2019-06-12 16:50:53 +00:00
#include "deviceuserargs.h"
2019-06-12 06:39:25 +00:00
2019-06-12 16:50:53 +00:00
QByteArray DeviceUserArgs::serialize() const
2019-06-12 06:39:25 +00:00
{
SimpleSerializer s(1);
QByteArray data;
QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
2019-06-12 16:50:53 +00:00
*stream << m_argsByDevice;
2019-06-12 06:39:25 +00:00
s.writeBlob(1, data);
return s.final();
}
2019-06-12 16:50:53 +00:00
bool DeviceUserArgs::deserialize(const QByteArray& data)
2019-06-12 06:39:25 +00:00
{
SimpleDeserializer d(data);
if (!d.isValid()) {
return false;
}
if(d.getVersion() == 1)
{
QByteArray data;
d.readBlob(1, &data);
QDataStream readStream(&data, QIODevice::ReadOnly);
2019-06-12 16:50:53 +00:00
readStream >> m_argsByDevice;
2019-06-12 06:39:25 +00:00
return true;
}
else
{
return false;
}
}
2019-06-12 16:50:53 +00:00
void DeviceUserArgs::splitDeviceKey(const QString& key, QString& id, int& sequence)
2019-06-12 06:39:25 +00:00
{
QStringList elms = key.split('-');
if (elms.size() > 0) {
2019-06-12 16:50:53 +00:00
id = elms[0];
2019-06-12 06:39:25 +00:00
}
if (elms.size() > 1)
{
bool ok;
QString seqStr = elms[1];
int seq = seqStr.toInt(&ok);
if (ok) {
sequence = seq;
}
}
}
2019-06-12 16:50:53 +00:00
void DeviceUserArgs::composeDeviceKey(const QString& id, int sequence, QString& key)
2019-06-12 06:39:25 +00:00
{
QStringList strList;
2019-06-12 16:50:53 +00:00
strList.append(id);
2019-06-12 06:39:25 +00:00
strList.append(QString::number(sequence));
key = strList.join('-');
}