mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-26 21:58:37 -05:00
Fix bad re-loading, setting and UI glitches for Device Runtime settings, and misc.
- Quite obvious on the SDRPlay RSP2 for ex. - Random cleanups by using the for-each construct at some places for clarity.
This commit is contained in:
parent
695d00d966
commit
33aa0cade6
@ -778,11 +778,14 @@ void AppFrame::updateDeviceParams() {
|
||||
if (settingArgs.size()) {
|
||||
newSettingsMenu->AppendSeparator();
|
||||
}
|
||||
|
||||
//for each Runtime option of index i:
|
||||
for (args_i = settingArgs.begin(); args_i != settingArgs.end(); args_i++) {
|
||||
|
||||
SoapySDR::ArgInfo arg = (*args_i);
|
||||
|
||||
std::string currentVal = soapyDev->readSetting(arg.key);
|
||||
if (arg.type == SoapySDR::ArgInfo::BOOL) {
|
||||
|
||||
if (arg.type == SoapySDR::ArgInfo::BOOL) {
|
||||
wxMenuItem *item = newSettingsMenu->AppendCheckItem(wxID_SETTINGS_BASE+i, arg.name, arg.description);
|
||||
item->Check(currentVal=="true");
|
||||
i++;
|
||||
@ -796,14 +799,16 @@ void AppFrame::updateDeviceParams() {
|
||||
if (arg.options.size()) {
|
||||
wxMenu *subMenu = new wxMenu;
|
||||
int j = 0;
|
||||
for (std::vector<std::string>::iterator str_i = arg.options.begin(); str_i != arg.options.end(); str_i++) {
|
||||
std::string optName = (*str_i);
|
||||
//for each of this options
|
||||
for (std::string optName : arg.options) {
|
||||
//by default the option name is the same as the displayed name.
|
||||
std::string displayName = optName;
|
||||
if (arg.optionNames.size()) {
|
||||
|
||||
if (arg.optionNames.size()) {
|
||||
displayName = arg.optionNames[j];
|
||||
}
|
||||
wxMenuItem *item = subMenu->AppendRadioItem(wxID_SETTINGS_BASE+i, displayName);
|
||||
if (currentVal == (*str_i)) {
|
||||
if (currentVal == optName) {
|
||||
item->Check(true);
|
||||
}
|
||||
j++;
|
||||
|
@ -119,11 +119,11 @@ void SDRDevicesDialog::refreshDeviceProperties() {
|
||||
|
||||
SoapySDR::Device *soapyDev = dev->getSoapyDevice();
|
||||
SoapySDR::ArgInfoList args = soapyDev->getSettingInfo();
|
||||
SoapySDR::ArgInfoList::const_iterator args_i;
|
||||
|
||||
m_propertyGrid->Append(new wxPropertyCategory("General Settings"));
|
||||
|
||||
devSettings.erase(devSettings.begin(),devSettings.end());
|
||||
devSettings.clear();
|
||||
|
||||
devSettings["name"] = m_propertyGrid->Append( new wxStringProperty("Name", wxPG_LABEL, devConfig->getDeviceName()) );
|
||||
devSettings["offset"] = m_propertyGrid->Append( new wxIntProperty("Offset (Hz)", wxPG_LABEL, devConfig->getOffset()) );
|
||||
|
||||
@ -137,9 +137,9 @@ void SDRDevicesDialog::refreshDeviceProperties() {
|
||||
SoapySDR::ArgInfo sampleRateArg;
|
||||
std::vector<long> rateOpts = selDev->getSampleRates(SOAPY_SDR_RX, 0);
|
||||
|
||||
for (std::vector<long>::iterator rate_i = rateOpts.begin(); rate_i != rateOpts.end(); rate_i++) {
|
||||
sampleRateArg.options.push_back(std::to_string(*rate_i));
|
||||
sampleRateArg.optionNames.push_back(frequencyToStr(*rate_i));
|
||||
for (long rate : rateOpts) {
|
||||
sampleRateArg.options.push_back(std::to_string(rate));
|
||||
sampleRateArg.optionNames.push_back(frequencyToStr(rate));
|
||||
}
|
||||
|
||||
sampleRateArg.type = SoapySDR::ArgInfo::STRING;
|
||||
@ -151,16 +151,26 @@ void SDRDevicesDialog::refreshDeviceProperties() {
|
||||
devSettings["sample_rate"] = addArgInfoProperty(m_propertyGrid, sampleRateArg);
|
||||
deviceArgs["sample_rate"] = sampleRateArg;
|
||||
|
||||
runtimeArgs.erase(runtimeArgs.begin(), runtimeArgs.end());
|
||||
runtimeProps.erase(runtimeProps.begin(), runtimeProps.end());
|
||||
streamProps.erase(streamProps.begin(), streamProps.end());
|
||||
runtimeArgs.clear();
|
||||
runtimeProps.clear();
|
||||
streamProps.clear();
|
||||
|
||||
if (args.size()) {
|
||||
m_propertyGrid->Append(new wxPropertyCategory("Run-time Settings"));
|
||||
|
||||
for (args_i = args.begin(); args_i != args.end(); args_i++) {
|
||||
for (SoapySDR::ArgInfoList::const_iterator args_i = args.begin(); args_i != args.end(); args_i++) {
|
||||
SoapySDR::ArgInfo arg = (*args_i);
|
||||
arg.value = soapyDev->readSetting(arg.key);
|
||||
//We-reread the Device configuration, else we use the user settings.
|
||||
if (dev) {
|
||||
//Apply saved settings
|
||||
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId());
|
||||
arg.value = devConfig->getSetting(arg.key, soapyDev->readSetting(arg.key)); //use SoapyDevice data as fallback.
|
||||
}
|
||||
else {
|
||||
//re-read the SoapyDevice
|
||||
arg.value = soapyDev->readSetting(arg.key);
|
||||
}
|
||||
|
||||
runtimeProps[arg.key] = addArgInfoProperty(m_propertyGrid, arg);
|
||||
runtimeArgs[arg.key] = arg;
|
||||
}
|
||||
@ -182,8 +192,8 @@ void SDRDevicesDialog::refreshDeviceProperties() {
|
||||
if (args.size()) {
|
||||
m_propertyGrid->Append(new wxPropertyCategory("Stream Settings"));
|
||||
|
||||
for (args_i = args.begin(); args_i != args.end(); args_i++) {
|
||||
SoapySDR::ArgInfo arg = (*args_i);
|
||||
for (SoapySDR::ArgInfo arg : args) {
|
||||
|
||||
streamProps[arg.key] = addArgInfoProperty(m_propertyGrid, arg);
|
||||
}
|
||||
}
|
||||
@ -199,10 +209,12 @@ void SDRDevicesDialog::refreshDeviceProperties() {
|
||||
|
||||
} else if (selDev && !selDev->isAvailable() && selDev->isManual()) {
|
||||
m_propertyGrid->Clear();
|
||||
devSettings.erase(devSettings.begin(),devSettings.end());
|
||||
runtimeArgs.erase(runtimeArgs.begin(), runtimeArgs.end());
|
||||
runtimeProps.erase(runtimeProps.begin(), runtimeProps.end());
|
||||
streamProps.erase(streamProps.begin(), streamProps.end());
|
||||
|
||||
devSettings.clear();
|
||||
runtimeArgs.clear();
|
||||
runtimeProps.clear();
|
||||
streamProps.clear();
|
||||
|
||||
removeId = devTree->GetSelection();
|
||||
dev = nullptr;
|
||||
selId = nullptr;
|
||||
@ -227,10 +239,10 @@ void SDRDevicesDialog::OnAddRemote( wxMouseEvent& /* event */) {
|
||||
if (selDev) {
|
||||
SDREnumerator::removeManual(selDev->getDriver(),selDev->getManualParams());
|
||||
m_propertyGrid->Clear();
|
||||
devSettings.erase(devSettings.begin(),devSettings.end());
|
||||
runtimeArgs.erase(runtimeArgs.begin(), runtimeArgs.end());
|
||||
runtimeProps.erase(runtimeProps.begin(), runtimeProps.end());
|
||||
streamProps.erase(streamProps.begin(), streamProps.end());
|
||||
devSettings.clear();
|
||||
runtimeArgs.clear();
|
||||
runtimeProps.clear();
|
||||
streamProps.clear();
|
||||
dev = nullptr;
|
||||
selId = nullptr;
|
||||
editId = nullptr;
|
||||
@ -284,14 +296,14 @@ SDRDeviceInfo *SDRDevicesDialog::getSelectedDevice(wxTreeItemId selId) {
|
||||
|
||||
void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event) {
|
||||
if (dev != NULL) {
|
||||
SoapySDR::ArgInfoList::const_iterator args_i;
|
||||
|
||||
SoapySDR::ArgInfoList args = dev->getSoapyDevice()->getSettingInfo();
|
||||
|
||||
SoapySDR::Kwargs settingArgs;
|
||||
SoapySDR::Kwargs streamArgs;
|
||||
|
||||
for (args_i = args.begin(); args_i != args.end(); args_i++) {
|
||||
SoapySDR::ArgInfo arg = (*args_i);
|
||||
for (SoapySDR::ArgInfo arg : args) {
|
||||
|
||||
wxPGProperty *prop = runtimeProps[arg.key];
|
||||
|
||||
if (arg.type == SoapySDR::ArgInfo::STRING && arg.options.size()) {
|
||||
@ -307,7 +319,7 @@ void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event) {
|
||||
args = dev->getSoapyDevice()->getStreamArgsInfo(SOAPY_SDR_RX, 0);
|
||||
|
||||
if (args.size()) {
|
||||
for (args_i = args.begin(); args_i != args.end(); args_i++) {
|
||||
for (SoapySDR::ArgInfoList::const_iterator args_i = args.begin(); args_i != args.end(); args_i++) {
|
||||
SoapySDR::ArgInfo arg = (*args_i);
|
||||
wxPGProperty *prop = streamProps[arg.key];
|
||||
|
||||
@ -392,18 +404,18 @@ void SDRDevicesDialog::OnDeviceTimer( wxTimerEvent& event ) {
|
||||
}
|
||||
|
||||
std::vector<std::string> remotes = SDREnumerator::getRemotes();
|
||||
std::vector<std::string>::iterator remotes_i;
|
||||
|
||||
std::vector<SDRDeviceInfo *>::iterator remoteDevs_i;
|
||||
|
||||
if (remotes.size()) {
|
||||
for (remotes_i = remotes.begin(); remotes_i != remotes.end(); remotes_i++) {
|
||||
devs[*remotes_i] = SDREnumerator::enumerate_devices(*remotes_i, true);
|
||||
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(*remotes_i);
|
||||
for (std::string remote : remotes) {
|
||||
devs[remote] = SDREnumerator::enumerate_devices(remote, true);
|
||||
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(remote);
|
||||
|
||||
wxTreeItemId remoteNode = devTree->AppendItem(remoteBranch, devConfig->getDeviceName());
|
||||
|
||||
if (devs[*remotes_i] != NULL) {
|
||||
for (remoteDevs_i = devs[*remotes_i]->begin(); remoteDevs_i != devs[*remotes_i]->end(); remoteDevs_i++) {
|
||||
if (devs[remote] != NULL) {
|
||||
for (remoteDevs_i = devs[remote]->begin(); remoteDevs_i != devs[remote]->end(); remoteDevs_i++) {
|
||||
devItems[devTree->AppendItem(remoteNode, (*remoteDevs_i)->getName())] = (*remoteDevs_i);
|
||||
}
|
||||
}
|
||||
@ -463,7 +475,7 @@ void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) {
|
||||
}
|
||||
} else if (editId && dev) {
|
||||
wxPGProperty *prop = event.GetProperty();
|
||||
|
||||
//change value of RuntimeProps
|
||||
for (std::map<std::string, wxPGProperty *>::iterator rtp = runtimeProps.begin(); rtp != runtimeProps.end(); rtp++) {
|
||||
if (rtp->second == prop) {
|
||||
SoapySDR::Device *soapyDev = dev->getSoapyDevice();
|
||||
@ -481,7 +493,8 @@ void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) {
|
||||
if (dev->isActive()) {
|
||||
wxGetApp().getSDRThread()->writeSetting(rtp->first, settingValue);
|
||||
}
|
||||
refreshDeviceProperties();
|
||||
|
||||
wxGetApp().notifyMainUIOfDeviceChange();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -502,10 +515,11 @@ void SDRDevicesDialog::doRefreshDevices() {
|
||||
devTree->DeleteAllItems();
|
||||
devTree->Disable();
|
||||
m_propertyGrid->Clear();
|
||||
runtimeArgs.erase(runtimeArgs.begin(), runtimeArgs.end());
|
||||
runtimeProps.erase(runtimeProps.begin(), runtimeProps.end());
|
||||
streamProps.erase(streamProps.begin(), streamProps.end());
|
||||
devSettings.erase(devSettings.begin(), devSettings.end());
|
||||
devSettings.clear();
|
||||
runtimeArgs.clear();
|
||||
runtimeProps.clear();
|
||||
streamProps.clear();
|
||||
|
||||
m_refreshButton->Disable();
|
||||
m_addRemoteButton->Disable();
|
||||
m_useSelectedButton->Disable();
|
||||
|
@ -183,8 +183,8 @@ std::vector<long> SDRDeviceInfo::getSampleRates(int direction, size_t channel) {
|
||||
|
||||
std::vector<long> result;
|
||||
std::vector<double> sampleRates = dev->listSampleRates(direction, channel);
|
||||
for (std::vector<double>::iterator si = sampleRates.begin(); si != sampleRates.end(); si++) {
|
||||
result.push_back((long)(*si));
|
||||
for (double si : sampleRates) {
|
||||
result.push_back((long)si);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -195,11 +195,11 @@ long SDRDeviceInfo::getSampleRateNear(int direction, size_t channel, long sample
|
||||
long returnRate = sampleRates[0];
|
||||
long sDelta = (long)sampleRate_in-sampleRates[0];
|
||||
long minDelta = std::abs(sDelta);
|
||||
for (std::vector<long>::iterator i = sampleRates.begin(); i != sampleRates.end(); i++) {
|
||||
long thisDelta = std::abs(sampleRate_in - (*i));
|
||||
for (long i : sampleRates) {
|
||||
long thisDelta = std::abs(sampleRate_in - i);
|
||||
if (thisDelta < minDelta) {
|
||||
minDelta = thisDelta;
|
||||
returnRate = (*i);
|
||||
returnRate = i;
|
||||
}
|
||||
}
|
||||
return returnRate;
|
||||
@ -210,8 +210,8 @@ SDRRangeMap SDRDeviceInfo::getGains(int direction, size_t channel) {
|
||||
std::vector<std::string> gainNames = dev->listGains(direction, channel);
|
||||
std::map<std::string, SoapySDR::Range> gainMap;
|
||||
|
||||
for (std::vector<std::string>::iterator gname = gainNames.begin(); gname!= gainNames.end(); gname++) {
|
||||
gainMap[(*gname)] = dev->getGainRange(direction, channel, (*gname));
|
||||
for (std::string gname : gainNames) {
|
||||
gainMap[gname] = dev->getGainRange(direction, channel, gname);
|
||||
}
|
||||
|
||||
return gainMap;
|
||||
|
@ -90,22 +90,22 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
||||
}
|
||||
|
||||
if (!soapy_initialized) {
|
||||
std::cout << "SoapySDR init.." << std::endl;
|
||||
std::cout << "\tAPI Version: v" << SoapySDR::getAPIVersion() << std::endl;
|
||||
std::cout << "\tABI Version: v" << SoapySDR::getABIVersion() << std::endl;
|
||||
std::cout << "\tInstall root: " << SoapySDR::getRootPath() << std::endl;
|
||||
std::cout << "SoapySDR init.." << std::endl << std::flush;
|
||||
std::cout << "\tAPI Version: v" << SoapySDR::getAPIVersion() << std::endl << std::flush;
|
||||
std::cout << "\tABI Version: v" << SoapySDR::getABIVersion() << std::endl << std::flush;
|
||||
std::cout << "\tInstall root: " << SoapySDR::getRootPath() << std::endl << std::flush;
|
||||
|
||||
std::cout << "\tLoading modules... " << std::endl;
|
||||
std::cout << "\tLoading modules... " << std::endl << std::flush;
|
||||
|
||||
std::string userModPath = wxGetApp().getModulePath();
|
||||
|
||||
if (userModPath != "") {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Loading SoapySDR modules from " + userModPath + "..");
|
||||
std::vector<std::string> localMods = SoapySDR::listModules(userModPath);
|
||||
for (std::vector<std::string>::iterator mods_i = localMods.begin(); mods_i != localMods.end(); mods_i++) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Initializing user specified SoapySDR module " + (*mods_i) + "..");
|
||||
std::cout << "Initializing user specified SoapySDR module " << (*mods_i) << ".." << std::endl;
|
||||
SoapySDR::loadModule(*mods_i);
|
||||
for (std::string mod : localMods) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Initializing user specified SoapySDR module " + (mod) + "..");
|
||||
std::cout << "Initializing user specified SoapySDR module " << (mod) << ".." << std::endl << std::flush;
|
||||
SoapySDR::loadModule(mod);
|
||||
}
|
||||
} else {
|
||||
#ifdef BUNDLE_SOAPY_MODS
|
||||
@ -114,28 +114,28 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
||||
std::vector<std::string> localMods = SoapySDR::listModules(exePath.GetPath().ToStdString() + "/modules/");
|
||||
for (std::vector<std::string>::iterator mods_i = localMods.begin(); mods_i != localMods.end(); mods_i++) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Initializing bundled SoapySDR module " + (*mods_i) + "..");
|
||||
std::cout << "Loading bundled SoapySDR module " << (*mods_i) << ".." << std::endl;
|
||||
std::cout << "Loading bundled SoapySDR module " << (*mods_i) << ".." << std::endl << std::flush;
|
||||
SoapySDR::loadModule(*mods_i);
|
||||
}
|
||||
#else
|
||||
bool localModPref = wxGetApp().getUseLocalMod();
|
||||
if (localModPref) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Loading SoapySDR modules..");
|
||||
std::cout << "Checking local system SoapySDR modules.." << std::flush;
|
||||
std::cout << "Checking local system SoapySDR modules.." << std::endl << std::flush;
|
||||
SoapySDR::loadModules();
|
||||
}
|
||||
|
||||
wxFileName exePath = wxFileName(wxStandardPaths::Get().GetExecutablePath());
|
||||
std::vector<std::string> localMods = SoapySDR::listModules(exePath.GetPath().ToStdString() + "/modules/");
|
||||
for (std::vector<std::string>::iterator mods_i = localMods.begin(); mods_i != localMods.end(); mods_i++) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Initializing bundled SoapySDR module " + (*mods_i) + "..");
|
||||
std::cout << "Loading bundled SoapySDR module " << (*mods_i) << ".." << std::endl;
|
||||
SoapySDR::loadModule(*mods_i);
|
||||
for (std::string mod : localMods) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Initializing bundled SoapySDR module " + (mod) + "..");
|
||||
std::cout << "Loading bundled SoapySDR module " << (mod) << ".." << std::endl << std::flush;
|
||||
SoapySDR::loadModule(mod);
|
||||
}
|
||||
|
||||
if (!localModPref) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Loading SoapySDR modules..");
|
||||
std::cout << "Checking system SoapySDR modules.." << std::flush;
|
||||
std::cout << "Checking system SoapySDR modules.." << std::endl << std::flush;
|
||||
SoapySDR::loadModules();
|
||||
}
|
||||
#endif
|
||||
@ -146,9 +146,8 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
||||
|
||||
}
|
||||
|
||||
if (SDREnumerator::factories.size()) {
|
||||
SDREnumerator::factories.erase(SDREnumerator::factories.begin(), SDREnumerator::factories.end());
|
||||
}
|
||||
SDREnumerator::factories.clear();
|
||||
|
||||
|
||||
std::cout << "\tAvailable factories...";
|
||||
SoapySDR::FindFunctions factories = SoapySDR::Registry::listFindFunctions();
|
||||
@ -275,6 +274,7 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
||||
|
||||
ConfigSettings devSettings = cfg->getSettings();
|
||||
if (devSettings.size()) {
|
||||
// Load the saved device settings to deviceArgs, and back to settingsInfo.
|
||||
for (ConfigSettings::const_iterator set_i = devSettings.begin(); set_i != devSettings.end(); set_i++) {
|
||||
deviceArgs[set_i->first] = set_i->second;
|
||||
}
|
||||
@ -318,10 +318,10 @@ void SDREnumerator::run() {
|
||||
SDREnumerator::enumerate_devices("");
|
||||
|
||||
if (remotes.size()) {
|
||||
std::vector<std::string>::iterator remote_i;
|
||||
for (remote_i = remotes.begin(); remote_i != remotes.end(); remote_i++) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Scanning devices at " + (*remote_i) + ", please wait..");
|
||||
SDREnumerator::enumerate_devices(*remote_i);
|
||||
|
||||
for (std::string remote : remotes) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Scanning devices at " + (remote) + ", please wait..");
|
||||
SDREnumerator::enumerate_devices(remote);
|
||||
}
|
||||
}
|
||||
|
||||
@ -400,15 +400,17 @@ bool SDREnumerator::hasRemoteModule() {
|
||||
|
||||
void SDREnumerator::reset() {
|
||||
soapy_initialized = false;
|
||||
factories.erase(factories.begin(), factories.end());
|
||||
modules.erase(modules.begin(), modules.end());
|
||||
factories.clear();
|
||||
modules.clear();
|
||||
|
||||
for (std::map< std::string, std::vector<SDRDeviceInfo *> >::iterator di = devs.begin(); di != devs.end(); di++) {
|
||||
|
||||
for (std::vector<SDRDeviceInfo *>::iterator i = di->second.begin(); i != di->second.end(); i++) {
|
||||
(*i)->setSoapyDevice(nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
devs.erase(devs.begin(), devs.end());
|
||||
devs.clear();
|
||||
}
|
||||
|
||||
std::vector<std::string> &SDREnumerator::getFactories() {
|
||||
|
Loading…
Reference in New Issue
Block a user