From 7bf0ad47c5401632e483f00ea124b2fc97bbad49 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 15 Feb 2016 15:07:57 -0500 Subject: [PATCH] Add swap I/Q setting for all devices --- src/AppFrame.cpp | 21 ++++++++++++++------- src/AppFrame.h | 2 ++ src/sdr/SoapySDRThread.cpp | 25 +++++++++++++++++-------- src/sdr/SoapySDRThread.h | 5 ++++- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 97239a4..0918122 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -561,26 +561,31 @@ void AppFrame::updateDeviceParams() { return; } + int i = 0; + SoapySDR::Device *soapyDev = devInfo->getSoapyDevice(); // Build settings menu wxMenu *newSettingsMenu = new wxMenu; showTipMenuItem = newSettingsMenu->AppendCheckItem(wxID_SET_TIPS, "Show Hover Tips"); - if (wxGetApp().getConfig()->getShowTips()) { - showTipMenuItem->Check(); - } + showTipMenuItem->Check(wxGetApp().getConfig()->getShowTips()); + newSettingsMenu->Append(wxID_SET_FREQ_OFFSET, "Frequency Offset"); + if (devInfo->hasCORR(SOAPY_SDR_RX, 0)) { newSettingsMenu->Append(wxID_SET_PPM, "Device PPM"); } - + + if (devInfo->getDriver() != "rtlsdr") { + iqSwapMenuItem = newSettingsMenu->AppendCheckItem(wxID_SET_IQSWAP, "I/Q Swap"); + iqSwapMenuItem->Check(wxGetApp().getSDRThread()->getIQSwap()); + } + agcMenuItem = newSettingsMenu->AppendCheckItem(wxID_AGC_CONTROL, "Automatic Gain"); agcMenuItem->Check(wxGetApp().getAGCMode()); SoapySDR::ArgInfoList::const_iterator args_i; - - int i = 0; - SoapySDR::Device *soapyDev = devInfo->getSoapyDevice(); settingArgs = soapyDev->getSettingInfo(); + for (args_i = settingArgs.begin(); args_i != settingArgs.end(); args_i++) { SoapySDR::ArgInfo arg = (*args_i); std::string currentVal = soapyDev->readSetting(arg.key); @@ -695,6 +700,8 @@ void AppFrame::OnMenu(wxCommandEvent& event) { } else { wxGetApp().getConfig()->setShowTips(true); } + } else if (event.GetId() == wxID_SET_IQSWAP) { + wxGetApp().getSDRThread()->setIQSwap(!wxGetApp().getSDRThread()->getIQSwap()); } else if (event.GetId() == wxID_SET_FREQ_OFFSET) { long ofs = wxGetNumberFromUser("Shift the displayed frequency by this amount.\ni.e. -125000000 for -125 MHz", "Frequency (Hz)", "Frequency Offset", wxGetApp().getOffset(), -2000000000, 2000000000, this); diff --git a/src/AppFrame.h b/src/AppFrame.h index bf0ec34..1fcbc37 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -27,6 +27,7 @@ #define wxID_RESET 2002 #define wxID_SET_PPM 2003 #define wxID_SET_TIPS 2004 +#define wxID_SET_IQSWAP 2005 #define wxID_SDR_DEVICES 2008 #define wxID_AGC_CONTROL 2009 @@ -127,6 +128,7 @@ private: wxMenuBar *menuBar; wxMenu *sampleRateMenu; wxMenuItem *agcMenuItem; + wxMenuItem *iqSwapMenuItem; wxMenu *settingsMenu; SoapySDR::ArgInfoList settingArgs; int settingsIdMax; diff --git a/src/sdr/SoapySDRThread.cpp b/src/sdr/SoapySDRThread.cpp index fac214c..ac17723 100644 --- a/src/sdr/SoapySDRThread.cpp +++ b/src/sdr/SoapySDRThread.cpp @@ -36,6 +36,7 @@ SDRThread::SDRThread() : IOThread(), buffers("SDRThreadBuffers") { frequency_lock_init.store(false); frequency_locked.store(false); lock_freq.store(0); + iq_swap.store(false); } SDRThread::~SDRThread() { @@ -194,15 +195,15 @@ void SDRThread::readStream(SDRThreadIQDataQueue* iqDataOutQueue) { if (n_read > 0 && !terminated) { SDRThreadIQData *dataOut = buffers.getBuffer(); -// if (hasHardwareDC) { + if (iq_swap.load()) { + dataOut->data.resize(n_read); + for (int i = 0; i < n_read; i++) { + dataOut->data[i].imag = inpBuffer.data[i].real; + dataOut->data[i].real = inpBuffer.data[i].imag; + } + } else { dataOut->data.assign(inpBuffer.data.begin(), inpBuffer.data.begin()+n_read); -// } else { -// if (dataOut->data.size() != n_read) { -// dataOut->data.resize(n_read); -// } -// iirfilt_crcf_execute_block(dcFilter, &inpBuffer.data[0], n_read, &dataOut->data[0]); -// } - + } dataOut->setRefCount(1); dataOut->frequency = frequency.load(); @@ -484,6 +485,14 @@ bool SDRThread::getAGCMode() { return agc_mode.load(); } +void SDRThread::setIQSwap(bool swap) { + iq_swap.store(swap); +} + +bool SDRThread::getIQSwap() { + return iq_swap.load(); +} + void SDRThread::setGain(std::string name, float value) { gain_busy.lock(); gainValues[name] = value; diff --git a/src/sdr/SoapySDRThread.h b/src/sdr/SoapySDRThread.h index ddb1718..fb4b32f 100644 --- a/src/sdr/SoapySDRThread.h +++ b/src/sdr/SoapySDRThread.h @@ -76,6 +76,9 @@ public: void setAGCMode(bool mode); bool getAGCMode(); + void setIQSwap(bool swap); + bool getIQSwap(); + void setGain(std::string name, float value); float getGain(std::string name); @@ -108,7 +111,7 @@ protected: std::atomic_int ppm, numElems, mtuElems, numChannels; std::atomic_bool hasPPM, hasHardwareDC; std::atomic_bool agc_mode, rate_changed, freq_changed, offset_changed, - ppm_changed, device_changed, agc_mode_changed, gain_value_changed, setting_value_changed, frequency_locked, frequency_lock_init; + ppm_changed, device_changed, agc_mode_changed, gain_value_changed, setting_value_changed, frequency_locked, frequency_lock_init, iq_swap; std::mutex gain_busy; std::map gainValues;