2015-09-02 21:57:54 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// FIXME: FCD is handled very badly!
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "dsp/dspcommands.h"
|
2015-09-03 22:10:38 -04:00
|
|
|
#include "fcdproplusinput.h"
|
2015-09-02 21:57:54 -04:00
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
#include "fcdproplusgui.h"
|
|
|
|
#include "fcdproplusserializer.h"
|
|
|
|
#include "fcdproplusthread.h"
|
2015-09-04 23:50:29 -04:00
|
|
|
#include "fcdtraits.h"
|
2015-09-05 05:46:56 -04:00
|
|
|
#include "fcdproplusconst.h"
|
2015-09-03 22:10:38 -04:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(FCDProPlusInput::MsgConfigureFCD, Message)
|
2015-09-02 21:57:54 -04:00
|
|
|
//MESSAGE_CLASS_DEFINITION(FCDInput::MsgReportFCD, Message)
|
|
|
|
|
2015-09-03 20:24:02 -04:00
|
|
|
/*
|
2015-09-02 21:57:54 -04:00
|
|
|
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");
|
|
|
|
|
2015-09-03 20:24:02 -04:00
|
|
|
const uint16_t FCDInput::m_productId = 0xFB56;
|
|
|
|
const int FCDInput::m_sampleRate = 96000;
|
|
|
|
const std::string FCDInput::m_deviceName("hw:CARD=V10");
|
|
|
|
*/
|
2015-09-02 21:57:54 -04:00
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
FCDProPlusInput::Settings::Settings() :
|
2015-09-02 21:57:54 -04:00
|
|
|
centerFrequency(435000000),
|
2015-09-05 05:46:56 -04:00
|
|
|
rangeLow(true),
|
|
|
|
lnaGain(true),
|
|
|
|
mixGain(true),
|
|
|
|
biasT(false),
|
|
|
|
ifGain(0),
|
|
|
|
ifFilterIndex(0),
|
2015-09-05 19:34:20 -04:00
|
|
|
rfFilterIndex(0),
|
|
|
|
LOppmTenths(0)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
void FCDProPlusInput::Settings::resetToDefaults()
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
centerFrequency = 435000000;
|
2015-09-05 05:46:56 -04:00
|
|
|
rangeLow = true;
|
|
|
|
lnaGain = true;
|
|
|
|
biasT = false;
|
|
|
|
ifGain = 0;
|
|
|
|
rfFilterIndex = 0;
|
|
|
|
ifFilterIndex = 0;
|
2015-09-05 19:34:20 -04:00
|
|
|
LOppmTenths = 0;
|
2015-09-02 21:57:54 -04:00
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
QByteArray FCDProPlusInput::Settings::serialize() const
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-03 22:10:38 -04:00
|
|
|
FCDProPlusSerializer::FCDData data;
|
2015-09-02 21:57:54 -04:00
|
|
|
|
2015-09-05 05:46:56 -04:00
|
|
|
data.m_data.m_lnaGain = lnaGain;
|
2015-09-05 19:34:20 -04:00
|
|
|
data.m_data.m_correction = LOppmTenths;
|
2015-09-05 05:46:56 -04:00
|
|
|
data.m_data.m_RxGain1 = ifGain;
|
2015-09-02 21:57:54 -04:00
|
|
|
data.m_data.m_frequency = centerFrequency;
|
2015-09-05 05:46:56 -04:00
|
|
|
data.m_rangeLow = rangeLow;
|
|
|
|
data.m_biasT = biasT;
|
2015-09-02 21:57:54 -04:00
|
|
|
|
|
|
|
QByteArray byteArray;
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
FCDProPlusSerializer::writeSerializedData(data, byteArray);
|
2015-09-02 21:57:54 -04:00
|
|
|
|
|
|
|
return byteArray;
|
|
|
|
|
|
|
|
/*
|
|
|
|
SimpleSerializer s(1);
|
|
|
|
s.writeU64(1, centerFrequency);
|
|
|
|
s.writeS32(2, range);
|
|
|
|
s.writeS32(3, gain);
|
|
|
|
s.writeS32(4, bias);
|
|
|
|
return s.final();*/
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
bool FCDProPlusInput::Settings::deserialize(const QByteArray& serializedData)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-03 22:10:38 -04:00
|
|
|
FCDProPlusSerializer::FCDData data;
|
2015-09-02 21:57:54 -04:00
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
bool valid = FCDProPlusSerializer::readSerializedData(serializedData, data);
|
2015-09-02 21:57:54 -04:00
|
|
|
|
2015-09-05 05:46:56 -04:00
|
|
|
lnaGain = data.m_data.m_lnaGain;
|
2015-09-05 19:34:20 -04:00
|
|
|
LOppmTenths = data.m_data.m_correction;
|
2015-09-05 05:46:56 -04:00
|
|
|
ifGain = data.m_data.m_RxGain1;
|
2015-09-02 21:57:54 -04:00
|
|
|
centerFrequency = data.m_data.m_frequency;
|
2015-09-05 05:46:56 -04:00
|
|
|
rangeLow = data.m_rangeLow;
|
|
|
|
biasT = data.m_biasT;
|
2015-09-02 21:57:54 -04:00
|
|
|
|
|
|
|
return valid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
SimpleDeserializer d(data);
|
|
|
|
|
|
|
|
if (d.isValid() && d.getVersion() == 1)
|
|
|
|
{
|
|
|
|
d.readU64(1, ¢erFrequency, 435000000);
|
|
|
|
d.readS32(2, &range, 0);
|
|
|
|
d.readS32(3, &gain, 0);
|
|
|
|
d.readS32(4, &bias, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetToDefaults();
|
|
|
|
return true;*/
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
FCDProPlusInput::FCDProPlusInput() :
|
2015-09-02 21:57:54 -04:00
|
|
|
m_dev(0),
|
|
|
|
m_settings(),
|
|
|
|
m_FCDThread(0),
|
2015-09-04 23:50:29 -04:00
|
|
|
m_deviceDescription(fcd_traits<ProPlus>::displayedName)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
FCDProPlusInput::~FCDProPlusInput()
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
bool FCDProPlusInput::init(const Message& cmd)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
bool FCDProPlusInput::start(int device)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-03 22:10:38 -04:00
|
|
|
qDebug() << "FCDProPlusInput::start with device #" << device;
|
2015-09-02 21:57:54 -04:00
|
|
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
|
|
if (m_FCDThread)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-04 23:50:29 -04:00
|
|
|
m_dev = fcdOpen(fcd_traits<ProPlus>::vendorId, fcd_traits<ProPlus>::productId, device);
|
2015-09-02 21:57:54 -04:00
|
|
|
|
|
|
|
if (m_dev == 0)
|
|
|
|
{
|
2015-09-03 22:10:38 -04:00
|
|
|
qCritical("FCDProPlusInput::start: could not open FCD");
|
2015-09-02 21:57:54 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply settings before streaming to avoid bus contention;
|
|
|
|
* there is very little spare bandwidth on a full speed USB device.
|
2015-09-03 02:39:57 -04:00
|
|
|
* Failure is harmless if no device is found
|
|
|
|
* ... This is rubbish...*/
|
2015-09-02 21:57:54 -04:00
|
|
|
|
2015-09-03 02:39:57 -04:00
|
|
|
//applySettings(m_settings, true);
|
2015-09-02 21:57:54 -04:00
|
|
|
|
|
|
|
if(!m_sampleFifo.setSize(96000*4))
|
|
|
|
{
|
|
|
|
qCritical("Could not allocate SampleFifo");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
if ((m_FCDThread = new FCDProPlusThread(&m_sampleFifo)) == NULL)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
qFatal("out of memory");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-03 02:39:57 -04:00
|
|
|
m_FCDThread->startWork();
|
|
|
|
|
|
|
|
mutexLocker.unlock();
|
|
|
|
applySettings(m_settings, true);
|
2015-09-02 21:57:54 -04:00
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
qDebug("FCDProPlusInput::started");
|
2015-09-02 21:57:54 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
void FCDProPlusInput::stop()
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
|
|
if (m_FCDThread)
|
|
|
|
{
|
|
|
|
m_FCDThread->stopWork();
|
|
|
|
// wait for thread to quit ?
|
|
|
|
delete m_FCDThread;
|
|
|
|
m_FCDThread = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fcdClose(m_dev);
|
|
|
|
m_dev = 0;
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
const QString& FCDProPlusInput::getDeviceDescription() const
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
int FCDProPlusInput::getSampleRate() const
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-04 23:50:29 -04:00
|
|
|
return fcd_traits<ProPlus>::sampleRate;
|
2015-09-02 21:57:54 -04:00
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
quint64 FCDProPlusInput::getCenterFrequency() const
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
return m_settings.centerFrequency;
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
bool FCDProPlusInput::handleMessage(const Message& message)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
if(MsgConfigureFCD::match(message))
|
|
|
|
{
|
2015-09-03 22:10:38 -04:00
|
|
|
qDebug() << "FCDProPlusInput::handleMessage: MsgConfigureFCD";
|
2015-09-02 21:57:54 -04:00
|
|
|
MsgConfigureFCD& conf = (MsgConfigureFCD&) message;
|
|
|
|
applySettings(conf.getSettings(), false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
void FCDProPlusInput::applySettings(const Settings& settings, bool force)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
bool signalChange = false;
|
|
|
|
|
2015-09-03 02:39:57 -04:00
|
|
|
if ((m_settings.centerFrequency != settings.centerFrequency) || force)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-03 22:10:38 -04:00
|
|
|
qDebug() << "FCDProPlusInput::applySettings: fc: " << settings.centerFrequency;
|
2015-09-02 21:57:54 -04:00
|
|
|
m_settings.centerFrequency = settings.centerFrequency;
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
set_center_freq((double) m_settings.centerFrequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
signalChange = true;
|
|
|
|
}
|
|
|
|
|
2015-09-05 05:46:56 -04:00
|
|
|
if ((m_settings.lnaGain != settings.lnaGain) || force)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-05 05:46:56 -04:00
|
|
|
m_settings.lnaGain = settings.lnaGain;
|
2015-09-02 21:57:54 -04:00
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
2015-09-05 19:34:20 -04:00
|
|
|
set_lna_gain(settings.lnaGain);
|
2015-09-02 21:57:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-05 05:46:56 -04:00
|
|
|
if ((m_settings.biasT != settings.biasT) || force)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-05 05:46:56 -04:00
|
|
|
m_settings.biasT = settings.biasT;
|
2015-09-02 21:57:54 -04:00
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
2015-09-05 19:34:20 -04:00
|
|
|
set_bias_t(settings.biasT);
|
2015-09-02 21:57:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-05 19:34:20 -04:00
|
|
|
if ((m_settings.mixGain != settings.mixGain) || force)
|
|
|
|
{
|
|
|
|
m_settings.mixGain = settings.mixGain;
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
set_mixer_gain(settings.mixGain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.ifGain != settings.ifGain) || force)
|
|
|
|
{
|
|
|
|
m_settings.ifGain = settings.ifGain;
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
set_if_gain(settings.ifGain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.ifFilterIndex != settings.ifFilterIndex) || force)
|
|
|
|
{
|
|
|
|
m_settings.ifFilterIndex = settings.ifFilterIndex;
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
set_if_filter(settings.ifFilterIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.rfFilterIndex != settings.rfFilterIndex) || force)
|
|
|
|
{
|
|
|
|
m_settings.rfFilterIndex = settings.rfFilterIndex;
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
set_rf_filter(settings.rfFilterIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.LOppmTenths != settings.LOppmTenths) || force)
|
|
|
|
{
|
|
|
|
m_settings.LOppmTenths = settings.LOppmTenths;
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
set_lo_ppm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (signalChange)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-04 23:50:29 -04:00
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(fcd_traits<ProPlus>::sampleRate, m_settings.centerFrequency);
|
2015-09-02 21:57:54 -04:00
|
|
|
getOutputMessageQueue()->push(notif);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
void FCDProPlusInput::set_center_freq(double freq)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
2015-09-05 19:34:20 -04:00
|
|
|
freq += freq*(((double) m_settings.LOppmTenths)/10000000.0);
|
|
|
|
|
2015-09-02 21:57:54 -04:00
|
|
|
if (fcdAppSetFreq(m_dev, freq) == FCD_MODE_NONE)
|
|
|
|
{
|
|
|
|
qDebug("No FCD HID found for frquency change");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
void FCDProPlusInput::set_bias_t(bool on)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
quint8 cmd = on ? 1 : 0;
|
|
|
|
|
2015-09-05 00:24:02 -04:00
|
|
|
fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_BIAS_TEE, &cmd, 1);
|
2015-09-02 21:57:54 -04:00
|
|
|
}
|
|
|
|
|
2015-09-03 22:10:38 -04:00
|
|
|
void FCDProPlusInput::set_lna_gain(bool on)
|
2015-09-02 21:57:54 -04:00
|
|
|
{
|
|
|
|
quint8 cmd = on ? 1 : 0;
|
|
|
|
|
2015-09-05 00:24:02 -04:00
|
|
|
fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_LNA_GAIN, &cmd, 1);
|
2015-09-02 21:57:54 -04:00
|
|
|
}
|
|
|
|
|
2015-09-05 05:46:56 -04:00
|
|
|
void FCDProPlusInput::set_mixer_gain(bool on)
|
|
|
|
{
|
|
|
|
quint8 cmd = on ? 1 : 0;
|
|
|
|
|
|
|
|
fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_MIXER_GAIN, &cmd, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FCDProPlusInput::set_if_gain(int gain)
|
|
|
|
{
|
|
|
|
if (gain < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint8 cmd_value = gain;
|
|
|
|
|
2015-09-05 19:34:20 -04:00
|
|
|
if (fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_IF_GAIN, &cmd_value, 1) != FCD_MODE_APP)
|
|
|
|
{
|
|
|
|
qWarning() << "FCDProPlusInput::set_if_gain: failed to set at " << cmd_value;
|
|
|
|
}
|
2015-09-05 05:46:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FCDProPlusInput::set_if_filter(int filterIndex)
|
|
|
|
{
|
|
|
|
if ((filterIndex < 0) || (filterIndex >= FCDProPlusConstants::fcdproplus_if_filter_nb_values()))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint8 cmd_value = FCDProPlusConstants::if_filters[filterIndex].value;
|
|
|
|
|
2015-09-05 19:34:20 -04:00
|
|
|
if (fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_IF_FILTER, &cmd_value, 1) != FCD_MODE_APP)
|
|
|
|
{
|
|
|
|
qWarning() << "FCDProPlusInput::set_if_filter: failed to set at " << cmd_value;
|
|
|
|
}
|
2015-09-05 05:46:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FCDProPlusInput::set_rf_filter(int filterIndex)
|
|
|
|
{
|
|
|
|
if ((filterIndex < 0) || (filterIndex >= FCDProPlusConstants::fcdproplus_rf_filter_nb_values()))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint8 cmd_value = FCDProPlusConstants::rf_filters[filterIndex].value;
|
|
|
|
|
2015-09-05 19:34:20 -04:00
|
|
|
if (fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_RF_FILTER, &cmd_value, 1) != FCD_MODE_APP)
|
|
|
|
{
|
|
|
|
qWarning() << "FCDProPlusInput::set_rf_filter: failed to set at " << cmd_value;
|
|
|
|
}
|
2015-09-05 05:46:56 -04:00
|
|
|
}
|
|
|
|
|
2015-09-05 19:34:20 -04:00
|
|
|
void FCDProPlusInput::set_lo_ppm()
|
|
|
|
{
|
|
|
|
set_center_freq((double) m_settings.centerFrequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-05 05:46:56 -04:00
|
|
|
|
2015-09-02 21:57:54 -04:00
|
|
|
|