diff --git a/src/forms/SDRDevices/SDRDevices.cpp b/src/forms/SDRDevices/SDRDevices.cpp index 986e31f..2309e71 100644 --- a/src/forms/SDRDevices/SDRDevices.cpp +++ b/src/forms/SDRDevices/SDRDevices.cpp @@ -408,7 +408,11 @@ void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) { for (std::map::iterator rtp = runtimeProps.begin(); rtp != runtimeProps.end(); rtp++) { if (rtp->second == prop) { SoapySDR::Device *soapyDev = dev->getSoapyDevice(); - soapyDev->writeSetting(rtp->first, prop->GetValueAsString().ToStdString()); + std::string settingValue = prop->GetValueAsString().ToStdString(); + soapyDev->writeSetting(rtp->first, settingValue); + if (dev->isActive()) { + wxGetApp().getSDRThread()->writeSetting(rtp->first, settingValue); + } refreshDeviceProperties(); return; } @@ -422,6 +426,10 @@ void SDRDevicesDialog::OnPropGridFocus( wxFocusEvent& /* event */) { void SDRDevicesDialog::doRefreshDevices() { + selId = nullptr; + editId = nullptr; + removeId = nullptr; + dev = nullptr; wxGetApp().stopDevice(); devTree->DeleteAllItems(); devTree->Disable(); @@ -433,10 +441,6 @@ void SDRDevicesDialog::doRefreshDevices() { m_addRemoteButton->Disable(); m_useSelectedButton->Disable(); wxGetApp().reEnumerateDevices(); - selId = nullptr; - editId = nullptr; - removeId = nullptr; - dev = nullptr; refresh = true; m_addRemoteButton->SetLabel("Add"); } diff --git a/src/sdr/SDRDeviceInfo.cpp b/src/sdr/SDRDeviceInfo.cpp index 345f236..a60202a 100644 --- a/src/sdr/SDRDeviceInfo.cpp +++ b/src/sdr/SDRDeviceInfo.cpp @@ -1,7 +1,7 @@ #include "SDRDeviceInfo.h" #include -SDRDeviceInfo::SDRDeviceInfo() : name(""), serial(""), available(false), remote(false), manual(false), soapyDevice(nullptr) { +SDRDeviceInfo::SDRDeviceInfo() : name(""), serial(""), available(false), remote(false), manual(false), active(false), soapyDevice(nullptr) { } @@ -37,6 +37,14 @@ void SDRDeviceInfo::setAvailable(bool available) { this->available = available; } +bool SDRDeviceInfo::isActive() const { + return active.load(); +} + +void SDRDeviceInfo::setActive(bool active) { + this->active.store(active); +} + const std::string& SDRDeviceInfo::getName() const { return name; } diff --git a/src/sdr/SDRDeviceInfo.h b/src/sdr/SDRDeviceInfo.h index 6b3998c..086efea 100644 --- a/src/sdr/SDRDeviceInfo.h +++ b/src/sdr/SDRDeviceInfo.h @@ -25,7 +25,10 @@ public: bool isAvailable() const; void setAvailable(bool available); - + + bool isActive() const; + void setActive(bool active); + const std::string& getName() const; void setName(const std::string& name); @@ -86,6 +89,7 @@ private: std::string name, serial, product, manufacturer, tuner; std::string driver, hardware, manual_params; bool timestamps, available, remote, manual; + std::atomic_bool active; SoapySDR::Kwargs deviceArgs, streamArgs; SoapySDR::Device *soapyDevice; diff --git a/src/sdr/SoapySDRThread.cpp b/src/sdr/SoapySDRThread.cpp index 7ed1cd4..fac214c 100644 --- a/src/sdr/SoapySDRThread.cpp +++ b/src/sdr/SoapySDRThread.cpp @@ -146,10 +146,8 @@ void SDRThread::init() { } void SDRThread::deinit() { - SDRDeviceInfo *devInfo = deviceInfo.load(); device->deactivateStream(stream); device->closeStream(stream); - devInfo->setSoapyDevice(nullptr); free(buffs[0]); } @@ -353,11 +351,15 @@ void SDRThread::run() { std::cout << "SDR thread starting." << std::endl; terminated.store(false); - if (deviceInfo.load() != NULL) { + SDRDeviceInfo *activeDev = deviceInfo.load(); + + if (activeDev != NULL) { std::cout << "device init()" << std::endl; init(); std::cout << "starting readLoop()" << std::endl; + activeDev->setActive(true); readLoop(); + activeDev->setActive(false); std::cout << "readLoop() ended." << std::endl; deinit(); std::cout << "device deinit()" << std::endl;