void CubicSDR::setDevice(SDRDeviceInfo *dev) { if (!sdrThread->isTerminated()) { sdrThread->terminate(); if (t_SDR) { t_SDR->join(); delete t_SDR; } } for (SoapySDR::Kwargs::const_iterator i = settingArgs.begin(); i != settingArgs.end(); i++) { sdrThread->writeSetting(i->first, i->second); } sdrThread->setStreamArgs(streamArgs); sdrThread->setDevice(dev); DeviceConfig *devConfig = config.getDevice(dev->getDeviceId()); SoapySDR::Device *soapyDev = dev->getSoapyDevice(); if (soapyDev) { if (long devSampleRate = devConfig->getSampleRate()) { sampleRate = dev->getSampleRateNear(SOAPY_SDR_RX, 0, devSampleRate); sampleRateInitialized.store(true); } if (!sampleRateInitialized.load()) { sampleRate = dev->getSampleRateNear(SOAPY_SDR_RX, 0, DEFAULT_SAMPLE_RATE); sampleRateInitialized.store(true); } else { sampleRate = dev->getSampleRateNear(SOAPY_SDR_RX, 0, sampleRate); } if (frequency < sampleRate/2) { frequency = sampleRate/2; } setFrequency(frequency); setSampleRate(sampleRate); setPPM(devConfig->getPPM()); setOffset(devConfig->getOffset()); if (devConfig->getAGCMode()) { setAGCMode(true); } else { setAGCMode(false); } t_SDR = new std::thread(&SDRThread::threadMain, sdrThread); } stoppedDev = nullptr; }
void SDRDevicesDialog::refreshDeviceProperties() { SDRDeviceInfo *selDev = getSelectedDevice(devTree->GetSelection()); if (selDev && selDev->isAvailable()) { dev = selDev; selId = devTree->GetSelection(); DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getName()); m_propertyGrid->Clear(); SoapySDR::Device *soapyDev = dev->getSoapyDevice(); SoapySDR::ArgInfoList args = soapyDev->getSettingInfo(); //A) General settings: name, offset, sample rate, agc, antennas (if > 1) m_propertyGrid->Append(new wxPropertyCategory("General Settings")); devSettings.clear(); //A-1) Name devSettings["name"] = m_propertyGrid->Append( new wxStringProperty("Name", wxPG_LABEL, devConfig->getDeviceName()) ); //A-2) Offset devSettings["offset"] = m_propertyGrid->Append( new wxIntProperty("Offset (KHz)", wxPG_LABEL, devConfig->getOffset() / 1000) ); //A-3) Antennas, is there are more than 1 RX antenna, else do not expose the setting. //get the saved setting const std::string& currentSetAntenna = devConfig->getAntennaName(); //compare to the list of existing antennas SoapySDR::ArgInfo antennasArg; std::vector<std::string> antennaOpts = selDev->getAntennaNames(SOAPY_SDR_RX, 0); //only do something if there is more than 1 antenna if (antennaOpts.size() > 1) { //by default, choose the first of the list. std::string antennaToSelect = antennaOpts.front(); auto found_i = std::find(antennaOpts.begin(), antennaOpts.end(), currentSetAntenna); if (found_i != antennaOpts.end()) { antennaToSelect = currentSetAntenna; } else { //erroneous antenna name, re-write device config with the first choice of teh list. devConfig->setAntennaName(antennaToSelect); } //build device settings for (std::string antenna : antennaOpts) { antennasArg.options.push_back(antenna); antennasArg.optionNames.push_back(antenna); } antennasArg.type = SoapySDR::ArgInfo::STRING; antennasArg.units = ""; antennasArg.name = "Antenna"; antennasArg.key = "antenna"; antennasArg.value = antennaToSelect; devSettings["antenna"] = addArgInfoProperty(m_propertyGrid, antennasArg); deviceArgs["antenna"] = antennasArg; } //end if more than 1 antenna else { devConfig->setAntennaName(""); } //A-4) Sample_rate: long currentSampleRate = wxGetApp().getSampleRate(); long deviceSampleRate = devConfig->getSampleRate(); if (!deviceSampleRate) { deviceSampleRate = selDev->getSampleRateNear(SOAPY_SDR_RX, 0, currentSampleRate); } SoapySDR::ArgInfo sampleRateArg; std::vector<long> rateOpts = selDev->getSampleRates(SOAPY_SDR_RX, 0); for (long rate : rateOpts) { sampleRateArg.options.push_back(std::to_string(rate)); sampleRateArg.optionNames.push_back(frequencyToStr(rate)); } sampleRateArg.type = SoapySDR::ArgInfo::STRING; sampleRateArg.units = "Hz"; sampleRateArg.name = "Sample Rate"; sampleRateArg.key = "sample_rate"; sampleRateArg.value = std::to_string(deviceSampleRate); devSettings["sample_rate"] = addArgInfoProperty(m_propertyGrid, sampleRateArg); deviceArgs["sample_rate"] = sampleRateArg; //B) Runtime Settings: runtimeArgs.clear(); runtimeProps.clear(); streamProps.clear(); if (args.size()) { m_propertyGrid->Append(new wxPropertyCategory("Run-time Settings")); for (SoapySDR::ArgInfoList::const_iterator args_i = args.begin(); args_i != args.end(); args_i++) { SoapySDR::ArgInfo arg = (*args_i); //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; } } if (dev) { args = dev->getSoapyDevice()->getStreamArgsInfo(SOAPY_SDR_RX, 0); DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId()); ConfigSettings devStreamOpts = devConfig->getStreamOpts(); if (devStreamOpts.size()) { for (int j = 0, jMax = args.size(); j < jMax; j++) { if (devStreamOpts.find(args[j].key) != devStreamOpts.end()) { args[j].value = devStreamOpts[args[j].key]; } } } if (args.size()) { m_propertyGrid->Append(new wxPropertyCategory("Stream Settings")); for (SoapySDR::ArgInfo arg : args) { streamProps[arg.key] = addArgInfoProperty(m_propertyGrid, arg); } } } if (selDev->isManual()) { m_addRemoteButton->SetLabel("Remove"); removeId = selId; } else { m_addRemoteButton->SetLabel("Add"); removeId = nullptr; } } else if (selDev && !selDev->isAvailable() && selDev->isManual()) { m_propertyGrid->Clear(); devSettings.clear(); runtimeArgs.clear(); runtimeProps.clear(); streamProps.clear(); removeId = devTree->GetSelection(); dev = nullptr; selId = nullptr; editId = nullptr; m_addRemoteButton->SetLabel("Remove"); } else if (!selDev) { m_addRemoteButton->SetLabel("Add"); removeId = nullptr; } }