Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote TCP Input fixes for #1467 #1495

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/samplesource/remotetcpinput/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ This is the correction to be applied to the remote device's local oscillator in

<h3>5: DC offset correction</h3>

Check this button to enable DC offset correction on the remote device. This is only supported when the remote server is SDRangel.
Check this button to enable DC offset correction.

<h3>6: IQ imbalance correction</h3>

Check this button to enable IQ imbalance correction on the remote device. This is only supported when the remote server is SDRangel.
Check this button to enable IQ imbalance correction.

<h3>7: Bias tee</h3>

Expand Down
9 changes: 9 additions & 0 deletions plugins/samplesource/remotetcpinput/remotetcpinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ void RemoteTCPInput::applySettings(const RemoteTCPInputSettings& settings, const
std::ostringstream os;
bool forwardChange = false;

// Should this only be applied if not applied on remote?
if (settingsKeys.contains("dcBlock") || settingsKeys.contains("iqCorrection") || force)
{
m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection);
qDebug("RemoteTCPInput::applySettings: corrections: DC block: %s IQ imbalance: %s",
settings.m_dcBlock ? "true" : "false",
settings.m_iqCorrection ? "true" : "false");
}

if (settingsKeys.contains("centerFrequency") || force) {
forwardChange = true;
}
Expand Down
2 changes: 0 additions & 2 deletions plugins/samplesource/remotetcpinput/remotetcpinputgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ bool RemoteTCPInputGui::handleMessage(const Message& message)
ui->sampleBits->removeItem(ui->sampleBits->count() - 1);
}
}
ui->dcOffset->setVisible(sdra);
ui->iqImbalance->setVisible(sdra);
if (sdra && (ui->decim->count() != 7))
{
ui->decim->addItem("2");
Expand Down
55 changes: 42 additions & 13 deletions plugins/samplesource/remotetcpinput/remotetcpinputtcphandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ RemoteTCPInputTCPHandler::RemoteTCPInputTCPHandler(SampleSinkFifo *sampleFifo, D
m_fillBuffer(true),
m_timer(this),
m_reconnectTimer(this),
m_sdra(false),
m_converterBuffer(nullptr),
m_converterBufferNbSamples(0),
m_settings()
Expand Down Expand Up @@ -218,6 +219,18 @@ void RemoteTCPInputTCPHandler::setTunerGain(int gain)
}
}

void RemoteTCPInputTCPHandler::setGainByIndex(int index)
{
QMutexLocker mutexLocker(&m_mutex);

quint8 request[5];
request[0] = RemoteTCPProtocol::setGainByIndex;
RemoteTCPProtocol::encodeUInt32(&request[1], index);
if (m_dataSocket) {
m_dataSocket->write((char*)request, sizeof(request));
}
}

void RemoteTCPInputTCPHandler::setFreqCorrection(int correction)
{
QMutexLocker mutexLocker(&m_mutex);
Expand Down Expand Up @@ -260,7 +273,7 @@ void RemoteTCPInputTCPHandler::setDirectSampling(bool enabled)

quint8 request[5];
request[0] = RemoteTCPProtocol::setDirectSampling;
RemoteTCPProtocol::encodeUInt32(&request[1], enabled);
RemoteTCPProtocol::encodeUInt32(&request[1], enabled ? 3 : 0);
if (m_dataSocket) {
m_dataSocket->write((char*)request, sizeof(request));
}
Expand Down Expand Up @@ -388,10 +401,14 @@ void RemoteTCPInputTCPHandler::applySettings(const RemoteTCPInputSettings& setti
setFreqCorrection(settings.m_loPpmCorrection);
}
if (settingsKeys.contains("dcBlock") || force) {
setDCOffsetRemoval(settings.m_dcBlock);
if (m_sdra) {
setDCOffsetRemoval(settings.m_dcBlock);
}
}
if (settingsKeys.contains("iqCorrection") || force) {
setIQCorrection(settings.m_iqCorrection);
if (m_sdra) {
setIQCorrection(settings.m_iqCorrection);
}
}
if (settingsKeys.contains("biasTee") || force) {
setBiasTee(settings.m_biasTee);
Expand All @@ -400,7 +417,9 @@ void RemoteTCPInputTCPHandler::applySettings(const RemoteTCPInputSettings& setti
setDirectSampling(settings.m_directSampling);
}
if (settingsKeys.contains("log2Decim") || force) {
setDecimation(settings.m_log2Decim);
if (m_sdra) {
setDecimation(settings.m_log2Decim);
}
}
if (settingsKeys.contains("devSampleRate") || force) {
setSampleRate(settings.m_devSampleRate);
Expand All @@ -417,17 +436,21 @@ void RemoteTCPInputTCPHandler::applySettings(const RemoteTCPInputSettings& setti
for (int i = 1; i < 3; i++)
{
if (settingsKeys.contains(QString("gain[%1]").arg(i)) || force) {
//setIFGain(i, 20 + settings.m_gain[i]);
setIFGain(i, settings.m_gain[i]);
}
}
if (settingsKeys.contains("rfBW") || force) {
setBandwidth(settings.m_rfBW);
}
if (settingsKeys.contains("inputFrequencyOffset") || force) {
setChannelFreqOffset(settings.m_inputFrequencyOffset);
if (m_sdra) {
setChannelFreqOffset(settings.m_inputFrequencyOffset);
}
}
if (settingsKeys.contains("channelGain") || force) {
setChannelGain(settings.m_channelGain);
if (m_sdra) {
setChannelGain(settings.m_channelGain);
}
}
if ((settings.m_channelSampleRate != m_settings.m_channelSampleRate) || force)
{
Expand All @@ -441,12 +464,16 @@ void RemoteTCPInputTCPHandler::applySettings(const RemoteTCPInputSettings& setti
m_tcpBuf = new char[m_sampleFifo->size()*2*4];
m_fillBuffer = true; // So we reprime FIFO
}
setChannelSampleRate(settings.m_channelSampleRate);
if (m_sdra) {
setChannelSampleRate(settings.m_channelSampleRate);
}
clearBuffer();
}
if (settingsKeys.contains("sampleBits") || force)
{
setSampleBitDepth(settings.m_sampleBits);
if (m_sdra) {
setSampleBitDepth(settings.m_sampleBits);
}
clearBuffer();
}

Expand Down Expand Up @@ -536,6 +563,7 @@ void RemoteTCPInputTCPHandler::dataReadyRead()

if (protocol == "RTL0")
{
m_sdra = false;
bytesRead = m_dataSocket->read((char *)&metaData[4], RemoteTCPProtocol::m_rtl0MetaDataSize-4);

RemoteTCPProtocol::Device tuner = (RemoteTCPProtocol::Device)RemoteTCPProtocol::extractUInt32(&metaData[4]);
Expand All @@ -557,6 +585,7 @@ void RemoteTCPInputTCPHandler::dataReadyRead()
}
else if (protocol == "SDRA")
{
m_sdra = true;
bytesRead = m_dataSocket->read((char *)&metaData[4], RemoteTCPProtocol::m_sdraMetaDataSize-4);

RemoteTCPProtocol::Device device = (RemoteTCPProtocol::Device)RemoteTCPProtocol::extractUInt32(&metaData[4]);
Expand Down Expand Up @@ -704,22 +733,22 @@ void RemoteTCPInputTCPHandler::convert(int nbSamples)
}
else if ((m_settings.m_sampleBits == 8) && (SDR_RX_SAMP_SZ == 16))
{
qint8 *in = (qint8 *)m_tcpBuf;
quint8 *in = (quint8 *)m_tcpBuf;
qint16 *out = (qint16 *)m_converterBuffer;

for (int is = 0; is < nbSamples*2; is++) {
out[is] = (((qint16)in[is]) - 128);
out[is] = (((qint16)in[is]) - 128) << 8;
}

m_sampleFifo->write(reinterpret_cast<quint8*>(out), nbSamples*sizeof(Sample));
}
else if ((m_settings.m_sampleBits == 8) && (SDR_RX_SAMP_SZ == 24))
{
qint8 *in = (qint8 *)m_tcpBuf;
quint8 *in = (quint8 *)m_tcpBuf;
qint32 *out = (qint32 *)m_converterBuffer;

for (int is = 0; is < nbSamples*2; is++) {
out[is] = (((qint32)in[is]) - 128) << 8; // Only shift by 8, rather than 16, to match levels of native driver
out[is] = (((qint32)in[is]) - 128) << 16;
}

m_sampleFifo->write(reinterpret_cast<quint8*>(out), nbSamples*sizeof(Sample));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public slots:
QTimer m_timer;
QTimer m_reconnectTimer;
QDateTime m_prevDateTime;
bool m_sdra;

int32_t *m_converterBuffer;
uint32_t m_converterBufferNbSamples;
Expand All @@ -155,6 +156,7 @@ public slots:
void setCenterFrequency(quint64 frequency);
void setTunerAGC(bool agc);
void setTunerGain(int gain);
void setGainByIndex(int gain);
void setFreqCorrection(int correction);
void setIFGain(quint16 stage, quint16 gain);
void setAGC(bool agc);
Expand Down