1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-15 12:51:49 -05:00

Channel marker own serializer/deserializer

This commit is contained in:
f4exb 2017-08-26 09:58:07 +02:00
parent a464ccd2cd
commit b2337e44dd
3 changed files with 86 additions and 4 deletions

View File

@ -88,10 +88,7 @@ QByteArray AMDemodGUI::serialize() const
s.writeS32(5, ui->squelch->value()); s.writeS32(5, ui->squelch->value());
s.writeU32(7, m_channelMarker.getColor().rgb()); s.writeU32(7, m_channelMarker.getColor().rgb());
s.writeBool(8, ui->bandpassEnable->isChecked()); s.writeBool(8, ui->bandpassEnable->isChecked());
s.writeString(9, m_channelMarker.getTitle()); s.writeBlob(9, m_channelMarker.serialize());
s.writeString(10, m_channelMarker.getUDPAddress());
s.writeU32(11, (quint32) m_channelMarker.getUDPReceivePort());
s.writeU32(12, (quint32) m_channelMarker.getUDPSendPort());
return s.final(); return s.final();
} }
@ -116,6 +113,8 @@ bool AMDemodGUI::deserialize(const QByteArray& data)
blockApplySettings(true); blockApplySettings(true);
m_channelMarker.blockSignals(true); m_channelMarker.blockSignals(true);
d.readBlob(9, &bytetmp);
m_channelMarker.deserialize(bytetmp);
d.readS32(1, &tmp, 0); d.readS32(1, &tmp, 0);
m_channelMarker.setCenterFrequency(tmp); m_channelMarker.setCenterFrequency(tmp);
d.readS32(2, &tmp, 4); d.readS32(2, &tmp, 4);

View File

@ -1,4 +1,5 @@
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "util/simpleserializer.h"
QRgb ChannelMarker::m_colorTable[] = { QRgb ChannelMarker::m_colorTable[] = {
qRgb(0xc0, 0x00, 0x00), qRgb(0xc0, 0x00, 0x00),
@ -121,3 +122,77 @@ void ChannelMarker::setUDPSendPort(quint16 port)
m_displayAddressSend = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPSendPort())); m_displayAddressSend = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPSendPort()));
emit changed(); emit changed();
} }
void ChannelMarker::resetToDefaults()
{
setTitle("Channel");
setCenterFrequency(0);
setColor(Qt::white);
setUDPAddress("127.0.0.1");
setUDPSendPort(9999);
setUDPReceivePort(9999);
setFrequencyScaleDisplayType(FScaleDisplay_freq);
}
QByteArray ChannelMarker::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, getCenterFrequency());
s.writeU32(2, getColor().rgb());
s.writeString(3, getTitle());
s.writeString(4, getUDPAddress());
s.writeU32(5, (quint32) getUDPReceivePort());
s.writeU32(6, (quint32) getUDPSendPort());
s.writeS32(7, (int) getFrequencyScaleDisplayType());
return s.final();
}
bool ChannelMarker::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if(!d.isValid())
{
resetToDefaults();
return false;
}
if(d.getVersion() == 1)
{
quint32 u32tmp;
qint32 tmp;
QString strtmp;
blockSignals(true);
d.readS32(1, &tmp, 0);
setCenterFrequency(tmp);
if(d.readU32(2, &u32tmp)) {
setColor(u32tmp);
}
d.readString(3, &strtmp, "Channel");
setTitle(strtmp);
d.readString(4, &strtmp, "127.0.0.1");
setUDPAddress(strtmp);
d.readU32(5, &u32tmp, 9999);
setUDPReceivePort(u32tmp);
d.readU32(6, &u32tmp, 9999);
setUDPSendPort(u32tmp);
d.readS32(7, &tmp, 0);
if ((tmp >= 0) || (tmp < FScaleDisplay_none)) {
setFrequencyScaleDisplayType((frequencyScaleDisplay_t) tmp);
} else {
setFrequencyScaleDisplayType(FScaleDisplay_freq);
}
blockSignals(false);
return true;
}
else
{
resetToDefaults();
return false;
}
}

View File

@ -3,6 +3,8 @@
#include <QObject> #include <QObject>
#include <QColor> #include <QColor>
#include <QByteArray>
#include "util/export.h" #include "util/export.h"
class SDRANGEL_API ChannelMarker : public QObject { class SDRANGEL_API ChannelMarker : public QObject {
@ -24,6 +26,7 @@ public:
FScaleDisplay_title, FScaleDisplay_title,
FScaleDisplay_addressSend, FScaleDisplay_addressSend,
FScaleDisplay_addressReceive, FScaleDisplay_addressReceive,
FScaleDisplay_none
} frequencyScaleDisplay_t; } frequencyScaleDisplay_t;
ChannelMarker(QObject* parent = NULL); ChannelMarker(QObject* parent = NULL);
@ -73,6 +76,9 @@ public:
const QString& getDisplayAddressSend() const { return m_displayAddressSend; } const QString& getDisplayAddressSend() const { return m_displayAddressSend; }
const QString& getDisplayAddressReceive() const { return m_displayAddressReceive; } const QString& getDisplayAddressReceive() const { return m_displayAddressReceive; }
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
protected: protected:
static QRgb m_colorTable[]; static QRgb m_colorTable[];
static int m_nextColor; static int m_nextColor;
@ -94,6 +100,8 @@ protected:
quint16 m_udpSendPort; quint16 m_udpSendPort;
frequencyScaleDisplay_t m_fScaleDisplayType; frequencyScaleDisplay_t m_fScaleDisplayType;
void resetToDefaults();
signals: signals:
void changed(); void changed();
}; };