uhdInput::uhdInput (QSettings *s, bool *success ) { this -> uhdSettings = s; this -> myFrame = new QFrame (NULL); setupUi (this -> myFrame); this -> myFrame -> show (); this -> inputRate = Khz (2048); this -> ringbufferSize = 1024; // blocks of 1024 complexes this -> theBuffer = NULL; // also indicates good init or not *success = false; lastFrequency = 100000; m_workerHandle = 0; // create a usrp device. std::string args; std::cout << std::endl; std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; try { m_usrp = uhd::usrp::multi_usrp::make (args); // Lock mboard clocks std::string ref("internal"); m_usrp -> set_clock_source (ref); std::cout << boost::format("Using Device: %s") % m_usrp->get_pp_string() << std::endl; // set sample rate m_usrp -> set_rx_rate (inputRate); inputRate = m_usrp -> get_rx_rate (); std::cout << boost::format("Actual RX Rate: %f Msps...") % (inputRate/1e6) << std::endl << std::endl; // allocate the rx buffer theBuffer = new RingBuffer<std::complex<float> >(ringbufferSize * 1024); } catch (...) { fprintf (stderr, "No luck with uhd\n"); return; } // some housekeeping for the local frame externalGain -> setMaximum (maxGain ()); uhdSettings -> beginGroup ("uhdSettings"); externalGain -> setValue ( uhdSettings -> value ("externalGain", 40). toInt ()); f_correction -> setValue ( uhdSettings -> value ("f_correction", 0). toInt ()); KhzOffset -> setValue ( uhdSettings -> value ("KhzOffset", 0). toInt ()); uhdSettings -> endGroup (); setExternalGain (externalGain -> value ()); set_KhzOffset (KhzOffset -> value ()); connect (externalGain, SIGNAL (valueChanged (int)), this, SLOT (setExternalGain (int))); connect (KhzOffset, SIGNAL (valueChanged (int)), this, SLOT (set_KhzOffset (int))); *success = true; }
sdrplay::sdrplay (QSettings *s, bool *success) { int err; float ver; sdrplaySettings = s; this -> myFrame = new QFrame (NULL); setupUi (this -> myFrame); this -> myFrame -> show (); this -> inputRate = Khz (2048); this -> bandWidth = Khz (1536); *success = false; _I_Buffer = NULL; theLoader = NULL; theLoader = new sdrplayLoader (success); if (!(*success)) { fprintf (stderr, " No success in loading sdrplay lib\n"); delete theLoader; theLoader = NULL; return; } err = theLoader -> my_mir_sdr_ApiVersion (&ver); // if (ver != MIR_SDR_API_VERSION) { // fprintf (stderr, "Foute API: %f, %d\n", ver, err); // statusLabel -> setText ("mirics error"); // return NULL; // } _I_Buffer = new RingBuffer<int16_t>(2 * 1024 * 1024); vfoFrequency = Khz (94700); currentGain = DEFAULT_GAIN; vfoOffset = 0; theWorker = NULL; sdrplaySettings -> beginGroup ("sdrplaySettings"); externalGain -> setValue ( sdrplaySettings -> value ("externalGain", 10). toInt ()); f_correction -> setValue ( sdrplaySettings -> value ("f_correction", 0). toInt ()); KhzOffset -> setValue ( sdrplaySettings -> value ("KhzOffset", 0). toInt ()); sdrplaySettings -> endGroup (); setExternalGain (externalGain -> value ()); set_KhzOffset (KhzOffset -> value ()); connect (externalGain, SIGNAL (valueChanged (int)), this, SLOT (setExternalGain (int))); connect (KhzOffset, SIGNAL (valueChanged (int)), this, SLOT (set_KhzOffset (int))); *success = true; }
// // Our wrapper is a simple classs dabStick::dabStick (QSettings *s, bool *success) { int16_t deviceCount; int32_t r; int16_t deviceIndex; int16_t i; QString temp; int k; dabstickSettings = s; *success = false; // just the default this -> myFrame = new QFrame (NULL); setupUi (this -> myFrame); this -> myFrame -> show (); inputRate = 2048000; libraryLoaded = false; open = false; _I_Buffer = NULL; workerHandle = NULL; lastFrequency = KHz (94700); // just a dummy this -> sampleCounter= 0; this -> vfoOffset = 0; gains = NULL; #ifdef __MINGW32__ const char *libraryString = "rtlsdr.dll"; Handle = LoadLibrary ((wchar_t *)L"rtlsdr.dll"); #else const char *libraryString = "librtlsdr.so"; Handle = dlopen ("librtlsdr.so", RTLD_NOW); #endif if (Handle == NULL) { fprintf (stderr, "failed to open %s\n", libraryString); return; } libraryLoaded = true; if (!load_rtlFunctions ()) goto err; // // Ok, from here we have the library functions accessible deviceCount = this -> rtlsdr_get_device_count (); if (deviceCount == 0) { fprintf (stderr, "No devices found\n"); return; } deviceIndex = 0; // default if (deviceCount > 1) { dongleSelector = new dongleSelect (); for (deviceIndex = 0; deviceIndex < deviceCount; deviceIndex ++) { dongleSelector -> addtoDongleList (rtlsdr_get_device_name (deviceIndex)); } deviceIndex = dongleSelector -> QDialog::exec (); delete dongleSelector; } // // OK, now open the hardware r = this -> rtlsdr_open (&device, deviceIndex); if (r < 0) { fprintf (stderr, "Opening dabstick failed\n"); *success = false; return; } open = true; r = this -> rtlsdr_set_sample_rate (device, inputRate); if (r < 0) { fprintf (stderr, "Setting samplerate failed\n"); *success = false; return; } r = this -> rtlsdr_get_sample_rate (device); fprintf (stderr, "samplerate set to %d\n", r); gainsCount = rtlsdr_get_tuner_gains (device, NULL); fprintf(stderr, "Supported gain values (%d): ", gainsCount); gains = new int [gainsCount]; gainsCount = rtlsdr_get_tuner_gains (device, gains); for (i = gainsCount; i > 0; i--) { fprintf(stderr, "%.1f ", gains [i - 1] / 10.0); combo_gain -> addItem (QString::number (gains [i - 1])); } rtlsdr_set_tuner_gain_mode (device, 1); rtlsdr_set_tuner_gain (device, gains [gainsCount / 2]); _I_Buffer = new RingBuffer<uint8_t>(1024 * 1024); dabstickSettings -> beginGroup ("dabstickSettings"); temp = dabstickSettings -> value ("externalGain", "10"). toString (); k = combo_gain -> findText (temp); if (k != -1) { combo_gain -> setCurrentIndex (k); rtlsdr_set_tuner_gain (device, temp. toInt ()); } temp = dabstickSettings -> value ("autogain", "autogain off"). toString (); rtlsdr_set_tuner_gain_mode (device, temp == "autogain off" ? 0 : 1); f_correction -> setValue (dabstickSettings -> value ("f_correction", 0). toInt ()); KhzOffset -> setValue (dabstickSettings -> value ("KhzOffset", 0). toInt ()); dabstickSettings -> endGroup (); set_fCorrection (f_correction -> value ()); set_KhzOffset (KhzOffset -> value ()); connect (combo_gain, SIGNAL (activated (const QString &)), this, SLOT (setExternalGain (const QString &))); connect (combo_autogain, SIGNAL (activated (const QString &)), this, SLOT (set_autogain (const QString &))); connect (f_correction, SIGNAL (valueChanged (int)), this, SLOT (set_fCorrection (int))); connect (KhzOffset, SIGNAL (valueChanged (int)), this, SLOT (set_KhzOffset (int))); *success = true; return; err: if (open) this -> rtlsdr_close (device); #ifdef __MINGW32__ FreeLibrary (Handle); #else dlclose (Handle); #endif libraryLoaded = false; open = false; *success = false; return; }