Fix refresh, allow device dialog to update active device

This commit is contained in:
Charles J. Cliffe 2016-02-02 20:05:32 -05:00
parent 2518e22682
commit cc189cc274
4 changed files with 28 additions and 10 deletions

View File

@ -408,7 +408,11 @@ void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) {
for (std::map<std::string, wxPGProperty *>::iterator rtp = runtimeProps.begin(); rtp != runtimeProps.end(); rtp++) { for (std::map<std::string, wxPGProperty *>::iterator rtp = runtimeProps.begin(); rtp != runtimeProps.end(); rtp++) {
if (rtp->second == prop) { if (rtp->second == prop) {
SoapySDR::Device *soapyDev = dev->getSoapyDevice(); 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(); refreshDeviceProperties();
return; return;
} }
@ -422,6 +426,10 @@ void SDRDevicesDialog::OnPropGridFocus( wxFocusEvent& /* event */) {
void SDRDevicesDialog::doRefreshDevices() { void SDRDevicesDialog::doRefreshDevices() {
selId = nullptr;
editId = nullptr;
removeId = nullptr;
dev = nullptr;
wxGetApp().stopDevice(); wxGetApp().stopDevice();
devTree->DeleteAllItems(); devTree->DeleteAllItems();
devTree->Disable(); devTree->Disable();
@ -433,10 +441,6 @@ void SDRDevicesDialog::doRefreshDevices() {
m_addRemoteButton->Disable(); m_addRemoteButton->Disable();
m_useSelectedButton->Disable(); m_useSelectedButton->Disable();
wxGetApp().reEnumerateDevices(); wxGetApp().reEnumerateDevices();
selId = nullptr;
editId = nullptr;
removeId = nullptr;
dev = nullptr;
refresh = true; refresh = true;
m_addRemoteButton->SetLabel("Add"); m_addRemoteButton->SetLabel("Add");
} }

View File

@ -1,7 +1,7 @@
#include "SDRDeviceInfo.h" #include "SDRDeviceInfo.h"
#include <cstdlib> #include <cstdlib>
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; 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 { const std::string& SDRDeviceInfo::getName() const {
return name; return name;
} }

View File

@ -25,7 +25,10 @@ public:
bool isAvailable() const; bool isAvailable() const;
void setAvailable(bool available); void setAvailable(bool available);
bool isActive() const;
void setActive(bool active);
const std::string& getName() const; const std::string& getName() const;
void setName(const std::string& name); void setName(const std::string& name);
@ -86,6 +89,7 @@ private:
std::string name, serial, product, manufacturer, tuner; std::string name, serial, product, manufacturer, tuner;
std::string driver, hardware, manual_params; std::string driver, hardware, manual_params;
bool timestamps, available, remote, manual; bool timestamps, available, remote, manual;
std::atomic_bool active;
SoapySDR::Kwargs deviceArgs, streamArgs; SoapySDR::Kwargs deviceArgs, streamArgs;
SoapySDR::Device *soapyDevice; SoapySDR::Device *soapyDevice;

View File

@ -146,10 +146,8 @@ void SDRThread::init() {
} }
void SDRThread::deinit() { void SDRThread::deinit() {
SDRDeviceInfo *devInfo = deviceInfo.load();
device->deactivateStream(stream); device->deactivateStream(stream);
device->closeStream(stream); device->closeStream(stream);
devInfo->setSoapyDevice(nullptr);
free(buffs[0]); free(buffs[0]);
} }
@ -353,11 +351,15 @@ void SDRThread::run() {
std::cout << "SDR thread starting." << std::endl; std::cout << "SDR thread starting." << std::endl;
terminated.store(false); terminated.store(false);
if (deviceInfo.load() != NULL) { SDRDeviceInfo *activeDev = deviceInfo.load();
if (activeDev != NULL) {
std::cout << "device init()" << std::endl; std::cout << "device init()" << std::endl;
init(); init();
std::cout << "starting readLoop()" << std::endl; std::cout << "starting readLoop()" << std::endl;
activeDev->setActive(true);
readLoop(); readLoop();
activeDev->setActive(false);
std::cout << "readLoop() ended." << std::endl; std::cout << "readLoop() ended." << std::endl;
deinit(); deinit();
std::cout << "device deinit()" << std::endl; std::cout << "device deinit()" << std::endl;