1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-09-10 02:37:47 -04:00

Beam steering CW Mod: update threading model. Part of #1346

This commit is contained in:
f4exb 2022-10-10 21:45:26 +02:00
parent 77cb80af90
commit f7bc2e1e56
2 changed files with 46 additions and 12 deletions

View File

@ -43,15 +43,15 @@ const char* const BeamSteeringCWMod::m_channelId = "BeamSteeringCWMod";
BeamSteeringCWMod::BeamSteeringCWMod(DeviceAPI *deviceAPI) : BeamSteeringCWMod::BeamSteeringCWMod(DeviceAPI *deviceAPI) :
ChannelAPI(m_channelIdURI, ChannelAPI::StreamMIMO), ChannelAPI(m_channelIdURI, ChannelAPI::StreamMIMO),
m_deviceAPI(deviceAPI), m_deviceAPI(deviceAPI),
m_thread(nullptr),
m_basebandSource(nullptr),
m_running(false),
m_guiMessageQueue(nullptr), m_guiMessageQueue(nullptr),
m_frequencyOffset(0), m_frequencyOffset(0),
m_basebandSampleRate(48000) m_basebandSampleRate(48000)
{ {
setObjectName(m_channelId); setObjectName(m_channelId);
m_thread = new QThread(this);
m_basebandSource = new BeamSteeringCWModBaseband();
m_basebandSource->moveToThread(m_thread);
m_deviceAPI->addMIMOChannel(this); m_deviceAPI->addMIMOChannel(this);
m_deviceAPI->addMIMOChannelAPI(this); m_deviceAPI->addMIMOChannelAPI(this);
@ -62,6 +62,7 @@ BeamSteeringCWMod::BeamSteeringCWMod(DeviceAPI *deviceAPI) :
this, this,
&BeamSteeringCWMod::networkManagerFinished &BeamSteeringCWMod::networkManagerFinished
); );
startSources();
} }
BeamSteeringCWMod::~BeamSteeringCWMod() BeamSteeringCWMod::~BeamSteeringCWMod()
@ -76,8 +77,7 @@ BeamSteeringCWMod::~BeamSteeringCWMod()
m_deviceAPI->removeChannelSinkAPI(this); m_deviceAPI->removeChannelSinkAPI(this);
m_deviceAPI->removeMIMOChannel(this); m_deviceAPI->removeMIMOChannel(this);
delete m_basebandSource; stopSources();
delete m_thread;
} }
void BeamSteeringCWMod::setDeviceAPI(DeviceAPI *deviceAPI) void BeamSteeringCWMod::setDeviceAPI(DeviceAPI *deviceAPI)
@ -94,9 +94,24 @@ void BeamSteeringCWMod::setDeviceAPI(DeviceAPI *deviceAPI)
void BeamSteeringCWMod::startSources() void BeamSteeringCWMod::startSources()
{ {
QMutexLocker mlock(&m_mutex);
if (m_running) {
return;
}
qDebug("BeamSteeringCWMod::startSources"); qDebug("BeamSteeringCWMod::startSources");
m_thread = new QThread(this);
m_basebandSource = new BeamSteeringCWModBaseband();
m_basebandSource->moveToThread(m_thread);
QObject::connect(m_thread, &QThread::finished, m_basebandSource, &QObject::deleteLater);
QObject::connect(m_thread, &QThread::finished, m_thread, &QThread::deleteLater);
m_basebandSource->reset(); m_basebandSource->reset();
m_thread->start(); m_thread->start();
m_running = true;
mlock.unlock();
BeamSteeringCWModBaseband::MsgSignalNotification *sig = BeamSteeringCWModBaseband::MsgSignalNotification::create( BeamSteeringCWModBaseband::MsgSignalNotification *sig = BeamSteeringCWModBaseband::MsgSignalNotification::create(
m_basebandSampleRate); m_basebandSampleRate);
@ -109,14 +124,25 @@ void BeamSteeringCWMod::startSources()
void BeamSteeringCWMod::stopSources() void BeamSteeringCWMod::stopSources()
{ {
QMutexLocker mlock(&m_mutex);
if (!m_running) {
return;
}
qDebug("BeamSteeringCWMod::stopSources"); qDebug("BeamSteeringCWMod::stopSources");
m_running = false;
m_thread->exit(); m_thread->exit();
m_thread->wait(); m_thread->wait();
m_basebandSource = nullptr;
m_thread = nullptr;
} }
void BeamSteeringCWMod::pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex) void BeamSteeringCWMod::pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex)
{ {
m_basebandSource->pull(begin, nbSamples, sourceIndex); if (m_running) {
m_basebandSource->pull(begin, nbSamples, sourceIndex);
}
} }
void BeamSteeringCWMod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex) void BeamSteeringCWMod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex)
@ -159,8 +185,11 @@ void BeamSteeringCWMod::applySettings(const BeamSteeringCWModSettings& settings,
reverseAPIKeys.append("filterChainHash"); reverseAPIKeys.append("filterChainHash");
} }
BeamSteeringCWModBaseband::MsgConfigureBeamSteeringCWModBaseband *msg = BeamSteeringCWModBaseband::MsgConfigureBeamSteeringCWModBaseband::create(settings, force); if (m_running)
m_basebandSource->getInputMessageQueue()->push(msg); {
BeamSteeringCWModBaseband::MsgConfigureBeamSteeringCWModBaseband *msg = BeamSteeringCWModBaseband::MsgConfigureBeamSteeringCWModBaseband::create(settings, force);
m_basebandSource->getInputMessageQueue()->push(msg);
}
QList<ObjectPipe*> pipes; QList<ObjectPipe*> pipes;
MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes);
@ -210,10 +239,13 @@ bool BeamSteeringCWMod::handleMessage(const Message& cmd)
calculateFrequencyOffset(); // This is when device sample rate changes calculateFrequencyOffset(); // This is when device sample rate changes
// Notify source of input sample rate change // Notify source of input sample rate change
BeamSteeringCWModBaseband::MsgSignalNotification *sig = BeamSteeringCWModBaseband::MsgSignalNotification::create( if (m_running)
m_basebandSampleRate); {
qDebug() << "BeamSteeringCWMod::handleMessage: DSPMIMOSignalNotification: push to source"; BeamSteeringCWModBaseband::MsgSignalNotification *sig = BeamSteeringCWModBaseband::MsgSignalNotification::create(
m_basebandSource->getInputMessageQueue()->push(sig); m_basebandSampleRate);
qDebug() << "BeamSteeringCWMod::handleMessage: DSPMIMOSignalNotification: push to source";
m_basebandSource->getInputMessageQueue()->push(sig);
}
if (m_guiMessageQueue) if (m_guiMessageQueue)
{ {

View File

@ -154,6 +154,8 @@ private:
DeviceAPI *m_deviceAPI; DeviceAPI *m_deviceAPI;
QThread *m_thread; QThread *m_thread;
BeamSteeringCWModBaseband* m_basebandSource; BeamSteeringCWModBaseband* m_basebandSource;
QMutex m_mutex;
bool m_running;
BasebandSampleSink* m_spectrumSink; BasebandSampleSink* m_spectrumSink;
BasebandSampleSink* m_scopeSink; BasebandSampleSink* m_scopeSink;
BeamSteeringCWModSettings m_settings; BeamSteeringCWModSettings m_settings;