more work on the rigctl module but removed tracking for now

This commit is contained in:
AlexandreRouma 2023-02-22 20:55:23 +01:00
parent 63416fe93a
commit edb4ac45b2

View File

@ -12,11 +12,9 @@
#include <radio_interface.h> #include <radio_interface.h>
#define CONCAT(a, b) ((std::string(a) + b).c_str()) #define CONCAT(a, b) ((std::string(a) + b).c_str())
#define MAX_COMMAND_LENGTH 8192
SDRPP_MOD_INFO{ SDRPP_MOD_INFO{
/* Name: */ "rigctl_client", /* Name: */ "rigctl_client",
/* Description: */ "My fancy new module", /* Description: */ "Client for the RigCTL protocol",
/* Author: */ "Ryzerth", /* Author: */ "Ryzerth",
/* Version: */ 0, 1, 0, /* Version: */ 0, 1, 0,
/* Max instances */ 1 /* Max instances */ 1
@ -29,8 +27,24 @@ public:
RigctlClientModule(std::string name) { RigctlClientModule(std::string name) {
this->name = name; this->name = name;
// Load default
strcpy(host, "127.0.0.1"); strcpy(host, "127.0.0.1");
// Load config
config.acquire();
if (config.conf[name].contains("host")) {
std::string h = config.conf[name]["host"];
strcpy(host, h.c_str());
}
if (config.conf[name].contains("port")) {
port = config.conf[name]["port"];
port = std::clamp<int>(port, 1, 65535);
}
if (config.conf[name].contains("ifFreq")) {
ifFreq = config.conf[name]["ifFreq"];
}
config.release();
_retuneHandler.ctx = this; _retuneHandler.ctx = this;
_retuneHandler.handler = retuneHandler; _retuneHandler.handler = retuneHandler;
@ -62,9 +76,20 @@ public:
std::lock_guard<std::recursive_mutex> lck(mtx); std::lock_guard<std::recursive_mutex> lck(mtx);
if (running) { return; } if (running) { return; }
// Connect to rigctl server
try {
client = net::rigctl::connect(host, port);
}
catch (std::exception e) {
spdlog::error("Could not connect: {0}", e.what());
return;
}
// Switch source to panadapter mode
sigpath::sourceManager.setPanadpterIF(ifFreq); sigpath::sourceManager.setPanadpterIF(ifFreq);
sigpath::sourceManager.setTuningMode(SourceManager::TuningMode::PANADAPTER); sigpath::sourceManager.setTuningMode(SourceManager::TuningMode::PANADAPTER);
sigpath::sourceManager.onRetune.bindHandler(&_retuneHandler); sigpath::sourceManager.onRetune.bindHandler(&_retuneHandler);
running = true; running = true;
} }
@ -72,8 +97,13 @@ public:
std::lock_guard<std::recursive_mutex> lck(mtx); std::lock_guard<std::recursive_mutex> lck(mtx);
if (!running) { return; } if (!running) { return; }
// Switch source back to normal mode
sigpath::sourceManager.onRetune.unbindHandler(&_retuneHandler); sigpath::sourceManager.onRetune.unbindHandler(&_retuneHandler);
sigpath::sourceManager.setTuningMode(SourceManager::TuningMode::NORMAL); sigpath::sourceManager.setTuningMode(SourceManager::TuningMode::NORMAL);
// Disconnect from rigctl server
client->close();
running = false; running = false;
} }
@ -115,14 +145,26 @@ private:
else if (!_this->running && ImGui::Button(CONCAT("Start##_rigctl_cli_stop_", _this->name), ImVec2(menuWidth, 0))) { else if (!_this->running && ImGui::Button(CONCAT("Start##_rigctl_cli_stop_", _this->name), ImVec2(menuWidth, 0))) {
_this->start(); _this->start();
} }
ImGui::TextUnformatted("Status:");
ImGui::SameLine();
if (_this->client && _this->client->isOpen() && _this->running) {
ImGui::TextColored(ImVec4(0.0, 1.0, 0.0, 1.0), "Connected");
}
else if (_this->client && _this->running) {
ImGui::TextColored(ImVec4(1.0, 1.0, 0.0, 1.0), "Disconnected");
}
else {
ImGui::TextUnformatted("Idle");
}
} }
static void retuneHandler(double freq, void* ctx) { static void retuneHandler(double freq, void* ctx) {
RigctlClientModule* _this = (RigctlClientModule*)ctx; RigctlClientModule* _this = (RigctlClientModule*)ctx;
if (!_this->client || !_this->client->isOpen()) { return; } if (!_this->client || !_this->client->isOpen()) { return; }
//spdlog::warn("PAN RETUNE: {0}", freq); if (_this->client->setFreq(freq)) {
spdlog::error("Could not set frequency");
_this->client->setFreq(freq); }
} }
std::string name; std::string name;