mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-23 00:18:37 -05:00
AM demod: use settings object serialization / deserialization
This commit is contained in:
parent
7159ffff09
commit
7f9b22ccac
@ -68,80 +68,24 @@ void AMDemodGUI::setCenterFrequency(qint64 centerFrequency)
|
||||
|
||||
void AMDemodGUI::resetToDefaults()
|
||||
{
|
||||
blockApplySettings(true);
|
||||
|
||||
ui->rfBW->setValue(50);
|
||||
ui->volume->setValue(20);
|
||||
ui->squelch->setValue(-40);
|
||||
ui->deltaFrequency->setValue(0);
|
||||
|
||||
blockApplySettings(false);
|
||||
applySettings();
|
||||
m_settings.resetToDefaults();
|
||||
displaySettings();
|
||||
applySettings(true);
|
||||
}
|
||||
|
||||
QByteArray AMDemodGUI::serialize() const
|
||||
{
|
||||
SimpleSerializer s(1);
|
||||
s.writeS32(1, m_channelMarker.getCenterFrequency());
|
||||
s.writeS32(2, ui->rfBW->value());
|
||||
s.writeS32(4, ui->volume->value());
|
||||
s.writeS32(5, ui->squelch->value());
|
||||
s.writeBlob(6, m_channelMarker.serialize());
|
||||
s.writeU32(7, m_channelMarker.getColor().rgb());
|
||||
s.writeBool(8, ui->bandpassEnable->isChecked());
|
||||
return s.final();
|
||||
return m_settings.serialize();
|
||||
}
|
||||
|
||||
bool AMDemodGUI::deserialize(const QByteArray& data)
|
||||
{
|
||||
SimpleDeserializer d(data);
|
||||
|
||||
if(!d.isValid())
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(d.getVersion() == 1)
|
||||
{
|
||||
QByteArray bytetmp;
|
||||
quint32 u32tmp;
|
||||
qint32 tmp;
|
||||
bool boolTmp;
|
||||
QString strtmp;
|
||||
|
||||
blockApplySettings(true);
|
||||
m_channelMarker.blockSignals(true);
|
||||
|
||||
d.readBlob(6, &bytetmp);
|
||||
m_channelMarker.deserialize(bytetmp);
|
||||
d.readS32(1, &tmp, 0);
|
||||
m_channelMarker.setCenterFrequency(tmp);
|
||||
d.readS32(2, &tmp, 4);
|
||||
ui->rfBW->setValue(tmp);
|
||||
d.readS32(3, &tmp, 3);
|
||||
//ui->afBW->setValue(tmp);
|
||||
d.readS32(4, &tmp, 20);
|
||||
ui->volume->setValue(tmp);
|
||||
d.readS32(5, &tmp, -40);
|
||||
ui->squelch->setValue(tmp);
|
||||
if(d.readU32(7, &u32tmp)) {
|
||||
m_channelMarker.setColor(u32tmp);
|
||||
}
|
||||
d.readBool(8, &boolTmp, false);
|
||||
ui->bandpassEnable->setChecked(boolTmp);
|
||||
|
||||
this->setWindowTitle(m_channelMarker.getTitle());
|
||||
displayUDPAddress();
|
||||
|
||||
blockApplySettings(false);
|
||||
m_channelMarker.blockSignals(false);
|
||||
|
||||
if(m_settings.deserialize(data)) {
|
||||
updateChannelMarker();
|
||||
displaySettings();
|
||||
applySettings(true);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
@ -158,7 +102,9 @@ void AMDemodGUI::channelMarkerChanged()
|
||||
m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency();
|
||||
m_settings.m_udpAddress = m_channelMarker.getUDPAddress(),
|
||||
m_settings.m_udpPort = m_channelMarker.getUDPSendPort(),
|
||||
m_settings.m_rgbColor = m_channelMarker.getColor().rgb();
|
||||
displayUDPAddress();
|
||||
m_settings.m_channelMarkerBytes = m_channelMarker.serialize();
|
||||
applySettings();
|
||||
}
|
||||
|
||||
@ -322,9 +268,13 @@ void AMDemodGUI::displaySettings()
|
||||
ui->bandpassEnable->setChecked(m_settings.m_bandpassEnable);
|
||||
ui->copyAudioToUDP->setChecked(m_settings.m_copyAudioToUDP);
|
||||
|
||||
m_channelMarker.blockSignals(true);
|
||||
m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset);
|
||||
m_channelMarker.setUDPAddress(m_settings.m_udpAddress);
|
||||
m_channelMarker.setUDPSendPort(m_settings.m_udpPort);
|
||||
m_channelMarker.setColor(m_settings.m_rgbColor);
|
||||
setTitleColor(m_settings.m_rgbColor);
|
||||
m_channelMarker.blockSignals(false);
|
||||
|
||||
blockApplySettings(false);
|
||||
}
|
||||
@ -334,6 +284,16 @@ void AMDemodGUI::displayUDPAddress()
|
||||
ui->copyAudioToUDP->setToolTip(QString("Copy audio output to UDP %1:%2").arg(m_channelMarker.getUDPAddress()).arg(m_channelMarker.getUDPSendPort()));
|
||||
}
|
||||
|
||||
void AMDemodGUI::updateChannelMarker()
|
||||
{
|
||||
m_channelMarker.blockSignals(true);
|
||||
|
||||
m_channelMarker.deserialize(m_settings.m_channelMarkerBytes);
|
||||
this->setWindowTitle(m_channelMarker.getTitle());
|
||||
|
||||
m_channelMarker.blockSignals(false);
|
||||
}
|
||||
|
||||
void AMDemodGUI::leaveEvent(QEvent*)
|
||||
{
|
||||
blockApplySettings(true);
|
||||
|
@ -74,6 +74,7 @@ private:
|
||||
void applySettings(bool force = false);
|
||||
void displaySettings();
|
||||
void displayUDPAddress();
|
||||
void updateChannelMarker();
|
||||
|
||||
void leaveEvent(QEvent*);
|
||||
void enterEvent(QEvent*);
|
||||
|
@ -42,10 +42,11 @@ QByteArray AMDemodSettings::serialize() const
|
||||
{
|
||||
SimpleSerializer s(1);
|
||||
s.writeS32(1, m_inputFrequencyOffset);
|
||||
s.writeS32(2, m_rfBandwidth/1000);
|
||||
s.writeS32(2, m_rfBandwidth/100);
|
||||
s.writeS32(4, m_volume*10);
|
||||
s.writeS32(5, m_squelch*10);
|
||||
s.writeS32(5, m_squelch);
|
||||
s.writeBlob(6, m_channelMarkerBytes);
|
||||
s.writeU32(7, m_rgbColor);
|
||||
s.writeBool(8, m_bandpassEnable);
|
||||
return s.final();
|
||||
}
|
||||
@ -68,12 +69,13 @@ bool AMDemodSettings::deserialize(const QByteArray& data)
|
||||
|
||||
d.readS32(1, &m_inputFrequencyOffset, 0);
|
||||
d.readS32(2, &tmp, 4);
|
||||
m_rfBandwidth = 1000 * tmp;
|
||||
m_rfBandwidth = 100 * tmp;
|
||||
d.readS32(4, &tmp, 20);
|
||||
m_volume = tmp * 0.1;
|
||||
d.readS32(5, &tmp, -40);
|
||||
m_squelch = tmp * 0.1;
|
||||
m_squelch = tmp;
|
||||
d.readBlob(6, &m_channelMarkerBytes);
|
||||
d.readU32(7, &m_rgbColor);
|
||||
d.readBool(8, &m_bandpassEnable, false);
|
||||
return true;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ struct AMDemodSettings
|
||||
bool m_copyAudioToUDP;
|
||||
QString m_udpAddress;
|
||||
quint16 m_udpPort;
|
||||
quint32 m_rgbColor;
|
||||
QByteArray m_channelMarkerBytes;
|
||||
|
||||
AMDemodSettings();
|
||||
|
Loading…
Reference in New Issue
Block a user