mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-27 04:47:51 +02:00
SDR++ server beta :)
This commit is contained in:
@ -10,6 +10,7 @@
|
||||
#include <options.h>
|
||||
#include <gui/widgets/stepped_slider.h>
|
||||
#include <utils/optionlist.h>
|
||||
#include <gui/smgui.h>
|
||||
|
||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||
|
||||
@ -23,9 +24,9 @@ SDRPP_MOD_INFO{
|
||||
|
||||
ConfigManager config;
|
||||
|
||||
class RFSpaceSource : public ModuleManager::Instance {
|
||||
class RFSpaceSourceModule : public ModuleManager::Instance {
|
||||
public:
|
||||
RFSpaceSource(std::string name) {
|
||||
RFSpaceSourceModule(std::string name) {
|
||||
this->name = name;
|
||||
|
||||
handler.ctx = this;
|
||||
@ -47,7 +48,7 @@ public:
|
||||
sigpath::sourceManager.registerSource("RFspace", &handler);
|
||||
}
|
||||
|
||||
~RFSpaceSource() {
|
||||
~RFSpaceSourceModule() {
|
||||
stop(this);
|
||||
sigpath::sourceManager.unregisterSource("RFspace");
|
||||
}
|
||||
@ -82,72 +83,73 @@ private:
|
||||
}
|
||||
|
||||
static void menuSelected(void* ctx) {
|
||||
RFSpaceSource* _this = (RFSpaceSource*)ctx;
|
||||
RFSpaceSourceModule* _this = (RFSpaceSourceModule*)ctx;
|
||||
core::setInputSampleRate(_this->sampleRate);
|
||||
gui::mainWindow.playButtonLocked = !(_this->client && _this->client->isOpen());
|
||||
spdlog::info("RFSpaceSource '{0}': Menu Select!", _this->name);
|
||||
spdlog::info("RFSpaceSourceModule '{0}': Menu Select!", _this->name);
|
||||
}
|
||||
|
||||
static void menuDeselected(void* ctx) {
|
||||
RFSpaceSource* _this = (RFSpaceSource*)ctx;
|
||||
RFSpaceSourceModule* _this = (RFSpaceSourceModule*)ctx;
|
||||
gui::mainWindow.playButtonLocked = false;
|
||||
spdlog::info("RFSpaceSource '{0}': Menu Deselect!", _this->name);
|
||||
spdlog::info("RFSpaceSourceModule '{0}': Menu Deselect!", _this->name);
|
||||
}
|
||||
|
||||
static void start(void* ctx) {
|
||||
RFSpaceSource* _this = (RFSpaceSource*)ctx;
|
||||
RFSpaceSourceModule* _this = (RFSpaceSourceModule*)ctx;
|
||||
if (_this->running) { return; }
|
||||
|
||||
// TODO: Set configuration here
|
||||
if (_this->client) { _this->client->start(rfspace::RFSPACE_SAMP_FORMAT_COMPLEX, rfspace::RFSPACE_SAMP_FORMAT_16BIT); }
|
||||
|
||||
_this->running = true;
|
||||
spdlog::info("RFSpaceSource '{0}': Start!", _this->name);
|
||||
spdlog::info("RFSpaceSourceModule '{0}': Start!", _this->name);
|
||||
}
|
||||
|
||||
static void stop(void* ctx) {
|
||||
RFSpaceSource* _this = (RFSpaceSource*)ctx;
|
||||
RFSpaceSourceModule* _this = (RFSpaceSourceModule*)ctx;
|
||||
if (!_this->running) { return; }
|
||||
|
||||
if (_this->client) { _this->client->stop(); }
|
||||
|
||||
_this->running = false;
|
||||
spdlog::info("RFSpaceSource '{0}': Stop!", _this->name);
|
||||
spdlog::info("RFSpaceSourceModule '{0}': Stop!", _this->name);
|
||||
}
|
||||
|
||||
static void tune(double freq, void* ctx) {
|
||||
RFSpaceSource* _this = (RFSpaceSource*)ctx;
|
||||
RFSpaceSourceModule* _this = (RFSpaceSourceModule*)ctx;
|
||||
if (_this->running && _this->client) {
|
||||
_this->client->setFrequency(freq);
|
||||
}
|
||||
_this->freq = freq;
|
||||
spdlog::info("RFSpaceSource '{0}': Tune: {1}!", _this->name, freq);
|
||||
spdlog::info("RFSpaceSourceModule '{0}': Tune: {1}!", _this->name, freq);
|
||||
}
|
||||
|
||||
static void menuHandler(void* ctx) {
|
||||
RFSpaceSource* _this = (RFSpaceSource*)ctx;
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
RFSpaceSourceModule* _this = (RFSpaceSourceModule*)ctx;
|
||||
|
||||
bool connected = (_this->client && _this->client->isOpen());
|
||||
gui::mainWindow.playButtonLocked = !connected;
|
||||
|
||||
if (connected) { style::beginDisabled(); }
|
||||
if (ImGui::InputText(CONCAT("##_rfspace_srv_host_", _this->name), _this->hostname, 1023)) {
|
||||
if (connected) { SmGui::BeginDisabled(); }
|
||||
if (SmGui::InputText(CONCAT("##_rfspace_srv_host_", _this->name), _this->hostname, 1023)) {
|
||||
config.acquire();
|
||||
config.conf["hostname"] = _this->hostname;
|
||||
config.release(true);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputInt(CONCAT("##_rfspace_srv_port_", _this->name), &_this->port, 0, 0)) {
|
||||
SmGui::SameLine();
|
||||
SmGui::FillWidth();
|
||||
if (SmGui::InputInt(CONCAT("##_rfspace_srv_port_", _this->name), &_this->port, 0, 0)) {
|
||||
config.acquire();
|
||||
config.conf["port"] = _this->port;
|
||||
config.release(true);
|
||||
}
|
||||
if (connected) { style::endDisabled(); }
|
||||
if (connected) { SmGui::EndDisabled(); }
|
||||
|
||||
if (_this->running) { style::beginDisabled(); }
|
||||
if (!connected && ImGui::Button("Connect##rfspace_source", ImVec2(menuWidth, 0))) {
|
||||
if (_this->running) { SmGui::BeginDisabled(); }
|
||||
SmGui::FillWidth();
|
||||
SmGui::ForceSync();
|
||||
if (!connected && SmGui::Button("Connect##rfspace_source")) {
|
||||
try {
|
||||
if (_this->client) { _this->client.reset(); }
|
||||
_this->client = rfspace::connect(_this->hostname, _this->port, &_this->stream);
|
||||
@ -157,18 +159,18 @@ private:
|
||||
spdlog::error("Could not connect to SDR: {0}", e.what());
|
||||
}
|
||||
}
|
||||
else if (connected && ImGui::Button("Disconnect##rfspace_source", ImVec2(menuWidth, 0))) {
|
||||
else if (connected && SmGui::Button("Disconnect##rfspace_source")) {
|
||||
_this->client->close();
|
||||
}
|
||||
if (_this->running) { style::endDisabled(); }
|
||||
if (_this->running) { SmGui::EndDisabled(); }
|
||||
|
||||
|
||||
if (connected) {
|
||||
if (_this->running) { style::beginDisabled(); }
|
||||
if (_this->running) { SmGui::BeginDisabled(); }
|
||||
|
||||
ImGui::LeftLabel("Samplerate");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::Combo("##rfspace_source_samp_rate", &_this->srId, _this->sampleRates.txt)) {
|
||||
SmGui::LeftLabel("Samplerate");
|
||||
SmGui::FillWidth();
|
||||
if (SmGui::Combo("##rfspace_source_samp_rate", &_this->srId, _this->sampleRates.txt)) {
|
||||
_this->sampleRate = _this->sampleRates[_this->srId];
|
||||
_this->client->setSampleRate(_this->sampleRate);
|
||||
core::setInputSampleRate(_this->sampleRate);
|
||||
@ -178,12 +180,12 @@ private:
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
if (_this->running) { style::endDisabled(); }
|
||||
if (_this->running) { SmGui::EndDisabled(); }
|
||||
|
||||
if (_this->client->deviceId == rfspace::RFSPACE_DEV_ID_CLOUD_IQ) {
|
||||
ImGui::LeftLabel("Antenna Port");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::Combo("##rfspace_source_rf_port", &_this->rfPortId, _this->rfPorts.txt)) {
|
||||
SmGui::LeftLabel("Antenna Port");
|
||||
SmGui::FillWidth();
|
||||
if (SmGui::Combo("##rfspace_source_rf_port", &_this->rfPortId, _this->rfPorts.txt)) {
|
||||
_this->client->setPort(_this->rfPorts[_this->rfPortId]);
|
||||
|
||||
config.acquire();
|
||||
@ -192,9 +194,9 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Gain");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloatWithSteps("##rfspace_source_gain", &_this->gain, -30, 0, 10, "%.0f dB")) {
|
||||
SmGui::LeftLabel("Gain");
|
||||
SmGui::FillWidth();
|
||||
if (SmGui::SliderFloatWithSteps("##rfspace_source_gain", &_this->gain, -30, 0, 10, SmGui::FMT_STR_FLOAT_DB_NO_DECIMAL)) {
|
||||
_this->client->setGain(_this->gain);
|
||||
|
||||
config.acquire();
|
||||
@ -202,14 +204,14 @@ private:
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
ImGui::Text("Status:");
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(ImVec4(0.0f, 1.0f, 0.0f, 1.0f), "Connected (%s)", _this->deviceName.c_str());
|
||||
SmGui::Text("Status:");
|
||||
SmGui::SameLine();
|
||||
SmGui::TextColored(ImVec4(0.0f, 1.0f, 0.0f, 1.0f), _this->connectedStr.c_str());
|
||||
}
|
||||
else {
|
||||
ImGui::Text("Status:");
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("Not connected");
|
||||
SmGui::Text("Status:");
|
||||
SmGui::SameLine();
|
||||
SmGui::Text("Not connected");
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,6 +220,8 @@ private:
|
||||
char buf[4096];
|
||||
sprintf(buf, "%s:%05d", hostname, port);
|
||||
devConfName = buf;
|
||||
sprintf(buf, "Connected (%s:%05d)", hostname, port);
|
||||
connectedStr = buf;
|
||||
|
||||
// Get device name
|
||||
if (deviceNames.find(client->deviceId) != deviceNames.end()) {
|
||||
@ -301,6 +305,7 @@ private:
|
||||
char hostname[1024];
|
||||
int port = 50000;
|
||||
std::string devConfName = "";
|
||||
std::string connectedStr = "";
|
||||
|
||||
std::string deviceName = "Unknown";
|
||||
std::map<rfspace::DeviceID, std::string> deviceNames = {
|
||||
@ -321,7 +326,7 @@ MOD_EXPORT void _INIT_() {
|
||||
def["hostname"] = "192.168.0.111";
|
||||
def["port"] = 50000;
|
||||
def["devices"] = json::object();
|
||||
config.setPath(options::opts.root + "/rfspace_config.json");
|
||||
config.setPath(options::opts.root + "/rfspace_source_config.json");
|
||||
config.load(def);
|
||||
config.enableAutoSave();
|
||||
|
||||
@ -336,11 +341,11 @@ MOD_EXPORT void _INIT_() {
|
||||
}
|
||||
|
||||
MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) {
|
||||
return new RFSpaceSource(name);
|
||||
return new RFSpaceSourceModule(name);
|
||||
}
|
||||
|
||||
MOD_EXPORT void _DELETE_INSTANCE_(ModuleManager::Instance* instance) {
|
||||
delete (RFSpaceSource*)instance;
|
||||
delete (RFSpaceSourceModule*)instance;
|
||||
}
|
||||
|
||||
MOD_EXPORT void _END_() {
|
||||
|
Reference in New Issue
Block a user