Esempio n. 1
0
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;
    }
}
Esempio n. 2
0
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();
        SoapySDR::ArgInfoList::const_iterator args_i;
        
        m_propertyGrid->Append(new wxPropertyCategory("General Settings"));
        
        devSettings.erase(devSettings.begin(),devSettings.end());
        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()) );
        
        runtimeArgs.erase(runtimeArgs.begin(), runtimeArgs.end());
        runtimeProps.erase(runtimeProps.begin(), runtimeProps.end());
        streamProps.erase(streamProps.begin(), streamProps.end());
        
        if (args.size()) {
            m_propertyGrid->Append(new wxPropertyCategory("Run-time Settings"));
            
            for (args_i = args.begin(); args_i != args.end(); args_i++) {
                SoapySDR::ArgInfo arg = (*args_i);
                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 (args_i = args.begin(); args_i != args.end(); args_i++) {
                    SoapySDR::ArgInfo arg = (*args_i);
                    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.erase(devSettings.begin(),devSettings.end());
        runtimeArgs.erase(runtimeArgs.begin(), runtimeArgs.end());
        runtimeProps.erase(runtimeProps.begin(), runtimeProps.end());
        streamProps.erase(streamProps.begin(), streamProps.end());
        removeId = devTree->GetSelection();
        dev = nullptr;
        selId = nullptr;
        editId = nullptr;
        
        m_addRemoteButton->SetLabel("Remove");
    } else if (!selDev) {
        m_addRemoteButton->SetLabel("Add");
        removeId = nullptr;
    }
}