diff --git a/plugins/channelrx/chanalyzer/chanalyzerwebapiadapter.cpp b/plugins/channelrx/chanalyzer/chanalyzerwebapiadapter.cpp index a90a5aaca..a79ef3d42 100644 --- a/plugins/channelrx/chanalyzer/chanalyzerwebapiadapter.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzerwebapiadapter.cpp @@ -155,6 +155,7 @@ int ChannelAnalyzerWebAPIAdapter::webapiSettingsPutPatch( (void) force; (void) errorMessage; webapiUpdateChannelSettings(m_settings, m_glScopeSettings, m_glSpectrumSettings, channelSettingsKeys, response); + return 200; } void ChannelAnalyzerWebAPIAdapter::webapiUpdateChannelSettings( diff --git a/sdrbase/dsp/glscopesettings.cpp b/sdrbase/dsp/glscopesettings.cpp index ecbb60181..f174c51e7 100644 --- a/sdrbase/dsp/glscopesettings.cpp +++ b/sdrbase/dsp/glscopesettings.cpp @@ -75,7 +75,7 @@ QByteArray GLScopeSettings::serialize() const std::vector::const_iterator triggerDataIt = m_triggersData.begin(); i = 0; - for (; triggerDataIt != m_triggersData.end(); i++) + for (; triggerDataIt != m_triggersData.end(); ++triggerDataIt, i++) { s.writeS32(210 + 16*i, (int) triggerDataIt->m_projectionType); s.writeS32(211 + 16*i, triggerDataIt->m_triggerRepeat); @@ -96,7 +96,6 @@ QByteArray GLScopeSettings::serialize() const bool GLScopeSettings::deserialize(const QByteArray& data) { - qDebug("GLScopeGUI::deserialize"); SimpleDeserializer d(data); if(!d.isValid()) { diff --git a/sdrbase/dsp/glspectrumsettings.cpp b/sdrbase/dsp/glspectrumsettings.cpp index 679d1327e..9961d6c99 100644 --- a/sdrbase/dsp/glspectrumsettings.cpp +++ b/sdrbase/dsp/glspectrumsettings.cpp @@ -53,6 +53,7 @@ void GLSpectrumSettings::resetToDefaults() QByteArray GLSpectrumSettings::serialize() const { SimpleSerializer s(1); + s.writeS32(1, m_fftSize); s.writeS32(2, m_fftOverlap); s.writeS32(3, m_fftWindow); @@ -74,6 +75,7 @@ QByteArray GLSpectrumSettings::serialize() const s.writeS32(19, (int) m_averagingMode); s.writeS32(20, (qint32) getAveragingValue(m_averagingIndex, m_averagingMode)); s.writeBool(21, m_linear); + return s.final(); } @@ -88,7 +90,8 @@ bool GLSpectrumSettings::deserialize(const QByteArray& data) int tmp; - if(d.getVersion() == 1) { + if (d.getVersion() == 1) + { d.readS32(1, &m_fftSize, 1024); d.readS32(2, &m_fftOverlap, 0); d.readS32(3, &m_fftWindow, FFTWindow::Hamming); @@ -115,7 +118,9 @@ bool GLSpectrumSettings::deserialize(const QByteArray& data) d.readBool(21, &m_linear, false); return true; - } else { + } + else + { resetToDefaults(); return false; } diff --git a/sdrbase/resources/webapi/doc/html2/index.html b/sdrbase/resources/webapi/doc/html2/index.html index 0540a91e7..421db4195 100644 --- a/sdrbase/resources/webapi/doc/html2/index.html +++ b/sdrbase/resources/webapi/doc/html2/index.html @@ -1805,7 +1805,7 @@ margin-bottom: 20px; }, "inputType" : { "type" : "integer", - "description" : "see ChannelAnalyzer::InputType" + "description" : "see ChannelAnalyzerSettings::InputType" }, "rgbColor" : { "type" : "integer" @@ -6779,6 +6779,9 @@ margin-bottom: 20px;
  • instanceConfigGet
  • +
  • + instanceConfigPatch +
  • instanceConfigPut
  • @@ -21074,6 +21077,393 @@ except ApiException as e:
    +
    +
    +
    +

    instanceConfigPatch

    +

    +
    +
    +
    +

    +

    Replace the Preferences, Working preset, Presets and Commands of the MainSettings object with the contents of the payload. Presets and Commands if available in the payload are added. Channels in the working preset are added. Devices in the working preset are patched or added (upsert).

    +

    +
    +
    /sdrangel/config
    +

    +

    Usage and SDK Samples

    +

    + + +
    +
    +
    curl -X PATCH "http://localhost/sdrangel/config"
    +
    +
    +
    import SWGSDRangel.*;
    +import SWGSDRangel.auth.*;
    +import SWGSDRangel.model.*;
    +import SWGSDRangel.api.InstanceApi;
    +
    +import java.io.File;
    +import java.util.*;
    +
    +public class InstanceApiExample {
    +
    +    public static void main(String[] args) {
    +        
    +        InstanceApi apiInstance = new InstanceApi();
    +        InstanceConfigResponse body = ; // InstanceConfigResponse | Config information
    +        try {
    +            SuccessResponse result = apiInstance.instanceConfigPatch(body);
    +            System.out.println(result);
    +        } catch (ApiException e) {
    +            System.err.println("Exception when calling InstanceApi#instanceConfigPatch");
    +            e.printStackTrace();
    +        }
    +    }
    +}
    +
    + +
    +
    import SWGSDRangel.api.InstanceApi;
    +
    +public class InstanceApiExample {
    +
    +    public static void main(String[] args) {
    +        InstanceApi apiInstance = new InstanceApi();
    +        InstanceConfigResponse body = ; // InstanceConfigResponse | Config information
    +        try {
    +            SuccessResponse result = apiInstance.instanceConfigPatch(body);
    +            System.out.println(result);
    +        } catch (ApiException e) {
    +            System.err.println("Exception when calling InstanceApi#instanceConfigPatch");
    +            e.printStackTrace();
    +        }
    +    }
    +}
    +
    + +
    +
    InstanceConfigResponse *body = ; // Config information
    +
    +InstanceApi *apiInstance = [[InstanceApi alloc] init];
    +
    +[apiInstance instanceConfigPatchWith:body
    +              completionHandler: ^(SuccessResponse output, NSError* error) {
    +                            if (output) {
    +                                NSLog(@"%@", output);
    +                            }
    +                            if (error) {
    +                                NSLog(@"Error: %@", error);
    +                            }
    +                        }];
    +
    +
    + +
    +
    var SdRangel = require('sd_rangel');
    +
    +var api = new SdRangel.InstanceApi()
    +
    +var body = ; // {InstanceConfigResponse} Config information
    +
    +
    +var callback = function(error, data, response) {
    +  if (error) {
    +    console.error(error);
    +  } else {
    +    console.log('API called successfully. Returned data: ' + data);
    +  }
    +};
    +api.instanceConfigPatch(body, callback);
    +
    +
    + + +
    +
    using System;
    +using System.Diagnostics;
    +using SWGSDRangel.Api;
    +using SWGSDRangel.Client;
    +using SWGSDRangel.Model;
    +
    +namespace Example
    +{
    +    public class instanceConfigPatchExample
    +    {
    +        public void main()
    +        {
    +            
    +            var apiInstance = new InstanceApi();
    +            var body = new InstanceConfigResponse(); // InstanceConfigResponse | Config information
    +
    +            try
    +            {
    +                SuccessResponse result = apiInstance.instanceConfigPatch(body);
    +                Debug.WriteLine(result);
    +            }
    +            catch (Exception e)
    +            {
    +                Debug.Print("Exception when calling InstanceApi.instanceConfigPatch: " + e.Message );
    +            }
    +        }
    +    }
    +}
    +
    +
    + +
    +
    <?php
    +require_once(__DIR__ . '/vendor/autoload.php');
    +
    +$api_instance = new Swagger\Client\Api\InstanceApi();
    +$body = ; // InstanceConfigResponse | Config information
    +
    +try {
    +    $result = $api_instance->instanceConfigPatch($body);
    +    print_r($result);
    +} catch (Exception $e) {
    +    echo 'Exception when calling InstanceApi->instanceConfigPatch: ', $e->getMessage(), PHP_EOL;
    +}
    +?>
    +
    + +
    +
    use Data::Dumper;
    +use SWGSDRangel::Configuration;
    +use SWGSDRangel::InstanceApi;
    +
    +my $api_instance = SWGSDRangel::InstanceApi->new();
    +my $body = SWGSDRangel::Object::InstanceConfigResponse->new(); # InstanceConfigResponse | Config information
    +
    +eval { 
    +    my $result = $api_instance->instanceConfigPatch(body => $body);
    +    print Dumper($result);
    +};
    +if ($@) {
    +    warn "Exception when calling InstanceApi->instanceConfigPatch: $@\n";
    +}
    +
    + +
    +
    from __future__ import print_statement
    +import time
    +import swagger_sdrangel
    +from swagger_sdrangel.rest import ApiException
    +from pprint import pprint
    +
    +# create an instance of the API class
    +api_instance = swagger_sdrangel.InstanceApi()
    +body =  # InstanceConfigResponse | Config information
    +
    +try: 
    +    api_response = api_instance.instance_config_patch(body)
    +    pprint(api_response)
    +except ApiException as e:
    +    print("Exception when calling InstanceApi->instanceConfigPatch: %s\n" % e)
    +
    +
    + +

    Parameters

    + + + +
    Body parameters
    + + + + + + + + + +
    NameDescription
    body * + + + +
    +
    + + + +

    Responses

    +

    Status: 200 - Success

    + + + +
    +
    +
    + +
    + +
    +
    + +

    Status: 500 - Error

    + + + +
    +
    +
    + +
    + +
    +
    + +

    Status: 501 - Function not implemented

    + + + +
    +
    +
    + +
    + +
    +
    + +
    +
    +
    @@ -21083,7 +21473,7 @@ except ApiException as e:

    -

    Replace the Preferences, Presets and Commands of the MainSettings object with the contents of the payload. Supports config restore.

    +

    Replace the Preferences, Working preset, Presets and Commands of the MainSettings object with the contents of the payload. Supports config restore.


    /sdrangel/config
    @@ -27607,7 +27997,7 @@ except ApiException as e:
    - Generated 2019-08-08T13:54:12.590+02:00 + Generated 2019-08-10T05:46:27.219+02:00
    diff --git a/sdrbase/resources/webapi/doc/swagger/include/ChannelAnalyzer.yaml b/sdrbase/resources/webapi/doc/swagger/include/ChannelAnalyzer.yaml index 4542b0a4f..377aa1af7 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/ChannelAnalyzer.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/ChannelAnalyzer.yaml @@ -32,7 +32,7 @@ ChannelAnalyzerSettings: pllPskOrder: type: integer inputType: - description: see ChannelAnalyzer::InputType + description: see ChannelAnalyzerSettings::InputType type: integer rgbColor: type: integer diff --git a/sdrbase/resources/webapi/doc/swagger/swagger.yaml b/sdrbase/resources/webapi/doc/swagger/swagger.yaml index 850c75c42..d6d38d0c6 100644 --- a/sdrbase/resources/webapi/doc/swagger/swagger.yaml +++ b/sdrbase/resources/webapi/doc/swagger/swagger.yaml @@ -93,7 +93,7 @@ paths: "501": $ref: "#/responses/Response_501" put: - description: Replace the Preferences, Presets and Commands of the MainSettings object with the contents of the payload. Supports config restore. + description: Replace the Preferences, Working preset, Presets and Commands of the MainSettings object with the contents of the payload. Supports config restore. operationId: instanceConfigPut tags: - Instance @@ -115,6 +115,29 @@ paths: $ref: "#/responses/Response_500" "501": $ref: "#/responses/Response_501" + patch: + description: Replace the Preferences, Working preset, Presets and Commands of the MainSettings object with the contents of the payload. Presets and Commands if available in the payload are added. Channels in the working preset are added. Devices in the working preset are patched or added (upsert). + operationId: instanceConfigPatch + tags: + - Instance + consumes: + - application/json + parameters: + - name: body + in: body + description: Config information + required: true + schema: + $ref: "#/definitions/InstanceConfigResponse" + responses: + "200": + description: Success + schema: + $ref: "#/definitions/SuccessResponse" + "500": + $ref: "#/responses/Response_500" + "501": + $ref: "#/responses/Response_501" /sdrangel/devices: x-swagger-router-controller: instance diff --git a/sdrbase/webapi/webapiadapterbase.cpp b/sdrbase/webapi/webapiadapterbase.cpp index 3f3296e1f..7cb285d26 100644 --- a/sdrbase/webapi/webapiadapterbase.cpp +++ b/sdrbase/webapi/webapiadapterbase.cpp @@ -181,30 +181,108 @@ void WebAPIAdapterBase::webapiUpdatePreset( bool force, SWGSDRangel::SWGPreset *apiPreset, const WebAPIAdapterInterface::PresetKeys& presetKeys, - Preset& preset + Preset *preset ) { if (presetKeys.m_keys.contains("centerFrequency")) { - preset.setCenterFrequency(apiPreset->getCenterFrequency()); + preset->setCenterFrequency(apiPreset->getCenterFrequency()); } if (presetKeys.m_keys.contains("dcOffsetCorrection")) { - preset.setDCOffsetCorrection(apiPreset->getDcOffsetCorrection() != 0); + preset->setDCOffsetCorrection(apiPreset->getDcOffsetCorrection() != 0); } if (presetKeys.m_keys.contains("iqImbalanceCorrection")) { - preset.setIQImbalanceCorrection(apiPreset->getIqImbalanceCorrection() != 0); + preset->setIQImbalanceCorrection(apiPreset->getIqImbalanceCorrection() != 0); } if (presetKeys.m_keys.contains("sourcePreset")) { - preset.setSourcePreset(apiPreset->getSourcePreset() != 0); + preset->setSourcePreset(apiPreset->getSourcePreset() != 0); } if (presetKeys.m_keys.contains("description")) { - preset.setDescription(*apiPreset->getDescription()); + preset->setDescription(*apiPreset->getDescription()); } if (presetKeys.m_keys.contains("group")) { - preset.setGroup(*apiPreset->getGroup()); + preset->setGroup(*apiPreset->getGroup()); } + GLSpectrumSettings spectrumSettings; + + if (!force) { + spectrumSettings.deserialize(preset->getSpectrumConfig()); + } + + QStringList::const_iterator spectrumIt = presetKeys.m_spectrumKeys.begin(); + for (; spectrumIt != presetKeys.m_spectrumKeys.end(); ++spectrumIt) + { + if (spectrumIt->contains("averagingMode")) { + spectrumSettings.m_averagingMode = (GLSpectrumSettings::AveragingMode) apiPreset->getSpectrumConfig()->getAveragingMode(); + } + if (spectrumIt->contains("averagingValue")) + { + spectrumSettings.m_averagingNb = apiPreset->getSpectrumConfig()->getAveragingValue(); + spectrumSettings.m_averagingIndex = GLSpectrumSettings::getAveragingIndex(spectrumSettings.m_averagingNb, spectrumSettings.m_averagingMode); + } + if (spectrumIt->contains("decay")) { + spectrumSettings.m_decay = apiPreset->getSpectrumConfig()->getDecay(); + } + if (spectrumIt->contains("decayDivisor")) { + spectrumSettings.m_decayDivisor = apiPreset->getSpectrumConfig()->getDecayDivisor(); + } + if (spectrumIt->contains("displayCurrent")) { + spectrumSettings.m_displayCurrent = apiPreset->getSpectrumConfig()->getDisplayCurrent() != 0; + } + if (spectrumIt->contains("displayGrid")) { + spectrumSettings.m_displayGrid = apiPreset->getSpectrumConfig()->getDisplayGrid() != 0; + } + if (spectrumIt->contains("displayGridIntensity")) { + spectrumSettings.m_displayGridIntensity = apiPreset->getSpectrumConfig()->getDisplayGridIntensity(); + } + if (spectrumIt->contains("displayHistogram")) { + spectrumSettings.m_displayHistogram = apiPreset->getSpectrumConfig()->getDisplayHistogram() != 0; + } + if (spectrumIt->contains("displayMaxHold")) { + spectrumSettings.m_displayMaxHold = apiPreset->getSpectrumConfig()->getDisplayMaxHold() != 0; + } + if (spectrumIt->contains("displayTraceIntensity")) { + spectrumSettings.m_displayTraceIntensity = apiPreset->getSpectrumConfig()->getDisplayTraceIntensity(); + } + if (spectrumIt->contains("displayWaterfall")) { + spectrumSettings.m_displayWaterfall = apiPreset->getSpectrumConfig()->getDisplayWaterfall(); + } + if (spectrumIt->contains("fftOverlap")) { + spectrumSettings.m_fftOverlap = apiPreset->getSpectrumConfig()->getFftOverlap(); + } + if (spectrumIt->contains("fftSize")) { + spectrumSettings.m_fftSize = apiPreset->getSpectrumConfig()->getFftSize(); + } + if (spectrumIt->contains("fftWindow")) { + spectrumSettings.m_fftWindow = apiPreset->getSpectrumConfig()->getFftWindow(); + } + if (spectrumIt->contains("histogramStroke")) { + spectrumSettings.m_histogramStroke = apiPreset->getSpectrumConfig()->getHistogramStroke(); + } + if (spectrumIt->contains("invert")) { + spectrumSettings.m_invert = apiPreset->getSpectrumConfig()->getInvert() != 0; + } + if (spectrumIt->contains("invertedWaterfall")) { + spectrumSettings.m_invertedWaterfall = apiPreset->getSpectrumConfig()->getInvertedWaterfall() != 0; + } + if (spectrumIt->contains("linear")) { + spectrumSettings.m_linear = apiPreset->getSpectrumConfig()->getLinear() != 0; + } + if (spectrumIt->contains("powerRange")) { + spectrumSettings.m_powerRange = apiPreset->getSpectrumConfig()->getPowerRange(); + } + if (spectrumIt->contains("refLevel")) { + spectrumSettings.m_refLevel = apiPreset->getSpectrumConfig()->getRefLevel(); + } + if (spectrumIt->contains("waterfallShare")) { + spectrumSettings.m_waterfallShare = apiPreset->getSpectrumConfig()->getWaterfallShare(); + } + } + + preset->setSpectrumConfig(spectrumSettings.serialize()); + if (force) { // PUT replaces devices list possibly erasing it if no devices are given - preset.clearDevices(); + preset->clearDevices(); } QString errorMessage; @@ -237,7 +315,7 @@ void WebAPIAdapterBase::webapiUpdatePreset( { if (!force) // In PATCH mode you must find the exact device and deserialize its current settings to be able to patch it { - const QByteArray *config = preset.findDeviceConfig(deviceId, deviceSerial, deviceSequence); + const QByteArray *config = preset->findDeviceConfig(deviceId, deviceSerial, deviceSequence); if (!config) { continue; @@ -256,12 +334,12 @@ void WebAPIAdapterBase::webapiUpdatePreset( ); QByteArray config = deviceWebAPIAdapter->serialize(); - preset.setDeviceConfig(deviceId, deviceSerial, deviceSequence, config); // add or update device + preset->setDeviceConfig(deviceId, deviceSerial, deviceSequence, config); // add or update device } } if (force) { // PUT replaces channel list possibly erasing it if no channels are given - preset.clearChannels(); + preset->clearChannels(); } QList::const_iterator channelKeysIt = presetKeys.m_channelsKeys.begin(); @@ -285,15 +363,17 @@ void WebAPIAdapterBase::webapiUpdatePreset( continue; } + SWGSDRangel::SWGChannelSettings *channelSettings = swgChannelConfig->getConfig(); + channelWebAPIAdapter->webapiSettingsPutPatch( true, // channels are always appended channelKeysIt->m_channelKeys, - *swgChannelConfig->getConfig(), + *channelSettings, errorMessage ); QByteArray config = channelWebAPIAdapter->serialize(); - preset.addChannel(*channelIdURI, config); + preset->addChannel(*channelIdURI, config); } } } diff --git a/sdrbase/webapi/webapiadapterbase.h b/sdrbase/webapi/webapiadapterbase.h index 4ce6ee6f5..99937205e 100644 --- a/sdrbase/webapi/webapiadapterbase.h +++ b/sdrbase/webapi/webapiadapterbase.h @@ -70,7 +70,7 @@ public: bool force, SWGSDRangel::SWGPreset *apiPreset, const WebAPIAdapterInterface::PresetKeys& presetKeys, - Preset& preset + Preset *preset ); static void webapiUpdateCommand( SWGSDRangel::SWGCommand *apiCommand, diff --git a/sdrbase/webapi/webapiadapterinterface.cpp b/sdrbase/webapi/webapiadapterinterface.cpp index ba07be5ec..30db1f828 100644 --- a/sdrbase/webapi/webapiadapterinterface.cpp +++ b/sdrbase/webapi/webapiadapterinterface.cpp @@ -76,6 +76,10 @@ void WebAPIAdapterInterface::ConfigKeys::debug() const foreach(QString presetKey, presetKeys.m_keys) { qDebug(" %s", qPrintable(presetKey)); } + qDebug(" spectrumConfig:"); + foreach(QString spectrumKey, presetKeys.m_spectrumKeys) { + qDebug(" %s", qPrintable(spectrumKey)); + } qDebug(" deviceConfigs:"); foreach(DeviceKeys deviceKeys, presetKeys.m_devicesKeys) { @@ -103,6 +107,10 @@ void WebAPIAdapterInterface::ConfigKeys::debug() const foreach(QString presetKey, m_workingPresetKeys.m_keys) { qDebug(" %s", qPrintable(presetKey)); } + qDebug(" spectrumConfig:"); + foreach(QString spectrumKey, m_workingPresetKeys.m_spectrumKeys) { + qDebug(" %s", qPrintable(spectrumKey)); + } qDebug(" deviceConfigs:"); foreach(DeviceKeys deviceKeys, m_workingPresetKeys.m_devicesKeys) { diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index 09d455a7c..b232cc1bd 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -364,7 +364,7 @@ void WebAPIRequestMapper::instanceConfigService(qtwebapp::HttpRequest& request, response.write(errorResponse.asJson().toUtf8()); } } - else if (request.getMethod() == "PUT") + else if ((request.getMethod() == "PUT") || (request.getMethod() == "PATCH")) { QString jsonStr = request.getBody(); QJsonObject jsonObject; @@ -379,14 +379,15 @@ void WebAPIRequestMapper::instanceConfigService(qtwebapp::HttpRequest& request, if (validateConfig(query, jsonObject, configKeys)) { int status = m_adapter->instanceConfigPutPatch( - true, + request.getMethod() == "PUT", query, configKeys, normalResponse, errorResponse ); response.setStatus(status); - qDebug("WebAPIRequestMapper::instanceConfigService: PUT: %d", status); + qDebug("WebAPIRequestMapper::instanceConfigService: %s: %d", + request.getMethod() == "PUT" ? "PUT" : "PATCH", status); if (status/100 == 2) { @@ -2311,7 +2312,7 @@ bool WebAPIRequestMapper::appendPresetKeys( } if (presetJson.contains("iqImbalanceCorrection")) { - preset->setIqImbalanceCorrection(presetJson["sourcePreset"].toInt()); + preset->setSourcePreset(presetJson["sourcePreset"].toInt()); presetKeys.m_keys.append("sourcePreset"); } if (presetJson.contains("description")) @@ -2390,6 +2391,7 @@ bool WebAPIRequestMapper::appendPresetChannelKeys( if (channelSettingsJson.contains("config") && m_channelURIToSettingsKey.contains(*channelURI)) { SWGSDRangel::SWGChannelSettings *channelSettings = new SWGSDRangel::SWGChannelSettings(); + channel->setConfig(channelSettings); return getChannel(m_channelURIToSettingsKey[*channelURI], channelSettings, channelSettingsJson["config"].toObject(), channelKeys.m_channelKeys); } else @@ -2561,6 +2563,7 @@ bool WebAPIRequestMapper::appendPresetDeviceKeys( if (deviceSettngsJson.contains("config") && m_deviceIdToSettingsKey.contains(*deviceId)) { SWGSDRangel::SWGDeviceSettings *deviceSettings = new SWGSDRangel::SWGDeviceSettings(); + device->setConfig(deviceSettings); return getDevice(m_deviceIdToSettingsKey[*deviceId], deviceSettings, deviceSettngsJson["config"].toObject(), devicelKeys.m_deviceKeys); } else @@ -2763,7 +2766,6 @@ void WebAPIRequestMapper::appendSettingsSubKeys( QStringList childSettingsKeys = childSettingsJsonObject.keys(); for (int i = 0; i < childSettingsKeys.size(); i++) { - qDebug("WebAPIRequestMapper::appendSettingsSubKeys: %s", qPrintable(childSettingsKeys.at(i))); keyList.append(parentKey + QString(".") + childSettingsKeys.at(i)); } } diff --git a/sdrgui/gui/glscopegui.cpp b/sdrgui/gui/glscopegui.cpp index c5f3ad09d..4c5f777c7 100644 --- a/sdrgui/gui/glscopegui.cpp +++ b/sdrgui/gui/glscopegui.cpp @@ -229,7 +229,6 @@ QByteArray GLScopeGUI::serialize() const bool GLScopeGUI::deserialize(const QByteArray& data) { - qDebug("GLScopeGUI::deserialize"); SimpleDeserializer d(data); if(!d.isValid()) { diff --git a/sdrgui/gui/glspectrumgui.cpp b/sdrgui/gui/glspectrumgui.cpp index 367ebc7d2..3c1dbaae1 100644 --- a/sdrgui/gui/glspectrumgui.cpp +++ b/sdrgui/gui/glspectrumgui.cpp @@ -85,6 +85,7 @@ void GLSpectrumGUI::resetToDefaults() QByteArray GLSpectrumGUI::serialize() const { SimpleSerializer s(1); + s.writeS32(1, m_fftSize); s.writeS32(2, m_fftOverlap); s.writeS32(3, m_fftWindow); @@ -106,7 +107,8 @@ QByteArray GLSpectrumGUI::serialize() const s.writeS32(19, (int) m_averagingMode); s.writeS32(20, (qint32) getAveragingValue(m_averagingIndex)); s.writeBool(21, m_linear); - return s.final(); + + return s.final(); } bool GLSpectrumGUI::deserialize(const QByteArray& data) @@ -120,7 +122,8 @@ bool GLSpectrumGUI::deserialize(const QByteArray& data) int tmp; - if(d.getVersion() == 1) { + if (d.getVersion() == 1) + { d.readS32(1, &m_fftSize, 1024); d.readS32(2, &m_fftOverlap, 0); d.readS32(3, &m_fftWindow, FFTWindow::Hamming); @@ -147,10 +150,12 @@ bool GLSpectrumGUI::deserialize(const QByteArray& data) m_averagingNb = getAveragingValue(m_averagingIndex); d.readBool(21, &m_linear, false); - m_glSpectrum->setWaterfallShare(waterfallShare); - applySettings(); + m_glSpectrum->setWaterfallShare(waterfallShare); + applySettings(); return true; - } else { + } + else + { resetToDefaults(); return false; } diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 21e47853e..71cf221f8 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -89,6 +89,7 @@ MESSAGE_CLASS_DEFINITION(MainWindow::MsgSetDevice, Message) MESSAGE_CLASS_DEFINITION(MainWindow::MsgAddChannel, Message) MESSAGE_CLASS_DEFINITION(MainWindow::MsgDeleteChannel, Message) MESSAGE_CLASS_DEFINITION(MainWindow::MsgDeviceSetFocus, Message) +MESSAGE_CLASS_DEFINITION(MainWindow::MsgApplySettings, Message) MainWindow *MainWindow::m_instance = 0; @@ -204,11 +205,6 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse loadPresetSettings(m_settings.getWorkingPreset(), 0); - splash->showStatusMessage("apply settings...", Qt::white); - qDebug() << "MainWindow::MainWindow: apply settings..."; - - applySettings(); - splash->showStatusMessage("update preset controls...", Qt::white); qDebug() << "MainWindow::MainWindow: update preset controls..."; @@ -742,17 +738,12 @@ void MainWindow::loadPresetSettings(const Preset* preset, int tabIndex) if (tabIndex >= 0) { DeviceUISet *deviceUI = m_deviceUIs[tabIndex]; + deviceUI->m_spectrumGUI->deserialize(preset->getSpectrumConfig()); + deviceUI->m_deviceAPI->loadSamplingDeviceSettings(preset); - if (deviceUI->m_deviceSourceEngine) // source device - { - deviceUI->m_spectrumGUI->deserialize(preset->getSpectrumConfig()); - deviceUI->m_deviceAPI->loadSamplingDeviceSettings(preset); + if (deviceUI->m_deviceSourceEngine) { // source device deviceUI->loadRxChannelSettings(preset, m_pluginManager->getPluginAPI()); - } - else if (deviceUI->m_deviceSinkEngine) // sink device - { - deviceUI->m_spectrumGUI->deserialize(preset->getSpectrumConfig()); - deviceUI->m_deviceAPI->loadSamplingDeviceSettings(preset); + } else if (deviceUI->m_deviceSinkEngine) { // sink device deviceUI->loadTxChannelSettings(preset, m_pluginManager->getPluginAPI()); } } @@ -920,6 +911,7 @@ QTreeWidgetItem* MainWindow::addCommandToTree(const Command* command) void MainWindow::applySettings() { + loadPresetSettings(m_settings.getWorkingPreset(), 0); } bool MainWindow::handleMessage(const Message& cmd) @@ -1034,6 +1026,11 @@ bool MainWindow::handleMessage(const Message& cmd) ui->tabInputsView->setCurrentIndex(index); } } + else if (MsgApplySettings::match(cmd)) + { + applySettings(); + return true; + } return false; } @@ -1552,7 +1549,6 @@ void MainWindow::on_presetLoad_clicked() } loadPresetSettings(preset, ui->tabInputsView->currentIndex()); - applySettings(); } void MainWindow::on_presetDelete_clicked() diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index e78eed3b8..3d58029f0 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -302,6 +302,20 @@ private: { } }; + class MsgApplySettings : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgApplySettings* create() { + return new MsgApplySettings(); + } + + private: + MsgApplySettings() : + Message() + { } + }; + static MainWindow *m_instance; Ui::MainWindow* ui; MessageQueue m_inputMessageQueue; diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index 1ceab85ab..0394e84d2 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -173,7 +173,7 @@ int WebAPIAdapterGUI::instanceConfigPutPatch( m_mainWindow.m_settings.setPreferences(newPreferences); Preset *workingPreset = m_mainWindow.m_settings.getWorkingPreset(); - webAPIAdapterBase.webapiUpdatePreset(force, query.getWorkingPreset(), configKeys.m_workingPresetKeys, *workingPreset); + webAPIAdapterBase.webapiUpdatePreset(force, query.getWorkingPreset(), configKeys.m_workingPresetKeys, workingPreset); QList::const_iterator presetKeysIt = configKeys.m_presetKeys.begin(); int i = 0; @@ -181,7 +181,7 @@ int WebAPIAdapterGUI::instanceConfigPutPatch( { Preset *newPreset = new Preset(); // created with default values SWGSDRangel::SWGPreset *swgPreset = query.getPresets()->at(i); - webAPIAdapterBase.webapiUpdatePreset(force, swgPreset, *presetKeysIt, *newPreset); + webAPIAdapterBase.webapiUpdatePreset(force, swgPreset, *presetKeysIt, newPreset); m_mainWindow.m_settings.addPreset(newPreset); } @@ -194,6 +194,11 @@ int WebAPIAdapterGUI::instanceConfigPutPatch( webAPIAdapterBase.webapiUpdateCommand(swgCommand, *commandKeysIt, *newCommand); m_mainWindow.m_settings.addCommand(newCommand); } + + MainWindow::MsgApplySettings *msg = MainWindow::MsgApplySettings::create(); + m_mainWindow.m_inputMessageQueue.push(msg); + + return 200; } int WebAPIAdapterGUI::instanceDevices( diff --git a/swagger/sdrangel/api/swagger/swagger.yaml b/swagger/sdrangel/api/swagger/swagger.yaml index 38744f583..5dbe9ffe3 100644 --- a/swagger/sdrangel/api/swagger/swagger.yaml +++ b/swagger/sdrangel/api/swagger/swagger.yaml @@ -93,7 +93,7 @@ paths: "501": $ref: "#/responses/Response_501" put: - description: Replace the Preferences, Presets and Commands of the MainSettings object with the contents of the payload. Supports config restore. + description: Replace the Preferences, Working preset, Presets and Commands of the MainSettings object with the contents of the payload. Supports config restore. operationId: instanceConfigPut tags: - Instance @@ -115,6 +115,29 @@ paths: $ref: "#/responses/Response_500" "501": $ref: "#/responses/Response_501" + patch: + description: Replace the Preferences, Working preset, Presets and Commands of the MainSettings object with the contents of the payload. Presets and Commands if available in the payload are added. Channels in the working preset are added. Devices in the working preset are patched or added (upsert). + operationId: instanceConfigPatch + tags: + - Instance + consumes: + - application/json + parameters: + - name: body + in: body + description: Config information + required: true + schema: + $ref: "#/definitions/InstanceConfigResponse" + responses: + "200": + description: Success + schema: + $ref: "#/definitions/SuccessResponse" + "500": + $ref: "#/responses/Response_500" + "501": + $ref: "#/responses/Response_501" /sdrangel/devices: x-swagger-router-controller: instance diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 0540a91e7..421db4195 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -1805,7 +1805,7 @@ margin-bottom: 20px; }, "inputType" : { "type" : "integer", - "description" : "see ChannelAnalyzer::InputType" + "description" : "see ChannelAnalyzerSettings::InputType" }, "rgbColor" : { "type" : "integer" @@ -6779,6 +6779,9 @@ margin-bottom: 20px;
  • instanceConfigGet
  • +
  • + instanceConfigPatch +
  • instanceConfigPut
  • @@ -21074,6 +21077,393 @@ except ApiException as e:
    +
    +
    +
    +

    instanceConfigPatch

    +

    +
    +
    +
    +

    +

    Replace the Preferences, Working preset, Presets and Commands of the MainSettings object with the contents of the payload. Presets and Commands if available in the payload are added. Channels in the working preset are added. Devices in the working preset are patched or added (upsert).

    +

    +
    +
    /sdrangel/config
    +

    +

    Usage and SDK Samples

    +

    + + +
    +
    +
    curl -X PATCH "http://localhost/sdrangel/config"
    +
    +
    +
    import SWGSDRangel.*;
    +import SWGSDRangel.auth.*;
    +import SWGSDRangel.model.*;
    +import SWGSDRangel.api.InstanceApi;
    +
    +import java.io.File;
    +import java.util.*;
    +
    +public class InstanceApiExample {
    +
    +    public static void main(String[] args) {
    +        
    +        InstanceApi apiInstance = new InstanceApi();
    +        InstanceConfigResponse body = ; // InstanceConfigResponse | Config information
    +        try {
    +            SuccessResponse result = apiInstance.instanceConfigPatch(body);
    +            System.out.println(result);
    +        } catch (ApiException e) {
    +            System.err.println("Exception when calling InstanceApi#instanceConfigPatch");
    +            e.printStackTrace();
    +        }
    +    }
    +}
    +
    + +
    +
    import SWGSDRangel.api.InstanceApi;
    +
    +public class InstanceApiExample {
    +
    +    public static void main(String[] args) {
    +        InstanceApi apiInstance = new InstanceApi();
    +        InstanceConfigResponse body = ; // InstanceConfigResponse | Config information
    +        try {
    +            SuccessResponse result = apiInstance.instanceConfigPatch(body);
    +            System.out.println(result);
    +        } catch (ApiException e) {
    +            System.err.println("Exception when calling InstanceApi#instanceConfigPatch");
    +            e.printStackTrace();
    +        }
    +    }
    +}
    +
    + +
    +
    InstanceConfigResponse *body = ; // Config information
    +
    +InstanceApi *apiInstance = [[InstanceApi alloc] init];
    +
    +[apiInstance instanceConfigPatchWith:body
    +              completionHandler: ^(SuccessResponse output, NSError* error) {
    +                            if (output) {
    +                                NSLog(@"%@", output);
    +                            }
    +                            if (error) {
    +                                NSLog(@"Error: %@", error);
    +                            }
    +                        }];
    +
    +
    + +
    +
    var SdRangel = require('sd_rangel');
    +
    +var api = new SdRangel.InstanceApi()
    +
    +var body = ; // {InstanceConfigResponse} Config information
    +
    +
    +var callback = function(error, data, response) {
    +  if (error) {
    +    console.error(error);
    +  } else {
    +    console.log('API called successfully. Returned data: ' + data);
    +  }
    +};
    +api.instanceConfigPatch(body, callback);
    +
    +
    + + +
    +
    using System;
    +using System.Diagnostics;
    +using SWGSDRangel.Api;
    +using SWGSDRangel.Client;
    +using SWGSDRangel.Model;
    +
    +namespace Example
    +{
    +    public class instanceConfigPatchExample
    +    {
    +        public void main()
    +        {
    +            
    +            var apiInstance = new InstanceApi();
    +            var body = new InstanceConfigResponse(); // InstanceConfigResponse | Config information
    +
    +            try
    +            {
    +                SuccessResponse result = apiInstance.instanceConfigPatch(body);
    +                Debug.WriteLine(result);
    +            }
    +            catch (Exception e)
    +            {
    +                Debug.Print("Exception when calling InstanceApi.instanceConfigPatch: " + e.Message );
    +            }
    +        }
    +    }
    +}
    +
    +
    + +
    +
    <?php
    +require_once(__DIR__ . '/vendor/autoload.php');
    +
    +$api_instance = new Swagger\Client\Api\InstanceApi();
    +$body = ; // InstanceConfigResponse | Config information
    +
    +try {
    +    $result = $api_instance->instanceConfigPatch($body);
    +    print_r($result);
    +} catch (Exception $e) {
    +    echo 'Exception when calling InstanceApi->instanceConfigPatch: ', $e->getMessage(), PHP_EOL;
    +}
    +?>
    +
    + +
    +
    use Data::Dumper;
    +use SWGSDRangel::Configuration;
    +use SWGSDRangel::InstanceApi;
    +
    +my $api_instance = SWGSDRangel::InstanceApi->new();
    +my $body = SWGSDRangel::Object::InstanceConfigResponse->new(); # InstanceConfigResponse | Config information
    +
    +eval { 
    +    my $result = $api_instance->instanceConfigPatch(body => $body);
    +    print Dumper($result);
    +};
    +if ($@) {
    +    warn "Exception when calling InstanceApi->instanceConfigPatch: $@\n";
    +}
    +
    + +
    +
    from __future__ import print_statement
    +import time
    +import swagger_sdrangel
    +from swagger_sdrangel.rest import ApiException
    +from pprint import pprint
    +
    +# create an instance of the API class
    +api_instance = swagger_sdrangel.InstanceApi()
    +body =  # InstanceConfigResponse | Config information
    +
    +try: 
    +    api_response = api_instance.instance_config_patch(body)
    +    pprint(api_response)
    +except ApiException as e:
    +    print("Exception when calling InstanceApi->instanceConfigPatch: %s\n" % e)
    +
    +
    + +

    Parameters

    + + + +
    Body parameters
    + + + + + + + + + +
    NameDescription
    body * + + + +
    +
    + + + +

    Responses

    +

    Status: 200 - Success

    + + + +
    +
    +
    + +
    + +
    +
    + +

    Status: 500 - Error

    + + + +
    +
    +
    + +
    + +
    +
    + +

    Status: 501 - Function not implemented

    + + + +
    +
    +
    + +
    + +
    +
    + +
    +
    +
    @@ -21083,7 +21473,7 @@ except ApiException as e:

    -

    Replace the Preferences, Presets and Commands of the MainSettings object with the contents of the payload. Supports config restore.

    +

    Replace the Preferences, Working preset, Presets and Commands of the MainSettings object with the contents of the payload. Supports config restore.


    /sdrangel/config
    @@ -27607,7 +27997,7 @@ except ApiException as e:
    - Generated 2019-08-08T13:54:12.590+02:00 + Generated 2019-08-10T05:46:27.219+02:00
    diff --git a/swagger/sdrangel/code/qt5/client/SWGInstanceApi.cpp b/swagger/sdrangel/code/qt5/client/SWGInstanceApi.cpp index 35a38c355..3d8a13c08 100644 --- a/swagger/sdrangel/code/qt5/client/SWGInstanceApi.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGInstanceApi.cpp @@ -782,6 +782,61 @@ SWGInstanceApi::instanceConfigGetCallback(SWGHttpRequestWorker * worker) { } } +void +SWGInstanceApi::instanceConfigPatch(SWGInstanceConfigResponse& body) { + QString fullPath; + fullPath.append(this->host).append(this->basePath).append("/sdrangel/config"); + + + + SWGHttpRequestWorker *worker = new SWGHttpRequestWorker(); + SWGHttpRequestInput input(fullPath, "PATCH"); + + + + QString output = body.asJson(); + input.request_body.append(output); + + + + foreach(QString key, this->defaultHeaders.keys()) { + input.headers.insert(key, this->defaultHeaders.value(key)); + } + + connect(worker, + &SWGHttpRequestWorker::on_execution_finished, + this, + &SWGInstanceApi::instanceConfigPatchCallback); + + worker->execute(&input); +} + +void +SWGInstanceApi::instanceConfigPatchCallback(SWGHttpRequestWorker * worker) { + QString msg; + QString error_str = worker->error_str; + QNetworkReply::NetworkError error_type = worker->error_type; + + if (worker->error_type == QNetworkReply::NoError) { + msg = QString("Success! %1 bytes").arg(worker->response.length()); + } + else { + msg = "Error: " + worker->error_str; + } + + + QString json(worker->response); + SWGSuccessResponse* output = static_cast(create(json, QString("SWGSuccessResponse"))); + worker->deleteLater(); + + if (worker->error_type == QNetworkReply::NoError) { + emit instanceConfigPatchSignal(output); + } else { + emit instanceConfigPatchSignalE(output, error_type, error_str); + emit instanceConfigPatchSignalEFull(worker, error_type, error_str); + } +} + void SWGInstanceApi::instanceConfigPut(SWGInstanceConfigResponse& body) { QString fullPath; diff --git a/swagger/sdrangel/code/qt5/client/SWGInstanceApi.h b/swagger/sdrangel/code/qt5/client/SWGInstanceApi.h index df9385c38..e462192f8 100644 --- a/swagger/sdrangel/code/qt5/client/SWGInstanceApi.h +++ b/swagger/sdrangel/code/qt5/client/SWGInstanceApi.h @@ -65,6 +65,7 @@ public: void instanceAudioOutputPatch(SWGAudioOutputDevice& body); void instanceChannels(qint32 direction); void instanceConfigGet(); + void instanceConfigPatch(SWGInstanceConfigResponse& body); void instanceConfigPut(SWGInstanceConfigResponse& body); void instanceDelete(); void instanceDeviceSetsGet(); @@ -97,6 +98,7 @@ private: void instanceAudioOutputPatchCallback (SWGHttpRequestWorker * worker); void instanceChannelsCallback (SWGHttpRequestWorker * worker); void instanceConfigGetCallback (SWGHttpRequestWorker * worker); + void instanceConfigPatchCallback (SWGHttpRequestWorker * worker); void instanceConfigPutCallback (SWGHttpRequestWorker * worker); void instanceDeleteCallback (SWGHttpRequestWorker * worker); void instanceDeviceSetsGetCallback (SWGHttpRequestWorker * worker); @@ -129,6 +131,7 @@ signals: void instanceAudioOutputPatchSignal(SWGAudioOutputDevice* summary); void instanceChannelsSignal(SWGInstanceChannelsResponse* summary); void instanceConfigGetSignal(SWGInstanceConfigResponse* summary); + void instanceConfigPatchSignal(SWGSuccessResponse* summary); void instanceConfigPutSignal(SWGSuccessResponse* summary); void instanceDeleteSignal(SWGInstanceSummaryResponse* summary); void instanceDeviceSetsGetSignal(SWGDeviceSetList* summary); @@ -160,6 +163,7 @@ signals: void instanceAudioOutputPatchSignalE(SWGAudioOutputDevice* summary, QNetworkReply::NetworkError error_type, QString& error_str); void instanceChannelsSignalE(SWGInstanceChannelsResponse* summary, QNetworkReply::NetworkError error_type, QString& error_str); void instanceConfigGetSignalE(SWGInstanceConfigResponse* summary, QNetworkReply::NetworkError error_type, QString& error_str); + void instanceConfigPatchSignalE(SWGSuccessResponse* summary, QNetworkReply::NetworkError error_type, QString& error_str); void instanceConfigPutSignalE(SWGSuccessResponse* summary, QNetworkReply::NetworkError error_type, QString& error_str); void instanceDeleteSignalE(SWGInstanceSummaryResponse* summary, QNetworkReply::NetworkError error_type, QString& error_str); void instanceDeviceSetsGetSignalE(SWGDeviceSetList* summary, QNetworkReply::NetworkError error_type, QString& error_str); @@ -191,6 +195,7 @@ signals: void instanceAudioOutputPatchSignalEFull(SWGHttpRequestWorker* worker, QNetworkReply::NetworkError error_type, QString& error_str); void instanceChannelsSignalEFull(SWGHttpRequestWorker* worker, QNetworkReply::NetworkError error_type, QString& error_str); void instanceConfigGetSignalEFull(SWGHttpRequestWorker* worker, QNetworkReply::NetworkError error_type, QString& error_str); + void instanceConfigPatchSignalEFull(SWGHttpRequestWorker* worker, QNetworkReply::NetworkError error_type, QString& error_str); void instanceConfigPutSignalEFull(SWGHttpRequestWorker* worker, QNetworkReply::NetworkError error_type, QString& error_str); void instanceDeleteSignalEFull(SWGHttpRequestWorker* worker, QNetworkReply::NetworkError error_type, QString& error_str); void instanceDeviceSetsGetSignalEFull(SWGHttpRequestWorker* worker, QNetworkReply::NetworkError error_type, QString& error_str);