Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync frequency from rigctl_client #1216

Open
svenschnelle opened this issue Oct 26, 2023 · 0 comments
Open

Sync frequency from rigctl_client #1216

svenschnelle opened this issue Oct 26, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@svenschnelle
Copy link

svenschnelle commented Oct 26, 2023

Hi,

i just stumbled across sdr++, and think it's a great program. However, one thing i'm missing is the sync of the VFO frequency from the radio (via rigctl_client) to sdr++. I'm using it as a Panadapter in combination with a Transceiver for Ham radio. Normally i'm tunig with the big dial on the Transceiver, and a sync back to sdrpp would greatly enhance usability.

I made a quick hack to implement that, but it's wrong because of missing locking and a crude way to ignore the tune event sent, and likely other issues :-)

commit 778f6a2dc429ca9a28b9388cb389f16e053e44fc (HEAD -> master)
Author: Sven Schnelle <svens@stackframe.org>
Date:   Thu Oct 26 18:51:50 2023 +0200

    vfo sync hack
    
    Signed-off-by: Sven Schnelle <svens@stackframe.org>

diff --git a/misc_modules/rigctl_client/src/main.cpp b/misc_modules/rigctl_client/src/main.cpp
index 3df6c07..d81d4f0 100644
--- a/misc_modules/rigctl_client/src/main.cpp
+++ b/misc_modules/rigctl_client/src/main.cpp
@@ -47,6 +47,9 @@ public:
 
         _retuneHandler.ctx = this;
         _retuneHandler.handler = retuneHandler;
+        radiofreq = -1;
+        event_count = 0;
+        workerThread = std::thread(&RigctlClientModule::worker, this);
 
         gui::menu.registerEntry(name, menuHandler, this, NULL);
     }
@@ -54,6 +57,7 @@ public:
     ~RigctlClientModule() {
         stop();
         gui::menu.removeEntry(name);
+       if (workerThread.joinable()) { workerThread.join(); }
     }
 
     void postInit() {
@@ -107,6 +111,21 @@ public:
         running = false;
     }
 
+    void worker() {
+           for(;;) {
+                   std::this_thread::sleep_for(std::chrono::milliseconds(250));
+                   std::lock_guard<std::recursive_mutex> lck(mtx);
+                   if (!running)
+                           continue;
+                   double freq = client->getFreq();
+                   if (radiofreq != freq) {
+                           event_count++;
+                           tuner::tune(tuner::TUNER_MODE_CENTER, gui::waterfall.selectedVFO, freq);
+                           radiofreq = freq;
+                   }
+           }
+    }
+
 private:
     static void menuHandler(void* ctx) {
         RigctlClientModule* _this = (RigctlClientModule*)ctx;
@@ -162,6 +181,9 @@ private:
     static void retuneHandler(double freq, void* ctx) {
         RigctlClientModule* _this = (RigctlClientModule*)ctx;
         if (!_this->client || !_this->client->isOpen()) { return; }
+        std::lock_guard<std::recursive_mutex> lck(_this->mtx);
+        if (_this->event_count-- > 0)
+            return;
         if (_this->client->setFreq(freq)) {
             flog::error("Could not set frequency");
         }
@@ -177,8 +199,10 @@ private:
     std::shared_ptr<net::rigctl::Client> client;
 
     double ifFreq = 8830000.0;
-
+    double radiofreq;
     EventHandler<double> _retuneHandler;
+    std::thread workerThread;
+    int event_count;
 };
 
 MOD_EXPORT void _INIT_() {
@svenschnelle svenschnelle added the enhancement New feature or request label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant