mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-15 20:28:52 -04:00
Web API: use message passing to start/stop device for all the rest of device plugins
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
@@ -34,6 +35,7 @@
|
||||
#include "hackrfoutputthread.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(HackRFOutput::MsgConfigureHackRF, Message)
|
||||
MESSAGE_CLASS_DEFINITION(HackRFOutput::MsgStartStop, Message)
|
||||
MESSAGE_CLASS_DEFINITION(HackRFOutput::MsgReportHackRF, Message)
|
||||
|
||||
HackRFOutput::HackRFOutput(DeviceSinkAPI *deviceAPI) :
|
||||
@@ -205,6 +207,27 @@ bool HackRFOutput::handleMessage(const Message& message)
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgStartStop::match(message))
|
||||
{
|
||||
MsgStartStop& cmd = (MsgStartStop&) message;
|
||||
qDebug() << "HackRFOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
||||
|
||||
if (cmd.getStartStop())
|
||||
{
|
||||
if (m_deviceAPI->initGeneration())
|
||||
{
|
||||
m_deviceAPI->startGeneration();
|
||||
DSPEngine::instance()->startAudioInput();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopGeneration();
|
||||
DSPEngine::instance()->stopAudioInput();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
@@ -413,19 +436,16 @@ int HackRFOutput::webapiRun(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
if (run)
|
||||
MsgStartStop *message = MsgStartStop::create(run);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
if (m_deviceAPI->initGeneration())
|
||||
{
|
||||
m_deviceAPI->startGeneration();
|
||||
DSPEngine::instance()->startAudioInputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopGeneration();
|
||||
MsgStartStop *messagetoGui = MsgStartStop::create(run);
|
||||
m_guiMessageQueue->push(messagetoGui);
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,25 @@ public:
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgStartStop : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
bool getStartStop() const { return m_startStop; }
|
||||
|
||||
static MsgStartStop* create(bool startStop) {
|
||||
return new MsgStartStop(startStop);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool m_startStop;
|
||||
|
||||
MsgStartStop(bool startStop) :
|
||||
Message(),
|
||||
m_startStop(startStop)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgReportHackRF : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
|
||||
@@ -136,6 +136,14 @@ bool HackRFOutputGui::handleMessage(const Message& message)
|
||||
displaySettings();
|
||||
return true;
|
||||
}
|
||||
else if (HackRFOutput::MsgStartStop::match(message))
|
||||
{
|
||||
HackRFOutput::MsgStartStop& notif = (HackRFOutput::MsgStartStop&) message;
|
||||
blockApplySettings(true);
|
||||
ui->startStop->setChecked(notif.getStartStop());
|
||||
blockApplySettings(false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
@@ -298,25 +306,10 @@ void HackRFOutputGui::on_txvga_valueChanged(int value)
|
||||
|
||||
void HackRFOutputGui::on_startStop_toggled(bool checked)
|
||||
{
|
||||
if (checked)
|
||||
if (m_doApplySettings)
|
||||
{
|
||||
// forcibly stop the Rx if present before starting
|
||||
if (m_deviceUISet->m_deviceSinkAPI->getSourceBuddies().size() > 0)
|
||||
{
|
||||
DeviceSourceAPI *buddy = m_deviceUISet->m_deviceSinkAPI->getSourceBuddies()[0];
|
||||
buddy->stopAcquisition();
|
||||
}
|
||||
|
||||
if (m_deviceUISet->m_deviceSinkAPI->initGeneration())
|
||||
{
|
||||
m_deviceUISet->m_deviceSinkAPI->startGeneration();
|
||||
DSPEngine::instance()->startAudioInput();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceUISet->m_deviceSinkAPI->stopGeneration();
|
||||
DSPEngine::instance()->startAudioInput();
|
||||
HackRFOutput::MsgStartStop *message = HackRFOutput::MsgStartStop::create(checked);
|
||||
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user