mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-27 18:14:44 +01:00
fix plutosdr commit persistence
This commit is contained in:
parent
6b5de78e80
commit
97d0a07ec7
@ -50,9 +50,9 @@ public:
|
|||||||
|
|
||||||
// Select device
|
// Select device
|
||||||
config.acquire();
|
config.acquire();
|
||||||
uri = config.conf["device"];
|
devName = config.conf["device"];
|
||||||
config.release();
|
config.release();
|
||||||
select(uri);
|
select(devName);
|
||||||
|
|
||||||
// Register source
|
// Register source
|
||||||
handler.ctx = this;
|
handler.ctx = this;
|
||||||
@ -121,9 +121,9 @@ private:
|
|||||||
for (ssize_t i = 0; i < count; i++) {
|
for (ssize_t i = 0; i < count; i++) {
|
||||||
iio_context_info* info = ctxInfoList[i];
|
iio_context_info* info = ctxInfoList[i];
|
||||||
std::string desc = iio_context_info_get_description(info);
|
std::string desc = iio_context_info_get_description(info);
|
||||||
std::string uri = iio_context_info_get_uri(info);
|
std::string duri = iio_context_info_get_uri(info);
|
||||||
|
|
||||||
devices.define(uri, desc, uri);
|
devices.define(desc, desc, duri);
|
||||||
}
|
}
|
||||||
iio_context_info_list_free(ctxInfoList);
|
iio_context_info_list_free(ctxInfoList);
|
||||||
|
|
||||||
@ -133,54 +133,46 @@ private:
|
|||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
// On Android, a default IP entry must be made (TODO: This is not ideal since the IP cannot be changed)
|
// On Android, a default IP entry must be made (TODO: This is not ideal since the IP cannot be changed)
|
||||||
const char* androidURI = "ip:192.168.2.1";
|
const char* androidURI = "ip:192.168.2.1";
|
||||||
devices.define(androidURI, "Default (192.168.2.1)", androidURI);
|
const char* androidName = "Default (192.168.2.1)";
|
||||||
|
devices.define(androidName, androidName, androidURI);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void select(const std::string& nuri) {
|
void select(const std::string& name) {
|
||||||
// If no device is available, give up
|
// If no device is available, give up
|
||||||
if (devices.empty()) {
|
if (devices.empty()) {
|
||||||
uri.clear();
|
devName.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the device is not available, select the first one
|
// If the device is not available, select the first one
|
||||||
if (!devices.keyExists(nuri)) {
|
if (!devices.keyExists(name)) {
|
||||||
select(devices.key(0));
|
select(devices.key(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update URI
|
// Update URI
|
||||||
uri = nuri;
|
devName = name;
|
||||||
|
uri = devices.value(devices.keyId(name));
|
||||||
|
|
||||||
// TODO: Enumerate capabilities
|
// TODO: Enumerate capabilities
|
||||||
|
|
||||||
|
// Load defaults
|
||||||
|
samplerate = 4000000;
|
||||||
|
bandwidth = 0;
|
||||||
|
gmId = 0;
|
||||||
|
gain = -1.0f;
|
||||||
|
|
||||||
// Load device config
|
// Load device config
|
||||||
config.acquire();
|
config.acquire();
|
||||||
if (config.conf["devices"][uri.c_str()].contains("samplerate")) {
|
if (config.conf["devices"][devName].contains("samplerate")) {
|
||||||
// Select given samplerate or default if invalid
|
samplerate = config.conf["devices"][devName]["samplerate"];
|
||||||
samplerate = config.conf["devices"][uri]["samplerate"];
|
|
||||||
if (samplerates.keyExists(samplerate)) {
|
|
||||||
srId = samplerates.keyId(samplerate);
|
|
||||||
}
|
}
|
||||||
else {
|
if (config.conf["devices"][devName].contains("bandwidth")) {
|
||||||
srId = 0;
|
bandwidth = config.conf["devices"][devName]["bandwidth"];
|
||||||
samplerate = samplerates.value(srId);
|
|
||||||
}
|
}
|
||||||
}
|
if (config.conf["devices"][devName].contains("gainMode")) {
|
||||||
if (config.conf["devices"][uri].contains("bandwidth")) {
|
|
||||||
// Select given bandwidth or default if invalid
|
|
||||||
bandwidth = config.conf["devices"][uri]["bandwidth"];
|
|
||||||
if (bandwidths.keyExists(bandwidth)) {
|
|
||||||
bwId = bandwidths.keyId(bandwidth);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bwId = 0;
|
|
||||||
bandwidth = bandwidths.value(bwId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (config.conf["devices"][uri].contains("gainMode")) {
|
|
||||||
// Select given gain mode or default if invalid
|
// Select given gain mode or default if invalid
|
||||||
std::string gm = config.conf["devices"][uri]["gainMode"];
|
std::string gm = config.conf["devices"][devName]["gainMode"];
|
||||||
if (gainModes.keyExists(gm)) {
|
if (gainModes.keyExists(gm)) {
|
||||||
gmId = gainModes.keyId(gm);
|
gmId = gainModes.keyId(gm);
|
||||||
}
|
}
|
||||||
@ -188,12 +180,30 @@ private:
|
|||||||
gmId = 0;
|
gmId = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.conf["devices"][uri].contains("gain")) {
|
if (config.conf["devices"][devName].contains("gain")) {
|
||||||
gain = config.conf["devices"][uri]["gain"];
|
gain = config.conf["devices"][devName]["gain"];
|
||||||
gain = std::clamp<int>(gain, -1.0f, 73.0f);
|
gain = std::clamp<int>(gain, -1.0f, 73.0f);
|
||||||
}
|
}
|
||||||
config.release();
|
config.release();
|
||||||
|
|
||||||
|
// Update samplerate ID
|
||||||
|
if (samplerates.keyExists(samplerate)) {
|
||||||
|
srId = samplerates.keyId(samplerate);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
srId = 0;
|
||||||
|
samplerate = samplerates.value(srId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update bandwidth ID
|
||||||
|
if (bandwidths.keyExists(bandwidth)) {
|
||||||
|
bwId = bandwidths.keyId(bandwidth);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bwId = 0;
|
||||||
|
bandwidth = bandwidths.value(bwId);
|
||||||
|
}
|
||||||
|
|
||||||
// Update core samplerate
|
// Update core samplerate
|
||||||
core::setInputSampleRate(samplerate);
|
core::setInputSampleRate(samplerate);
|
||||||
}
|
}
|
||||||
@ -213,6 +223,9 @@ private:
|
|||||||
PlutoSDRSourceModule* _this = (PlutoSDRSourceModule*)ctx;
|
PlutoSDRSourceModule* _this = (PlutoSDRSourceModule*)ctx;
|
||||||
if (_this->running) { return; }
|
if (_this->running) { return; }
|
||||||
|
|
||||||
|
// If no device is selected, give up
|
||||||
|
if (_this->devName.empty() || _this->uri.empty()) { return; }
|
||||||
|
|
||||||
// Open context
|
// Open context
|
||||||
_this->ctx = iio_create_context_from_uri(_this->uri.c_str());
|
_this->ctx = iio_create_context_from_uri(_this->uri.c_str());
|
||||||
if (_this->ctx == NULL) {
|
if (_this->ctx == NULL) {
|
||||||
@ -296,7 +309,7 @@ private:
|
|||||||
SmGui::FillWidth();
|
SmGui::FillWidth();
|
||||||
SmGui::ForceSync();
|
SmGui::ForceSync();
|
||||||
if (SmGui::Combo("##plutosdr_dev_sel", &_this->devId, _this->devices.txt)) {
|
if (SmGui::Combo("##plutosdr_dev_sel", &_this->devId, _this->devices.txt)) {
|
||||||
_this->select(_this->devices.value(_this->devId));
|
_this->select(_this->devices.key(_this->devId));
|
||||||
config.acquire();
|
config.acquire();
|
||||||
config.conf["device"] = _this->devices.key(_this->devId);
|
config.conf["device"] = _this->devices.key(_this->devId);
|
||||||
config.release(true);
|
config.release(true);
|
||||||
@ -305,9 +318,9 @@ private:
|
|||||||
if (SmGui::Combo(CONCAT("##_pluto_sr_", _this->name), &_this->srId, _this->samplerates.txt)) {
|
if (SmGui::Combo(CONCAT("##_pluto_sr_", _this->name), &_this->srId, _this->samplerates.txt)) {
|
||||||
_this->samplerate = _this->samplerates.value(_this->srId);
|
_this->samplerate = _this->samplerates.value(_this->srId);
|
||||||
core::setInputSampleRate(_this->samplerate);
|
core::setInputSampleRate(_this->samplerate);
|
||||||
if (!_this->uri.empty()) {
|
if (!_this->devName.empty()) {
|
||||||
config.acquire();
|
config.acquire();
|
||||||
config.conf["devices"][_this->uri]["samplerate"] = _this->samplerate;
|
config.conf["devices"][_this->devName]["samplerate"] = _this->samplerate;
|
||||||
config.release(true);
|
config.release(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,7 +331,7 @@ private:
|
|||||||
SmGui::ForceSync();
|
SmGui::ForceSync();
|
||||||
if (SmGui::Button(CONCAT("Refresh##_pluto_refr_", _this->name))) {
|
if (SmGui::Button(CONCAT("Refresh##_pluto_refr_", _this->name))) {
|
||||||
_this->refresh();
|
_this->refresh();
|
||||||
_this->select(_this->uri);
|
_this->select(_this->devName);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (_this->running) { SmGui::EndDisabled(); }
|
if (_this->running) { SmGui::EndDisabled(); }
|
||||||
@ -330,9 +343,9 @@ private:
|
|||||||
if (_this->running) {
|
if (_this->running) {
|
||||||
_this->setBandwidth(_this->bandwidth);
|
_this->setBandwidth(_this->bandwidth);
|
||||||
}
|
}
|
||||||
if (!_this->uri.empty()) {
|
if (!_this->devName.empty()) {
|
||||||
config.acquire();
|
config.acquire();
|
||||||
config.conf["devices"][_this->uri]["bandwidth"] = _this->bandwidth;
|
config.conf["devices"][_this->devName]["bandwidth"] = _this->bandwidth;
|
||||||
config.release(true);
|
config.release(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -344,9 +357,9 @@ private:
|
|||||||
if (_this->running) {
|
if (_this->running) {
|
||||||
iio_channel_attr_write(_this->rxChan, "gain_control_mode", _this->gainModes.value(_this->gmId).c_str());
|
iio_channel_attr_write(_this->rxChan, "gain_control_mode", _this->gainModes.value(_this->gmId).c_str());
|
||||||
}
|
}
|
||||||
if (!_this->uri.empty()) {
|
if (!_this->devName.empty()) {
|
||||||
config.acquire();
|
config.acquire();
|
||||||
config.conf["devices"][_this->uri]["gainMode"] = _this->gainModes.key(_this->gmId);
|
config.conf["devices"][_this->devName]["gainMode"] = _this->gainModes.key(_this->gmId);
|
||||||
config.release(true);
|
config.release(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,9 +371,9 @@ private:
|
|||||||
if (_this->running) {
|
if (_this->running) {
|
||||||
iio_channel_attr_write_double(_this->rxChan, "hardwaregain", _this->gain);
|
iio_channel_attr_write_double(_this->rxChan, "hardwaregain", _this->gain);
|
||||||
}
|
}
|
||||||
if (!_this->uri.empty()) {
|
if (!_this->devName.empty()) {
|
||||||
config.acquire();
|
config.acquire();
|
||||||
config.conf["devices"][_this->uri]["gain"] = _this->gain;
|
config.conf["devices"][_this->devName]["gain"] = _this->gain;
|
||||||
config.release(true);
|
config.release(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -435,6 +448,7 @@ private:
|
|||||||
iio_channel* rxChan = NULL;
|
iio_channel* rxChan = NULL;
|
||||||
bool running = false;
|
bool running = false;
|
||||||
|
|
||||||
|
std::string devName = "";
|
||||||
std::string uri = "";
|
std::string uri = "";
|
||||||
|
|
||||||
double freq;
|
double freq;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user