diff --git a/sdrbase/settings/preferences.h b/sdrbase/settings/preferences.h index 31a04b2e0..cf8d72b96 100644 --- a/sdrbase/settings/preferences.h +++ b/sdrbase/settings/preferences.h @@ -37,8 +37,6 @@ public: bool getUseLogFile() const { return m_useLogFile; } const QString& getLogFileName() const { return m_logFileName; } - friend class WebAPIAdapterBase; - protected: QString m_sourceDevice; //!< Identification of the source used in R0 tab (GUI flavor) at startup int m_sourceIndex; //!< Index of the source used in R0 tab (GUI flavor) at startup diff --git a/sdrbase/settings/preset.h b/sdrbase/settings/preset.h index c2e3e8658..62a8b87df 100644 --- a/sdrbase/settings/preset.h +++ b/sdrbase/settings/preset.h @@ -77,6 +77,9 @@ public: void setSpectrumConfig(const QByteArray& data) { m_spectrumConfig = data; } const QByteArray& getSpectrumConfig() const { return m_spectrumConfig; } + bool hasDCOffsetCorrection() const { return m_dcOffsetCorrection; } + bool hasIQImbalanceCorrection() const { return m_iqImbalanceCorrection; } + void setLayout(const QByteArray& data) { m_layout = data; } const QByteArray& getLayout() const { return m_layout; } @@ -117,8 +120,6 @@ public: } } - friend class WebAPIAdapterBase; - protected: bool m_sourcePreset; diff --git a/sdrbase/webapi/webapiadapterbase.cpp b/sdrbase/webapi/webapiadapterbase.cpp index ed8019f86..725fb9e1c 100644 --- a/sdrbase/webapi/webapiadapterbase.cpp +++ b/sdrbase/webapi/webapiadapterbase.cpp @@ -24,16 +24,16 @@ void WebAPIAdapterBase::webapiFormatPreferences( ) { apiPreferences->init(); - apiPreferences->setSourceDevice(new QString(preferences.m_sourceDevice)); - apiPreferences->setSourceIndex(preferences.m_sourceIndex); - apiPreferences->setAudioType(new QString(preferences.m_audioType)); - apiPreferences->setAudioDevice(new QString(preferences.m_audioDevice)); - apiPreferences->setLatitude(preferences.m_latitude); - apiPreferences->setLongitude(preferences.m_longitude); - apiPreferences->setConsoleMinLogLevel((int) preferences.m_consoleMinLogLevel); - apiPreferences->setUseLogFile(preferences.m_useLogFile ? 1 : 0); - apiPreferences->setLogFileName(new QString(preferences.m_logFileName)); - apiPreferences->setFileMinLogLevel((int) preferences.m_fileMinLogLevel); + apiPreferences->setSourceDevice(new QString(preferences.getSourceDevice())); + apiPreferences->setSourceIndex(preferences.getSourceIndex()); + apiPreferences->setAudioType(new QString(preferences.getAudioType())); + apiPreferences->setAudioDevice(new QString(preferences.getAudioDevice())); + apiPreferences->setLatitude(preferences.getLatitude()); + apiPreferences->setLongitude(preferences.getLongitude()); + apiPreferences->setConsoleMinLogLevel((int) preferences.getConsoleMinLogLevel()); + apiPreferences->setUseLogFile(preferences.getUseLogFile() ? 1 : 0); + apiPreferences->setLogFileName(new QString(preferences.getLogFileName())); + apiPreferences->setFileMinLogLevel((int) preferences.getFileMinLogLevel()); } void WebAPIAdapterBase::webapiFormatPreset( @@ -42,13 +42,13 @@ void WebAPIAdapterBase::webapiFormatPreset( ) { apiPreset->init(); - apiPreset->setSourcePreset(preset.m_sourcePreset ? 1 : 0); - apiPreset->setGroup(new QString(preset.m_group)); - apiPreset->setDescription(new QString(preset.m_description)); - apiPreset->setCenterFrequency(preset.m_centerFrequency); + apiPreset->setSourcePreset(preset.isSourcePreset() ? 1 : 0); + apiPreset->setGroup(new QString(preset.getGroup())); + apiPreset->setDescription(new QString(preset.getDescription())); + apiPreset->setCenterFrequency(preset.getCenterFrequency()); apiPreset->getSpectrumConfig()->init(); // TODO when spectrum config is extracted to sdrbase - apiPreset->setDcOffsetCorrection(preset.m_dcOffsetCorrection ? 1 : 0); - apiPreset->setIqImbalanceCorrection(preset.m_iqImbalanceCorrection ? 1 : 0); + apiPreset->setDcOffsetCorrection(preset.hasDCOffsetCorrection() ? 1 : 0); + apiPreset->setIqImbalanceCorrection(preset.hasIQImbalanceCorrection() ? 1 : 0); int nbChannels = preset.getChannelCount(); for (int i = 0; i < nbChannels; i++) @@ -70,3 +70,19 @@ void WebAPIAdapterBase::webapiFormatPreset( swgdeviceConfigs->back()->setDeviceSequence(deviceConfig.m_deviceSequence); } } + +void WebAPIAdapterBase::webapiFormatCommand( + SWGSDRangel::SWGCommand *apiCommand, + const Command& command +) +{ + apiCommand->init(); + apiCommand->setGroup(new QString(command.getGroup())); + apiCommand->setDescription(new QString(command.getDescription())); + apiCommand->setCommand(new QString(command.getCommand())); + apiCommand->setArgString(new QString(command.getArgString())); + apiCommand->setKey((int) command.getKey()); + apiCommand->setKeyModifiers((int) command.getKeyModifiers()); + apiCommand->setAssociateKey(command.getAssociateKey() ? 1 : 0); + apiCommand->setRelease(command.getRelease() ? 1 : 0); +} \ No newline at end of file diff --git a/sdrbase/webapi/webapiadapterbase.h b/sdrbase/webapi/webapiadapterbase.h index 778246e3b..12f1c9546 100644 --- a/sdrbase/webapi/webapiadapterbase.h +++ b/sdrbase/webapi/webapiadapterbase.h @@ -22,8 +22,10 @@ #include "export.h" #include "SWGPreferences.h" #include "SWGPreset.h" +#include "SWGCommand.h" #include "settings/preferences.h" #include "settings/preset.h" +#include "commands/command.h" /** * Adapter between API and objects in sdrbase library @@ -39,6 +41,10 @@ public: SWGSDRangel::SWGPreset *apiPreset, const Preset& preset ); + static void webapiFormatCommand( + SWGSDRangel::SWGCommand *apiCommand, + const Command& command + ); }; #endif // SDRBASE_WEBAPI_WEBAPIADAPTERBASE_H_ \ No newline at end of file diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index 9a09cde4c..5d37e3474 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -136,6 +136,16 @@ int WebAPIAdapterGUI::instanceConfigGet( WebAPIAdapterBase::webapiFormatPreset(swgPresets->back(), *preset); } + int nbCommands = m_mainWindow.m_settings.getCommandCount(); + QList *swgCommands = response.getCommands(); + + for (int i = 0; i < nbCommands; i++) + { + const Command *command = m_mainWindow.m_settings.getCommand(i); + swgCommands->append(new SWGSDRangel::SWGCommand); + WebAPIAdapterBase::webapiFormatCommand(swgCommands->back(), *command); + } + return 200; } diff --git a/sdrsrv/webapi/webapiadaptersrv.cpp b/sdrsrv/webapi/webapiadaptersrv.cpp index 8e63bee04..18f834e26 100644 --- a/sdrsrv/webapi/webapiadaptersrv.cpp +++ b/sdrsrv/webapi/webapiadaptersrv.cpp @@ -135,6 +135,16 @@ int WebAPIAdapterSrv::instanceConfigGet( WebAPIAdapterBase::webapiFormatPreset(swgPresets->back(), *preset); } + int nbCommands = m_mainCore.m_settings.getCommandCount(); + QList *swgCommands = response.getCommands(); + + for (int i = 0; i < nbCommands; i++) + { + const Command *command = m_mainCore.m_settings.getCommand(i); + swgCommands->append(new SWGSDRangel::SWGCommand); + WebAPIAdapterBase::webapiFormatCommand(swgCommands->back(), *command); + } + return 200; }