From 8dd65e70f2aee62c2d4e5ba4a451dcfe0da85da3 Mon Sep 17 00:00:00 2001
From: f4exb <f4exb06@gmail.com>
Date: Thu, 2 Aug 2018 23:27:22 +0200
Subject: [PATCH] Web API: AM demod: added pll and syncAMOperation settings
 processing

---
 debian/changelog                              |  1 +
 plugins/channelrx/demodam/amdemod.cpp         | 14 +++++++
 sdrbase/resources/webapi/doc/html2/index.html | 10 ++++-
 .../webapi/doc/swagger/include/AMDemod.yaml   |  6 +++
 .../sdrangel/api/swagger/include/AMDemod.yaml |  6 +++
 swagger/sdrangel/code/html2/index.html        | 10 ++++-
 .../code/qt5/client/SWGAMDemodSettings.cpp    | 42 +++++++++++++++++++
 .../code/qt5/client/SWGAMDemodSettings.h      | 12 ++++++
 8 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 2f224939d..b947fcf68 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,7 @@
 sdrangel (4.0.6-1) unstable; urgency=medium
 
   * Web API: RTL-SDR: fixed RF bandwidth setting
+  * Web API: enhnaced DV serial and AM demod interfaces
 
  -- Edouard Griffiths, F4EXB <f4exb06@gmail.com>  Sun, 05 Aug 2018 09:14:18 +0200
   
diff --git a/plugins/channelrx/demodam/amdemod.cpp b/plugins/channelrx/demodam/amdemod.cpp
index 0232d6927..50c1caa88 100644
--- a/plugins/channelrx/demodam/amdemod.cpp
+++ b/plugins/channelrx/demodam/amdemod.cpp
@@ -549,6 +549,17 @@ int AMDemod::webapiSettingsPutPatch(
         settings.m_audioDeviceName = *response.getAmDemodSettings()->getAudioDeviceName();
     }
 
+    if (channelSettingsKeys.contains("pll")) {
+        settings.m_pll = response.getAmDemodSettings()->getPll();
+    }
+
+    if (channelSettingsKeys.contains("syncAMOperation")) {
+        qint32 syncAMOperationCode = response.getAmDemodSettings()->getSyncAmOperation();
+        settings.m_syncAMOperation = syncAMOperationCode < 0 ?
+                AMDemodSettings::SyncAMDSB : syncAMOperationCode > 2 ?
+                        AMDemodSettings::SyncAMDSB : (AMDemodSettings::SyncAMOperation) syncAMOperationCode;
+    }
+
     if (frequencyOffsetChanged)
     {
         MsgConfigureChannelizer* channelConfigMsg = MsgConfigureChannelizer::create(
@@ -602,6 +613,9 @@ void AMDemod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respo
     } else {
         response.getAmDemodSettings()->setAudioDeviceName(new QString(settings.m_audioDeviceName));
     }
+
+    response.getAmDemodSettings()->setPll(settings.m_pll ? 1 : 0);
+    response.getAmDemodSettings()->setSyncAmOperation((int) m_settings.m_syncAMOperation);
 }
 
 void AMDemod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response)
diff --git a/sdrbase/resources/webapi/doc/html2/index.html b/sdrbase/resources/webapi/doc/html2/index.html
index edaf05042..5ba6c571f 100644
--- a/sdrbase/resources/webapi/doc/html2/index.html
+++ b/sdrbase/resources/webapi/doc/html2/index.html
@@ -752,6 +752,14 @@ margin-bottom: 20px;
     },
     "audioDeviceName" : {
       "type" : "string"
+    },
+    "pll" : {
+      "type" : "integer",
+      "description" : "PLL active (for synchronous AM)"
+    },
+    "syncAMOperation" : {
+      "type" : "integer",
+      "description" : "Synchronous AM sidebands mode (DSB, USB, LSB)"
     }
   },
   "description" : "AMDemod"
@@ -22947,7 +22955,7 @@ except ApiException as e:
           </div>
           <div id="generator">
             <div class="content">
-              Generated 2018-08-02T21:39:46.879+02:00
+              Generated 2018-08-02T23:13:51.054+02:00
             </div>
           </div>
       </div>
diff --git a/sdrbase/resources/webapi/doc/swagger/include/AMDemod.yaml b/sdrbase/resources/webapi/doc/swagger/include/AMDemod.yaml
index 9505df9c5..08c6f601d 100644
--- a/sdrbase/resources/webapi/doc/swagger/include/AMDemod.yaml
+++ b/sdrbase/resources/webapi/doc/swagger/include/AMDemod.yaml
@@ -27,6 +27,12 @@ AMDemodSettings:
       type: string
     audioDeviceName:
       type: string
+    pll:
+      description: PLL active (for synchronous AM)
+      type: integer
+    syncAMOperation:
+      description: Synchronous AM sidebands mode (DSB, USB, LSB)
+      type: integer
 
 AMDemodReport:
   description: AMDemod
diff --git a/swagger/sdrangel/api/swagger/include/AMDemod.yaml b/swagger/sdrangel/api/swagger/include/AMDemod.yaml
index 9505df9c5..08c6f601d 100644
--- a/swagger/sdrangel/api/swagger/include/AMDemod.yaml
+++ b/swagger/sdrangel/api/swagger/include/AMDemod.yaml
@@ -27,6 +27,12 @@ AMDemodSettings:
       type: string
     audioDeviceName:
       type: string
+    pll:
+      description: PLL active (for synchronous AM)
+      type: integer
+    syncAMOperation:
+      description: Synchronous AM sidebands mode (DSB, USB, LSB)
+      type: integer
 
 AMDemodReport:
   description: AMDemod
diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html
index edaf05042..5ba6c571f 100644
--- a/swagger/sdrangel/code/html2/index.html
+++ b/swagger/sdrangel/code/html2/index.html
@@ -752,6 +752,14 @@ margin-bottom: 20px;
     },
     "audioDeviceName" : {
       "type" : "string"
+    },
+    "pll" : {
+      "type" : "integer",
+      "description" : "PLL active (for synchronous AM)"
+    },
+    "syncAMOperation" : {
+      "type" : "integer",
+      "description" : "Synchronous AM sidebands mode (DSB, USB, LSB)"
     }
   },
   "description" : "AMDemod"
@@ -22947,7 +22955,7 @@ except ApiException as e:
           </div>
           <div id="generator">
             <div class="content">
-              Generated 2018-08-02T21:39:46.879+02:00
+              Generated 2018-08-02T23:13:51.054+02:00
             </div>
           </div>
       </div>
diff --git a/swagger/sdrangel/code/qt5/client/SWGAMDemodSettings.cpp b/swagger/sdrangel/code/qt5/client/SWGAMDemodSettings.cpp
index 51b88b5eb..5f81d57a6 100644
--- a/swagger/sdrangel/code/qt5/client/SWGAMDemodSettings.cpp
+++ b/swagger/sdrangel/code/qt5/client/SWGAMDemodSettings.cpp
@@ -46,6 +46,10 @@ SWGAMDemodSettings::SWGAMDemodSettings() {
     m_title_isSet = false;
     audio_device_name = nullptr;
     m_audio_device_name_isSet = false;
+    pll = 0;
+    m_pll_isSet = false;
+    sync_am_operation = 0;
+    m_sync_am_operation_isSet = false;
 }
 
 SWGAMDemodSettings::~SWGAMDemodSettings() {
@@ -72,6 +76,10 @@ SWGAMDemodSettings::init() {
     m_title_isSet = false;
     audio_device_name = new QString("");
     m_audio_device_name_isSet = false;
+    pll = 0;
+    m_pll_isSet = false;
+    sync_am_operation = 0;
+    m_sync_am_operation_isSet = false;
 }
 
 void
@@ -89,6 +97,8 @@ SWGAMDemodSettings::cleanup() {
     if(audio_device_name != nullptr) { 
         delete audio_device_name;
     }
+
+
 }
 
 SWGAMDemodSettings*
@@ -120,6 +130,10 @@ SWGAMDemodSettings::fromJsonObject(QJsonObject &pJson) {
     
     ::SWGSDRangel::setValue(&audio_device_name, pJson["audioDeviceName"], "QString", "QString");
     
+    ::SWGSDRangel::setValue(&pll, pJson["pll"], "qint32", "");
+    
+    ::SWGSDRangel::setValue(&sync_am_operation, pJson["syncAMOperation"], "qint32", "");
+    
 }
 
 QString
@@ -163,6 +177,12 @@ SWGAMDemodSettings::asJsonObject() {
     if(audio_device_name != nullptr && *audio_device_name != QString("")){
         toJsonValue(QString("audioDeviceName"), audio_device_name, obj, QString("QString"));
     }
+    if(m_pll_isSet){
+        obj->insert("pll", QJsonValue(pll));
+    }
+    if(m_sync_am_operation_isSet){
+        obj->insert("syncAMOperation", QJsonValue(sync_am_operation));
+    }
 
     return obj;
 }
@@ -257,6 +277,26 @@ SWGAMDemodSettings::setAudioDeviceName(QString* audio_device_name) {
     this->m_audio_device_name_isSet = true;
 }
 
+qint32
+SWGAMDemodSettings::getPll() {
+    return pll;
+}
+void
+SWGAMDemodSettings::setPll(qint32 pll) {
+    this->pll = pll;
+    this->m_pll_isSet = true;
+}
+
+qint32
+SWGAMDemodSettings::getSyncAmOperation() {
+    return sync_am_operation;
+}
+void
+SWGAMDemodSettings::setSyncAmOperation(qint32 sync_am_operation) {
+    this->sync_am_operation = sync_am_operation;
+    this->m_sync_am_operation_isSet = true;
+}
+
 
 bool
 SWGAMDemodSettings::isSet(){
@@ -271,6 +311,8 @@ SWGAMDemodSettings::isSet(){
         if(m_rgb_color_isSet){ isObjectUpdated = true; break;}
         if(title != nullptr && *title != QString("")){ isObjectUpdated = true; break;}
         if(audio_device_name != nullptr && *audio_device_name != QString("")){ isObjectUpdated = true; break;}
+        if(m_pll_isSet){ isObjectUpdated = true; break;}
+        if(m_sync_am_operation_isSet){ isObjectUpdated = true; break;}
     }while(false);
     return isObjectUpdated;
 }
diff --git a/swagger/sdrangel/code/qt5/client/SWGAMDemodSettings.h b/swagger/sdrangel/code/qt5/client/SWGAMDemodSettings.h
index 93b5f77ea..401be5ee9 100644
--- a/swagger/sdrangel/code/qt5/client/SWGAMDemodSettings.h
+++ b/swagger/sdrangel/code/qt5/client/SWGAMDemodSettings.h
@@ -69,6 +69,12 @@ public:
     QString* getAudioDeviceName();
     void setAudioDeviceName(QString* audio_device_name);
 
+    qint32 getPll();
+    void setPll(qint32 pll);
+
+    qint32 getSyncAmOperation();
+    void setSyncAmOperation(qint32 sync_am_operation);
+
 
     virtual bool isSet() override;
 
@@ -100,6 +106,12 @@ private:
     QString* audio_device_name;
     bool m_audio_device_name_isSet;
 
+    qint32 pll;
+    bool m_pll_isSet;
+
+    qint32 sync_am_operation;
+    bool m_sync_am_operation_isSet;
+
 };
 
 }