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

UDP source: added settings class

This commit is contained in:
f4exb 2017-10-05 00:55:14 +02:00
parent 58a17f421c
commit d0f07f0ccd
4 changed files with 219 additions and 2 deletions

View File

@ -4,12 +4,14 @@ set(udpsrc_SOURCES
udpsrc.cpp udpsrc.cpp
udpsrcgui.cpp udpsrcgui.cpp
udpsrcplugin.cpp udpsrcplugin.cpp
udpsrcsettings.cpp
) )
set(udpsrc_HEADERS set(udpsrc_HEADERS
udpsrc.h udpsrc.h
udpsrcgui.h udpsrcgui.h
udpsrcplugin.h udpsrcplugin.h
udpsrcsettings.h
) )
set(udpsrc_FORMS set(udpsrc_FORMS

View File

@ -25,11 +25,13 @@ CONFIG(Debug):build_subdir = debug
SOURCES += udpsrc.cpp\ SOURCES += udpsrc.cpp\
udpsrcgui.cpp\ udpsrcgui.cpp\
udpsrcplugin.cpp udpsrcplugin.cpp\
udpsrcsettings.cpp
HEADERS += udpsrc.h\ HEADERS += udpsrc.h\
udpsrcgui.h\ udpsrcgui.h\
udpsrcplugin.h udpsrcplugin.h\
udpsrcsettings.h
FORMS += udpsrcgui.ui FORMS += udpsrcgui.ui

View File

@ -0,0 +1,138 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 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 //
// //
// 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 "dsp/dspengine.h"
#include "util/simpleserializer.h"
#include "settings/serializable.h"
#include "udpsrcsettings.h"
UDPSrcSettings::UDPSrcSettings() :
m_channelMarker(0),
m_spectrumGUI(0)
{
resetToDefaults();
}
void UDPSrcSettings::resetToDefaults()
{
m_outputSampleRate = 48000;
m_sampleFormat = FormatS16LE;
m_inputSampleRate = 48000;
m_inputFrequencyOffset = 0;
m_rfBandwidth = 12500;
m_fmDeviation = 2500;
m_channelMute = false;
m_gain = 1.0;
m_squelch = -60.0;
m_squelchGate = 0.0;
m_squelchEnabled = true;
m_agc = false;
m_audioActive = false;
m_audioStereo = false;
m_volume = 20;
m_udpAddressStr = "127.0.0.1";
m_udpPort = 9999;
m_audioPort = 9998;
}
QByteArray UDPSrcSettings::serialize() const
{
SimpleSerializer s(1);
s.writeS32(2, m_inputFrequencyOffset);
s.writeS32(3, m_sampleFormat);
s.writeReal(4, m_outputSampleRate);
s.writeReal(5, m_rfBandwidth);
if (m_channelMarker) {
s.writeBlob(6, m_channelMarker->serialize());
}
if (m_spectrumGUI) {
s.writeBlob(7, m_spectrumGUI->serialize());
}
s.writeS32(8, m_gain*10.0);
s.writeBool(11, m_audioActive);
s.writeS32(12, m_volume);
s.writeBool(14, m_audioStereo);
s.writeS32(15, m_fmDeviation);
s.writeS32(16, m_squelch);
s.writeS32(17, m_squelchGate * 100.0);
s.writeBool(18, m_agc);
return s.final();
}
bool UDPSrcSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
QByteArray bytetmp;
QString strtmp;
int32_t s32tmp;
if (m_channelMarker) {
d.readBlob(6, &bytetmp);
m_channelMarker->deserialize(bytetmp);
}
d.readS32(2, &s32tmp, 0);
m_inputFrequencyOffset = s32tmp;
d.readS32(3, &s32tmp, FormatS16LE);
if ((s32tmp >= 0) && (s32tmp < (int) FormatNone)) {
m_sampleFormat = (SampleFormat) s32tmp;
} else {
m_sampleFormat = FormatS16LE;
}
d.readReal(4, &m_outputSampleRate, 48000.0);
d.readReal(5, &m_rfBandwidth, 32000.0);
if (m_spectrumGUI) {
d.readBlob(7, &bytetmp);
m_spectrumGUI->deserialize(bytetmp);
}
d.readS32(8, &s32tmp, 10);
m_gain = s32tmp / 10.0;
d.readBool(11, &m_audioActive, false);
d.readS32(12, &m_volume, 20);
d.readBool(14, &m_audioStereo, false);
d.readS32(15, &m_fmDeviation, 2500);
d.readS32(16, &s32tmp, -60);
m_squelch = s32tmp * 1.0;
d.readS32(17, &s32tmp, 5);
m_squelchGate = s32tmp / 100.0;
d.readBool(18, &m_agc, false);
return true;
}
else
{
resetToDefaults();
return false;
}
}

View File

@ -0,0 +1,75 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 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 //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_CHANNELRX_UDPSRC_UDPSRCSETTINGS_H_
#define PLUGINS_CHANNELRX_UDPSRC_UDPSRCSETTINGS_H_
#include <QByteArray>
#include <QString>
#include <stdint.h>
struct Serializable;
struct UDPSrcSettings
{
enum SampleFormat {
FormatS16LE,
FormatNFM,
FormatNFMMono,
FormatLSB,
FormatUSB,
FormatLSBMono,
FormatUSBMono,
FormatAMMono,
FormatAMNoDCMono,
FormatAMBPFMono,
FormatNone
};
float m_outputSampleRate;
SampleFormat m_sampleFormat;
float m_inputSampleRate;
int64_t m_inputFrequencyOffset;
float m_rfBandwidth;
int m_fmDeviation;
bool m_channelMute;
float m_gain;
float m_squelch; //!< squared magnitude
float m_squelchGate; //!< seconds
bool m_squelchEnabled;
bool m_agc;
bool m_audioActive;
bool m_audioStereo;
int m_volume;
QString m_udpAddressStr;
uint16_t m_udpPort;
uint16_t m_audioPort;
Serializable *m_channelMarker;
Serializable *m_spectrumGUI;
UDPSrcSettings();
void resetToDefaults();
void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; }
void setSpectrumGUI(Serializable *spectrumGUI) { m_spectrumGUI = spectrumGUI; }
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif /* PLUGINS_CHANNELRX_UDPSRC_UDPSRCSETTINGS_H_ */