From 7577e6f145dc7240bc16dc41dabc56489479d120 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 24 Dec 2017 04:19:44 +0100 Subject: [PATCH] Web API: NFM modulator settings parameters optional --- plugins/channeltx/modnfm/nfmmod.cpp | 117 ++++++++++++++++++------- sdrbase/webapi/webapirequestmapper.cpp | 21 +++++ sdrbase/webapi/webapirequestmapper.h | 6 ++ 3 files changed, 114 insertions(+), 30 deletions(-) diff --git a/plugins/channeltx/modnfm/nfmmod.cpp b/plugins/channeltx/modnfm/nfmmod.cpp index 9d24a501c..856fd31b2 100644 --- a/plugins/channeltx/modnfm/nfmmod.cpp +++ b/plugins/channeltx/modnfm/nfmmod.cpp @@ -537,42 +537,99 @@ int NFMMod::webapiSettingsPutPatch( QString& errorMessage __attribute__((unused))) { NFMModSettings settings; - settings.m_afBandwidth = response.getNfmModSettings()->getAfBandwidth(); - settings.m_audioSampleRate = response.getNfmModSettings()->getAudioSampleRate(); - settings.m_basebandSampleRate = response.getNfmModSettings()->getBasebandSampleRate(); - settings.m_channelMute = response.getNfmModSettings()->getChannelMute() != 0; - settings.m_ctcssIndex = response.getNfmModSettings()->getCtcssIndex(); - settings.m_ctcssOn = response.getNfmModSettings()->getCtcssOn() != 0; - settings.m_fmDeviation = response.getNfmModSettings()->getFmDeviation(); - settings.m_inputFrequencyOffset = response.getNfmModSettings()->getInputFrequencyOffset(); - settings.m_modAFInput = (NFMModSettings::NFMModInputAF) response.getNfmModSettings()->getModAfInput(); - settings.m_outputSampleRate = response.getNfmModSettings()->getOutputSampleRate(); - settings.m_playLoop = response.getNfmModSettings()->getPlayLoop() != 0; - settings.m_rfBandwidth = response.getNfmModSettings()->getRfBandwidth(); - settings.m_rgbColor = response.getNfmModSettings()->getRgbColor(); - settings.m_title = *response.getNfmModSettings()->getTitle(); - settings.m_toneFrequency = response.getNfmModSettings()->getToneFrequency(); - settings.m_volumeFactor = response.getNfmModSettings()->getVolumeFactor(); - SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getNfmModSettings()->getCwKeyer(); - CWKeyerSettings cwKeyerSettings; - cwKeyerSettings.m_loop = apiCwKeyerSettings->getLoop() != 0; - cwKeyerSettings.m_mode = (CWKeyerSettings::CWMode) apiCwKeyerSettings->getMode(); - cwKeyerSettings.m_sampleRate = apiCwKeyerSettings->getSampleRate(); - cwKeyerSettings.m_text = *apiCwKeyerSettings->getText(); - cwKeyerSettings.m_wpm = apiCwKeyerSettings->getWpm(); - m_cwKeyer.setLoop(cwKeyerSettings.m_loop); - m_cwKeyer.setMode(cwKeyerSettings.m_mode); - m_cwKeyer.setSampleRate(cwKeyerSettings.m_sampleRate); - m_cwKeyer.setText(cwKeyerSettings.m_text); - m_cwKeyer.setWPM(cwKeyerSettings.m_wpm); + +// for (int i = 0; i < channelSettingsKeys.size(); i++) { +// qDebug("NFMMod::webapiSettingsPutPatch: settingKey: %s", qPrintable(channelSettingsKeys.at(i))); +// } + + if (channelSettingsKeys.contains("afBandwidth")) { + settings.m_afBandwidth = response.getNfmModSettings()->getAfBandwidth(); + } + if (channelSettingsKeys.contains("audioSampleRate")) { + settings.m_audioSampleRate = response.getNfmModSettings()->getAudioSampleRate(); + } + if (channelSettingsKeys.contains("basebandSampleRate")) { + settings.m_basebandSampleRate = response.getNfmModSettings()->getBasebandSampleRate(); + } + if (channelSettingsKeys.contains("channelMute")) { + settings.m_channelMute = response.getNfmModSettings()->getChannelMute() != 0; + } + if (channelSettingsKeys.contains("ctcssIndex")) { + settings.m_ctcssIndex = response.getNfmModSettings()->getCtcssIndex(); + } + if (channelSettingsKeys.contains("ctcssOn")) { + settings.m_ctcssOn = response.getNfmModSettings()->getCtcssOn() != 0; + } + if (channelSettingsKeys.contains("fmDeviation")) { + settings.m_fmDeviation = response.getNfmModSettings()->getFmDeviation(); + } + if (channelSettingsKeys.contains("inputFrequencyOffset")) { + settings.m_inputFrequencyOffset = response.getNfmModSettings()->getInputFrequencyOffset(); + } + if (channelSettingsKeys.contains("modAFInput")) { + settings.m_modAFInput = (NFMModSettings::NFMModInputAF) response.getNfmModSettings()->getModAfInput(); + } + if (channelSettingsKeys.contains("outputSampleRate")) { + settings.m_outputSampleRate = response.getNfmModSettings()->getOutputSampleRate(); + } + if (channelSettingsKeys.contains("playLoop")) { + settings.m_playLoop = response.getNfmModSettings()->getPlayLoop() != 0; + } + if (channelSettingsKeys.contains("rfBandwidth")) { + settings.m_rfBandwidth = response.getNfmModSettings()->getRfBandwidth(); + } + if (channelSettingsKeys.contains("rgbColor")) { + settings.m_rgbColor = response.getNfmModSettings()->getRgbColor(); + } + if (channelSettingsKeys.contains("title")) { + settings.m_title = *response.getNfmModSettings()->getTitle(); + } + if (channelSettingsKeys.contains("toneFrequency")) { + settings.m_toneFrequency = response.getNfmModSettings()->getToneFrequency(); + } + if (channelSettingsKeys.contains("volumeFactor")) { + settings.m_volumeFactor = response.getNfmModSettings()->getVolumeFactor(); + } + + if (channelSettingsKeys.contains("cwKeyer")) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getNfmModSettings()->getCwKeyer(); + CWKeyerSettings cwKeyerSettings = m_cwKeyer.getSettings(); + + if (channelSettingsKeys.contains("cwKeyer.loop")) { + cwKeyerSettings.m_loop = apiCwKeyerSettings->getLoop() != 0; + } + if (channelSettingsKeys.contains("cwKeyer.mode")) { + cwKeyerSettings.m_mode = (CWKeyerSettings::CWMode) apiCwKeyerSettings->getMode(); + } + if (channelSettingsKeys.contains("cwKeyer.text")) { + cwKeyerSettings.m_text = *apiCwKeyerSettings->getText(); + } + if (channelSettingsKeys.contains("cwKeyer.sampleRate")) { + cwKeyerSettings.m_sampleRate = apiCwKeyerSettings->getSampleRate(); + } + if (channelSettingsKeys.contains("cwKeyer.wpm")) { + cwKeyerSettings.m_wpm = apiCwKeyerSettings->getWpm(); + } + + m_cwKeyer.setLoop(cwKeyerSettings.m_loop); + m_cwKeyer.setMode(cwKeyerSettings.m_mode); + m_cwKeyer.setSampleRate(cwKeyerSettings.m_sampleRate); + m_cwKeyer.setText(cwKeyerSettings.m_text); + m_cwKeyer.setWPM(cwKeyerSettings.m_wpm); + + if (m_guiMessageQueue) // forward to GUI if any + { + CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); + m_guiMessageQueue->push(msgCwKeyer); + } + } MsgConfigureNFMMod *msg = MsgConfigureNFMMod::create(settings, force); m_inputMessageQueue.push(msg); if (m_guiMessageQueue) // forward to GUI if any { - CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); - m_guiMessageQueue->push(msgCwKeyer); MsgConfigureNFMMod *msgToGUI = MsgConfigureNFMMod::create(settings, force); m_guiMessageQueue->push(msgToGUI); } diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index ad74ab74e..60bed0b36 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -1468,6 +1468,13 @@ bool WebAPIRequestMapper::validateChannelSettings( { QJsonObject nfmModSettingsJsonObject = jsonObject["NFMModSettings"].toObject(); channelSettingsKeys = nfmModSettingsJsonObject.keys(); + + if (channelSettingsKeys.contains("cwKeyer")) + { + QJsonObject cwKeyerSettingsJsonObject; + appendSettingsSubKeys(nfmModSettingsJsonObject, cwKeyerSettingsJsonObject, "cwKeyer", channelSettingsKeys); + } + channelSettings.setNfmModSettings(new SWGSDRangel::SWGNFMModSettings()); channelSettings.getNfmModSettings()->fromJsonObject(nfmModSettingsJsonObject); return true; @@ -1482,6 +1489,20 @@ bool WebAPIRequestMapper::validateChannelSettings( } } +void WebAPIRequestMapper::appendSettingsSubKeys( + const QJsonObject& parentSettingsJsonObject, + QJsonObject& childSettingsJsonObject, + const QString& parentKey, + QStringList& keyList) +{ + childSettingsJsonObject = parentSettingsJsonObject[parentKey].toObject(); + QStringList childSettingsKeys = childSettingsJsonObject.keys(); + + for (int i = 0; i < childSettingsKeys.size(); i++) { + keyList.append(parentKey + QString(".") + childSettingsKeys.at(i)); + } +} + void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings) { deviceSettings.cleanup(); diff --git a/sdrbase/webapi/webapirequestmapper.h b/sdrbase/webapi/webapirequestmapper.h index 39b24124e..cffb96b12 100644 --- a/sdrbase/webapi/webapirequestmapper.h +++ b/sdrbase/webapi/webapirequestmapper.h @@ -73,6 +73,12 @@ private: bool validateDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings, QJsonObject& jsonObject); bool validateChannelSettings(SWGSDRangel::SWGChannelSettings& deviceSettings, QJsonObject& jsonObject, QStringList& channelSettingsKeys); + void appendSettingsSubKeys( + const QJsonObject& parentSettingsJsonObject, + QJsonObject& childSettingsJsonObject, + const QString& parentKey, + QStringList& keyList); + bool parseJsonBody(QString& jsonStr, QJsonObject& jsonObject, qtwebapp::HttpResponse& response); void resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings);