2014-10-27 21:22:29 -04:00
|
|
|
#include "AppFrame.h"
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
|
|
|
#endif
|
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
#include <vector>
|
|
|
|
#include "SDRThread.h"
|
2014-11-17 22:58:56 -05:00
|
|
|
#include "DemodulatorMgr.h"
|
2014-11-16 16:51:45 -05:00
|
|
|
#include "AudioThread.h"
|
2014-11-16 19:02:40 -05:00
|
|
|
#include "CubicSDR.h"
|
2014-10-27 21:22:29 -04:00
|
|
|
|
2014-11-21 21:50:14 -05:00
|
|
|
#include <thread>
|
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(AppFrame, wxFrame)
|
|
|
|
//EVT_MENU(wxID_NEW, AppFrame::OnNewWindow)
|
2014-10-27 21:22:29 -04:00
|
|
|
EVT_MENU(wxID_CLOSE, AppFrame::OnClose)
|
2014-11-17 18:14:37 -05:00
|
|
|
EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread)
|
2014-10-28 21:39:59 -04:00
|
|
|
EVT_IDLE(AppFrame::OnIdle)
|
2014-10-27 21:22:29 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
|
|
AppFrame::AppFrame() :
|
2014-11-04 19:52:11 -05:00
|
|
|
wxFrame(NULL, wxID_ANY, wxT("CubicSDR")), frequency(DEFAULT_FREQ) {
|
2014-10-27 21:22:29 -04:00
|
|
|
|
2014-11-15 23:41:41 -05:00
|
|
|
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
scopeCanvas = new ScopeCanvas(this, NULL);
|
|
|
|
vbox->Add(scopeCanvas, 1, wxEXPAND | wxALL, 0);
|
|
|
|
vbox->AddSpacer(2);
|
|
|
|
spectrumCanvas = new SpectrumCanvas(this, NULL);
|
|
|
|
vbox->Add(spectrumCanvas, 1, wxEXPAND | wxALL, 0);
|
|
|
|
vbox->AddSpacer(2);
|
|
|
|
waterfallCanvas = new WaterfallCanvas(this, NULL);
|
|
|
|
vbox->Add(waterfallCanvas, 4, wxEXPAND | wxALL, 0);
|
|
|
|
|
|
|
|
this->SetSizer(vbox);
|
2014-10-27 21:22:29 -04:00
|
|
|
|
2014-10-27 23:52:25 -04:00
|
|
|
// SetIcon(wxICON(sample));
|
2014-10-27 21:22:29 -04:00
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
// Make a menubar
|
2014-10-27 21:22:29 -04:00
|
|
|
wxMenu *menu = new wxMenu;
|
|
|
|
// menu->Append(wxID_NEW);
|
|
|
|
// menu->AppendSeparator();
|
|
|
|
menu->Append(wxID_CLOSE);
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
menuBar->Append(menu, wxT("&File"));
|
|
|
|
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
CreateStatusBar();
|
2014-11-16 19:02:40 -05:00
|
|
|
SetClientSize(1280, 600);
|
2014-10-31 01:37:01 -04:00
|
|
|
Centre();
|
2014-10-27 21:22:29 -04:00
|
|
|
Show();
|
|
|
|
|
2014-11-22 20:57:06 -05:00
|
|
|
audioInputQueue = new AudioThreadInputQueue;
|
|
|
|
audioThread = new AudioThread(audioInputQueue);
|
|
|
|
|
|
|
|
t1 = new std::thread(&AudioThread::threadMain, audioThread);
|
2014-11-16 16:51:45 -05:00
|
|
|
|
2014-11-18 18:00:06 -05:00
|
|
|
demodulatorTest = demodMgr.newThread(this);
|
2014-11-22 20:57:06 -05:00
|
|
|
demodulatorTest->params.audioInputQueue = audioInputQueue;
|
2014-11-18 18:00:06 -05:00
|
|
|
demodulatorTest->run();
|
|
|
|
|
2014-11-22 20:57:06 -05:00
|
|
|
threadCmdQueueSDR = new SDRThreadCommandQueue;
|
|
|
|
sdrThread = new SDRThread(threadCmdQueueSDR);
|
|
|
|
sdrThread->bindDemodulator(*demodulatorTest);
|
|
|
|
|
|
|
|
iqVisualQueue = new SDRThreadIQDataQueue;
|
|
|
|
sdrThread->setIQVisualQueue(iqVisualQueue);
|
|
|
|
|
|
|
|
t_SDR = new std::thread(&SDRThread::threadMain, sdrThread);
|
|
|
|
|
2014-10-27 21:22:29 -04:00
|
|
|
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
|
|
|
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
|
|
|
// ShowFullScreen(true);
|
|
|
|
}
|
|
|
|
|
2014-11-04 18:39:08 -05:00
|
|
|
AppFrame::~AppFrame() {
|
|
|
|
|
2014-11-16 16:51:45 -05:00
|
|
|
// delete t_SDR;
|
2014-11-22 20:57:06 -05:00
|
|
|
delete audioInputQueue;
|
|
|
|
delete audioThread;
|
|
|
|
delete threadCmdQueueSDR;
|
2014-11-11 20:25:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppFrame::OnClose(wxCommandEvent& WXUNUSED(event)) {
|
|
|
|
|
2014-10-27 21:22:29 -04:00
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) {
|
|
|
|
new AppFrame();
|
|
|
|
}
|
2014-10-28 21:39:59 -04:00
|
|
|
|
2014-11-17 18:14:37 -05:00
|
|
|
void AppFrame::OnThread(wxCommandEvent& event) {
|
|
|
|
SDRThreadIQData *iqData;
|
2014-11-17 19:37:53 -05:00
|
|
|
DemodulatorThreadAudioData *demodAudioData;
|
|
|
|
|
|
|
|
std::vector<signed char> *new_uc_buffer;
|
|
|
|
std::vector<float> *new_float_buffer;
|
2014-11-21 21:50:14 -05:00
|
|
|
std::string asdf("beep");
|
2014-11-17 18:14:37 -05:00
|
|
|
|
|
|
|
switch (event.GetId()) {
|
|
|
|
|
|
|
|
// SDR IQ -> Demodulator
|
|
|
|
|
2014-11-17 19:37:53 -05:00
|
|
|
case DemodulatorThreadTask::DEMOD_THREAD_AUDIO_DATA:
|
|
|
|
demodAudioData = (DemodulatorThreadAudioData *) event.GetClientData();
|
|
|
|
new_float_buffer = &(demodAudioData->data);
|
2014-11-18 18:00:06 -05:00
|
|
|
if (new_float_buffer != NULL && new_float_buffer->size()) {
|
2014-11-17 19:37:53 -05:00
|
|
|
|
|
|
|
if (scopeCanvas->waveform_points.size() != new_float_buffer->size() * 2) {
|
|
|
|
scopeCanvas->waveform_points.resize(new_float_buffer->size() * 2);
|
|
|
|
}
|
2014-11-17 18:14:37 -05:00
|
|
|
|
2014-11-17 19:37:53 -05:00
|
|
|
for (int i = 0, iMax = new_float_buffer->size(); i < iMax; i++) {
|
|
|
|
scopeCanvas->waveform_points[i * 2 + 1] = (*new_float_buffer)[i] * 0.5f;
|
|
|
|
scopeCanvas->waveform_points[i * 2] = ((double) i / (double) iMax);
|
|
|
|
}
|
2014-11-16 19:14:15 -05:00
|
|
|
|
2014-11-17 19:37:53 -05:00
|
|
|
} else {
|
|
|
|
std::cout << "Incoming Demodulator data empty?" << std::endl;
|
2014-11-16 19:14:15 -05:00
|
|
|
}
|
2014-11-17 19:37:53 -05:00
|
|
|
delete demodAudioData;
|
2014-11-16 19:14:15 -05:00
|
|
|
|
2014-11-17 19:37:53 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
event.Skip();
|
2014-11-16 16:51:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
void AppFrame::OnIdle(wxIdleEvent& event) {
|
2014-11-22 20:57:06 -05:00
|
|
|
bool work_done = false;
|
2014-10-28 21:39:59 -04:00
|
|
|
|
2014-11-22 20:57:06 -05:00
|
|
|
if (!iqVisualQueue->empty()) {
|
|
|
|
SDRThreadIQData iqData;
|
|
|
|
iqVisualQueue->pop(iqData);
|
|
|
|
|
|
|
|
if (iqData.data.size()) {
|
|
|
|
spectrumCanvas->setData(&iqData.data);
|
|
|
|
waterfallCanvas->setData(&iqData.data);
|
|
|
|
} else {
|
|
|
|
std::cout << "Incoming IQ data empty?" << std::endl;
|
|
|
|
}
|
|
|
|
work_done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!work_done) {
|
|
|
|
event.Skip();
|
|
|
|
}
|
2014-10-28 21:39:59 -04:00
|
|
|
}
|
2014-11-04 19:52:11 -05:00
|
|
|
|
|
|
|
void AppFrame::setFrequency(unsigned int freq) {
|
|
|
|
frequency = freq;
|
2014-11-22 20:57:06 -05:00
|
|
|
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_TUNE);
|
|
|
|
command.int_value = freq;
|
|
|
|
threadCmdQueueSDR->push(command);
|
2014-11-04 19:52:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int AppFrame::getFrequency() {
|
|
|
|
return frequency;
|
|
|
|
}
|