mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-26 05:38:39 -05:00
SDRThread now passes IQ Data transaction object
Also using sdr thread queue and standard thread event to send payload now.
This commit is contained in:
parent
a7d7ec0d93
commit
e91696c012
@ -19,9 +19,9 @@
|
||||
wxBEGIN_EVENT_TABLE(AppFrame, wxFrame)
|
||||
//EVT_MENU(wxID_NEW, AppFrame::OnNewWindow)
|
||||
EVT_MENU(wxID_CLOSE, AppFrame::OnClose)
|
||||
EVT_THREAD(EVENT_SDR_INPUT, AppFrame::OnEventInput)
|
||||
EVT_THREAD(EVENT_DEMOD_INPUT, AppFrame::OnDemodInput)
|
||||
EVT_THREAD(EVENT_AUDIO_INPUT, AppFrame::OnAudioInput)
|
||||
EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread)
|
||||
EVT_IDLE(AppFrame::OnIdle)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
@ -138,25 +138,39 @@ void AppFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) {
|
||||
new AppFrame();
|
||||
}
|
||||
|
||||
// SDR IQ -> Demodulator
|
||||
void AppFrame::OnEventInput(wxThreadEvent& event) {
|
||||
std::vector<signed char> *new_buffer = event.GetPayload<std::vector<signed char> *>();
|
||||
// std::cout << new_buffer->size() << std::endl;
|
||||
if (new_buffer->size()) {
|
||||
DemodulatorThreadTask task = DemodulatorThreadTask(DemodulatorThreadTask::DEMOD_THREAD_DATA);
|
||||
task.setData(*new_buffer);
|
||||
threadQueueDemod->addTask(task, DemodulatorThreadQueue::DEMOD_PRIORITY_HIGHEST);
|
||||
|
||||
// test_demod.writeBuffer(new_buffer);
|
||||
// scopeCanvas->setWaveformPoints(test_demod.waveform_points);
|
||||
spectrumCanvas->setData(new_buffer);
|
||||
waterfallCanvas->setData(new_buffer);
|
||||
} else {
|
||||
std::cout << "Incoming IQ data empty?" << std::endl;
|
||||
void AppFrame::OnThread(wxCommandEvent& event) {
|
||||
SDRThreadIQData *iqData;
|
||||
std::vector<signed char> *new_buffer;
|
||||
|
||||
switch (event.GetId()) {
|
||||
|
||||
// SDR IQ -> Demodulator
|
||||
case SDRThreadTask::SDR_THREAD_DATA:
|
||||
iqData = (SDRThreadIQData *) event.GetClientData();
|
||||
new_buffer = &(iqData->data);
|
||||
if (new_buffer->size()) {
|
||||
DemodulatorThreadTask task = DemodulatorThreadTask(DemodulatorThreadTask::DEMOD_THREAD_DATA);
|
||||
task.setData(*new_buffer);
|
||||
|
||||
threadQueueDemod->addTask(task, DemodulatorThreadQueue::DEMOD_PRIORITY_HIGHEST);
|
||||
|
||||
spectrumCanvas->setData(new_buffer);
|
||||
waterfallCanvas->setData(new_buffer);
|
||||
} else {
|
||||
std::cout << "Incoming IQ data empty?" << std::endl;
|
||||
}
|
||||
delete iqData;
|
||||
|
||||
break; // thread wants to exit: disable controls and destroy main window
|
||||
default:
|
||||
event.Skip();
|
||||
}
|
||||
delete new_buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Demodulator -> Audio
|
||||
void AppFrame::OnDemodInput(wxThreadEvent& event) {
|
||||
std::vector<float> *new_buffer = event.GetPayload<std::vector<float> *>();
|
||||
|
@ -15,6 +15,7 @@ class AppFrame: public wxFrame {
|
||||
public:
|
||||
AppFrame();
|
||||
~AppFrame();
|
||||
void OnThread (wxCommandEvent& event);
|
||||
void OnEventInput(wxThreadEvent& event);
|
||||
void OnDemodInput(wxThreadEvent& event);
|
||||
void OnAudioInput(wxThreadEvent& event);
|
||||
|
@ -103,9 +103,12 @@ wxThread::ExitCode SDRThread::Entry() {
|
||||
|
||||
signed char *buf = (signed char *) malloc(BUF_SIZE);
|
||||
|
||||
unsigned int frequency = DEFAULT_FREQ;
|
||||
unsigned int bandwidth = SRATE;
|
||||
|
||||
rtlsdr_open(&dev, first_available);
|
||||
rtlsdr_set_sample_rate(dev, SRATE);
|
||||
rtlsdr_set_center_freq(dev, DEFAULT_FREQ);
|
||||
rtlsdr_set_sample_rate(dev, bandwidth);
|
||||
rtlsdr_set_center_freq(dev, frequency);
|
||||
rtlsdr_set_agc_mode(dev, 1);
|
||||
rtlsdr_set_offset_tuning(dev, 1);
|
||||
rtlsdr_reset_buffer(dev);
|
||||
@ -136,17 +139,18 @@ wxThread::ExitCode SDRThread::Entry() {
|
||||
}
|
||||
|
||||
if (freq_changed) {
|
||||
rtlsdr_set_center_freq(dev, new_freq);
|
||||
frequency = new_freq;
|
||||
rtlsdr_set_center_freq(dev, frequency);
|
||||
}
|
||||
}
|
||||
|
||||
rtlsdr_read_sync(dev, buf, BUF_SIZE, &n_read);
|
||||
|
||||
if (!TestDestroy()) {
|
||||
std::vector<signed char> *new_buffer = new std::vector<signed char>();
|
||||
std::vector<signed char> new_buffer;
|
||||
|
||||
for (int i = 0; i < n_read; i++) {
|
||||
new_buffer->push_back(buf[i] - 127);
|
||||
new_buffer.push_back(buf[i] - 127);
|
||||
}
|
||||
|
||||
double time_slice = (double) n_read / (double) sample_rate;
|
||||
@ -154,11 +158,8 @@ wxThread::ExitCode SDRThread::Entry() {
|
||||
|
||||
// std::cout << "Time Slice: " << time_slice << std::endl;
|
||||
if (!TestDestroy()) {
|
||||
wxThreadEvent event(wxEVT_THREAD, EVENT_SDR_INPUT);
|
||||
event.SetPayload(new_buffer);
|
||||
wxQueueEvent(m_pQueue->getHandler(), event.Clone());
|
||||
} else {
|
||||
delete new_buffer;
|
||||
SDRThreadIQData *iqData = new SDRThreadIQData(bandwidth,frequency,new_buffer);
|
||||
m_pQueue->sendIQData(SDRThreadTask::SDR_THREAD_DATA, iqData);
|
||||
}
|
||||
} else {
|
||||
this->Yield();
|
||||
|
@ -26,10 +26,11 @@ SDRThreadTask SDRThreadQueue::pop() {
|
||||
return element;
|
||||
}
|
||||
|
||||
void SDRThreadQueue::report(const SDRThreadTask::SDR_COMMAND& cmd, const wxString& sArg, int iArg) {
|
||||
void SDRThreadQueue::sendIQData(const SDRThreadTask::SDR_COMMAND& cmd, SDRThreadIQData *data) {
|
||||
wxCommandEvent evt(wxEVT_THREAD, cmd);
|
||||
evt.SetString(sArg);
|
||||
evt.SetInt(iArg);
|
||||
|
||||
evt.SetClientData(data);
|
||||
|
||||
m_pParent->AddPendingEvent(evt);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "SDRThreadTask.h"
|
||||
|
||||
#include "wx/event.h"
|
||||
@ -13,7 +14,7 @@ public:
|
||||
SDRThreadQueue(wxEvtHandler* pParent);
|
||||
|
||||
void addTask(const SDRThreadTask& task, const SDR_PRIORITY& priority = SDR_PRIORITY_NORMAL);
|
||||
void report(const SDRThreadTask::SDR_COMMAND& cmd, const wxString& sArg = wxEmptyString, int iArg = 0);
|
||||
void sendIQData(const SDRThreadTask::SDR_COMMAND& cmd, SDRThreadIQData *data);
|
||||
|
||||
SDRThreadTask pop();
|
||||
size_t stackSize();
|
||||
|
@ -1,12 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "wx/defs.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/object.h"
|
||||
|
||||
class SDRThreadIQData: public wxObject {
|
||||
public:
|
||||
unsigned int frequency;
|
||||
unsigned int bandwidth;
|
||||
std::vector<signed char> data;
|
||||
|
||||
SDRThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector<signed char> data) :
|
||||
data(data), frequency(frequency), bandwidth(bandwidth) {
|
||||
|
||||
}
|
||||
|
||||
~SDRThreadIQData() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class SDRThreadTask {
|
||||
public:
|
||||
enum SDR_COMMAND {
|
||||
SDR_THREAD_EXIT = wxID_EXIT, SDR_THREAD_NULL = wxID_HIGHEST + 1, SDR_THREAD_STARTED, SDR_THREAD_PROCESS, SDR_THREAD_ERROR, SDR_THREAD_TUNING
|
||||
SDR_THREAD_EXIT = wxID_EXIT,
|
||||
SDR_THREAD_NULL = wxID_HIGHEST + 1,
|
||||
SDR_THREAD_STARTED,
|
||||
SDR_THREAD_PROCESS,
|
||||
SDR_THREAD_ERROR,
|
||||
SDR_THREAD_TUNING,
|
||||
SDR_THREAD_DATA
|
||||
};
|
||||
|
||||
SDRThreadTask() :
|
||||
|
Loading…
Reference in New Issue
Block a user