2014-05-18 11:52:39 -04:00
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
#include "settings/preset.h"
|
|
|
|
|
2015-08-09 04:33:04 -04:00
|
|
|
#include <QDebug>
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
Preset::Preset()
|
|
|
|
{
|
|
|
|
resetToDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preset::resetToDefaults()
|
|
|
|
{
|
|
|
|
m_group = "default";
|
|
|
|
m_description = "no name";
|
|
|
|
m_centerFrequency = 0;
|
|
|
|
m_spectrumConfig.clear();
|
|
|
|
m_layout.clear();
|
|
|
|
m_spectrumConfig.clear();
|
|
|
|
m_channelConfigs.clear();
|
2015-09-30 00:57:40 -04:00
|
|
|
m_sourceId.clear();
|
2014-05-18 11:52:39 -04:00
|
|
|
m_sourceConfig.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Preset::serialize() const
|
|
|
|
{
|
2015-09-30 00:57:40 -04:00
|
|
|
qDebug() << "Preset::serialize (" << this->getSourceId().toStdString().c_str() << ")";
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
SimpleSerializer s(1);
|
|
|
|
s.writeString(1, m_group);
|
|
|
|
s.writeString(2, m_description);
|
|
|
|
s.writeU64(3, m_centerFrequency);
|
2015-09-29 21:46:46 -04:00
|
|
|
s.writeBlob(4, m_layout);
|
|
|
|
s.writeBlob(5, m_spectrumConfig);
|
2015-09-30 00:57:40 -04:00
|
|
|
s.writeString(6, m_sourceId);
|
2015-09-29 22:39:09 -04:00
|
|
|
s.writeBlob(7, m_sourceConfig);
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-06-06 21:30:28 -04:00
|
|
|
s.writeS32(200, m_channelConfigs.size());
|
|
|
|
|
2015-08-09 05:11:28 -04:00
|
|
|
qDebug() << " m_group: " << m_group.toStdString().c_str();
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
for(int i = 0; i < m_channelConfigs.size(); i++) {
|
2015-06-06 21:30:28 -04:00
|
|
|
s.writeString(201 + i * 2, m_channelConfigs[i].m_channel);
|
|
|
|
s.writeBlob(202 + i * 2, m_channelConfigs[i].m_config);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return s.final();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Preset::deserialize(const QByteArray& data)
|
|
|
|
{
|
2015-09-30 00:57:40 -04:00
|
|
|
qDebug() << "Preset::deserialize (" << this->getSourceId().toStdString().c_str() << ")";
|
2014-05-18 11:52:39 -04:00
|
|
|
SimpleDeserializer d(data);
|
|
|
|
|
|
|
|
if(!d.isValid()) {
|
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d.getVersion() == 1) {
|
|
|
|
d.readString(1, &m_group, "default");
|
|
|
|
d.readString(2, &m_description, "no name");
|
|
|
|
d.readU64(3, &m_centerFrequency, 0);
|
2015-09-29 21:46:46 -04:00
|
|
|
d.readBlob(4, &m_layout);
|
|
|
|
d.readBlob(5, &m_spectrumConfig);
|
2015-09-30 00:57:40 -04:00
|
|
|
d.readString(6, &m_sourceId);
|
2015-09-29 22:39:09 -04:00
|
|
|
d.readBlob(7, &m_sourceConfig);
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-09-29 22:39:09 -04:00
|
|
|
qDebug() << "Preset::deserialize: m_group: " << m_group.toStdString().c_str();
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
qint32 channelCount = 0;
|
2015-06-06 21:30:28 -04:00
|
|
|
d.readS32(200, &channelCount, 0);
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
for(int i = 0; i < channelCount; i++) {
|
|
|
|
QString channel;
|
|
|
|
QByteArray config;
|
2015-06-06 21:30:28 -04:00
|
|
|
d.readString(201 + i * 2, &channel, "unknown-channel");
|
|
|
|
d.readBlob(202 + i * 2, &config);
|
2014-05-18 11:52:39 -04:00
|
|
|
m_channelConfigs.append(ChannelConfig(channel, config));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|