Example #1
0
void DeviceConfig::load(DataNode *node) {
    busy_lock.lock();
    if (node->hasAnother("name")) {
        deviceName = node->getNext("name")->element()->toString();
    }
    if (node->hasAnother("ppm")) {
        DataNode *ppm_node = node->getNext("ppm");
        int ppmValue = 0;
        ppm_node->element()->get(ppmValue);
        setPPM(ppmValue);
        std::cout << "Loaded PPM for device '" << deviceId << "' at " << ppmValue << "ppm" << std::endl;
    }
    if (node->hasAnother("offset")) {
        DataNode *offset_node = node->getNext("offset");
        long long offsetValue = 0;
        offset_node->element()->get(offsetValue);
        setOffset(offsetValue);
        std::cout << "Loaded offset for device '" << deviceId << "' at " << offsetValue << "Hz" << std::endl;
    }
    if (node->hasAnother("streamOpts")) {
        DataNode *streamOptsNode = node->getNext("streamOpts");
        for (int i = 0, iMax = streamOptsNode->numChildren(); i<iMax; i++) {
            DataNode *streamOptNode = streamOptsNode->child(i);
            std::string keyName = streamOptNode->getName();
            std::string strSettingValue = streamOptNode->element()->toString();
            
            if (keyName != "") {
                setStreamOpt(keyName, strSettingValue);
            }
        }
    }
    if (node->hasAnother("settings")) {
        DataNode *settingsNode = node->getNext("settings");
        for (int i = 0, iMax = settingsNode->numChildren(); i<iMax; i++) {
            DataNode *settingNode = settingsNode->child(i);
            std::string keyName = settingNode->getName();
            std::string strSettingValue = settingNode->element()->toString();
            
            if (keyName != "") {
                setSetting(keyName, strSettingValue);
            }
        }
    }
    if (node->hasAnother("rig_ifs")) {
        DataNode *rigIFNodes = node->getNext("rig_ifs");
        while (rigIFNodes->hasAnother("rig_if")) {
            DataNode *rigIFNode = rigIFNodes->getNext("rig_if");
            if (rigIFNode->hasAnother("model") && rigIFNode->hasAnother("sdr_if")) {
                int load_model;
                long long load_freq;
                
                rigIFNode->getNext("model")->element()->get(load_model);
                rigIFNode->getNext("sdr_if")->element()->get(load_freq);
                
                rigIF[load_model] = load_freq;
            }
        }
    }
    busy_lock.unlock();
}
Example #2
0
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;
}
Example #3
0
void CubicSDR::setDevice(int deviceId) {
    sdrThread->setDeviceId(deviceId);
    SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_DEVICE);
    command.llong_value = deviceId;
    pipeSDRCommand->push(command);

    SDRDeviceInfo *dev = (*getDevices())[deviceId];
    DeviceConfig *devConfig = config.getDevice(dev->getDeviceId());

    setPPM(devConfig->getPPM());
    setDirectSampling(devConfig->getDirectSampling());
    setSwapIQ(devConfig->getIQSwap());
    setOffset(devConfig->getOffset());
}
Example #4
0
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) {
        //long long freqHigh, freqLow;
        
        //SoapySDR::RangeList freqRange = soapyDev->getFrequencyRange(SOAPY_SDR_RX, 0);
        
        //freqLow = freqRange[0].minimum();
        //freqHigh = freqRange[freqRange.size()-1].maximum();

        // Try for a reasonable default sample rate.
        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());

        t_SDR = new std::thread(&SDRThread::threadMain, sdrThread);
    }
}
Example #5
0
void DeviceConfig::load(DataNode *node) {
    busy_lock.lock();
    if (node->hasAnother("ppm")) {
        DataNode *ppm_node = node->getNext("ppm");
        int ppmValue = 0;
        ppm_node->element()->get(ppmValue);
        setPPM(ppmValue);
        std::cout << "Loaded PPM for device '" << deviceId << "' at " << ppmValue << "ppm" << std::endl;
    }
    if (node->hasAnother("iq_swap")) {
        DataNode *iq_swap_node = node->getNext("iq_swap");
        int iqSwapValue = 0;
        iq_swap_node->element()->get(iqSwapValue);
        setIQSwap(iqSwapValue?true:false);
        std::cout << "Loaded I/Q Swap for device '" << deviceId << "' as " << (iqSwapValue?"swapped":"not swapped") << std::endl;
    }
    if (node->hasAnother("direct_sampling")) {
        DataNode *direct_sampling_node = node->getNext("direct_sampling");
        int directSamplingValue = 0;
        direct_sampling_node->element()->get(directSamplingValue);
        setDirectSampling(directSamplingValue);
        std::cout << "Loaded Direct Sampling Mode for device '" << deviceId << "':  ";
        switch (directSamplingValue) {
        case 0:
            std::cout << "off" << std::endl;
            break;
        case 1:
            std::cout << "I-ADC" << std::endl;
            break;
        case 2:
            std::cout << "Q-ADC" << std::endl;
            break;

        }
    }
    if (node->hasAnother("offset")) {
        DataNode *offset_node = node->getNext("offset");
        long long offsetValue = 0;
        offset_node->element()->get(offsetValue);
        setOffset(offsetValue);
        std::cout << "Loaded offset for device '" << deviceId << "' at " << offsetValue << "Hz" << std::endl;
    }
    busy_lock.unlock();
}
Example #6
0
void DeviceConfig::load(DataNode *node) {
    std::lock_guard < std::mutex > lock(busy_lock);
    if (node->hasAnother("name")) {
        deviceName = node->getNext("name")->element()->toString();
    }
    if (node->hasAnother("ppm")) {
        DataNode *ppm_node = node->getNext("ppm");
        int ppmValue = 0;
        ppm_node->element()->get(ppmValue);
        setPPM(ppmValue);
    }
    if (node->hasAnother("offset")) {
        DataNode *offset_node = node->getNext("offset");
        long long offsetValue = 0;
        offset_node->element()->get(offsetValue);
        setOffset(offsetValue);
    }
    if (node->hasAnother("agc_mode")) {
        DataNode *agc_node = node->getNext("agc_mode");
        int agcModeValue = 0;
        agc_node->element()->get(agcModeValue);
        setAGCMode(agcModeValue?true:false);
    }
    if (node->hasAnother("sample_rate")) {
        DataNode *sample_rate_node = node->getNext("sample_rate");
        long sampleRateValue = 0;
        sample_rate_node->element()->get(sampleRateValue);
        setSampleRate(sampleRateValue);
    }
    if (node->hasAnother("antenna")) {
        DataNode *antenna_node = node->getNext("antenna");
        std::string antennaNameValue;
        antenna_node->element()->get(antennaNameValue);
        setAntennaName(antennaNameValue);
    }
    if (node->hasAnother("streamOpts")) {
        DataNode *streamOptsNode = node->getNext("streamOpts");
        for (int i = 0, iMax = streamOptsNode->numChildren(); i<iMax; i++) {
            DataNode *streamOptNode = streamOptsNode->child(i);
            std::string keyName = streamOptNode->getName();
            std::string strSettingValue = streamOptNode->element()->toString();
            
            if (keyName != "") {
                setStreamOpt(keyName, strSettingValue);
            }
        }
    }
    if (node->hasAnother("settings")) {
        DataNode *settingsNode = node->getNext("settings");
        for (int i = 0, iMax = settingsNode->numChildren(); i<iMax; i++) {
            DataNode *settingNode = settingsNode->child(i);
            std::string keyName = settingNode->getName();
            std::string strSettingValue = settingNode->element()->toString();
            
            if (keyName != "") {
                setSetting(keyName, strSettingValue);
            }
        }
    }
    if (node->hasAnother("rig_ifs")) {
        DataNode *rigIFNodes = node->getNext("rig_ifs");
        while (rigIFNodes->hasAnother("rig_if")) {
            DataNode *rigIFNode = rigIFNodes->getNext("rig_if");
            if (rigIFNode->hasAnother("model") && rigIFNode->hasAnother("sdr_if")) {
                int load_model;
                long long load_freq;
                
                rigIFNode->getNext("model")->element()->get(load_model);
                rigIFNode->getNext("sdr_if")->element()->get(load_freq);
                
                rigIF[load_model] = load_freq;
            }
        }
    }
    if (node->hasAnother("gains")) {
        DataNode *gainsNode = node->getNext("gains");
        while (gainsNode->hasAnother("gain")) {
            DataNode *gainNode = gainsNode->getNext("gain");
            std::string keyName;
            float fltSettingValue;
            
            gainNode->getNext("id")->element()->get(keyName);
            gainNode->getNext("value")->element()->get(fltSettingValue);

            if (keyName != "" && !(fltSettingValue!=fltSettingValue)) {
                setGain(keyName, fltSettingValue);
            }
        }
    }
   
}