1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-27 15:26:33 -04:00

RTL-SDR: replaced serializer by setting class

This commit is contained in:
f4exb 2015-10-01 04:39:00 +02:00
parent 3540efc696
commit 3cc73fbf61
6 changed files with 90 additions and 99 deletions

View File

@ -4,7 +4,7 @@ set(rtlsdr_SOURCES
rtlsdrgui.cpp
rtlsdrinput.cpp
rtlsdrplugin.cpp
rtlsdrserializer.cpp
rtlsdrsettings.cpp
rtlsdrthread.cpp
)
@ -12,7 +12,7 @@ set(rtlsdr_HEADERS
rtlsdrgui.h
rtlsdrinput.h
rtlsdrplugin.h
rtlsdrserializer.h
rtlsdrsettings.h
rtlsdrthread.h
)

View File

@ -34,7 +34,7 @@ private:
Ui::RTLSDRGui* ui;
PluginAPI* m_pluginAPI;
RTLSDRInput::Settings m_settings;
RTLSDRSettings m_settings;
QTimer m_updateTimer;
std::vector<int> m_gains;
SampleSource* m_sampleSource;

View File

@ -23,61 +23,10 @@
#include "rtlsdrgui.h"
#include "dsp/dspcommands.h"
#include "dsp/dspengine.h"
#include "rtlsdrserializer.h"
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgConfigureRTLSDR, Message)
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgReportRTLSDR, Message)
RTLSDRInput::Settings::Settings() :
m_devSampleRate(1024*1000),
m_centerFrequency(435000*1000),
m_gain(0),
m_loPpmCorrection(0),
m_log2Decim(4)
{
}
void RTLSDRInput::Settings::resetToDefaults()
{
m_devSampleRate = 1024*1000;
m_centerFrequency = 435000*1000;
m_gain = 0;
m_loPpmCorrection = 0;
m_log2Decim = 4;
}
QByteArray RTLSDRInput::Settings::serialize() const
{
SampleSourceSerializer::Data data;
data.m_lnaGain = m_gain;
data.m_log2Decim = m_log2Decim;
data.m_frequency = m_centerFrequency;
data.m_rate = m_devSampleRate;
data.m_correction = m_loPpmCorrection;
QByteArray byteArray;
RTLSDRSerializer::writeSerializedData(data, byteArray);
return byteArray;
}
bool RTLSDRInput::Settings::deserialize(const QByteArray& serializedData)
{
SampleSourceSerializer::Data data;
bool valid = RTLSDRSerializer::readSerializedData(serializedData, data);
m_gain = data.m_lnaGain;
m_log2Decim = data.m_log2Decim;
m_centerFrequency = data.m_frequency;
m_devSampleRate = data.m_rate;
m_loPpmCorrection = data.m_correction;
return valid;
}
RTLSDRInput::RTLSDRInput() :
m_settings(),
m_dev(0),
@ -260,7 +209,7 @@ bool RTLSDRInput::handleMessage(const Message& message)
}
}
bool RTLSDRInput::applySettings(const Settings& settings, bool force)
bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
{
QMutexLocker mutexLocker(&m_mutex);
bool forwardChange = false;

View File

@ -19,6 +19,7 @@
#define INCLUDE_RTLSDRINPUT_H
#include "dsp/samplesource.h"
#include "rtlsdrsettings.h"
#include <rtl-sdr.h>
#include <QString>
@ -26,34 +27,21 @@ class RTLSDRThread;
class RTLSDRInput : public SampleSource {
public:
struct Settings {
int m_devSampleRate;
quint64 m_centerFrequency;
qint32 m_gain;
qint32 m_loPpmCorrection;
quint32 m_log2Decim;
Settings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
class MsgConfigureRTLSDR : public Message {
MESSAGE_CLASS_DECLARATION
public:
const Settings& getSettings() const { return m_settings; }
const RTLSDRSettings& getSettings() const { return m_settings; }
static MsgConfigureRTLSDR* create(const Settings& settings)
static MsgConfigureRTLSDR* create(const RTLSDRSettings& settings)
{
return new MsgConfigureRTLSDR(settings);
}
private:
Settings m_settings;
RTLSDRSettings m_settings;
MsgConfigureRTLSDR(const Settings& settings) :
MsgConfigureRTLSDR(const RTLSDRSettings& settings) :
Message(),
m_settings(settings)
{ }
@ -96,13 +84,13 @@ public:
private:
QMutex m_mutex;
Settings m_settings;
RTLSDRSettings m_settings;
rtlsdr_dev_t* m_dev;
RTLSDRThread* m_rtlSDRThread;
QString m_deviceDescription;
std::vector<int> m_gains;
bool applySettings(const Settings& settings, bool force);
bool applySettings(const RTLSDRSettings& settings, bool force);
};
#endif // INCLUDE_RTLSDRINPUT_H

View File

@ -14,19 +14,66 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_RTLSDR_RTLSDRSERIALIZER_H_
#define PLUGINS_SAMPLESOURCE_RTLSDR_RTLSDRSERIALIZER_H_
#include <QtGlobal>
#include "util/simpleserializer.h"
#include "rtlsdrsettings.h"
#include "util/samplesourceserializer.h"
class RTLSDRSerializer
RTLSDRSettings::RTLSDRSettings()
{
public:
SampleSourceSerializer::Data m_data;
resetToDefaults();
}
void RTLSDRSettings::resetToDefaults()
{
m_devSampleRate = 1024*1000;
m_centerFrequency = 435000*1000;
m_gain = 0;
m_loPpmCorrection = 0;
m_log2Decim = 4;
m_dcBlock = false;
m_iqImbalance = false;
}
QByteArray RTLSDRSettings::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_devSampleRate);
s.writeS32(2, m_gain);
s.writeS32(3, m_loPpmCorrection);
s.writeU32(4, m_log2Decim);
s.writeBool(5, m_dcBlock);
s.writeBool(6, m_iqImbalance);
return s.final();
}
bool RTLSDRSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
d.readS32(1, &m_devSampleRate, 0);
d.readS32(2, &m_gain, 0);
d.readS32(3, &m_loPpmCorrection, 0);
d.readU32(4, &m_log2Decim, 4);
d.readBool(5, &m_dcBlock, false);
d.readBool(6, &m_iqImbalance, false);
return true;
}
else
{
resetToDefaults();
return false;
}
}
static void writeSerializedData(const SampleSourceSerializer::Data& data, QByteArray& serializedData);
static bool readSerializedData(const QByteArray& serializedData, SampleSourceSerializer::Data& data);
static void setDefaults(SampleSourceSerializer::Data& data);
};
#endif /* PLUGINS_SAMPLESOURCE_RTLSDR_RTLSDRSERIALIZER_H_ */

View File

@ -14,19 +14,26 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "rtlsdrserializer.h"
#ifndef _RTLSDR_RTLSDRSETTINGS_H_
#define _RTLSDR_RTLSDRSETTINGS_H_
void RTLSDRSerializer::writeSerializedData(const SampleSourceSerializer::Data& data, QByteArray& serializedData)
{
SampleSourceSerializer::writeSerializedData(data, serializedData);
}
struct RTLSDRSettings {
int m_devSampleRate;
quint64 m_centerFrequency;
qint32 m_gain;
qint32 m_loPpmCorrection;
quint32 m_log2Decim;
bool m_dcBlock;
bool m_iqImbalance;
bool RTLSDRSerializer::readSerializedData(const QByteArray& serializedData, SampleSourceSerializer::Data& data)
{
return SampleSourceSerializer::readSerializedData(serializedData, data);
}
RTLSDRSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
void RTLSDRSerializer::setDefaults(SampleSourceSerializer::Data& data)
{
SampleSourceSerializer::setDefaults(data);
}
#endif /* _RTLSDR_RTLSDRSETTINGS_H_ */