LimeRFE USB support: REST API: GUI and server adapters

pull/480/head
f4exb 2020-01-13 01:57:39 +01:00
rodzic 1062b6a648
commit d83da57a1e
5 zmienionych plików z 376 dodań i 3 usunięć

Wyświetl plik

@ -38,6 +38,7 @@
#include "plugin/pluginmanager.h"
#include "channel/channelapi.h"
#include "webapi/webapiadapterbase.h"
#include "util/serialutil.h"
#include "SWGInstanceSummaryResponse.h"
#include "SWGInstanceConfigResponse.h"
@ -63,6 +64,12 @@
#include "SWGSuccessResponse.h"
#include "SWGErrorResponse.h"
#include "SWGDeviceState.h"
#include "SWGLimeRFEDevices.h"
#include "SWGLimeRFESettings.h"
#ifdef HAS_LIMERFE
#include "limerfe/limerfecontroller.h"
#endif
#include "webapiadaptergui.h"
@ -829,6 +836,162 @@ int WebAPIAdapterGUI::instanceAMBEDevicesPatch(
return 200;
}
#ifdef HAS_LIMERFE
int WebAPIAdapterGUI::instanceLimeRFESerialGet(
SWGSDRangel::SWGLimeRFEDevices& response,
SWGSDRangel::SWGErrorResponse& error)
{
(void) error;
std::vector<std::string> comPorts;
SerialUtil::getComPorts(comPorts, "ttyUSB[0-9]+"); // regex is for Linux only
response.setNbDevices((int) comPorts.size());
QList<SWGSDRangel::SWGLimeRFEDevice*> *deviceNamesList = response.getLimeRfeDevices();
std::vector<std::string>::iterator it = comPorts.begin();
while (it != comPorts.end())
{
deviceNamesList->append(new SWGSDRangel::SWGLimeRFEDevice);
deviceNamesList->back()->init();
*deviceNamesList->back()->getDeviceRef() = QString::fromStdString(*it);
++it;
}
return 200;
}
int WebAPIAdapterGUI::instanceLimeRFEConfigGet(
const QString& serial,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error)
{
LimeRFEController controller;
int rc = controller.openDevice(serial.toStdString());
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error opening LimeRFE device %1: %2")
.arg(serial).arg(controller.getError(rc).c_str());
return 400;
}
rc = controller.getState();
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error getting config from LimeRFE device %1: %2")
.arg(serial).arg(controller.getError(rc).c_str());
return 500;
}
controller.closeDevice();
LimeRFEController::LimeRFESettings settings;
controller.stateToSettings(settings);
response.init();
response.setDevicePath(new QString(serial));
response.setRxChannels((int) settings.m_rxChannels);
response.setRxWidebandChannel((int) settings.m_rxWidebandChannel);
response.setRxHamChannel((int) settings.m_rxHAMChannel);
response.setRxCellularChannel((int) settings.m_rxCellularChannel);
response.setRxPort((int) settings.m_rxPort);
response.setRxOn(settings.m_rxOn ? 1 : 0);
response.setAmfmNotch(settings.m_amfmNotch ? 1 : 0);
response.setAttenuationFactor(settings.m_attenuationFactor);
response.setTxChannels((int) settings.m_txChannels);
response.setTxWidebandChannel((int) settings.m_txWidebandChannel);
response.setTxHamChannel((int) settings.m_txHAMChannel);
response.setTxCellularChannel((int) settings.m_txCellularChannel);
response.setTxPort((int) settings.m_txPort);
response.setTxOn(settings.m_txOn ? 1 : 0);
return 200;
}
int WebAPIAdapterGUI::instanceLimeRFEConfigPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error)
{
LimeRFEController controller;
int rc = controller.openDevice(query.getDevicePath()->toStdString());
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error opening LimeRFE device %1: %2")
.arg(*query.getDevicePath()).arg(controller.getError(rc).c_str());
return 400;
}
LimeRFEController::LimeRFESettings settings;
settings.m_rxChannels = (LimeRFEController::ChannelGroups) query.getRxChannels();
settings.m_rxWidebandChannel = (LimeRFEController::WidebandChannel) query.getRxWidebandChannel();
settings.m_rxHAMChannel = (LimeRFEController::HAMChannel) query.getRxHamChannel();
settings.m_rxCellularChannel = (LimeRFEController::CellularChannel) query.getRxCellularChannel();
settings.m_rxPort = (LimeRFEController::RxPort) query.getRxPort();
settings.m_amfmNotch = query.getAmfmNotch() != 0;
settings.m_attenuationFactor = query.getAttenuationFactor();
settings.m_txChannels = (LimeRFEController::ChannelGroups) query.getTxChannels();
settings.m_txWidebandChannel = (LimeRFEController::WidebandChannel) query.getTxWidebandChannel();
settings.m_txHAMChannel = (LimeRFEController::HAMChannel) query.getTxHamChannel();
settings.m_txCellularChannel = (LimeRFEController::CellularChannel) query.getTxCellularChannel();
settings.m_txPort = (LimeRFEController::TxPort) query.getTxPort();
controller.settingsToState(settings);
rc = controller.configure();
response.init();
response = query;
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error configuring LimeRFE device %1: %2")
.arg(*query.getDevicePath()).arg(controller.getError(rc).c_str());
return 500;
}
return 200;
}
int WebAPIAdapterGUI::instanceLimeRFERunPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error)
{
LimeRFEController controller;
int rc = controller.openDevice(query.getDevicePath()->toStdString());
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error opening LimeRFE device %1: %2")
.arg(*query.getDevicePath()).arg(controller.getError(rc).c_str());
return 400;
}
LimeRFEController::LimeRFESettings settings;
settings.m_rxOn = query.getRxOn() != 0;
settings.m_txOn = query.getTxOn() != 0;
rc = controller.setRx(settings, settings.m_rxOn);
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error setting Rx/Tx LimeRFE device %1: %2")
.arg(*query.getDevicePath()).arg(controller.getError(rc).c_str());
return 400;
}
response.init();
return 200;
}
#endif
int WebAPIAdapterGUI::instancePresetsGet(
SWGSDRangel::SWGPresets& response,
SWGSDRangel::SWGErrorResponse& error)

Wyświetl plik

@ -140,6 +140,27 @@ public:
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
#ifdef HAS_LIMERFE
virtual int instanceLimeRFESerialGet(
SWGSDRangel::SWGLimeRFEDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFEConfigGet(
const QString& serial,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFEConfigPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFERunPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
#endif
virtual int instancePresetsGet(
SWGSDRangel::SWGPresets& response,
SWGSDRangel::SWGErrorResponse& error);

Wyświetl plik

@ -1,8 +1,8 @@
project (sdrsrv)
set(sdrsrv_SOURCES
maincore.cpp
device/deviceset.cpp
maincore.cpp
device/deviceset.cpp
webapi/webapiadaptersrv.cpp
)
@ -12,12 +12,17 @@ set(sdrsrv_HEADERS
webapi/webapiadaptersrv.h
)
if (LIMERFE_FOUND)
include_directories(${LIMESUITE_INCLUDE_DIR})
set(sdrgui_LIMERFE_LIB ${LIMESUITE_LIBRARY})
endif (LIMERFE_FOUND)
include_directories(
${CMAKE_SOURCE_DIR}/exports
${CMAKE_SOURCE_DIR}/sdrbase
${CMAKE_SOURCE_DIR}/logging
${CMAKE_SOURCE_DIR}/httpserver
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${OPENGL_INCLUDE_DIR}
)

Wyświetl plik

@ -43,6 +43,8 @@
#include "SWGErrorResponse.h"
#include "SWGDeviceState.h"
#include "SWGDeviceReport.h"
#include "SWGLimeRFEDevices.h"
#include "SWGLimeRFESettings.h"
#include "maincore.h"
#include "loggerwithfile.h"
@ -59,9 +61,14 @@
#include "channel/channelapi.h"
#include "plugin/pluginapi.h"
#include "plugin/pluginmanager.h"
#include "util/serialutil.h"
#include "webapi/webapiadapterbase.h"
#include "webapiadaptersrv.h"
#ifdef HAS_LIMERFE
#include "limerfe/limerfecontroller.h"
#endif
WebAPIAdapterSrv::WebAPIAdapterSrv(MainCore& mainCore) :
m_mainCore(mainCore)
{
@ -812,6 +819,162 @@ int WebAPIAdapterSrv::instanceAMBEDevicesPatch(
return 200;
}
#ifdef HAS_LIMERFE
int WebAPIAdapterSrv::instanceLimeRFESerialGet(
SWGSDRangel::SWGLimeRFEDevices& response,
SWGSDRangel::SWGErrorResponse& error)
{
(void) error;
std::vector<std::string> comPorts;
SerialUtil::getComPorts(comPorts, "ttyUSB[0-9]+"); // regex is for Linux only
response.setNbDevices((int) comPorts.size());
QList<SWGSDRangel::SWGLimeRFEDevice*> *deviceNamesList = response.getLimeRfeDevices();
std::vector<std::string>::iterator it = comPorts.begin();
while (it != comPorts.end())
{
deviceNamesList->append(new SWGSDRangel::SWGLimeRFEDevice);
deviceNamesList->back()->init();
*deviceNamesList->back()->getDeviceRef() = QString::fromStdString(*it);
++it;
}
return 200;
}
int WebAPIAdapterSrv::instanceLimeRFEConfigGet(
const QString& serial,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error)
{
LimeRFEController controller;
int rc = controller.openDevice(serial.toStdString());
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error opening LimeRFE device %1: %2")
.arg(serial).arg(controller.getError(rc).c_str());
return 400;
}
rc = controller.getState();
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error getting config from LimeRFE device %1: %2")
.arg(serial).arg(controller.getError(rc).c_str());
return 500;
}
controller.closeDevice();
LimeRFEController::LimeRFESettings settings;
controller.stateToSettings(settings);
response.init();
response.setDevicePath(new QString(serial));
response.setRxChannels((int) settings.m_rxChannels);
response.setRxWidebandChannel((int) settings.m_rxWidebandChannel);
response.setRxHamChannel((int) settings.m_rxHAMChannel);
response.setRxCellularChannel((int) settings.m_rxCellularChannel);
response.setRxPort((int) settings.m_rxPort);
response.setRxOn(settings.m_rxOn ? 1 : 0);
response.setAmfmNotch(settings.m_amfmNotch ? 1 : 0);
response.setAttenuationFactor(settings.m_attenuationFactor);
response.setTxChannels((int) settings.m_txChannels);
response.setTxWidebandChannel((int) settings.m_txWidebandChannel);
response.setTxHamChannel((int) settings.m_txHAMChannel);
response.setTxCellularChannel((int) settings.m_txCellularChannel);
response.setTxPort((int) settings.m_txPort);
response.setTxOn(settings.m_txOn ? 1 : 0);
return 200;
}
int WebAPIAdapterSrv::instanceLimeRFEConfigPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error)
{
LimeRFEController controller;
int rc = controller.openDevice(query.getDevicePath()->toStdString());
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error opening LimeRFE device %1: %2")
.arg(*query.getDevicePath()).arg(controller.getError(rc).c_str());
return 400;
}
LimeRFEController::LimeRFESettings settings;
settings.m_rxChannels = (LimeRFEController::ChannelGroups) query.getRxChannels();
settings.m_rxWidebandChannel = (LimeRFEController::WidebandChannel) query.getRxWidebandChannel();
settings.m_rxHAMChannel = (LimeRFEController::HAMChannel) query.getRxHamChannel();
settings.m_rxCellularChannel = (LimeRFEController::CellularChannel) query.getRxCellularChannel();
settings.m_rxPort = (LimeRFEController::RxPort) query.getRxPort();
settings.m_amfmNotch = query.getAmfmNotch() != 0;
settings.m_attenuationFactor = query.getAttenuationFactor();
settings.m_txChannels = (LimeRFEController::ChannelGroups) query.getTxChannels();
settings.m_txWidebandChannel = (LimeRFEController::WidebandChannel) query.getTxWidebandChannel();
settings.m_txHAMChannel = (LimeRFEController::HAMChannel) query.getTxHamChannel();
settings.m_txCellularChannel = (LimeRFEController::CellularChannel) query.getTxCellularChannel();
settings.m_txPort = (LimeRFEController::TxPort) query.getTxPort();
controller.settingsToState(settings);
rc = controller.configure();
response.init();
response = query;
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error configuring LimeRFE device %1: %2")
.arg(*query.getDevicePath()).arg(controller.getError(rc).c_str());
return 500;
}
return 200;
}
int WebAPIAdapterSrv::instanceLimeRFERunPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error)
{
LimeRFEController controller;
int rc = controller.openDevice(query.getDevicePath()->toStdString());
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error opening LimeRFE device %1: %2")
.arg(*query.getDevicePath()).arg(controller.getError(rc).c_str());
return 400;
}
LimeRFEController::LimeRFESettings settings;
settings.m_rxOn = query.getRxOn() != 0;
settings.m_txOn = query.getTxOn() != 0;
rc = controller.setRx(settings, settings.m_rxOn);
if (rc != 0)
{
error.init();
*error.getMessage() = QString("Error setting Rx/Tx LimeRFE device %1: %2")
.arg(*query.getDevicePath()).arg(controller.getError(rc).c_str());
return 400;
}
response.init();
return 200;
}
#endif
int WebAPIAdapterSrv::instancePresetFilePut(
SWGSDRangel::SWGPresetImport& query,
SWGSDRangel::SWGPresetIdentifier& response,

Wyświetl plik

@ -140,6 +140,27 @@ public:
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
#ifdef HAS_LIMERFE
virtual int instanceLimeRFESerialGet(
SWGSDRangel::SWGLimeRFEDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFEConfigGet(
const QString& serial,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFEConfigPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFERunPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
#endif
virtual int instancePresetFilePut(
SWGSDRangel::SWGPresetImport& query,
SWGSDRangel::SWGPresetIdentifier& response,