Sync frequency from rigctl_client
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 <[email protected]>
Date: Thu Oct 26 18:51:50 2023 +0200
vfo sync hack
Signed-off-by: Sven Schnelle <[email protected]>
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_() {
It would be nice to see this implemented with an option to toggle sync to rigctl server freq from another fellow amateur operator. Something like the above might work, but ideally would like to see an option to let the rigctl server change the frequency in sdr++.
Going to try to hack @svenschnelle into the current rev for now.
This would be nice.