diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index ff51ba0..bd049e9 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -6,6 +6,8 @@ #include "wx/wx.h" #endif +#include "wx/numdlg.h" + #if !wxUSE_GLCANVAS #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" #endif @@ -107,7 +109,8 @@ AppFrame::AppFrame() : wxMenuBar *menuBar = new wxMenuBar; wxMenu *menu = new wxMenu; // menu->Append(wxID_NEW); -// menu->AppendSeparator(); + menu->Append(wxID_SET_FREQ_OFFSET, "Set Frequency Offset"); + menu->AppendSeparator(); menu->Append(wxID_CLOSE); menuBar->Append(menu, wxT("&File")); @@ -167,6 +170,9 @@ void AppFrame::OnMenu(wxCommandEvent& event) { activeDemodulator->setOutputDevice(event.GetId() - wxID_RT_AUDIO_DEVICE); activeDemodulator = NULL; } + } 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", 0, -2000000000, 2000000000, this); + wxGetApp().setOffset(ofs); } } diff --git a/src/AppFrame.h b/src/AppFrame.h index 78f6a83..4df734d 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -13,6 +13,7 @@ #include #define wxID_RT_AUDIO_DEVICE 1000 +#define wxID_SET_FREQ_OFFSET 2001 // Define a new frame type class AppFrame: public wxFrame { diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index dacf40c..396b9dc 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -20,6 +20,7 @@ bool CubicSDR::OnInit() { return false; frequency = DEFAULT_FREQ; + offset = 0; audioVisualQueue = new DemodulatorThreadOutputQueue(); audioVisualQueue->set_max_num_items(1); @@ -110,6 +111,17 @@ void CubicSDR::setFrequency(long long freq) { threadCmdQueueSDR->push(command); } +long long CubicSDR::getOffset() { + return offset; +} + +void CubicSDR::setOffset(long long ofs) { + offset = ofs; + SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_OFFSET); + command.llong_value = ofs; + threadCmdQueueSDR->push(command); +} + long long CubicSDR::getFrequency() { return frequency; } diff --git a/src/CubicSDR.h b/src/CubicSDR.h index 1355dcd..6317273 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -32,6 +32,9 @@ public: void setFrequency(long long freq); long long getFrequency(); + void setOffset(long long ofs); + long long getOffset(); + DemodulatorThreadOutputQueue* getAudioVisualQueue(); DemodulatorThreadInputQueue* getIQVisualQueue(); DemodulatorMgr &getDemodMgr(); @@ -45,6 +48,7 @@ private: DemodulatorMgr demodMgr; long long frequency; + long long offset; SDRThread *sdrThread; SDRPostThread *sdrPostThread; diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index 8f4e97c..f36ae3f 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -4,7 +4,7 @@ #include "CubicSDR.h" SDRThread::SDRThread(SDRThreadCommandQueue* pQueue) : - commandQueue(pQueue), iqDataOutQueue(NULL), terminated(false) { + commandQueue(pQueue), iqDataOutQueue(NULL), terminated(false), offset(0) { dev = NULL; sampleRate = SRATE; } @@ -137,7 +137,9 @@ void SDRThread::threadMain() { if (!cmdQueue->empty()) { bool freq_changed = false; + bool offset_changed = false; long long new_freq; + long long new_offset; while (!cmdQueue->empty()) { SDRThreadCommand command; @@ -152,14 +154,24 @@ void SDRThread::threadMain() { } std::cout << "Set frequency: " << new_freq << std::endl; break; + case SDRThreadCommand::SDR_THREAD_CMD_SET_OFFSET: + offset_changed = true; + new_offset = command.llong_value; + std::cout << "Set offset: " << new_offset << std::endl; + break; default: break; } } + if (offset_changed && !freq_changed) { + new_freq = frequency; + freq_changed = true; + offset = new_offset; + } if (freq_changed) { frequency = new_freq; - rtlsdr_set_center_freq(dev, frequency); + rtlsdr_set_center_freq(dev, frequency+offset); } } diff --git a/src/sdr/SDRThread.h b/src/sdr/SDRThread.h index 3c83870..3143d4c 100644 --- a/src/sdr/SDRThread.h +++ b/src/sdr/SDRThread.h @@ -17,7 +17,7 @@ class SDRThreadCommand { public: enum SDRThreadCommandEnum { - SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE + SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET }; SDRThreadCommand() : @@ -76,6 +76,7 @@ public: void terminate(); protected: uint32_t sampleRate; + long long offset; std::atomic commandQueue; std::atomic iqDataOutQueue;