2014-10-27 20:05:40 -04:00
|
|
|
#define OPENGL
|
|
|
|
|
|
|
|
#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-27 21:22:29 -04:00
|
|
|
#include "CubicSDR.h"
|
|
|
|
#include "AppFrame.h"
|
2014-10-27 20:05:40 -04:00
|
|
|
|
|
|
|
IMPLEMENT_APP(CubicSDR)
|
|
|
|
|
|
|
|
bool CubicSDR::OnInit() {
|
|
|
|
if (!wxApp::OnInit())
|
|
|
|
return false;
|
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
frequency = DEFAULT_FREQ;
|
|
|
|
|
|
|
|
demodulatorTest = demodMgr.newThread();
|
2014-11-26 21:05:19 -05:00
|
|
|
demodulatorTest->getParams().frequency = DEFAULT_FREQ;
|
|
|
|
demodulatorTest->run();
|
2014-11-23 19:39:27 -05:00
|
|
|
|
|
|
|
audioVisualQueue = new DemodulatorThreadOutputQueue();
|
|
|
|
demodulatorTest->setVisualOutputQueue(audioVisualQueue);
|
|
|
|
|
|
|
|
threadCmdQueueSDR = new SDRThreadCommandQueue;
|
|
|
|
sdrThread = new SDRThread(threadCmdQueueSDR);
|
|
|
|
|
2014-11-29 13:58:20 -05:00
|
|
|
sdrPostThread = new SDRPostThread();
|
|
|
|
|
|
|
|
iqPostDataQueue = new SDRThreadIQDataQueue;
|
2014-11-23 19:39:27 -05:00
|
|
|
iqVisualQueue = new SDRThreadIQDataQueue;
|
|
|
|
|
2014-11-29 13:58:20 -05:00
|
|
|
sdrThread->setIQDataOutQueue(iqPostDataQueue);
|
|
|
|
sdrPostThread->setIQDataInQueue(iqPostDataQueue);
|
|
|
|
sdrPostThread->setIQVisualQueue(iqVisualQueue);
|
|
|
|
|
|
|
|
sdrPostThread->bindDemodulator(demodulatorTest);
|
|
|
|
|
2014-11-30 17:11:29 -05:00
|
|
|
t_PostSDR = new std::thread(&SDRPostThread::threadMain, sdrPostThread);
|
|
|
|
t_SDR = new std::thread(&SDRThread::threadMain, sdrThread);
|
2014-11-23 19:39:27 -05:00
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
AppFrame *appframe = new AppFrame();
|
|
|
|
|
2014-12-05 18:20:28 -05:00
|
|
|
#ifdef __APPLE__
|
2014-12-04 22:25:18 -05:00
|
|
|
int main_policy;
|
|
|
|
struct sched_param main_param;
|
|
|
|
|
|
|
|
main_policy = SCHED_OTHER;
|
|
|
|
main_param.sched_priority = sched_get_priority_min(SCHED_OTHER);
|
|
|
|
|
|
|
|
pthread_setschedparam(pthread_self(), main_policy, &main_param);
|
2014-12-05 18:20:28 -05:00
|
|
|
#endif
|
2014-12-04 22:25:18 -05:00
|
|
|
|
2014-10-27 20:05:40 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CubicSDR::OnExit() {
|
2014-11-23 19:39:27 -05:00
|
|
|
std::cout << "Terminating SDR thread.." << std::endl;
|
|
|
|
sdrThread->terminate();
|
2014-11-30 17:11:29 -05:00
|
|
|
t_SDR->join();
|
2014-10-27 20:05:40 -04:00
|
|
|
|
2014-11-30 17:11:29 -05:00
|
|
|
std::cout << "Terminating SDR post-processing thread.." << std::endl;
|
2014-11-29 13:58:20 -05:00
|
|
|
sdrPostThread->terminate();
|
2014-11-30 17:11:29 -05:00
|
|
|
t_PostSDR->join();
|
2014-11-29 13:58:20 -05:00
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
delete sdrThread;
|
2014-11-30 17:11:29 -05:00
|
|
|
delete t_SDR;
|
2014-11-23 19:39:27 -05:00
|
|
|
|
2014-11-29 13:58:20 -05:00
|
|
|
delete sdrPostThread;
|
2014-11-30 17:11:29 -05:00
|
|
|
delete t_PostSDR;
|
2014-11-29 13:58:20 -05:00
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
demodMgr.terminateAll();
|
|
|
|
|
|
|
|
|
|
|
|
delete threadCmdQueueSDR;
|
|
|
|
|
|
|
|
delete iqVisualQueue;
|
|
|
|
delete audioVisualQueue;
|
2014-11-29 13:58:20 -05:00
|
|
|
delete iqPostDataQueue;
|
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
delete m_glContext;
|
2014-10-27 20:05:40 -04:00
|
|
|
|
|
|
|
return wxApp::OnExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrimaryGLContext& CubicSDR::GetContext(wxGLCanvas *canvas) {
|
|
|
|
PrimaryGLContext *glContext;
|
|
|
|
if (!m_glContext) {
|
2014-11-12 21:55:11 -05:00
|
|
|
m_glContext = new PrimaryGLContext(canvas, NULL);
|
2014-10-27 20:05:40 -04:00
|
|
|
}
|
|
|
|
glContext = m_glContext;
|
|
|
|
|
|
|
|
glContext->SetCurrent(*canvas);
|
|
|
|
|
|
|
|
return *glContext;
|
|
|
|
}
|
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
void CubicSDR::setFrequency(unsigned int freq) {
|
|
|
|
frequency = freq;
|
2014-11-27 22:13:21 -05:00
|
|
|
// demodulatorTest->getParams().frequency = freq;
|
2014-11-23 19:39:27 -05:00
|
|
|
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_TUNE);
|
|
|
|
command.int_value = freq;
|
|
|
|
threadCmdQueueSDR->push(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CubicSDR::getFrequency() {
|
|
|
|
return frequency;
|
|
|
|
}
|