1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-01 21:54:55 -04:00

Web API: use message passing to start/stop device for all the rest of device plugins

This commit is contained in:
f4exb
2017-12-14 18:02:49 +01:00
parent db86bc5813
commit 966767a44a
42 changed files with 884 additions and 389 deletions
@@ -18,6 +18,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <QDebug>
#include "SWGDeviceSettings.h"
@@ -38,6 +39,7 @@
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgConfigureHackRF, Message)
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgReportHackRF, Message)
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgFileRecord, Message)
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgStartStop, Message)
HackRFInput::HackRFInput(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
@@ -226,6 +228,27 @@ bool HackRFInput::handleMessage(const Message& message)
return true;
}
else if (MsgStartStop::match(message))
{
MsgStartStop& cmd = (MsgStartStop&) message;
qDebug() << "HackRFInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
if (cmd.getStartStop())
{
if (m_deviceAPI->initAcquisition())
{
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
}
return true;
}
else
{
return false;
@@ -502,19 +525,16 @@ int HackRFInput::webapiRun(
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage __attribute__((unused)))
{
if (run)
MsgStartStop *message = MsgStartStop::create(run);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue) // forward to GUI if any
{
if (m_deviceAPI->initAcquisition())
{
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutputImmediate();
}
}
else
{
m_deviceAPI->stopAcquisition();
MsgStartStop *msgToGUI = MsgStartStop::create(run);
m_guiMessageQueue->push(msgToGUI);
}
usleep(100000);
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
return 200;
}
@@ -72,6 +72,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 MsgFileRecord : public Message {
MESSAGE_CLASS_DECLARATION
@@ -130,6 +130,15 @@ bool HackRFInputGui::handleMessage(const Message& message)
displaySettings();
return true;
}
else if (HackRFInput::MsgStartStop::match(message))
{
HackRFInput::MsgStartStop& notif = (HackRFInput::MsgStartStop&) message;
blockApplySettings(true);
ui->startStop->setChecked(notif.getStartStop());
blockApplySettings(false);
return true;
}
else
{
return false;
@@ -333,25 +342,10 @@ void HackRFInputGui::on_vga_valueChanged(int value)
void HackRFInputGui::on_startStop_toggled(bool checked)
{
if (checked)
if (m_doApplySettings)
{
// forcibly stop the Tx if present before starting
if (m_deviceUISet->m_deviceSourceAPI->getSinkBuddies().size() > 0)
{
DeviceSinkAPI *buddy = m_deviceUISet->m_deviceSourceAPI->getSinkBuddies()[0];
buddy->stopGeneration();
}
if (m_deviceUISet->m_deviceSourceAPI->initAcquisition())
{
m_deviceUISet->m_deviceSourceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceUISet->m_deviceSourceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
HackRFInput::MsgStartStop *message = HackRFInput::MsgStartStop::create(checked);
m_sampleSource->getInputMessageQueue()->push(message);
}
}