mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-04 14:17:50 -04:00
Web API: implement devicesetDeviceGet (1)
This commit is contained in:
parent
a3fb30107b
commit
7dafae3fa1
@ -41,6 +41,11 @@ public:
|
|||||||
|
|
||||||
virtual bool handleMessage(const Message& message) = 0;
|
virtual bool handleMessage(const Message& message) = 0;
|
||||||
|
|
||||||
|
virtual int webapiSettingsGet(
|
||||||
|
SWGSDRangel::SWGObject *response __attribute__((unused)),
|
||||||
|
QString& errorMessage)
|
||||||
|
{ errorMessage = "Not implemented"; return 501; }
|
||||||
|
|
||||||
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
||||||
void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
||||||
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
||||||
|
@ -41,6 +41,11 @@ public:
|
|||||||
|
|
||||||
virtual bool handleMessage(const Message& message) = 0;
|
virtual bool handleMessage(const Message& message) = 0;
|
||||||
|
|
||||||
|
virtual int webapiSettingsGet(
|
||||||
|
SWGSDRangel::SWGObject *response __attribute__((unused)),
|
||||||
|
QString& errorMessage)
|
||||||
|
{ errorMessage = "Not implemented"; return 501; }
|
||||||
|
|
||||||
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
||||||
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
||||||
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
||||||
|
@ -226,7 +226,7 @@ public:
|
|||||||
{ return 501; }
|
{ return 501; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler of /sdrangel/devicesets (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
* Handler of /sdrangel/deviceset/{devicesetIndex}/device (PUT) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||||
* returns the Http status code (default 501: not implemented)
|
* returns the Http status code (default 501: not implemented)
|
||||||
*/
|
*/
|
||||||
virtual int devicesetDevicePut(
|
virtual int devicesetDevicePut(
|
||||||
@ -235,6 +235,16 @@ public:
|
|||||||
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
||||||
{ return 501; }
|
{ return 501; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler of /sdrangel/deviceset/{devicesetIndex}/device (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||||
|
* returns the Http status code (default 501: not implemented)
|
||||||
|
*/
|
||||||
|
virtual int devicesetDeviceGet(
|
||||||
|
int deviceSetIndex __attribute__((unused)),
|
||||||
|
SWGSDRangel::SWGDeviceSettings& response __attribute__((unused)),
|
||||||
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
||||||
|
{ return 501; }
|
||||||
|
|
||||||
static QString instanceSummaryURL;
|
static QString instanceSummaryURL;
|
||||||
static QString instanceDevicesURL;
|
static QString instanceDevicesURL;
|
||||||
static QString instanceChannelsURL;
|
static QString instanceChannelsURL;
|
||||||
|
@ -86,9 +86,9 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
|||||||
std::string pathStr(path.constData(), path.length());
|
std::string pathStr(path.constData(), path.length());
|
||||||
|
|
||||||
if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetURLRe)) {
|
if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetURLRe)) {
|
||||||
deviceset(std::string(desc_match[1]), request, response);
|
devicesetService(std::string(desc_match[1]), request, response);
|
||||||
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceURLRe)) {
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceURLRe)) {
|
||||||
devicesetDevice(std::string(desc_match[1]), request, response);
|
devicesetDeviceService(std::string(desc_match[1]), request, response);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -539,7 +539,7 @@ void WebAPIRequestMapper::instanceDeviceSetsService(qtwebapp::HttpRequest& reque
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAPIRequestMapper::deviceset(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
void WebAPIRequestMapper::devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||||
{
|
{
|
||||||
SWGSDRangel::SWGErrorResponse errorResponse;
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
||||||
|
|
||||||
@ -573,7 +573,7 @@ void WebAPIRequestMapper::deviceset(const std::string& indexStr, qtwebapp::HttpR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAPIRequestMapper::devicesetDevice(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
void WebAPIRequestMapper::devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||||
{
|
{
|
||||||
SWGSDRangel::SWGErrorResponse errorResponse;
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
||||||
|
|
||||||
@ -600,6 +600,18 @@ void WebAPIRequestMapper::devicesetDevice(const std::string& indexStr, qtwebapp:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (request.getMethod() == "GET")
|
||||||
|
{
|
||||||
|
SWGSDRangel::SWGDeviceSettings normalResponse;
|
||||||
|
int status = m_adapter->devicesetDeviceGet(deviceSetIndex, normalResponse, errorResponse);
|
||||||
|
response.setStatus(status);
|
||||||
|
|
||||||
|
if (status == 200) {
|
||||||
|
response.write(normalResponse.asJson().toUtf8());
|
||||||
|
} else {
|
||||||
|
response.write(errorResponse.asJson().toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response.setStatus(405,"Invalid HTTP method");
|
response.setStatus(405,"Invalid HTTP method");
|
||||||
|
@ -55,8 +55,8 @@ private:
|
|||||||
void instancePresetService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
void instancePresetService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
void instanceDeviceSetsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
void instanceDeviceSetsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
|
|
||||||
void deviceset(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
void devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
void devicesetDevice(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
void devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
|
|
||||||
bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer);
|
bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer);
|
||||||
bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
|
bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
|
||||||
|
@ -693,6 +693,48 @@ int WebAPIAdapterGUI::devicesetDevicePut(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebAPIAdapterGUI::devicesetDeviceGet(
|
||||||
|
int deviceSetIndex,
|
||||||
|
SWGSDRangel::SWGDeviceSettings& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error)
|
||||||
|
{
|
||||||
|
if ((deviceSetIndex >= 0) && (m_mainWindow.m_deviceUIs < (int) m_mainWindow.m_deviceUIs.size()))
|
||||||
|
{
|
||||||
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
||||||
|
int tx = response.getTx();
|
||||||
|
|
||||||
|
if ((tx == 0) && (deviceSet->m_deviceSinkEngine))
|
||||||
|
{
|
||||||
|
*error.getMessage() = QString("Device type (Rx) and device set type (Tx) mismatch");
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((tx != 0) && (deviceSet->m_deviceSourceEngine))
|
||||||
|
{
|
||||||
|
*error.getMessage() = QString("Device type (Tx) and device set type (Rx) mismatch");
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx == 0) // Rx
|
||||||
|
{
|
||||||
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
||||||
|
return source->webapiSettingsGet(response.getData(), *error.getMessage());
|
||||||
|
}
|
||||||
|
else // Tx
|
||||||
|
{
|
||||||
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
||||||
|
return sink->webapiSettingsGet(response.getData(), *error.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.init();
|
||||||
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||||
|
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebAPIAdapterGUI::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
void WebAPIAdapterGUI::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
||||||
{
|
{
|
||||||
deviceSetList->init();
|
deviceSetList->init();
|
||||||
|
@ -120,6 +120,11 @@ public:
|
|||||||
SWGSDRangel::SWGDeviceListItem& response,
|
SWGSDRangel::SWGDeviceListItem& response,
|
||||||
SWGSDRangel::SWGErrorResponse& error);
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
|
virtual int devicesetDeviceGet(
|
||||||
|
int deviceSetIndex,
|
||||||
|
SWGSDRangel::SWGDeviceSettings& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainWindow& m_mainWindow;
|
MainWindow& m_mainWindow;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user