Menu option for frequency offset (up/down converters)

This commit is contained in:
Charles J. Cliffe 2015-01-06 00:57:57 -05:00
parent 726113e9ea
commit 1671e625e4
6 changed files with 40 additions and 4 deletions

View File

@ -6,6 +6,8 @@
#include "wx/wx.h" #include "wx/wx.h"
#endif #endif
#include "wx/numdlg.h"
#if !wxUSE_GLCANVAS #if !wxUSE_GLCANVAS
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
#endif #endif
@ -107,7 +109,8 @@ AppFrame::AppFrame() :
wxMenuBar *menuBar = new wxMenuBar; wxMenuBar *menuBar = new wxMenuBar;
wxMenu *menu = new wxMenu; wxMenu *menu = new wxMenu;
// menu->Append(wxID_NEW); // menu->Append(wxID_NEW);
// menu->AppendSeparator(); menu->Append(wxID_SET_FREQ_OFFSET, "Set Frequency Offset");
menu->AppendSeparator();
menu->Append(wxID_CLOSE); menu->Append(wxID_CLOSE);
menuBar->Append(menu, wxT("&File")); menuBar->Append(menu, wxT("&File"));
@ -167,6 +170,9 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
activeDemodulator->setOutputDevice(event.GetId() - wxID_RT_AUDIO_DEVICE); activeDemodulator->setOutputDevice(event.GetId() - wxID_RT_AUDIO_DEVICE);
activeDemodulator = NULL; 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);
} }
} }

View File

@ -13,6 +13,7 @@
#include <map> #include <map>
#define wxID_RT_AUDIO_DEVICE 1000 #define wxID_RT_AUDIO_DEVICE 1000
#define wxID_SET_FREQ_OFFSET 2001
// Define a new frame type // Define a new frame type
class AppFrame: public wxFrame { class AppFrame: public wxFrame {

View File

@ -20,6 +20,7 @@ bool CubicSDR::OnInit() {
return false; return false;
frequency = DEFAULT_FREQ; frequency = DEFAULT_FREQ;
offset = 0;
audioVisualQueue = new DemodulatorThreadOutputQueue(); audioVisualQueue = new DemodulatorThreadOutputQueue();
audioVisualQueue->set_max_num_items(1); audioVisualQueue->set_max_num_items(1);
@ -110,6 +111,17 @@ void CubicSDR::setFrequency(long long freq) {
threadCmdQueueSDR->push(command); 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() { long long CubicSDR::getFrequency() {
return frequency; return frequency;
} }

View File

@ -32,6 +32,9 @@ public:
void setFrequency(long long freq); void setFrequency(long long freq);
long long getFrequency(); long long getFrequency();
void setOffset(long long ofs);
long long getOffset();
DemodulatorThreadOutputQueue* getAudioVisualQueue(); DemodulatorThreadOutputQueue* getAudioVisualQueue();
DemodulatorThreadInputQueue* getIQVisualQueue(); DemodulatorThreadInputQueue* getIQVisualQueue();
DemodulatorMgr &getDemodMgr(); DemodulatorMgr &getDemodMgr();
@ -45,6 +48,7 @@ private:
DemodulatorMgr demodMgr; DemodulatorMgr demodMgr;
long long frequency; long long frequency;
long long offset;
SDRThread *sdrThread; SDRThread *sdrThread;
SDRPostThread *sdrPostThread; SDRPostThread *sdrPostThread;

View File

@ -4,7 +4,7 @@
#include "CubicSDR.h" #include "CubicSDR.h"
SDRThread::SDRThread(SDRThreadCommandQueue* pQueue) : SDRThread::SDRThread(SDRThreadCommandQueue* pQueue) :
commandQueue(pQueue), iqDataOutQueue(NULL), terminated(false) { commandQueue(pQueue), iqDataOutQueue(NULL), terminated(false), offset(0) {
dev = NULL; dev = NULL;
sampleRate = SRATE; sampleRate = SRATE;
} }
@ -137,7 +137,9 @@ void SDRThread::threadMain() {
if (!cmdQueue->empty()) { if (!cmdQueue->empty()) {
bool freq_changed = false; bool freq_changed = false;
bool offset_changed = false;
long long new_freq; long long new_freq;
long long new_offset;
while (!cmdQueue->empty()) { while (!cmdQueue->empty()) {
SDRThreadCommand command; SDRThreadCommand command;
@ -152,14 +154,24 @@ void SDRThread::threadMain() {
} }
std::cout << "Set frequency: " << new_freq << std::endl; std::cout << "Set frequency: " << new_freq << std::endl;
break; 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: default:
break; break;
} }
} }
if (offset_changed && !freq_changed) {
new_freq = frequency;
freq_changed = true;
offset = new_offset;
}
if (freq_changed) { if (freq_changed) {
frequency = new_freq; frequency = new_freq;
rtlsdr_set_center_freq(dev, frequency); rtlsdr_set_center_freq(dev, frequency+offset);
} }
} }

View File

@ -17,7 +17,7 @@
class SDRThreadCommand { class SDRThreadCommand {
public: public:
enum SDRThreadCommandEnum { enum SDRThreadCommandEnum {
SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET
}; };
SDRThreadCommand() : SDRThreadCommand() :
@ -76,6 +76,7 @@ public:
void terminate(); void terminate();
protected: protected:
uint32_t sampleRate; uint32_t sampleRate;
long long offset;
std::atomic<SDRThreadCommandQueue*> commandQueue; std::atomic<SDRThreadCommandQueue*> commandQueue;
std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue; std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue;