mirror of https://github.com/f4exb/sdrangel.git
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 <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "SWGDeviceSettings.h"
|
#include "SWGDeviceSettings.h"
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
#include "bladerfoutputthread.h"
|
#include "bladerfoutputthread.h"
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(BladerfOutput::MsgConfigureBladerf, Message)
|
MESSAGE_CLASS_DEFINITION(BladerfOutput::MsgConfigureBladerf, Message)
|
||||||
|
MESSAGE_CLASS_DEFINITION(BladerfOutput::MsgStartStop, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(BladerfOutput::MsgReportBladerf, Message)
|
MESSAGE_CLASS_DEFINITION(BladerfOutput::MsgReportBladerf, Message)
|
||||||
|
|
||||||
BladerfOutput::BladerfOutput(DeviceSinkAPI *deviceAPI) :
|
BladerfOutput::BladerfOutput(DeviceSinkAPI *deviceAPI) :
|
||||||
|
@ -216,6 +218,27 @@ bool BladerfOutput::handleMessage(const Message& message)
|
||||||
qDebug("BladeRF config error");
|
qDebug("BladeRF config error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -486,19 +509,16 @@ int BladerfOutput::webapiRun(
|
||||||
SWGSDRangel::SWGDeviceState& response,
|
SWGSDRangel::SWGDeviceState& response,
|
||||||
QString& errorMessage __attribute__((unused)))
|
QString& errorMessage __attribute__((unused)))
|
||||||
{
|
{
|
||||||
if (run)
|
MsgStartStop *message = MsgStartStop::create(run);
|
||||||
|
m_inputMessageQueue.push(message);
|
||||||
|
|
||||||
|
if (m_guiMessageQueue)
|
||||||
{
|
{
|
||||||
if (m_deviceAPI->initGeneration())
|
MsgStartStop *messagetoGui = MsgStartStop::create(run);
|
||||||
{
|
m_guiMessageQueue->push(messagetoGui);
|
||||||
m_deviceAPI->startGeneration();
|
|
||||||
DSPEngine::instance()->startAudioInputImmediate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_deviceAPI->stopGeneration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usleep(100000);
|
||||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||||
return 200;
|
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 {
|
class MsgReportBladerf : public Message {
|
||||||
MESSAGE_CLASS_DECLARATION
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ BladerfOutputGui::BladerfOutputGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::BladerfOutputGui),
|
ui(new Ui::BladerfOutputGui),
|
||||||
m_deviceUISet(deviceUISet),
|
m_deviceUISet(deviceUISet),
|
||||||
|
m_doApplySettings(true),
|
||||||
m_forceSettings(true),
|
m_forceSettings(true),
|
||||||
m_settings(),
|
m_settings(),
|
||||||
m_deviceSampleSink(NULL),
|
m_deviceSampleSink(NULL),
|
||||||
|
@ -306,18 +307,10 @@ void BladerfOutputGui::on_xb200_currentIndexChanged(int index)
|
||||||
|
|
||||||
void BladerfOutputGui::on_startStop_toggled(bool checked)
|
void BladerfOutputGui::on_startStop_toggled(bool checked)
|
||||||
{
|
{
|
||||||
if (checked)
|
if (m_doApplySettings)
|
||||||
{
|
{
|
||||||
if (m_deviceUISet->m_deviceSinkAPI->initGeneration())
|
BladerfOutput::MsgStartStop *message = BladerfOutput::MsgStartStop::create(checked);
|
||||||
{
|
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
||||||
m_deviceUISet->m_deviceSinkAPI->startGeneration();
|
|
||||||
DSPEngine::instance()->startAudioInput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_deviceUISet->m_deviceSinkAPI->stopGeneration();
|
|
||||||
DSPEngine::instance()->stopAudioInput();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ private:
|
||||||
Ui::BladerfOutputGui* ui;
|
Ui::BladerfOutputGui* ui;
|
||||||
|
|
||||||
DeviceUISet* m_deviceUISet;
|
DeviceUISet* m_deviceUISet;
|
||||||
|
bool m_doApplySettings;
|
||||||
bool m_forceSettings;
|
bool m_forceSettings;
|
||||||
BladeRFOutputSettings m_settings;
|
BladeRFOutputSettings m_settings;
|
||||||
QTimer m_updateTimer;
|
QTimer m_updateTimer;
|
||||||
|
@ -65,6 +66,7 @@ private:
|
||||||
int m_lastEngineState;
|
int m_lastEngineState;
|
||||||
MessageQueue m_inputMessageQueue;
|
MessageQueue m_inputMessageQueue;
|
||||||
|
|
||||||
|
void blockApplySettings(bool block) { m_doApplySettings = !block; }
|
||||||
void displaySettings();
|
void displaySettings();
|
||||||
void sendSettings();
|
void sendSettings();
|
||||||
unsigned int getXb200Index(bool xb_200, bladerf_xb200_path xb200Path, bladerf_xb200_filter xb200Filter);
|
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),
|
QWidget(parent),
|
||||||
ui(new Ui::FileSinkGui),
|
ui(new Ui::FileSinkGui),
|
||||||
m_deviceUISet(deviceUISet),
|
m_deviceUISet(deviceUISet),
|
||||||
|
m_doApplySettings(true),
|
||||||
m_forceSettings(true),
|
m_forceSettings(true),
|
||||||
m_settings(),
|
m_settings(),
|
||||||
m_fileName("./test.sdriq"),
|
m_fileName("./test.sdriq"),
|
||||||
|
@ -142,6 +143,14 @@ bool FileSinkGui::handleMessage(const Message& message)
|
||||||
updateWithStreamTime();
|
updateWithStreamTime();
|
||||||
return true;
|
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
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -259,22 +268,10 @@ void FileSinkGui::on_interp_currentIndexChanged(int index)
|
||||||
|
|
||||||
void FileSinkGui::on_startStop_toggled(bool checked)
|
void FileSinkGui::on_startStop_toggled(bool checked)
|
||||||
{
|
{
|
||||||
if (checked)
|
if (m_doApplySettings)
|
||||||
{
|
{
|
||||||
if (m_deviceUISet->m_deviceSinkAPI->initGeneration())
|
FileSinkOutput::MsgStartStop *message = FileSinkOutput::MsgStartStop::create(checked);
|
||||||
{
|
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ private:
|
||||||
Ui::FileSinkGui* ui;
|
Ui::FileSinkGui* ui;
|
||||||
|
|
||||||
DeviceUISet* m_deviceUISet;
|
DeviceUISet* m_deviceUISet;
|
||||||
|
bool m_doApplySettings;
|
||||||
bool m_forceSettings;
|
bool m_forceSettings;
|
||||||
FileSinkSettings m_settings;
|
FileSinkSettings m_settings;
|
||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
|
@ -72,6 +73,7 @@ private:
|
||||||
int m_lastEngineState;
|
int m_lastEngineState;
|
||||||
MessageQueue m_inputMessageQueue;
|
MessageQueue m_inputMessageQueue;
|
||||||
|
|
||||||
|
void blockApplySettings(bool block) { m_doApplySettings = !block; }
|
||||||
void displaySettings();
|
void displaySettings();
|
||||||
void displayTime();
|
void displayTime();
|
||||||
void sendSettings();
|
void sendSettings();
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "filesinkthread.h"
|
#include "filesinkthread.h"
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSink, Message)
|
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSink, Message)
|
||||||
|
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgStartStop, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkName, Message)
|
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkName, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkWork, Message)
|
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkWork, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkStreamTiming, Message)
|
MESSAGE_CLASS_DEFINITION(FileSinkOutput::MsgConfigureFileSinkStreamTiming, Message)
|
||||||
|
@ -159,6 +160,27 @@ bool FileSinkOutput::handleMessage(const Message& message)
|
||||||
openFileStream();
|
openFileStream();
|
||||||
return true;
|
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))
|
else if (MsgConfigureFileSink::match(message))
|
||||||
{
|
{
|
||||||
qDebug() << "FileSinkOutput::handleMessage: MsgConfigureFileSink";
|
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 {
|
class MsgConfigureFileSinkName : public Message {
|
||||||
MESSAGE_CLASS_DECLARATION
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue