diff --git a/plugins/channelrx/demodam/amdemodgui.cpp b/plugins/channelrx/demodam/amdemodgui.cpp index c42d1b392..5d138da0e 100644 --- a/plugins/channelrx/demodam/amdemodgui.cpp +++ b/plugins/channelrx/demodam/amdemodgui.cpp @@ -88,10 +88,7 @@ QByteArray AMDemodGUI::serialize() const s.writeS32(5, ui->squelch->value()); s.writeU32(7, m_channelMarker.getColor().rgb()); s.writeBool(8, ui->bandpassEnable->isChecked()); - s.writeString(9, m_channelMarker.getTitle()); - s.writeString(10, m_channelMarker.getUDPAddress()); - s.writeU32(11, (quint32) m_channelMarker.getUDPReceivePort()); - s.writeU32(12, (quint32) m_channelMarker.getUDPSendPort()); + s.writeBlob(9, m_channelMarker.serialize()); return s.final(); } @@ -116,6 +113,8 @@ bool AMDemodGUI::deserialize(const QByteArray& data) blockApplySettings(true); m_channelMarker.blockSignals(true); + d.readBlob(9, &bytetmp); + m_channelMarker.deserialize(bytetmp); d.readS32(1, &tmp, 0); m_channelMarker.setCenterFrequency(tmp); d.readS32(2, &tmp, 4); diff --git a/sdrbase/dsp/channelmarker.cpp b/sdrbase/dsp/channelmarker.cpp index 1a83aceed..0a74aa700 100644 --- a/sdrbase/dsp/channelmarker.cpp +++ b/sdrbase/dsp/channelmarker.cpp @@ -1,4 +1,5 @@ #include "dsp/channelmarker.h" +#include "util/simpleserializer.h" QRgb ChannelMarker::m_colorTable[] = { qRgb(0xc0, 0x00, 0x00), @@ -121,3 +122,77 @@ void ChannelMarker::setUDPSendPort(quint16 port) m_displayAddressSend = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPSendPort())); 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; + } +} + diff --git a/sdrbase/dsp/channelmarker.h b/sdrbase/dsp/channelmarker.h index b3fcb0fab..f64365b5e 100644 --- a/sdrbase/dsp/channelmarker.h +++ b/sdrbase/dsp/channelmarker.h @@ -3,6 +3,8 @@ #include #include +#include + #include "util/export.h" class SDRANGEL_API ChannelMarker : public QObject { @@ -24,6 +26,7 @@ public: FScaleDisplay_title, FScaleDisplay_addressSend, FScaleDisplay_addressReceive, + FScaleDisplay_none } frequencyScaleDisplay_t; ChannelMarker(QObject* parent = NULL); @@ -73,6 +76,9 @@ public: const QString& getDisplayAddressSend() const { return m_displayAddressSend; } const QString& getDisplayAddressReceive() const { return m_displayAddressReceive; } + QByteArray serialize() const; + bool deserialize(const QByteArray& data); + protected: static QRgb m_colorTable[]; static int m_nextColor; @@ -94,6 +100,8 @@ protected: quint16 m_udpSendPort; frequencyScaleDisplay_t m_fScaleDisplayType; + void resetToDefaults(); + signals: void changed(); };