2019-10-23 01:09:47 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Copyright (C) 2019 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 //
|
|
|
|
|
// (at your option) any later version. //
|
|
|
|
|
// //
|
|
|
|
|
// 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 <QMutexLocker>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
#include "dsp/upsamplechannelizer.h"
|
2019-10-23 01:09:47 +02:00
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
#include "beamsteeringcwmodsource.h"
|
2019-10-23 01:09:47 +02:00
|
|
|
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
MESSAGE_CLASS_DEFINITION(BeamSteeringCWModSource::MsgConfigureChannelizer, Message)
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(BeamSteeringCWModSource::MsgSignalNotification, Message)
|
2019-10-25 08:30:01 +02:00
|
|
|
MESSAGE_CLASS_DEFINITION(BeamSteeringCWModSource::MsgConfigureSteeringAngle, Message)
|
2019-10-23 01:09:47 +02:00
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
BeamSteeringCWModSource::BeamSteeringCWModSource() :
|
2019-10-25 08:30:01 +02:00
|
|
|
m_steeringDegrees(90),
|
2019-10-23 01:09:47 +02:00
|
|
|
m_mutex(QMutex::Recursive)
|
|
|
|
|
{
|
|
|
|
|
m_sampleMOFifo.init(2, 96000 * 8);
|
|
|
|
|
m_vbegin.resize(2);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
2019-10-25 08:30:01 +02:00
|
|
|
m_streamSources[i].setStreamIndex(i);
|
|
|
|
|
m_channelizers[i] = new UpSampleChannelizer(&m_streamSources[i]);
|
2019-10-23 01:09:47 +02:00
|
|
|
m_sizes[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
|
&m_sampleMOFifo,
|
|
|
|
|
&SampleMOFifo::dataSyncRead,
|
|
|
|
|
this,
|
2019-10-24 01:23:38 +02:00
|
|
|
&BeamSteeringCWModSource::handleData,
|
2019-10-23 01:09:47 +02:00
|
|
|
Qt::QueuedConnection
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
|
|
|
|
m_lastStream = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
BeamSteeringCWModSource::~BeamSteeringCWModSource()
|
2019-10-23 01:09:47 +02:00
|
|
|
{
|
2019-10-25 08:30:01 +02:00
|
|
|
for (int i = 0; i < 2; i++) {
|
2019-10-23 01:09:47 +02:00
|
|
|
delete m_channelizers[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
void BeamSteeringCWModSource::reset()
|
2019-10-23 01:09:47 +02:00
|
|
|
{
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
m_sampleMOFifo.reset();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
2019-10-25 08:30:01 +02:00
|
|
|
m_streamSources[i].reset();
|
2019-10-23 01:09:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 08:30:01 +02:00
|
|
|
void BeamSteeringCWModSource::setSteeringDegrees(int steeringDegrees)
|
|
|
|
|
{
|
|
|
|
|
m_steeringDegrees = steeringDegrees < -180 ? -180 : steeringDegrees > 180 ? 180 : steeringDegrees;
|
|
|
|
|
MsgConfigureSteeringAngle *msg = MsgConfigureSteeringAngle::create((m_steeringDegrees/180.0f)*M_PI);
|
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BeamSteeringCWModSource::pull(const SampleVector::iterator& begin, unsigned int nbSamples, unsigned int streamIndex)
|
2019-10-23 01:09:47 +02:00
|
|
|
{
|
|
|
|
|
if (streamIndex > 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (streamIndex == m_lastStream) {
|
2019-10-24 01:23:38 +02:00
|
|
|
qWarning("BeamSteeringCWModSource::pull: twice same stream in a row: %u", streamIndex);
|
2019-10-23 01:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_lastStream = streamIndex;
|
|
|
|
|
m_vbegin[streamIndex] = begin;
|
|
|
|
|
m_sizes[streamIndex] = nbSamples;
|
|
|
|
|
|
|
|
|
|
if (streamIndex == 1)
|
|
|
|
|
{
|
2019-10-25 08:30:01 +02:00
|
|
|
unsigned int part1Begin, part1End, part2Begin, part2End, size;
|
|
|
|
|
|
2019-10-23 01:09:47 +02:00
|
|
|
if (m_sizes[0] != m_sizes[1])
|
|
|
|
|
{
|
2019-10-24 01:23:38 +02:00
|
|
|
qWarning("BeamSteeringCWModSource::pull: unequal sizes: [0]: %d [1]: %d", m_sizes[0], m_sizes[1]);
|
2019-10-25 08:30:01 +02:00
|
|
|
size = std::min(m_sizes[0], m_sizes[1]);
|
2019-10-23 01:09:47 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-25 08:30:01 +02:00
|
|
|
size = m_sizes[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<SampleVector>& data = m_sampleMOFifo.getData();
|
|
|
|
|
m_sampleMOFifo.readSync(size, part1Begin, part1End, part2Begin, part2End);
|
|
|
|
|
|
|
|
|
|
if (part1Begin != part1End)
|
|
|
|
|
{
|
|
|
|
|
std::copy(data[0].begin() + part1Begin, data[0].begin() + part1End, m_vbegin[0]);
|
|
|
|
|
std::copy(data[1].begin() + part1Begin, data[1].begin() + part1End, m_vbegin[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (part2Begin != part2End)
|
|
|
|
|
{
|
|
|
|
|
std::copy(data[0].begin() + part2Begin, data[0].begin() + part2End, m_vbegin[0]);
|
|
|
|
|
std::copy(data[1].begin() + part2Begin, data[1].begin() + part2End, m_vbegin[1]);
|
2019-10-23 01:09:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
void BeamSteeringCWModSource::handleData()
|
2019-10-23 01:09:47 +02:00
|
|
|
{
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
2019-10-25 08:30:01 +02:00
|
|
|
std::vector<SampleVector>& data = m_sampleMOFifo.getData();
|
2019-10-23 01:09:47 +02:00
|
|
|
|
|
|
|
|
unsigned int ipart1begin;
|
|
|
|
|
unsigned int ipart1end;
|
|
|
|
|
unsigned int ipart2begin;
|
|
|
|
|
unsigned int ipart2end;
|
|
|
|
|
unsigned int remainder = m_sampleMOFifo.remainderSync();
|
|
|
|
|
|
|
|
|
|
while ((remainder > 0) && (m_inputMessageQueue.size() == 0))
|
|
|
|
|
{
|
2019-10-23 18:36:09 +02:00
|
|
|
m_sampleMOFifo.writeSync(remainder, ipart1begin, ipart1end, ipart2begin, ipart2end);
|
2019-10-23 01:09:47 +02:00
|
|
|
|
|
|
|
|
if (ipart1begin != ipart1end) { // first part of FIFO data
|
|
|
|
|
processFifo(data, ipart1begin, ipart1end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ipart2begin != ipart2end) { // second part of FIFO data (used when block wraps around)
|
|
|
|
|
processFifo(data, ipart2begin, ipart2end);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-23 18:36:09 +02:00
|
|
|
m_sampleMOFifo.commitWriteSync(remainder);
|
2019-10-23 01:09:47 +02:00
|
|
|
remainder = m_sampleMOFifo.remainderSync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 08:30:01 +02:00
|
|
|
void BeamSteeringCWModSource::processFifo(std::vector<SampleVector>& data, unsigned int ibegin, unsigned int iend)
|
2019-10-23 01:09:47 +02:00
|
|
|
{
|
|
|
|
|
for (unsigned int stream = 0; stream < 2; stream++) {
|
2019-10-25 08:30:01 +02:00
|
|
|
m_channelizers[stream]->pull(data[stream].begin() + ibegin, iend - ibegin);
|
2019-10-23 01:09:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
void BeamSteeringCWModSource::handleInputMessages()
|
2019-10-23 01:09:47 +02:00
|
|
|
{
|
2019-10-24 01:23:38 +02:00
|
|
|
qDebug("BeamSteeringCWModSource::handleInputMessage");
|
2019-10-23 01:09:47 +02:00
|
|
|
Message* message;
|
|
|
|
|
|
|
|
|
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
|
|
|
|
{
|
|
|
|
|
if (handleMessage(*message)) {
|
|
|
|
|
delete message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
bool BeamSteeringCWModSource::handleMessage(const Message& cmd)
|
2019-10-23 01:09:47 +02:00
|
|
|
{
|
|
|
|
|
if (MsgConfigureChannelizer::match(cmd))
|
|
|
|
|
{
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
|
|
|
|
|
int log2Interp = cfg.getLog2Interp();
|
|
|
|
|
int filterChainHash = cfg.getFilterChainHash();
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
qDebug() << "BeamSteeringCWModSource::handleMessage: MsgConfigureChannelizer:"
|
2019-10-23 01:09:47 +02:00
|
|
|
<< " log2Interp: " << log2Interp
|
|
|
|
|
<< " filterChainHash: " << filterChainHash;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
2019-10-25 08:30:01 +02:00
|
|
|
m_channelizers[i]->setInterpolation(log2Interp, filterChainHash);
|
|
|
|
|
m_streamSources[i].reset();
|
2019-10-23 01:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (MsgSignalNotification::match(cmd))
|
|
|
|
|
{
|
2019-10-25 08:30:01 +02:00
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
2019-10-23 01:09:47 +02:00
|
|
|
MsgSignalNotification& cfg = (MsgSignalNotification&) cmd;
|
|
|
|
|
int outputSampleRate = cfg.getOutputSampleRate();
|
|
|
|
|
|
2019-10-24 01:23:38 +02:00
|
|
|
qDebug() << "BeamSteeringCWModSource::handleMessage: MsgSignalNotification:"
|
2019-10-23 01:09:47 +02:00
|
|
|
<< " outputSampleRate: " << outputSampleRate
|
2019-10-25 08:30:01 +02:00
|
|
|
<< " centerFrequency: " << cfg.getCenterFrequency();
|
2019-10-23 01:09:47 +02:00
|
|
|
|
2019-10-25 08:30:01 +02:00
|
|
|
for (int i = 0; i < 2; i++)
|
2019-10-23 01:09:47 +02:00
|
|
|
{
|
2019-10-25 08:30:01 +02:00
|
|
|
m_channelizers[i]->setOutputSampleRate(outputSampleRate);
|
|
|
|
|
m_streamSources[i].reset();
|
2019-10-23 01:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-10-25 08:30:01 +02:00
|
|
|
else if (MsgConfigureSteeringAngle::match(cmd))
|
|
|
|
|
{
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
MsgConfigureSteeringAngle& cfg = (MsgConfigureSteeringAngle&) cmd;
|
|
|
|
|
float steeringAngle = cfg.getSteeringAngle();
|
|
|
|
|
steeringAngle = steeringAngle < -M_PI ? -M_PI : steeringAngle > M_PI ? M_PI : steeringAngle;
|
|
|
|
|
|
|
|
|
|
qDebug() << "BeamSteeringCWModSource::handleMessage: MsgConfigureSteeringAngle:"
|
|
|
|
|
<< " steeringAngle: " << steeringAngle;
|
|
|
|
|
|
|
|
|
|
m_streamSources[1].setPhase(M_PI*cos(steeringAngle));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-10-23 01:09:47 +02:00
|
|
|
else
|
|
|
|
|
{
|
2019-10-24 01:23:38 +02:00
|
|
|
qDebug("BeamSteeringCWModSource::handleMessage: unhandled: %s", cmd.getIdentifier());
|
2019-10-23 01:09:47 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|