diff --git a/sdrbase/resources/index.html b/sdrbase/resources/index.html index 1c6401143..b0bf4ac9c 100644 --- a/sdrbase/resources/index.html +++ b/sdrbase/resources/index.html @@ -14268,7 +14268,7 @@ $(document).ready(function() {

-

Update device set settings on an existing preset.

+

Update an existing preset with device set settings.


/sdrangel/preset
@@ -15011,7 +15011,7 @@ except ApiException as e:
- Generated 2017-12-20T00:50:19.499+01:00 + Generated 2017-12-20T14:24:11.587+01:00
diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index d113007c2..4c7f983e7 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -379,7 +379,7 @@ int WebAPIAdapterGUI::instancePresetPatch( SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset(); int nbDeviceSets = m_mainWindow.m_deviceUIs.size(); - if (deviceSetIndex > nbDeviceSets) + if (deviceSetIndex >= nbDeviceSets) { *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets); return 404; diff --git a/sdrsrv/maincore.cpp b/sdrsrv/maincore.cpp index 8791a828a..1247bcb4a 100644 --- a/sdrsrv/maincore.cpp +++ b/sdrsrv/maincore.cpp @@ -35,6 +35,7 @@ #include "maincore.h" MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteInstance, Message) +MESSAGE_CLASS_DEFINITION(MainCore::MsgLoadPreset, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgAddDeviceSet, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message) @@ -100,6 +101,12 @@ bool MainCore::handleMessage(const Message& cmd) emit finished(); return true; } + else if (MsgLoadPreset::match(cmd)) + { + MsgLoadPreset& notif = (MsgLoadPreset&) cmd; + loadPresetSettings(notif.getPreset(), notif.getDeviceSetIndex()); + return true; + } else if (MsgAddDeviceSet::match(cmd)) { MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd; @@ -290,6 +297,29 @@ void MainCore::removeLastDevice() m_deviceSets.pop_back(); } +void MainCore::loadPresetSettings(const Preset* preset, int tabIndex) +{ + qDebug("MainCore::loadPresetSettings: preset [%s | %s]", + qPrintable(preset->getGroup()), + qPrintable(preset->getDescription())); + + if (tabIndex >= 0) + { + DeviceSet *deviceSet = m_deviceSets[tabIndex]; + + if (deviceSet->m_deviceSourceEngine) // source device + { + deviceSet->m_deviceSourceAPI->loadSourceSettings(preset); + deviceSet->loadRxChannelSettings(preset, m_pluginManager->getPluginAPI()); + } + else if (deviceSet->m_deviceSinkEngine) // sink device + { + deviceSet->m_deviceSinkAPI->loadSinkSettings(preset); + deviceSet->loadTxChannelSettings(preset, m_pluginManager->getPluginAPI()); + } + } +} + void MainCore::savePresetSettings(Preset* preset, int tabIndex) { qDebug("MainCore::savePresetSettings: preset [%s | %s]", diff --git a/sdrsrv/maincore.h b/sdrsrv/maincore.h index 4131e902c..35311bd11 100644 --- a/sdrsrv/maincore.h +++ b/sdrsrv/maincore.h @@ -70,6 +70,29 @@ signals: void finished(); private: + class MsgLoadPreset : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const Preset *getPreset() const { return m_preset; } + int getDeviceSetIndex() const { return m_deviceSetIndex; } + + static MsgLoadPreset* create(const Preset *preset, int deviceSetIndex) + { + return new MsgLoadPreset(preset, deviceSetIndex); + } + + private: + const Preset *m_preset; + int m_deviceSetIndex; + + MsgLoadPreset(const Preset *preset, int deviceSetIndex) : + Message(), + m_preset(preset), + m_deviceSetIndex(deviceSetIndex) + { } + }; + class MsgDeleteInstance : public Message { MESSAGE_CLASS_DECLARATION @@ -138,6 +161,7 @@ private: WebAPIAdapterSrv *m_apiAdapter; void loadSettings(); + void loadPresetSettings(const Preset* preset, int tabIndex); void savePresetSettings(Preset* preset, int tabIndex); void setLoggingOptions(); diff --git a/sdrsrv/webapi/webapiadaptersrv.cpp b/sdrsrv/webapi/webapiadaptersrv.cpp index 68fd1bd02..f1bee0a10 100644 --- a/sdrsrv/webapi/webapiadaptersrv.cpp +++ b/sdrsrv/webapi/webapiadaptersrv.cpp @@ -33,6 +33,7 @@ #include "SWGPresetImport.h" #include "SWGPresetExport.h" #include "SWGPresets.h" +#include "SWGPresetTransfer.h" #include "SWGSuccessResponse.h" #include "SWGErrorResponse.h" @@ -484,6 +485,60 @@ int WebAPIAdapterSrv::instancePresetGet( return 200; } +int WebAPIAdapterSrv::instancePresetPatch( + SWGSDRangel::SWGPresetTransfer& query, + SWGSDRangel::SWGPresetIdentifier& response, + SWGSDRangel::SWGErrorResponse& error) +{ + int deviceSetIndex = query.getDeviceSetIndex(); + SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset(); + int nbDeviceSets = m_mainCore.m_deviceSets.size(); + + if (deviceSetIndex >= nbDeviceSets) + { + *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets); + return 404; + } + + const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(), + presetIdentifier->getCenterFrequency(), + *presetIdentifier->getName()); + + if (selectedPreset == 0) + { + *error.getMessage() = QString("There is no preset [%1, %2, %3]") + .arg(*presetIdentifier->getGroupName()) + .arg(presetIdentifier->getCenterFrequency()) + .arg(*presetIdentifier->getName()); + return 404; + } + + DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex]; + + if (deviceSet->m_deviceSourceEngine && !selectedPreset->isSourcePreset()) + { + *error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch"); + return 404; + } + + if (deviceSet->m_deviceSinkEngine && selectedPreset->isSourcePreset()) + { + *error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch"); + return 404; + } + + MainCore::MsgLoadPreset *msg = MainCore::MsgLoadPreset::create(selectedPreset, deviceSetIndex); + m_mainCore.m_inputMessageQueue.push(msg); + + response.init(); + response.setCenterFrequency(selectedPreset->getCenterFrequency()); + *response.getGroupName() = selectedPreset->getGroup(); + *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T"; + *response.getName() = selectedPreset->getDescription(); + + return 200; +} + int WebAPIAdapterSrv::instanceDeviceSetsPost( bool tx, SWGSDRangel::SWGSuccessResponse& response, diff --git a/sdrsrv/webapi/webapiadaptersrv.h b/sdrsrv/webapi/webapiadaptersrv.h index 1a8654fd6..fb2603235 100644 --- a/sdrsrv/webapi/webapiadaptersrv.h +++ b/sdrsrv/webapi/webapiadaptersrv.h @@ -93,6 +93,11 @@ public: SWGSDRangel::SWGPresets& response, SWGSDRangel::SWGErrorResponse& error); + virtual int instancePresetPatch( + SWGSDRangel::SWGPresetTransfer& query, + SWGSDRangel::SWGPresetIdentifier& response, + SWGSDRangel::SWGErrorResponse& error); + virtual int instanceDeviceSetsPost( bool tx, SWGSDRangel::SWGSuccessResponse& response, diff --git a/swagger/sdrangel/api/swagger/swagger.yaml b/swagger/sdrangel/api/swagger/swagger.yaml index 6d2df9445..60a3e8fc0 100644 --- a/swagger/sdrangel/api/swagger/swagger.yaml +++ b/swagger/sdrangel/api/swagger/swagger.yaml @@ -337,7 +337,7 @@ paths: "501": description: Function not implemented put: - description: Update device set settings on an existing preset. + description: Update an existing preset with device set settings. operationId: instancePresetPut tags: - Instance diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 1c6401143..b0bf4ac9c 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -14268,7 +14268,7 @@ $(document).ready(function() {

-

Update device set settings on an existing preset.

+

Update an existing preset with device set settings.


/sdrangel/preset
@@ -15011,7 +15011,7 @@ except ApiException as e:
- Generated 2017-12-20T00:50:19.499+01:00 + Generated 2017-12-20T14:24:11.587+01:00