mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-04-04 02:28:33 -04:00
Web API: /sdrangel/preset (GET) implementation
This commit is contained in:
parent
f4c1269540
commit
2b41601b83
@ -82,10 +82,17 @@ public:
|
||||
|
||||
static bool presetCompare(const Preset *p1, Preset *p2)
|
||||
{
|
||||
if (p1->m_centerFrequency != p2->m_centerFrequency) {
|
||||
return p1->m_centerFrequency < p2->m_centerFrequency;
|
||||
} else {
|
||||
return p1->m_description < p2->m_description;
|
||||
if (p1->m_group != p2->m_group)
|
||||
{
|
||||
return p1->m_group < p2->m_group;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p1->m_centerFrequency != p2->m_centerFrequency) {
|
||||
return p1->m_centerFrequency < p2->m_centerFrequency;
|
||||
} else {
|
||||
return p1->m_description < p2->m_description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,3 +25,4 @@ QString WebAPIAdapterInterface::instanceLoggingURL = "/sdrangel/logging";
|
||||
QString WebAPIAdapterInterface::instanceAudioURL = "/sdrangel/audio";
|
||||
QString WebAPIAdapterInterface::instanceLocationURL = "/sdrangel/location";
|
||||
QString WebAPIAdapterInterface::instanceDVSerialURL = "/sdrangel/dvserial";
|
||||
QString WebAPIAdapterInterface::instancePresetURL = "/sdrangel/preset";
|
||||
|
@ -32,6 +32,7 @@ namespace Swagger
|
||||
class SWGLocationInformation;
|
||||
class SWGDVSeralDevices;
|
||||
class SWGErrorResponse;
|
||||
class SWGPresets;
|
||||
}
|
||||
|
||||
class WebAPIAdapterInterface
|
||||
@ -132,6 +133,15 @@ public:
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/location (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int instancePresetGet(
|
||||
Swagger::SWGPresets& response __attribute__((unused)),
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
static QString instanceSummaryURL;
|
||||
static QString instanceDevicesURL;
|
||||
static QString instanceChannelsURL;
|
||||
@ -139,6 +149,7 @@ public:
|
||||
static QString instanceAudioURL;
|
||||
static QString instanceLocationURL;
|
||||
static QString instanceDVSerialURL;
|
||||
static QString instancePresetURL;
|
||||
};
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "SWGAudioDevicesSelect.h"
|
||||
#include "SWGLocationInformation.h"
|
||||
#include "SWGDVSeralDevices.h"
|
||||
#include "SWGPresets.h"
|
||||
#include "SWGErrorResponse.h"
|
||||
|
||||
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
||||
@ -70,6 +71,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
||||
instanceLocationService(request, response);
|
||||
} else if (path == WebAPIAdapterInterface::instanceDVSerialURL) {
|
||||
instanceDVSerialService(request, response);
|
||||
} else if (path == WebAPIAdapterInterface::instancePresetURL) {
|
||||
instancePresetService(request, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -322,6 +325,29 @@ void WebAPIRequestMapper::instanceDVSerialService(qtwebapp::HttpRequest& request
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIRequestMapper::instancePresetService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||
{
|
||||
Swagger::SWGPresets normalResponse;
|
||||
Swagger::SWGErrorResponse errorResponse;
|
||||
|
||||
if (request.getMethod() == "GET")
|
||||
{
|
||||
int status = m_adapter->instancePresetGet(normalResponse, errorResponse);
|
||||
response.setStatus(status);
|
||||
|
||||
if (status == 200) {
|
||||
response.write(normalResponse.asJson().toUtf8());
|
||||
} else {
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(405,"Invalid HTTP method");
|
||||
response.write("Invalid HTTP method");
|
||||
}
|
||||
}
|
||||
|
||||
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response)
|
||||
{
|
||||
Swagger::SWGErrorResponse errorResponse;
|
||||
|
@ -46,6 +46,7 @@ private:
|
||||
void instanceAudioService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
void instanceLocationService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
void instanceDVSerialService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
void instancePresetService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
|
||||
bool parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response);
|
||||
};
|
||||
|
@ -506,10 +506,16 @@ void MainWindow::loadSettings()
|
||||
|
||||
m_settings.load();
|
||||
m_settings.sortPresets();
|
||||
int middleIndex = m_settings.getPresetCount() / 2;
|
||||
QTreeWidgetItem *treeItem;
|
||||
|
||||
for(int i = 0; i < m_settings.getPresetCount(); ++i)
|
||||
for (int i = 0; i < m_settings.getPresetCount(); ++i)
|
||||
{
|
||||
ui->presetTree->setCurrentItem(addPresetToTree(m_settings.getPreset(i)));
|
||||
treeItem = addPresetToTree(m_settings.getPreset(i));
|
||||
|
||||
if (i == middleIndex) {
|
||||
ui->presetTree->setCurrentItem(treeItem);
|
||||
}
|
||||
}
|
||||
|
||||
setLoggingOpions();
|
||||
@ -696,6 +702,8 @@ void MainWindow::on_presetSave_clicked()
|
||||
|
||||
ui->presetTree->setCurrentItem(addPresetToTree(preset));
|
||||
}
|
||||
|
||||
m_settings.sortPresets();
|
||||
}
|
||||
|
||||
void MainWindow::on_presetUpdate_clicked()
|
||||
@ -711,6 +719,8 @@ void MainWindow::on_presetUpdate_clicked()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_settings.sortPresets();
|
||||
}
|
||||
|
||||
void MainWindow::on_presetExport_clicked()
|
||||
|
@ -42,6 +42,9 @@
|
||||
#include "SWGLocationInformation.h"
|
||||
#include "SWGDVSeralDevices.h"
|
||||
#include "SWGDVSerialDevice.h"
|
||||
#include "SWGPresets.h"
|
||||
#include "SWGPresetGroup.h"
|
||||
#include "SWGPresetItem.h"
|
||||
#include "SWGErrorResponse.h"
|
||||
|
||||
#include "webapiadaptergui.h"
|
||||
@ -383,6 +386,50 @@ int WebAPIAdapterGUI::instanceDVSerialPatch(
|
||||
return 200;
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::instancePresetGet(
|
||||
Swagger::SWGPresets& response,
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{
|
||||
int nbPresets = m_mainWindow.m_settings.getPresetCount();
|
||||
int nbGroups = 0;
|
||||
int nbPresetsThisGroup = 0;
|
||||
QString groupName;
|
||||
response.init();
|
||||
QList<Swagger::SWGPresetGroup*> *groups = response.getGroups();
|
||||
QList<Swagger::SWGPresetItem*> *swgPresets = 0;
|
||||
int i = 0;
|
||||
|
||||
// Presets are sorted by group first
|
||||
|
||||
for (; i < nbPresets; i++)
|
||||
{
|
||||
const Preset *preset = m_mainWindow.m_settings.getPreset(i);
|
||||
|
||||
if ((i == 0) || (groupName != preset->getGroup())) // new group
|
||||
{
|
||||
if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
|
||||
groups->append(new Swagger::SWGPresetGroup);
|
||||
groups->back()->init();
|
||||
groupName = preset->getGroup();
|
||||
*groups->back()->getGroupName() = groupName;
|
||||
swgPresets = groups->back()->getPresets();
|
||||
nbGroups++;
|
||||
nbPresetsThisGroup = 0;
|
||||
}
|
||||
|
||||
swgPresets->append(new Swagger::SWGPresetItem);
|
||||
swgPresets->back()->setCenterFrequency(preset->getCenterFrequency());
|
||||
*swgPresets->back()->getType() = preset->isSourcePreset() ? "R" : "T";
|
||||
*swgPresets->back()->getName() = preset->getDescription();
|
||||
nbPresetsThisGroup++;
|
||||
}
|
||||
|
||||
if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
|
||||
response.setNbGroups(nbGroups);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString)
|
||||
{
|
||||
if (msgTypeString == "debug") {
|
||||
|
@ -74,6 +74,10 @@ public:
|
||||
Swagger::SWGDVSeralDevices& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
virtual int instancePresetGet(
|
||||
Swagger::SWGPresets& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
private:
|
||||
MainWindow& m_mainWindow;
|
||||
|
||||
|
@ -778,9 +778,9 @@ definitions:
|
||||
- name
|
||||
properties:
|
||||
centerFrequency:
|
||||
description: "Center freqeuency in MHz"
|
||||
type: number
|
||||
format: float
|
||||
description: "Center freqeuency in Hz"
|
||||
type: integer
|
||||
format: int64
|
||||
type:
|
||||
description: "Type of device set (R: Rx, T: Tx)"
|
||||
type: string
|
||||
|
@ -37,7 +37,7 @@ SWGPresetItem::~SWGPresetItem() {
|
||||
|
||||
void
|
||||
SWGPresetItem::init() {
|
||||
center_frequency = 0.0f;
|
||||
center_frequency = 0L;
|
||||
type = new QString("");
|
||||
name = new QString("");
|
||||
}
|
||||
@ -66,7 +66,7 @@ SWGPresetItem::fromJson(QString &json) {
|
||||
|
||||
void
|
||||
SWGPresetItem::fromJsonObject(QJsonObject &pJson) {
|
||||
::Swagger::setValue(¢er_frequency, pJson["centerFrequency"], "float", "");
|
||||
::Swagger::setValue(¢er_frequency, pJson["centerFrequency"], "qint64", "");
|
||||
::Swagger::setValue(&type, pJson["type"], "QString", "QString");
|
||||
::Swagger::setValue(&name, pJson["name"], "QString", "QString");
|
||||
}
|
||||
@ -94,12 +94,12 @@ SWGPresetItem::asJsonObject() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
float
|
||||
qint64
|
||||
SWGPresetItem::getCenterFrequency() {
|
||||
return center_frequency;
|
||||
}
|
||||
void
|
||||
SWGPresetItem::setCenterFrequency(float center_frequency) {
|
||||
SWGPresetItem::setCenterFrequency(qint64 center_frequency) {
|
||||
this->center_frequency = center_frequency;
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ public:
|
||||
void fromJsonObject(QJsonObject &json);
|
||||
SWGPresetItem* fromJson(QString &jsonString);
|
||||
|
||||
float getCenterFrequency();
|
||||
void setCenterFrequency(float center_frequency);
|
||||
qint64 getCenterFrequency();
|
||||
void setCenterFrequency(qint64 center_frequency);
|
||||
|
||||
QString* getType();
|
||||
void setType(QString* type);
|
||||
@ -53,7 +53,7 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
float center_frequency;
|
||||
qint64 center_frequency;
|
||||
QString* type;
|
||||
QString* name;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user