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

FCD Pro+: replaced serializer with settings

This commit is contained in:
f4exb 2015-10-01 03:37:53 +02:00
parent b31033c0a2
commit a25fa4ef97
7 changed files with 123 additions and 228 deletions

View File

@ -4,7 +4,7 @@ set(fcdproplus_SOURCES
fcdproplusgui.cpp
fcdproplusinput.cpp
fcdproplusplugin.cpp
fcdproplusserializer.cpp
fcdproplussettings.cpp
fcdproplusthread.cpp
)
@ -12,7 +12,7 @@ set(fcdproplus_HEADERS
fcdproplusgui.h
fcdproplusinput.h
fcdproplusplugin.h
fcdproplusserializer.h
fcdproplussettings.h
fcdproplusthread.h
)

View File

@ -66,12 +66,12 @@ void FCDProPlusGui::resetToDefaults()
qint64 FCDProPlusGui::getCenterFrequency() const
{
return m_settings.centerFrequency;
return m_settings.m_centerFrequency;
}
void FCDProPlusGui::setCenterFrequency(qint64 centerFrequency)
{
m_settings.centerFrequency = centerFrequency;
m_settings.m_centerFrequency = centerFrequency;
displaySettings();
sendSettings();
}
@ -103,16 +103,16 @@ bool FCDProPlusGui::handleMessage(const Message& message)
void FCDProPlusGui::displaySettings()
{
ui->centerFrequency->setValue(m_settings.centerFrequency / 1000);
ui->checkBoxG->setChecked(m_settings.lnaGain);
ui->checkBoxB->setChecked(m_settings.biasT);
ui->mixGain->setChecked(m_settings.mixGain);
ui->ifGain->setValue(m_settings.ifGain);
ui->ifGainText->setText(QString("%1dB").arg(m_settings.ifGain));
ui->filterIF->setCurrentIndex(m_settings.ifFilterIndex);
ui->filterRF->setCurrentIndex(m_settings.rfFilterIndex);
ui->ppm->setValue(m_settings.LOppmTenths);
ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.LOppmTenths/10.0, 'f', 1)));
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->checkBoxG->setChecked(m_settings.m_lnaGain);
ui->checkBoxB->setChecked(m_settings.m_biasT);
ui->mixGain->setChecked(m_settings.m_mixGain);
ui->ifGain->setValue(m_settings.m_ifGain);
ui->ifGainText->setText(QString("%1dB").arg(m_settings.m_ifGain));
ui->filterIF->setCurrentIndex(m_settings.m_ifFilterIndex);
ui->filterRF->setCurrentIndex(m_settings.m_rfFilterIndex);
ui->ppm->setValue(m_settings.m_LOppmTenths);
ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
}
void FCDProPlusGui::sendSettings()
@ -123,7 +123,7 @@ void FCDProPlusGui::sendSettings()
void FCDProPlusGui::on_centerFrequency_changed(quint64 value)
{
m_settings.centerFrequency = value * 1000;
m_settings.m_centerFrequency = value * 1000;
sendSettings();
}
@ -136,44 +136,44 @@ void FCDProPlusGui::updateHardware()
void FCDProPlusGui::on_checkBoxG_stateChanged(int state)
{
m_settings.lnaGain = (state == Qt::Checked);
m_settings.m_lnaGain = (state == Qt::Checked);
sendSettings();
}
void FCDProPlusGui::on_checkBoxB_stateChanged(int state)
{
m_settings.biasT = (state == Qt::Checked);
m_settings.m_biasT = (state == Qt::Checked);
sendSettings();
}
void FCDProPlusGui::on_mixGain_stateChanged(int state)
{
m_settings.mixGain = (state == Qt::Checked);
m_settings.m_mixGain = (state == Qt::Checked);
sendSettings();
}
void FCDProPlusGui::on_filterIF_currentIndexChanged(int index)
{
m_settings.ifFilterIndex = index;
m_settings.m_ifFilterIndex = index;
sendSettings();
}
void FCDProPlusGui::on_filterRF_currentIndexChanged(int index)
{
m_settings.rfFilterIndex = index;
m_settings.m_rfFilterIndex = index;
sendSettings();
}
void FCDProPlusGui::on_ifGain_valueChanged(int value)
{
m_settings.ifGain = value;
m_settings.m_ifGain = value;
displaySettings();
sendSettings();
}
void FCDProPlusGui::on_ppm_valueChanged(int value)
{
m_settings.LOppmTenths = value;
m_settings.m_LOppmTenths = value;
displaySettings();
sendSettings();
}

View File

@ -35,7 +35,7 @@ private:
Ui::FCDProPlusGui* ui;
PluginAPI* m_pluginAPI;
FCDProPlusInput::Settings m_settings;
FCDProPlusSettings m_settings;
QTimer m_updateTimer;
std::vector<int> m_gains;
SampleSource* m_sampleSource;

View File

@ -25,106 +25,11 @@
#include "fcdproplusinput.h"
#include "fcdproplusgui.h"
#include "fcdproplusserializer.h"
#include "fcdproplusthread.h"
#include "fcdtraits.h"
#include "fcdproplusconst.h"
MESSAGE_CLASS_DEFINITION(FCDProPlusInput::MsgConfigureFCD, Message)
//MESSAGE_CLASS_DEFINITION(FCDInput::MsgReportFCD, Message)
/*
const uint16_t FCDInput::m_vendorId = 0x04D8;
const uint16_t FCDInput::m_productId = 0xFB31;
const int FCDInput::m_sampleRate = 192000;
const std::string FCDInput::m_deviceName("hw:CARD=V20");
const uint16_t FCDInput::m_productId = 0xFB56;
const int FCDInput::m_sampleRate = 96000;
const std::string FCDInput::m_deviceName("hw:CARD=V10");
*/
FCDProPlusInput::Settings::Settings() :
centerFrequency(435000000),
rangeLow(true),
lnaGain(true),
mixGain(true),
biasT(false),
ifGain(0),
ifFilterIndex(0),
rfFilterIndex(0),
LOppmTenths(0)
{
}
void FCDProPlusInput::Settings::resetToDefaults()
{
centerFrequency = 435000000;
rangeLow = true;
lnaGain = true;
biasT = false;
ifGain = 0;
rfFilterIndex = 0;
ifFilterIndex = 0;
LOppmTenths = 0;
}
QByteArray FCDProPlusInput::Settings::serialize() const
{
FCDProPlusSerializer::FCDData data;
data.m_data.m_lnaGain = lnaGain;
data.m_data.m_correction = LOppmTenths;
data.m_data.m_RxGain1 = ifGain;
data.m_data.m_frequency = centerFrequency;
data.m_rangeLow = rangeLow;
data.m_biasT = biasT;
QByteArray byteArray;
FCDProPlusSerializer::writeSerializedData(data, byteArray);
return byteArray;
/*
SimpleSerializer s(1);
s.writeU64(1, centerFrequency);
s.writeS32(2, range);
s.writeS32(3, gain);
s.writeS32(4, bias);
return s.final();*/
}
bool FCDProPlusInput::Settings::deserialize(const QByteArray& serializedData)
{
FCDProPlusSerializer::FCDData data;
bool valid = FCDProPlusSerializer::readSerializedData(serializedData, data);
lnaGain = data.m_data.m_lnaGain;
LOppmTenths = data.m_data.m_correction;
ifGain = data.m_data.m_RxGain1;
centerFrequency = data.m_data.m_frequency;
rangeLow = data.m_rangeLow;
biasT = data.m_biasT;
return valid;
/*
SimpleDeserializer d(data);
if (d.isValid() && d.getVersion() == 1)
{
d.readU64(1, &centerFrequency, 435000000);
d.readS32(2, &range, 0);
d.readS32(3, &gain, 0);
d.readS32(4, &bias, 0);
return true;
}
resetToDefaults();
return true;*/
}
FCDProPlusInput::FCDProPlusInput() :
m_dev(0),
@ -219,7 +124,7 @@ int FCDProPlusInput::getSampleRate() const
quint64 FCDProPlusInput::getCenterFrequency() const
{
return m_settings.centerFrequency;
return m_settings.m_centerFrequency;
}
bool FCDProPlusInput::handleMessage(const Message& message)
@ -237,86 +142,86 @@ bool FCDProPlusInput::handleMessage(const Message& message)
}
}
void FCDProPlusInput::applySettings(const Settings& settings, bool force)
void FCDProPlusInput::applySettings(const FCDProPlusSettings& settings, bool force)
{
bool signalChange = false;
if ((m_settings.centerFrequency != settings.centerFrequency) || force)
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force)
{
qDebug() << "FCDProPlusInput::applySettings: fc: " << settings.centerFrequency;
m_settings.centerFrequency = settings.centerFrequency;
qDebug() << "FCDProPlusInput::applySettings: fc: " << settings.m_centerFrequency;
m_settings.m_centerFrequency = settings.m_centerFrequency;
if (m_dev != 0)
{
set_center_freq((double) m_settings.centerFrequency);
set_center_freq((double) m_settings.m_centerFrequency);
}
signalChange = true;
}
if ((m_settings.lnaGain != settings.lnaGain) || force)
if ((m_settings.m_lnaGain != settings.m_lnaGain) || force)
{
m_settings.lnaGain = settings.lnaGain;
m_settings.m_lnaGain = settings.m_lnaGain;
if (m_dev != 0)
{
set_lna_gain(settings.lnaGain);
set_lna_gain(settings.m_lnaGain);
}
}
if ((m_settings.biasT != settings.biasT) || force)
if ((m_settings.m_biasT != settings.m_biasT) || force)
{
m_settings.biasT = settings.biasT;
m_settings.m_biasT = settings.m_biasT;
if (m_dev != 0)
{
set_bias_t(settings.biasT);
set_bias_t(settings.m_biasT);
}
}
if ((m_settings.mixGain != settings.mixGain) || force)
if ((m_settings.m_mixGain != settings.m_mixGain) || force)
{
m_settings.mixGain = settings.mixGain;
m_settings.m_mixGain = settings.m_mixGain;
if (m_dev != 0)
{
set_mixer_gain(settings.mixGain);
set_mixer_gain(settings.m_mixGain);
}
}
if ((m_settings.ifGain != settings.ifGain) || force)
if ((m_settings.m_ifGain != settings.m_ifGain) || force)
{
m_settings.ifGain = settings.ifGain;
m_settings.m_ifGain = settings.m_ifGain;
if (m_dev != 0)
{
set_if_gain(settings.ifGain);
set_if_gain(settings.m_ifGain);
}
}
if ((m_settings.ifFilterIndex != settings.ifFilterIndex) || force)
if ((m_settings.m_ifFilterIndex != settings.m_ifFilterIndex) || force)
{
m_settings.ifFilterIndex = settings.ifFilterIndex;
m_settings.m_ifFilterIndex = settings.m_ifFilterIndex;
if (m_dev != 0)
{
set_if_filter(settings.ifFilterIndex);
set_if_filter(settings.m_ifFilterIndex);
}
}
if ((m_settings.rfFilterIndex != settings.rfFilterIndex) || force)
if ((m_settings.m_rfFilterIndex != settings.m_rfFilterIndex) || force)
{
m_settings.rfFilterIndex = settings.rfFilterIndex;
m_settings.m_rfFilterIndex = settings.m_rfFilterIndex;
if (m_dev != 0)
{
set_rf_filter(settings.rfFilterIndex);
set_rf_filter(settings.m_rfFilterIndex);
}
}
if ((m_settings.LOppmTenths != settings.LOppmTenths) || force)
if ((m_settings.m_LOppmTenths != settings.m_LOppmTenths) || force)
{
m_settings.LOppmTenths = settings.LOppmTenths;
m_settings.m_LOppmTenths = settings.m_LOppmTenths;
if (m_dev != 0)
{
@ -326,14 +231,14 @@ void FCDProPlusInput::applySettings(const Settings& settings, bool force)
if (signalChange)
{
DSPSignalNotification *notif = new DSPSignalNotification(fcd_traits<ProPlus>::sampleRate, m_settings.centerFrequency);
DSPSignalNotification *notif = new DSPSignalNotification(fcd_traits<ProPlus>::sampleRate, m_settings.m_centerFrequency);
DSPEngine::instance()->getInputMessageQueue()->push(notif);
}
}
void FCDProPlusInput::set_center_freq(double freq)
{
freq += freq*(((double) m_settings.LOppmTenths)/10000000.0);
freq += freq*(((double) m_settings.m_LOppmTenths)/10000000.0);
if (fcdAppSetFreq(m_dev, freq) == FCD_MODE_NONE)
{
@ -410,7 +315,7 @@ void FCDProPlusInput::set_rf_filter(int filterIndex)
void FCDProPlusInput::set_lo_ppm()
{
set_center_freq((double) m_settings.centerFrequency);
set_center_freq((double) m_settings.m_centerFrequency);
}

View File

@ -18,6 +18,7 @@
#ifndef INCLUDE_FCDINPUT_H
#define INCLUDE_FCDINPUT_H
#include "fcdproplussettings.h"
#include "dsp/samplesource.h"
#include "fcdhid.h"
#include <QString>
@ -32,37 +33,21 @@ class FCDProPlusThread;
class FCDProPlusInput : public SampleSource {
public:
struct Settings {
Settings();
quint64 centerFrequency;
bool rangeLow;
bool lnaGain;
bool mixGain;
bool biasT;
quint32 ifGain;
qint32 ifFilterIndex;
qint32 rfFilterIndex;
qint32 LOppmTenths;
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
class MsgConfigureFCD : public Message {
MESSAGE_CLASS_DECLARATION
public:
const Settings& getSettings() const { return m_settings; }
const FCDProPlusSettings& getSettings() const { return m_settings; }
static MsgConfigureFCD* create(const Settings& settings)
static MsgConfigureFCD* create(const FCDProPlusSettings& settings)
{
return new MsgConfigureFCD(settings);
}
private:
Settings m_settings;
FCDProPlusSettings m_settings;
MsgConfigureFCD(const Settings& settings) :
MsgConfigureFCD(const FCDProPlusSettings& settings) :
Message(),
m_settings(settings)
{ }
@ -91,11 +76,11 @@ public:
void set_lo_ppm();
private:
void applySettings(const Settings& settings, bool force);
void applySettings(const FCDProPlusSettings& settings, bool force);
hid_device *m_dev;
QMutex m_mutex;
Settings m_settings;
FCDProPlusSettings m_settings;
FCDProPlusThread* m_FCDThread;
QString m_deviceDescription;
};

View File

@ -14,64 +14,72 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "fcdproplusserializer.h"
#include <QtGlobal>
#include "util/simpleserializer.h"
#include "fcdproplussettings.h"
void FCDProPlusSerializer::writeSerializedData(const FCDData& data, QByteArray& serializedData)
FCDProPlusSettings::FCDProPlusSettings()
{
QByteArray sampleSourceSerialized;
SampleSourceSerializer::writeSerializedData(data.m_data, sampleSourceSerialized);
SimpleSerializer s(1);
s.writeBlob(1, sampleSourceSerialized);
s.writeBool(2, data.m_biasT);
s.writeBool(3, data.m_rangeLow);
s.writeBool(4, data.m_mixGain);
s.writeS32(5, data.m_ifFilterIndex);
s.writeS32(6, data.m_rfFilterIndex);
serializedData = s.final();
resetToDefaults();
}
bool FCDProPlusSerializer::readSerializedData(const QByteArray& serializedData, FCDData& data)
void FCDProPlusSettings::resetToDefaults()
{
bool valid = SampleSourceSerializer::readSerializedData(serializedData, data.m_data);
m_centerFrequency = 435000000;
m_rangeLow = true;
m_lnaGain = true;
m_biasT = false;
m_ifGain = 0;
m_rfFilterIndex = 0;
m_ifFilterIndex = 0;
m_LOppmTenths = 0;
m_dcBlock = false;
m_iqImbalance = false;
}
QByteArray sampleSourceSerialized;
QByteArray FCDProPlusSettings::serialize() const
{
SimpleSerializer s(1);
SimpleDeserializer d(serializedData);
s.writeBool(1, m_biasT);
s.writeBool(2, m_rangeLow);
s.writeBool(3, m_mixGain);
s.writeS32(4, m_ifFilterIndex);
s.writeS32(5, m_rfFilterIndex);
s.writeBool(6, m_dcBlock);
s.writeBool(7, m_iqImbalance);
return s.final();
}
bool FCDProPlusSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
setDefaults(data);
resetToDefaults();
return false;
}
if (d.getVersion() == SampleSourceSerializer::getSerializerVersion())
if (d.getVersion() == 1)
{
int intval;
d.readBlob(1, &sampleSourceSerialized);
d.readBool(2, &data.m_biasT, false);
d.readBool(3, &data.m_rangeLow, false);
d.readBool(4, &data.m_mixGain, true);
d.readS32(5, &data.m_ifFilterIndex, 0);
d.readS32(6, &data.m_rfFilterIndex, 0);
d.readBool(1, &m_biasT, false);
d.readBool(2, &m_rangeLow, false);
d.readBool(3, &m_mixGain, true);
d.readS32(4, &m_ifFilterIndex, 0);
d.readS32(5, &m_rfFilterIndex, 0);
d.readBool(6, &m_dcBlock, false);
d.readBool(7, &m_iqImbalance, false);
return SampleSourceSerializer::readSerializedData(sampleSourceSerialized, data.m_data);
return true;
}
else
{
setDefaults(data);
resetToDefaults();
return false;
}
}
void FCDProPlusSerializer::setDefaults(FCDData& data)
{
data.m_rangeLow = false;
data.m_biasT = false;
data.m_mixGain = true;
data.m_ifFilterIndex = 0;
data.m_rfFilterIndex = 0;
}

View File

@ -14,29 +14,26 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_FCD_FCDPROPLUSSERIALIZER_H_
#define PLUGINS_SAMPLESOURCE_FCD_FCDPROPLUSSERIALIZER_H_
#ifndef _FCDPROPLUS_FCDPROPLUSSETTINGS_H_
#define _FCDPROPLUS_FCDPROPLUSSETTINGS_H_
#include "util/samplesourceserializer.h"
struct FCDProPlusSettings {
quint64 m_centerFrequency;
bool m_rangeLow;
bool m_lnaGain;
bool m_mixGain;
bool m_biasT;
quint32 m_ifGain;
qint32 m_ifFilterIndex;
qint32 m_rfFilterIndex;
qint32 m_LOppmTenths;
bool m_dcBlock;
bool m_iqImbalance;
class FCDProPlusSerializer
{
public:
struct FCDData
{
SampleSourceSerializer::Data m_data;
bool m_mixGain;
bool m_biasT;
bool m_rangeLow;
qint32 m_ifFilterIndex;
qint32 m_rfFilterIndex;
};
static void writeSerializedData(const FCDData& data, QByteArray& serializedData);
static bool readSerializedData(const QByteArray& serializedData, FCDData& data);
static void setDefaults(FCDData& data);
FCDProPlusSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif /* PLUGINS_SAMPLESOURCE_FCD_FCDPROPLUSSERIALIZER_H_ */
#endif /* _FCDPROPLUS_FCDPROPLUSSETTINGS_H_ */