mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-26 01:34:43 +01:00
Fixed autostart for networked sources
This commit is contained in:
parent
039ef5eae3
commit
e03e95cc54
@ -109,6 +109,12 @@ private:
|
|||||||
SDRPPServerSourceModule* _this = (SDRPPServerSourceModule*)ctx;
|
SDRPPServerSourceModule* _this = (SDRPPServerSourceModule*)ctx;
|
||||||
if (_this->running) { return; }
|
if (_this->running) { return; }
|
||||||
|
|
||||||
|
// Try to connect if not already connected
|
||||||
|
if (!_this->client) {
|
||||||
|
_this->tryConnect();
|
||||||
|
if (!_this->client) { return; }
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Set configuration here
|
// TODO: Set configuration here
|
||||||
if (_this->client) {
|
if (_this->client) {
|
||||||
_this->client->setFrequency(_this->freq);
|
_this->client->setFrequency(_this->freq);
|
||||||
@ -166,15 +172,7 @@ private:
|
|||||||
|
|
||||||
if (_this->running) { style::beginDisabled(); }
|
if (_this->running) { style::beginDisabled(); }
|
||||||
if (!connected && ImGui::Button("Connect##sdrpp_srv_source", ImVec2(menuWidth, 0))) {
|
if (!connected && ImGui::Button("Connect##sdrpp_srv_source", ImVec2(menuWidth, 0))) {
|
||||||
try {
|
_this->tryConnect();
|
||||||
if (_this->client) { _this->client.reset(); }
|
|
||||||
_this->client = server::connect(_this->hostname, _this->port, &_this->stream);
|
|
||||||
_this->deviceInit();
|
|
||||||
}
|
|
||||||
catch (std::exception e) {
|
|
||||||
spdlog::error("Could not connect to SDR: {0}", e.what());
|
|
||||||
if (!strcmp(e.what(), "Server busy")) { _this->serverBusy = true; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (connected && ImGui::Button("Disconnect##sdrpp_srv_source", ImVec2(menuWidth, 0))) {
|
else if (connected && ImGui::Button("Disconnect##sdrpp_srv_source", ImVec2(menuWidth, 0))) {
|
||||||
_this->client->close();
|
_this->client->close();
|
||||||
@ -231,6 +229,18 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tryConnect() {
|
||||||
|
try {
|
||||||
|
if (client) { client.reset(); }
|
||||||
|
client = server::connect(hostname, port, &stream);
|
||||||
|
deviceInit();
|
||||||
|
}
|
||||||
|
catch (std::exception e) {
|
||||||
|
spdlog::error("Could not connect to SDR: {0}", e.what());
|
||||||
|
if (!strcmp(e.what(), "Server busy")) { serverBusy = true; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void deviceInit() {
|
void deviceInit() {
|
||||||
// Generate the config name
|
// Generate the config name
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
@ -120,6 +120,12 @@ private:
|
|||||||
static void start(void* ctx) {
|
static void start(void* ctx) {
|
||||||
SpyServerSourceModule* _this = (SpyServerSourceModule*)ctx;
|
SpyServerSourceModule* _this = (SpyServerSourceModule*)ctx;
|
||||||
if (_this->running) { return; }
|
if (_this->running) { return; }
|
||||||
|
|
||||||
|
// Try to connect if not already connected
|
||||||
|
if (!_this->client) {
|
||||||
|
_this->tryConnect();
|
||||||
|
if (!_this->client) { return; }
|
||||||
|
}
|
||||||
|
|
||||||
int srvBits = streamFormatsBitCount[_this->iqType];
|
int srvBits = streamFormatsBitCount[_this->iqType];
|
||||||
_this->client->setSetting(SPYSERVER_SETTING_IQ_FORMAT, streamFormats[_this->iqType]);
|
_this->client->setSetting(SPYSERVER_SETTING_IQ_FORMAT, streamFormats[_this->iqType]);
|
||||||
@ -178,51 +184,7 @@ private:
|
|||||||
SmGui::FillWidth();
|
SmGui::FillWidth();
|
||||||
SmGui::ForceSync();
|
SmGui::ForceSync();
|
||||||
if (!connected && SmGui::Button("Connect##spyserver_source")) {
|
if (!connected && SmGui::Button("Connect##spyserver_source")) {
|
||||||
try {
|
_this->tryConnect();
|
||||||
if (_this->client) { _this->client.reset(); }
|
|
||||||
_this->client = spyserver::connect(_this->hostname, _this->port, &_this->stream);
|
|
||||||
|
|
||||||
if (!_this->client->waitForDevInfo(3000)) {
|
|
||||||
spdlog::error("SpyServer didn't respond with device information");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
char buf[1024];
|
|
||||||
sprintf(buf, "%s [%08X]", deviceTypesStr[_this->client->devInfo.DeviceType], _this->client->devInfo.DeviceSerial);
|
|
||||||
_this->devRef = std::string(buf);
|
|
||||||
|
|
||||||
config.acquire();
|
|
||||||
if (!config.conf["devices"].contains(_this->devRef)) {
|
|
||||||
config.conf["devices"][_this->devRef]["sampleRateId"] = 0;
|
|
||||||
config.conf["devices"][_this->devRef]["sampleBitDepthId"] = 1;
|
|
||||||
config.conf["devices"][_this->devRef]["gainId"] = 0;
|
|
||||||
}
|
|
||||||
_this->srId = config.conf["devices"][_this->devRef]["sampleRateId"];
|
|
||||||
_this->iqType = config.conf["devices"][_this->devRef]["sampleBitDepthId"];
|
|
||||||
_this->gain = config.conf["devices"][_this->devRef]["gainId"];
|
|
||||||
config.release(true);
|
|
||||||
|
|
||||||
_this->gain = std::clamp<int>(_this->gain, 0, _this->client->devInfo.MaximumGainIndex);
|
|
||||||
|
|
||||||
// Refresh sample rates
|
|
||||||
_this->sampleRates.clear();
|
|
||||||
_this->sampleRatesTxt.clear();
|
|
||||||
for (int i = _this->client->devInfo.MinimumIQDecimation; i <= _this->client->devInfo.DecimationStageCount; i++) {
|
|
||||||
double sr = (double)_this->client->devInfo.MaximumSampleRate / ((double)(1 << i));
|
|
||||||
_this->sampleRates.push_back(sr);
|
|
||||||
_this->sampleRatesTxt += _this->getBandwdithScaled(sr);
|
|
||||||
_this->sampleRatesTxt += '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
_this->srId = std::clamp<int>(_this->srId, 0, _this->sampleRates.size() - 1);
|
|
||||||
|
|
||||||
_this->sampleRate = _this->sampleRates[_this->srId];
|
|
||||||
core::setInputSampleRate(_this->sampleRate);
|
|
||||||
spdlog::info("Connected to server");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (std::exception e) {
|
|
||||||
spdlog::error("Could not connect to spyserver {0}", e.what());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (connected && SmGui::Button("Disconnect##spyserver_source")) {
|
else if (connected && SmGui::Button("Disconnect##spyserver_source")) {
|
||||||
_this->client->close();
|
_this->client->close();
|
||||||
@ -278,6 +240,54 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tryConnect() {
|
||||||
|
try {
|
||||||
|
if (client) { client.reset(); }
|
||||||
|
client = spyserver::connect(hostname, port, &stream);
|
||||||
|
|
||||||
|
if (!client->waitForDevInfo(3000)) {
|
||||||
|
spdlog::error("SpyServer didn't respond with device information");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
char buf[1024];
|
||||||
|
sprintf(buf, "%s [%08X]", deviceTypesStr[client->devInfo.DeviceType], client->devInfo.DeviceSerial);
|
||||||
|
devRef = std::string(buf);
|
||||||
|
|
||||||
|
config.acquire();
|
||||||
|
if (!config.conf["devices"].contains(devRef)) {
|
||||||
|
config.conf["devices"][devRef]["sampleRateId"] = 0;
|
||||||
|
config.conf["devices"][devRef]["sampleBitDepthId"] = 1;
|
||||||
|
config.conf["devices"][devRef]["gainId"] = 0;
|
||||||
|
}
|
||||||
|
srId = config.conf["devices"][devRef]["sampleRateId"];
|
||||||
|
iqType = config.conf["devices"][devRef]["sampleBitDepthId"];
|
||||||
|
gain = config.conf["devices"][devRef]["gainId"];
|
||||||
|
config.release(true);
|
||||||
|
|
||||||
|
gain = std::clamp<int>(gain, 0, client->devInfo.MaximumGainIndex);
|
||||||
|
|
||||||
|
// Refresh sample rates
|
||||||
|
sampleRates.clear();
|
||||||
|
sampleRatesTxt.clear();
|
||||||
|
for (int i = client->devInfo.MinimumIQDecimation; i <= client->devInfo.DecimationStageCount; i++) {
|
||||||
|
double sr = (double)client->devInfo.MaximumSampleRate / ((double)(1 << i));
|
||||||
|
sampleRates.push_back(sr);
|
||||||
|
sampleRatesTxt += getBandwdithScaled(sr);
|
||||||
|
sampleRatesTxt += '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
srId = std::clamp<int>(srId, 0, sampleRates.size() - 1);
|
||||||
|
|
||||||
|
sampleRate = sampleRates[srId];
|
||||||
|
core::setInputSampleRate(sampleRate);
|
||||||
|
spdlog::info("Connected to server");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception e) {
|
||||||
|
spdlog::error("Could not connect to spyserver {0}", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
bool running = false;
|
bool running = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user