mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
Web API: implemented device run APIs for BladeRF output, HackRF, PlutoSDR and LimeSDR ourput
This commit is contained in:
parent
9819e01da5
commit
565083e5f5
@ -1,5 +1,7 @@
|
||||
project(bladerfoutput)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
set(bladerfoutput_SOURCES
|
||||
bladerfoutputgui.cpp
|
||||
bladerfoutput.cpp
|
||||
@ -24,6 +26,7 @@ if (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBBLADERFLIBSRC}/include
|
||||
${LIBBLADERFLIBSRC}/src
|
||||
@ -32,6 +35,7 @@ else (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBBLADERF_INCLUDE_DIR}
|
||||
)
|
||||
@ -57,6 +61,7 @@ target_link_libraries(outputbladerf
|
||||
bladerf
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
bladerfdevice
|
||||
)
|
||||
else (BUILD_DEBIAN)
|
||||
@ -65,6 +70,7 @@ target_link_libraries(outputbladerf
|
||||
${LIBBLADERF_LIBRARIES}
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
bladerfdevice
|
||||
)
|
||||
endif (BUILD_DEBIAN)
|
||||
|
@ -18,9 +18,11 @@
|
||||
#include <errno.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "device/devicesinkapi.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "bladerf/devicebladerfshared.h"
|
||||
@ -469,3 +471,33 @@ bool BladerfOutput::applySettings(const BladeRFOutputSettings& settings, bool fo
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int BladerfOutput::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int BladerfOutput::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
if (m_deviceAPI->initGeneration())
|
||||
{
|
||||
m_deviceAPI->startGeneration();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopGeneration();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,15 @@ public:
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
private:
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
|
@ -22,6 +22,7 @@ CONFIG(MINGW64):LIBBLADERFSRC = "D:\softs\bladeRF\host\libraries\libbladeRF\incl
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += ../../../sdrbase
|
||||
INCLUDEPATH += ../../../sdrgui
|
||||
INCLUDEPATH += ../../../swagger/sdrangel/code/qt5/client
|
||||
INCLUDEPATH += ../../../devices
|
||||
INCLUDEPATH += $$LIBBLADERFSRC
|
||||
|
||||
@ -44,6 +45,7 @@ FORMS += bladerfoutputgui.ui
|
||||
|
||||
LIBS += -L../../../sdrbase/$${build_subdir} -lsdrbase
|
||||
LIBS += -L../../../sdrgui/$${build_subdir} -lsdrgui
|
||||
LIBS += -L../../../swagger/$${build_subdir} -lswagger
|
||||
LIBS += -L../../../libbladerf/$${build_subdir} -llibbladerf
|
||||
LIBS += -L../../../devices/$${build_subdir} -ldevices
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
const PluginDescriptor BladerfOutputPlugin::m_pluginDescriptor = {
|
||||
QString("BladerRF Output"),
|
||||
QString("3.8.0"),
|
||||
QString("3.8.6"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -1,5 +1,7 @@
|
||||
project(hackrfoutput)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
set(hackrfoutput_SOURCES
|
||||
hackrfoutputgui.cpp
|
||||
hackrfoutput.cpp
|
||||
@ -24,6 +26,7 @@ if (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBHACKRFSRC}
|
||||
${LIBHACKRFSRC}/libhackrf/src
|
||||
@ -32,6 +35,7 @@ else (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBHACKRF_INCLUDE_DIR}
|
||||
)
|
||||
@ -58,6 +62,7 @@ target_link_libraries(outputhackrf
|
||||
hackrf
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
hackrfdevice
|
||||
)
|
||||
else (BUILD_DEBIAN)
|
||||
@ -66,6 +71,7 @@ target_link_libraries(outputhackrf
|
||||
${LIBHACKRF_LIBRARIES}
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
hackrfdevice
|
||||
)
|
||||
endif (BUILD_DEBIAN)
|
||||
|
@ -20,6 +20,9 @@
|
||||
#include <errno.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
@ -396,3 +399,34 @@ bool HackRFOutput::applySettings(const HackRFOutputSettings& settings, bool forc
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int HackRFOutput::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int HackRFOutput::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
if (m_deviceAPI->initGeneration())
|
||||
{
|
||||
m_deviceAPI->startGeneration();
|
||||
DSPEngine::instance()->startAudioInputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopGeneration();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,15 @@ public:
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
private:
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
const PluginDescriptor HackRFOutputPlugin::m_pluginDescriptor = {
|
||||
QString("HackRF Output"),
|
||||
QString("3.8.0"),
|
||||
QString("3.8.6"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -22,10 +22,12 @@
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGLimeSdrOutputSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "device/devicesinkapi.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "limesdroutputthread.h"
|
||||
#include "limesdr/devicelimesdrparam.h"
|
||||
#include "limesdr/devicelimesdr.h"
|
||||
@ -1077,3 +1079,33 @@ int LimeSDROutput::webapiSettingsPutPatch(
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
int LimeSDROutput::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int LimeSDROutput::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
if (m_deviceAPI->initGeneration())
|
||||
{
|
||||
m_deviceAPI->startGeneration();
|
||||
DSPEngine::instance()->startAudioInputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopGeneration();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
@ -187,6 +187,15 @@ public:
|
||||
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
std::size_t getChannelIndex();
|
||||
void getLORange(float& minF, float& maxF, float& stepF) const;
|
||||
void getSRRange(float& minF, float& maxF, float& stepF) const;
|
||||
|
@ -1,5 +1,7 @@
|
||||
project(plutosdroutput)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
set(plutosdroutput_SOURCES
|
||||
plutosdroutputgui.cpp
|
||||
plutosdroutput.cpp
|
||||
@ -24,6 +26,7 @@ if (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBIIOSRC}
|
||||
)
|
||||
@ -31,6 +34,7 @@ else (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBIIO_INCLUDE_DIR}
|
||||
)
|
||||
@ -56,6 +60,7 @@ target_link_libraries(outputplutosdr
|
||||
iio
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
plutosdrdevice
|
||||
)
|
||||
else (BUILD_DEBIAN)
|
||||
@ -64,6 +69,7 @@ target_link_libraries(outputplutosdr
|
||||
${LIBIIO_LIBRARIES}
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
plutosdrdevice
|
||||
)
|
||||
endif (BUILD_DEBIAN)
|
||||
|
@ -16,7 +16,11 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "device/devicesinkapi.h"
|
||||
#include "plutosdr/deviceplutosdrparams.h"
|
||||
@ -473,3 +477,34 @@ float PlutoSDROutput::getTemperature()
|
||||
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
|
||||
return plutoBox->getTemp();
|
||||
}
|
||||
|
||||
int PlutoSDROutput::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int PlutoSDROutput::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
if (m_deviceAPI->initGeneration())
|
||||
{
|
||||
m_deviceAPI->startGeneration();
|
||||
DSPEngine::instance()->startAudioInputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopGeneration();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,15 @@ public:
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
uint32_t getDACSampleRate() const { return m_deviceSampleRates.m_addaConnvRate; }
|
||||
uint32_t getFIRSampleRate() const { return m_deviceSampleRates.m_hb1Rate; }
|
||||
void getRSSI(std::string& rssiStr);
|
||||
|
@ -23,6 +23,7 @@ CONFIG(MINGW64):LIBIIOSRC = "D:\softs\libiio"
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += ../../../sdrbase
|
||||
INCLUDEPATH += ../../../sdrgui
|
||||
INCLUDEPATH += ../../../swagger/sdrangel/code/qt5/client
|
||||
INCLUDEPATH += ../../../devices
|
||||
INCLUDEPATH += ../../../libiio/includemw
|
||||
INCLUDEPATH += $$LIBIIOSRC
|
||||
@ -46,6 +47,7 @@ FORMS += plutosdroutputgui.ui
|
||||
|
||||
LIBS += -L../../../sdrbase/$${build_subdir} -lsdrbase
|
||||
LIBS += -L../../../sdrgui/$${build_subdir} -lsdrgui
|
||||
LIBS += -L../../../swagger/$${build_subdir} -lswagger
|
||||
LIBS += -L../../../libiio/$${build_subdir} -llibiio
|
||||
LIBS += -L../../../devices/$${build_subdir} -ldevices
|
||||
|
||||
|
@ -28,7 +28,7 @@ class DeviceSourceAPI;
|
||||
|
||||
const PluginDescriptor PlutoSDROutputPlugin::m_pluginDescriptor = {
|
||||
QString("PlutoSDR Output"),
|
||||
QString("3.8.0"),
|
||||
QString("3.8.6"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGRtlSdrSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
@ -564,13 +563,12 @@ int BladerfInput::webapiRun(
|
||||
if (m_deviceAPI->initAcquisition())
|
||||
{
|
||||
m_deviceAPI->startAcquisition();
|
||||
DSPEngine::instance()->startAudioOutput();
|
||||
DSPEngine::instance()->startAudioOutputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopAcquisition();
|
||||
DSPEngine::instance()->stopAudioOutput();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
|
@ -1,5 +1,7 @@
|
||||
project(hackrfinput)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
set(hackrfinput_SOURCES
|
||||
hackrfinputgui.cpp
|
||||
hackrfinput.cpp
|
||||
@ -24,6 +26,7 @@ if (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBHACKRFSRC}
|
||||
${LIBHACKRFSRC}/libhackrf/src
|
||||
@ -32,6 +35,7 @@ else (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBHACKRF_INCLUDE_DIR}
|
||||
)
|
||||
@ -58,6 +62,7 @@ target_link_libraries(inputhackrf
|
||||
hackrf
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
hackrfdevice
|
||||
)
|
||||
else (BUILD_DEBIAN)
|
||||
@ -66,6 +71,7 @@ target_link_libraries(inputhackrf
|
||||
${LIBHACKRF_LIBRARIES}
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
hackrfdevice
|
||||
)
|
||||
endif (BUILD_DEBIAN)
|
||||
|
@ -20,6 +20,9 @@
|
||||
#include <errno.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
@ -486,6 +489,36 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, bool force)
|
||||
return true;
|
||||
}
|
||||
|
||||
int HackRFInput::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int HackRFInput::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
if (m_deviceAPI->initAcquisition())
|
||||
{
|
||||
m_deviceAPI->startAcquisition();
|
||||
DSPEngine::instance()->startAudioOutputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopAcquisition();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
//hackrf_device *HackRFInput::open_hackrf_from_sequence(int sequence)
|
||||
//{
|
||||
// hackrf_device_list_t *hackrf_devices = hackrf_device_list();
|
||||
|
@ -104,6 +104,16 @@ public:
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
|
||||
private:
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
|
@ -22,6 +22,7 @@ CONFIG(MINGW64):LIBHACKRFSRC = "D:\softs\hackrf\host"
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += ../../../sdrbase
|
||||
INCLUDEPATH += ../../../sdrgui
|
||||
INCLUDEPATH += ../../../swagger/sdrangel/code/qt5/client
|
||||
INCLUDEPATH += ../../../devices
|
||||
!macx:INCLUDEPATH += $$LIBHACKRFSRC
|
||||
macx:INCLUDEPATH += /opt/local/include
|
||||
@ -45,6 +46,7 @@ FORMS += hackrfinputgui.ui
|
||||
|
||||
LIBS += -L../../../sdrbase/$${build_subdir} -lsdrbase
|
||||
LIBS += -L../../../sdrgui/$${build_subdir} -lsdrgui
|
||||
LIBS += -L../../../swagger/$${build_subdir} -lswagger
|
||||
!macx:LIBS += -L../../../libhackrf/$${build_subdir} -llibhackrf
|
||||
macx:LIBS += -L/opt/local/lib -lhackrf
|
||||
LIBS += -L../../../devices/$${build_subdir} -ldevices
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
const PluginDescriptor HackRFInputPlugin::m_pluginDescriptor = {
|
||||
QString("HackRF Input"),
|
||||
QString("3.8.2"),
|
||||
QString("3.8.6"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -22,11 +22,13 @@
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGLimeSdrInputSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "device/devicesinkapi.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/filerecord.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "limesdrinput.h"
|
||||
#include "limesdrinputthread.h"
|
||||
#include "limesdr/devicelimesdrparam.h"
|
||||
@ -1243,3 +1245,33 @@ int LimeSDRInput::webapiSettingsPutPatch(
|
||||
return 200;
|
||||
}
|
||||
|
||||
int LimeSDRInput::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int LimeSDRInput::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
if (m_deviceAPI->initAcquisition())
|
||||
{
|
||||
m_deviceAPI->startAcquisition();
|
||||
DSPEngine::instance()->startAudioOutputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopAcquisition();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
@ -207,6 +207,15 @@ public:
|
||||
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
std::size_t getChannelIndex();
|
||||
void getLORange(float& minF, float& maxF, float& stepF) const;
|
||||
void getSRRange(float& minF, float& maxF, float& stepF) const;
|
||||
|
@ -1,5 +1,7 @@
|
||||
project(plutosdrinput)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
set(plutosdrinput_SOURCES
|
||||
plutosdrinputgui.cpp
|
||||
plutosdrinput.cpp
|
||||
@ -24,6 +26,7 @@ if (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBIIOSRC}
|
||||
)
|
||||
@ -31,6 +34,7 @@ else (BUILD_DEBIAN)
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
${CMAKE_SOURCE_DIR}/devices
|
||||
${LIBIIO_INCLUDE_DIR}
|
||||
)
|
||||
@ -56,6 +60,7 @@ target_link_libraries(inputplutosdr
|
||||
iio
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
plutosdrdevice
|
||||
)
|
||||
else (BUILD_DEBIAN)
|
||||
@ -64,6 +69,7 @@ target_link_libraries(inputplutosdr
|
||||
${LIBIIO_LIBRARIES}
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
plutosdrdevice
|
||||
)
|
||||
endif (BUILD_DEBIAN)
|
||||
|
@ -16,8 +16,12 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "dsp/filerecord.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "device/devicesinkapi.h"
|
||||
#include "plutosdr/deviceplutosdrparams.h"
|
||||
@ -560,3 +564,34 @@ float PlutoSDRInput::getTemperature()
|
||||
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
|
||||
return plutoBox->getTemp();
|
||||
}
|
||||
|
||||
int PlutoSDRInput::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int PlutoSDRInput::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
if (m_deviceAPI->initAcquisition())
|
||||
{
|
||||
m_deviceAPI->startAcquisition();
|
||||
DSPEngine::instance()->startAudioOutputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopAcquisition();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,15 @@ public:
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
uint32_t getADCSampleRate() const { return m_deviceSampleRates.m_addaConnvRate; }
|
||||
uint32_t getFIRSampleRate() const { return m_deviceSampleRates.m_hb1Rate; }
|
||||
void getRSSI(std::string& rssiStr);
|
||||
|
@ -23,6 +23,7 @@ CONFIG(MINGW64):LIBIIOSRC = "D:\softs\libiio"
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += ../../../sdrbase
|
||||
INCLUDEPATH += ../../../sdrgui
|
||||
INCLUDEPATH += ../../../swagger/sdrangel/code/qt5/client
|
||||
INCLUDEPATH += ../../../devices
|
||||
INCLUDEPATH += ../../../libiio/includemw
|
||||
INCLUDEPATH += $$LIBIIOSRC
|
||||
@ -46,6 +47,7 @@ FORMS += plutosdrinputgui.ui
|
||||
|
||||
LIBS += -L../../../sdrbase/$${build_subdir} -lsdrbase
|
||||
LIBS += -L../../../sdrgui/$${build_subdir} -lsdrgui
|
||||
LIBS += -L../../../swagger/$${build_subdir} -lswagger
|
||||
LIBS += -L../../../libiio/$${build_subdir} -llibiio
|
||||
LIBS += -L../../../devices/$${build_subdir} -ldevices
|
||||
|
||||
|
@ -28,7 +28,7 @@ class DeviceSourceAPI;
|
||||
|
||||
const PluginDescriptor PlutoSDRInputPlugin::m_pluginDescriptor = {
|
||||
QString("PlutoSDR Input"),
|
||||
QString("3.8.0"),
|
||||
QString("3.8.6"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -546,13 +546,12 @@ int RTLSDRInput::webapiRun(
|
||||
if (m_deviceAPI->initAcquisition())
|
||||
{
|
||||
m_deviceAPI->startAcquisition();
|
||||
DSPEngine::instance()->startAudioOutput();
|
||||
DSPEngine::instance()->startAudioOutputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopAcquisition();
|
||||
DSPEngine::instance()->stopAudioOutput();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGRtlSdrSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
@ -228,13 +227,12 @@ int SDRdaemonSourceInput::webapiRun(
|
||||
if (m_deviceAPI->initAcquisition())
|
||||
{
|
||||
m_deviceAPI->startAcquisition();
|
||||
DSPEngine::instance()->startAudioOutput();
|
||||
DSPEngine::instance()->startAudioOutputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopAcquisition();
|
||||
DSPEngine::instance()->stopAudioOutput();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGRtlSdrSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
@ -588,13 +587,12 @@ int SDRPlayInput::webapiRun(
|
||||
if (m_deviceAPI->initAcquisition())
|
||||
{
|
||||
m_deviceAPI->startAcquisition();
|
||||
DSPEngine::instance()->startAudioOutput();
|
||||
DSPEngine::instance()->startAudioOutputImmediate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopAcquisition();
|
||||
DSPEngine::instance()->stopAudioOutput();
|
||||
}
|
||||
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
|
@ -117,6 +117,79 @@ bool AudioInput::start(int device, int rate)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioInput::startImmediate(int device, int rate)
|
||||
{
|
||||
|
||||
if (QIODevice::isOpen())
|
||||
{
|
||||
qInfo("AudioInput::startImmediate: already started");
|
||||
return true;
|
||||
}
|
||||
|
||||
QAudioDeviceInfo devInfo;
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if (device < 0)
|
||||
{
|
||||
devInfo = QAudioDeviceInfo::defaultInputDevice();
|
||||
qWarning("AudioInput::startImmediate: using default device %s", qPrintable(devInfo.defaultInputDevice().deviceName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<QAudioDeviceInfo> devicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
|
||||
if (device < devicesInfo.size())
|
||||
{
|
||||
devInfo = devicesInfo[device];
|
||||
qWarning("AudioInput::startImmediate: using audio device #%d: %s", device, qPrintable(devInfo.defaultInputDevice().deviceName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
devInfo = QAudioDeviceInfo::defaultInputDevice();
|
||||
qWarning("AudioInput::startImmediate: audio device #%d does not exist. Using default device %s", device, qPrintable(devInfo.defaultInputDevice().deviceName()));
|
||||
}
|
||||
}
|
||||
|
||||
//QAudioDeviceInfo devInfo(QAudioDeviceInfo::defaultOutputDevice());
|
||||
|
||||
m_audioFormat.setSampleRate(rate);
|
||||
m_audioFormat.setChannelCount(2);
|
||||
m_audioFormat.setSampleSize(16);
|
||||
m_audioFormat.setCodec("audio/pcm");
|
||||
m_audioFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_audioFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
if (!devInfo.isFormatSupported(m_audioFormat))
|
||||
{
|
||||
m_audioFormat = devInfo.nearestFormat(m_audioFormat);
|
||||
qWarning("AudioInput::startImmediate: %d Hz S16_LE audio format not supported. New rate: %d", rate, m_audioFormat.sampleRate());
|
||||
}
|
||||
else
|
||||
{
|
||||
qInfo("AudioInput::startImmediate: audio format OK");
|
||||
}
|
||||
|
||||
if (m_audioFormat.sampleSize() != 16)
|
||||
{
|
||||
qWarning("AudioInput::startImmediate: Audio device ( %s ) failed", qPrintable(devInfo.defaultInputDevice().deviceName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_audioInput = new QAudioInput(devInfo, m_audioFormat);
|
||||
m_audioInput->setVolume(m_volume);
|
||||
|
||||
QIODevice::open(QIODevice::ReadWrite);
|
||||
|
||||
m_audioInput->start(this);
|
||||
|
||||
if (m_audioInput->state() != QAudio::ActiveState)
|
||||
{
|
||||
qWarning("AudioInput::startImmediate: cannot start");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AudioInput::stop()
|
||||
{
|
||||
qDebug("AudioInput::stop");
|
||||
@ -129,6 +202,7 @@ void AudioInput::stop()
|
||||
|
||||
if (m_audioUsageCount == 0)
|
||||
{
|
||||
qDebug("AudioInput::stop: effectively close QIODevice");
|
||||
QIODevice::close();
|
||||
|
||||
if (!m_onExit) {
|
||||
@ -138,6 +212,21 @@ void AudioInput::stop()
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInput::stopImmediate()
|
||||
{
|
||||
if (!QIODevice::isOpen())
|
||||
{
|
||||
qInfo("AudioInput::stopImmediate: already stopped");
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("AudioInput::stopImmediate");
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
QIODevice::close();
|
||||
delete m_audioInput;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInput::addFifo(AudioFifo* audioFifo)
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
@ -37,7 +37,10 @@ public:
|
||||
bool start(int device, int rate);
|
||||
void stop();
|
||||
|
||||
void addFifo(AudioFifo* audioFifo);
|
||||
bool startImmediate(int device, int rate);
|
||||
void stopImmediate();
|
||||
|
||||
void addFifo(AudioFifo* audioFifo);
|
||||
void removeFifo(AudioFifo* audioFifo);
|
||||
|
||||
uint getRate() const { return m_audioFormat.sampleRate(); }
|
||||
|
@ -116,6 +116,77 @@ bool AudioOutput::start(int device, int rate)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioOutput::startImmediate(int device, int rate)
|
||||
{
|
||||
if (QIODevice::isOpen())
|
||||
{
|
||||
qInfo("AudioOutput::startImmediate: already open");
|
||||
return true;
|
||||
}
|
||||
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
QAudioDeviceInfo devInfo;
|
||||
|
||||
if (device < 0)
|
||||
{
|
||||
devInfo = QAudioDeviceInfo::defaultOutputDevice();
|
||||
qWarning("AudioOutput::startImmediate: using default device %s", qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<QAudioDeviceInfo> devicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
|
||||
if (device < devicesInfo.size())
|
||||
{
|
||||
devInfo = devicesInfo[device];
|
||||
qWarning("AudioOutput::startImmediate: using audio device #%d: %s", device, qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
devInfo = QAudioDeviceInfo::defaultOutputDevice();
|
||||
qWarning("AudioOutput::startImmediate: audio device #%d does not exist. Using default device %s", device, qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
}
|
||||
|
||||
//QAudioDeviceInfo devInfo(QAudioDeviceInfo::defaultOutputDevice());
|
||||
|
||||
m_audioFormat.setSampleRate(rate);
|
||||
m_audioFormat.setChannelCount(2);
|
||||
m_audioFormat.setSampleSize(16);
|
||||
m_audioFormat.setCodec("audio/pcm");
|
||||
m_audioFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_audioFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
if (!devInfo.isFormatSupported(m_audioFormat))
|
||||
{
|
||||
m_audioFormat = devInfo.nearestFormat(m_audioFormat);
|
||||
qWarning("AudioOutput::startImmediate: %d Hz S16_LE audio format not supported. New rate: %d", rate, m_audioFormat.sampleRate());
|
||||
}
|
||||
else
|
||||
{
|
||||
qInfo("AudioOutput::startImmediate: audio format OK");
|
||||
}
|
||||
|
||||
if (m_audioFormat.sampleSize() != 16)
|
||||
{
|
||||
qWarning("AudioOutput::startImmediate: Audio device ( %s ) failed", qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_audioOutput = new QAudioOutput(devInfo, m_audioFormat);
|
||||
|
||||
QIODevice::open(QIODevice::ReadOnly);
|
||||
|
||||
m_audioOutput->start(this);
|
||||
|
||||
if (m_audioOutput->state() != QAudio::ActiveState)
|
||||
{
|
||||
qWarning("AudioOutput::startImmediate: cannot start");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AudioOutput::stop()
|
||||
{
|
||||
qDebug("AudioOutput::stop");
|
||||
@ -137,6 +208,21 @@ void AudioOutput::stop()
|
||||
}
|
||||
}
|
||||
|
||||
void AudioOutput::stopImmediate()
|
||||
{
|
||||
if (!QIODevice::isOpen())
|
||||
{
|
||||
qInfo("AudioOutput::stopImmediate");
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("AudioOutput::stopImmediate");
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
QIODevice::close();
|
||||
delete m_audioOutput;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioOutput::addFifo(AudioFifo* audioFifo)
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
@ -37,6 +37,9 @@ public:
|
||||
bool start(int device, int rate);
|
||||
void stop();
|
||||
|
||||
bool startImmediate(int device, int rate);
|
||||
void stopImmediate();
|
||||
|
||||
void addFifo(AudioFifo* audioFifo);
|
||||
void removeFifo(AudioFifo* audioFifo);
|
||||
|
||||
|
@ -104,13 +104,13 @@ void DSPEngine::stopAudioOutput()
|
||||
|
||||
void DSPEngine::startAudioOutputImmediate()
|
||||
{
|
||||
m_audioOutput.start(m_audioOutputDeviceIndex, m_audioOutputSampleRate);
|
||||
m_audioOutput.startImmediate(m_audioOutputDeviceIndex, m_audioOutputSampleRate);
|
||||
m_audioOutputSampleRate = m_audioOutput.getRate(); // update with actual rate
|
||||
}
|
||||
|
||||
void DSPEngine::stopAudioOutputImmediate()
|
||||
{
|
||||
m_audioOutput.stop();
|
||||
m_audioOutput.stopImmediate();
|
||||
}
|
||||
|
||||
void DSPEngine::startAudioInput()
|
||||
@ -126,13 +126,13 @@ void DSPEngine::stopAudioInput()
|
||||
|
||||
void DSPEngine::startAudioInputImmediate()
|
||||
{
|
||||
m_audioInput.start(m_audioInputDeviceIndex, m_audioInputSampleRate);
|
||||
m_audioInput.startImmediate(m_audioInputDeviceIndex, m_audioInputSampleRate);
|
||||
m_audioInputSampleRate = m_audioInput.getRate(); // update with actual rate
|
||||
}
|
||||
|
||||
void DSPEngine::stopAudioInputImmediate()
|
||||
{
|
||||
m_audioInput.stop();
|
||||
m_audioInput.stopImmediate();
|
||||
}
|
||||
|
||||
void DSPEngine::addAudioSink(AudioFifo* audioFifo)
|
||||
|
107
swagger/sdrangel/examples/start_stop.py
Normal file
107
swagger/sdrangel/examples/start_stop.py
Normal file
@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import requests, json, traceback, sys
|
||||
from optparse import OptionParser
|
||||
|
||||
base_url = "http://127.0.0.1:8888/sdrangel"
|
||||
|
||||
# ======================================================================
|
||||
def getInputOptions():
|
||||
|
||||
parser = OptionParser(usage="usage: %%prog [-t]\n")
|
||||
parser.add_option("-a", "--address", dest="address", help="address and port", metavar="ADDRESS", type="string")
|
||||
parser.add_option("-d", "--device-index", dest="device_index", help="device set index", metavar="INDEX", type="int")
|
||||
parser.add_option("-t", "--stop", dest="stop", help="stop device", metavar="STOP", action="store_true", default=False)
|
||||
parser.add_option("-s", "--start", dest="start", help="start device", metavar="START", action="store_true", default=False)
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if (options.address == None):
|
||||
options.address = "127.0.0.1:8888"
|
||||
|
||||
if options.device_index < 0:
|
||||
otions.device_index = 0
|
||||
|
||||
if options.start and options.stop:
|
||||
print("Cannot start and stop at the same time")
|
||||
exit(1)
|
||||
|
||||
if not options.start and not options.stop:
|
||||
print("Must start or stop")
|
||||
exit(1)
|
||||
|
||||
return options
|
||||
|
||||
# ======================================================================
|
||||
def startDevice(deviceIndex):
|
||||
dev_run_url = base_url+("/deviceset/%d/device/run" % deviceIndex)
|
||||
r = requests.get(url=dev_run_url)
|
||||
if r.status_code == 200:
|
||||
rj = r.json()
|
||||
state = rj.get("state", None)
|
||||
if state is not None:
|
||||
if state == "idle":
|
||||
r = requests.post(url=dev_run_url)
|
||||
if r.status_code == 200:
|
||||
print("Device %d started" % deviceIndex)
|
||||
else:
|
||||
print("Error starting device %d" % deviceIndex)
|
||||
else:
|
||||
print("device %d not in idle state" % deviceIndex)
|
||||
else:
|
||||
print("Cannot get device %d running state" % deviceIndex)
|
||||
else:
|
||||
print("Error getting device %d running state" % deviceIndex)
|
||||
|
||||
# ======================================================================
|
||||
def stopDevice(deviceIndex):
|
||||
dev_run_url = base_url+("/deviceset/%d/device/run" % deviceIndex)
|
||||
r = requests.get(url=dev_run_url)
|
||||
if r.status_code == 200:
|
||||
rj = r.json()
|
||||
state = rj.get("state", None)
|
||||
if state is not None:
|
||||
if state == "running":
|
||||
r = requests.delete(url=dev_run_url)
|
||||
if r.status_code == 200:
|
||||
print("Device %d stopped" % deviceIndex)
|
||||
else:
|
||||
print("Error stopping device %d" % deviceIndex)
|
||||
else:
|
||||
print("device %d not in running state" % deviceIndex)
|
||||
else:
|
||||
print("Cannot get device %d running state" % deviceIndex)
|
||||
else:
|
||||
print("Error getting device %d running state" % deviceIndex)
|
||||
|
||||
# ======================================================================
|
||||
def main():
|
||||
try:
|
||||
options = getInputOptions()
|
||||
global base_url
|
||||
base_url = "http://%s/sdrangel" % options.address
|
||||
r = requests.get(url=base_url+"/devicesets")
|
||||
if r.status_code == 200:
|
||||
rj = r.json()
|
||||
deviceSets = rj.get("deviceSets", None)
|
||||
if deviceSets is not None:
|
||||
if options.device_index < len(deviceSets):
|
||||
if options.start:
|
||||
startDevice(options.device_index)
|
||||
if options.stop:
|
||||
stopDevice(options.device_index)
|
||||
else:
|
||||
print("Invalid device set index. Number of device sets is %d" % len(deviceSets))
|
||||
else:
|
||||
print("Cannot get device sets configuration")
|
||||
else:
|
||||
print("Error getting device sets configuration")
|
||||
|
||||
except Exception, msg:
|
||||
tb = traceback.format_exc()
|
||||
print >> sys.stderr, tb
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user