mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 17:58:43 -05:00
Web API: use message passing to start/stop device, applied to BladeRF output and file output
This commit is contained in:
parent
53925bd4fd
commit
db86bc5813
@ -16,6 +16,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
@ -33,6 +34,7 @@
|
||||
#include "bladerfoutputthread.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(BladerfOutput::MsgConfigureBladerf, Message)
|
||||
MESSAGE_CLASS_DEFINITION(BladerfOutput::MsgStartStop, Message)
|
||||
MESSAGE_CLASS_DEFINITION(BladerfOutput::MsgReportBladerf, Message)
|
||||
|
||||
BladerfOutput::BladerfOutput(DeviceSinkAPI *deviceAPI) :
|
||||
@ -218,6 +220,27 @@ bool BladerfOutput::handleMessage(const Message& message)
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgStartStop::match(message))
|
||||
{
|
||||
MsgStartStop& cmd = (MsgStartStop&) message;
|
||||
qDebug() << "SDRPlayInput::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;
|
||||
@ -486,19 +509,16 @@ int BladerfOutput::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 MsgReportBladerf : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
|
@ -33,6 +33,7 @@ BladerfOutputGui::BladerfOutputGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::BladerfOutputGui),
|
||||
m_deviceUISet(deviceUISet),
|
||||
m_doApplySettings(true),
|
||||
m_forceSettings(true),
|
||||
m_settings(),
|
||||
m_deviceSampleSink(NULL),
|
||||
@ -306,18 +307,10 @@ void BladerfOutputGui::on_xb200_currentIndexChanged(int index)
|
||||
|
||||
void BladerfOutputGui::on_startStop_toggled(bool checked)
|
||||
{
|
||||
if (checked)
|
||||
if (m_doApplySettings)
|
||||
{
|
||||
if (m_deviceUISet->m_deviceSinkAPI->initGeneration())
|
||||
{
|
||||
m_deviceUISet->m_deviceSinkAPI->startGeneration();
|
||||
DSPEngine::instance()->startAudioInput();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceUISet->m_deviceSinkAPI->stopGeneration();
|
||||
DSPEngine::instance()->stopAudioInput();
|
||||
BladerfOutput::MsgStartStop *message = BladerfOutput::MsgStartStop::create(checked);
|
||||
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,7 @@ private:
|
||||
Ui::BladerfOutputGui* ui;
|
||||
|
||||
DeviceUISet* m_deviceUISet;
|
||||
bool m_doApplySettings;
|
||||
bool m_forceSettings;
|
||||
BladeRFOutputSettings m_settings;
|
||||
QTimer m_updateTimer;
|
||||
@ -65,6 +66,7 @@ private:
|
||||
int m_lastEngineState;
|
||||
MessageQueue m_inputMessageQueue;
|
||||
|
||||
void blockApplySettings(bool block) { m_doApplySettings = !block; }
|
||||
void displaySettings();
|
||||
void sendSettings();
|
||||
unsigned int getXb200Index(bool xb_200, bladerf_xb200_path xb200Path, bladerf_xb200_filter xb200Filter);
|
||||
|
@ -39,6 +39,7 @@ FileSinkGui::FileSinkGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::FileSinkGui),
|
||||
m_deviceUISet(deviceUISet),
|
||||
m_doApplySettings(true),
|
||||
m_forceSettings(true),
|
||||
m_settings(),
|
||||
m_fileName("./test.sdriq"),
|
||||
@ -142,6 +143,14 @@ bool FileSinkGui::handleMessage(const Message& message)
|
||||
updateWithStreamTime();
|
||||
return true;
|
||||
}
|
||||
else if (FileSinkOutput::MsgStartStop::match(message))
|
||||
{
|
||||
FileSinkOutput::MsgStartStop& notif = (FileSinkOutput::MsgStartStop&) message;
|
||||
blockApplySettings(true);
|
||||
ui->startStop->setChecked(notif.getStartStop());
|
||||
blockApplySettings(false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
@ -259,22 +268,10 @@ void FileSinkGui::on_interp_currentIndexChanged(int index)
|
||||
|
||||
void FileSinkGui::on_startStop_toggled(bool checked)
|
||||
{
|
||||
if (checked)
|
||||
if (m_doApplySettings)
|
||||
{
|
||||
if (m_deviceUISet->m_deviceSinkAPI->initGeneration())
|
||||
{
|
||||
if (!m_deviceUISet->m_deviceSinkAPI->startGeneration())
|
||||
{
|
||||
qDebug("FileSinkGui::on_startStop_toggled: device start failed");
|
||||
}
|
||||
|
||||
DSPEngine::instance()->startAudioInput();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceUISet->m_deviceSinkAPI->stopGeneration();
|
||||
DSPEngine::instance()->stopAudioInput();
|
||||
FileSinkOutput::MsgStartStop *message = FileSinkOutput::MsgStartStop::create(checked);
|
||||
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ private:
|
||||
Ui::FileSinkGui* ui;
|
||||
|
||||
DeviceUISet* m_deviceUISet;
|
||||
bool m_doApplySettings;
|
||||
bool m_forceSettings;
|
||||
FileSinkSettings m_settings;
|
||||
QString m_fileName;
|
||||
@ -72,6 +73,7 @@ private:
|
||||
int m_lastEngineState;
|
||||
MessageQueue m_inputMessageQueue;
|
||||
|
||||
void blockApplySettings(bool block) { m_doApplySettings = !block; }
|
||||
void displaySettings();
|
||||
void displayTime();
|
||||
void sendSettings();
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "filesinkthread.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSink, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgStartStop, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkName, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkWork, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkStreamTiming, Message)
|
||||
@ -159,6 +160,27 @@ bool FileSinkOutput::handleMessage(const Message& message)
|
||||
openFileStream();
|
||||
return true;
|
||||
}
|
||||
else if (MsgStartStop::match(message))
|
||||
{
|
||||
MsgStartStop& cmd = (MsgStartStop&) message;
|
||||
qDebug() << "FileSinkOutput::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 if (MsgConfigureFileSink::match(message))
|
||||
{
|
||||
qDebug() << "FileSinkOutput::handleMessage: MsgConfigureFileSink";
|
||||
|
@ -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 MsgConfigureFileSinkName : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user