mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-15 00:21:47 -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)
|
wxBEGIN_EVENT_TABLE(AppFrame, wxFrame)
|
||||||
//EVT_MENU(wxID_NEW, AppFrame::OnNewWindow)
|
//EVT_MENU(wxID_NEW, AppFrame::OnNewWindow)
|
||||||
EVT_MENU(wxID_CLOSE, AppFrame::OnClose)
|
EVT_MENU(wxID_CLOSE, AppFrame::OnClose)
|
||||||
EVT_THREAD(EVENT_SDR_INPUT, AppFrame::OnEventInput)
|
|
||||||
EVT_THREAD(EVENT_DEMOD_INPUT, AppFrame::OnDemodInput)
|
EVT_THREAD(EVENT_DEMOD_INPUT, AppFrame::OnDemodInput)
|
||||||
EVT_THREAD(EVENT_AUDIO_INPUT, AppFrame::OnAudioInput)
|
EVT_THREAD(EVENT_AUDIO_INPUT, AppFrame::OnAudioInput)
|
||||||
|
EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread)
|
||||||
EVT_IDLE(AppFrame::OnIdle)
|
EVT_IDLE(AppFrame::OnIdle)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
@ -138,25 +138,39 @@ void AppFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) {
|
|||||||
new AppFrame();
|
new AppFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SDR IQ -> Demodulator
|
|
||||||
void AppFrame::OnEventInput(wxThreadEvent& event) {
|
void AppFrame::OnThread(wxCommandEvent& event) {
|
||||||
std::vector<signed char> *new_buffer = event.GetPayload<std::vector<signed char> *>();
|
SDRThreadIQData *iqData;
|
||||||
// std::cout << new_buffer->size() << std::endl;
|
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()) {
|
if (new_buffer->size()) {
|
||||||
DemodulatorThreadTask task = DemodulatorThreadTask(DemodulatorThreadTask::DEMOD_THREAD_DATA);
|
DemodulatorThreadTask task = DemodulatorThreadTask(DemodulatorThreadTask::DEMOD_THREAD_DATA);
|
||||||
task.setData(*new_buffer);
|
task.setData(*new_buffer);
|
||||||
|
|
||||||
threadQueueDemod->addTask(task, DemodulatorThreadQueue::DEMOD_PRIORITY_HIGHEST);
|
threadQueueDemod->addTask(task, DemodulatorThreadQueue::DEMOD_PRIORITY_HIGHEST);
|
||||||
|
|
||||||
// test_demod.writeBuffer(new_buffer);
|
|
||||||
// scopeCanvas->setWaveformPoints(test_demod.waveform_points);
|
|
||||||
spectrumCanvas->setData(new_buffer);
|
spectrumCanvas->setData(new_buffer);
|
||||||
waterfallCanvas->setData(new_buffer);
|
waterfallCanvas->setData(new_buffer);
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Incoming IQ data empty?" << std::endl;
|
std::cout << "Incoming IQ data empty?" << std::endl;
|
||||||
}
|
}
|
||||||
delete new_buffer;
|
delete iqData;
|
||||||
|
|
||||||
|
break; // thread wants to exit: disable controls and destroy main window
|
||||||
|
default:
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Demodulator -> Audio
|
// Demodulator -> Audio
|
||||||
void AppFrame::OnDemodInput(wxThreadEvent& event) {
|
void AppFrame::OnDemodInput(wxThreadEvent& event) {
|
||||||
std::vector<float> *new_buffer = event.GetPayload<std::vector<float> *>();
|
std::vector<float> *new_buffer = event.GetPayload<std::vector<float> *>();
|
||||||
|
@ -15,6 +15,7 @@ class AppFrame: public wxFrame {
|
|||||||
public:
|
public:
|
||||||
AppFrame();
|
AppFrame();
|
||||||
~AppFrame();
|
~AppFrame();
|
||||||
|
void OnThread (wxCommandEvent& event);
|
||||||
void OnEventInput(wxThreadEvent& event);
|
void OnEventInput(wxThreadEvent& event);
|
||||||
void OnDemodInput(wxThreadEvent& event);
|
void OnDemodInput(wxThreadEvent& event);
|
||||||
void OnAudioInput(wxThreadEvent& event);
|
void OnAudioInput(wxThreadEvent& event);
|
||||||
|
@ -103,9 +103,12 @@ wxThread::ExitCode SDRThread::Entry() {
|
|||||||
|
|
||||||
signed char *buf = (signed char *) malloc(BUF_SIZE);
|
signed char *buf = (signed char *) malloc(BUF_SIZE);
|
||||||
|
|
||||||
|
unsigned int frequency = DEFAULT_FREQ;
|
||||||
|
unsigned int bandwidth = SRATE;
|
||||||
|
|
||||||
rtlsdr_open(&dev, first_available);
|
rtlsdr_open(&dev, first_available);
|
||||||
rtlsdr_set_sample_rate(dev, SRATE);
|
rtlsdr_set_sample_rate(dev, bandwidth);
|
||||||
rtlsdr_set_center_freq(dev, DEFAULT_FREQ);
|
rtlsdr_set_center_freq(dev, frequency);
|
||||||
rtlsdr_set_agc_mode(dev, 1);
|
rtlsdr_set_agc_mode(dev, 1);
|
||||||
rtlsdr_set_offset_tuning(dev, 1);
|
rtlsdr_set_offset_tuning(dev, 1);
|
||||||
rtlsdr_reset_buffer(dev);
|
rtlsdr_reset_buffer(dev);
|
||||||
@ -136,17 +139,18 @@ wxThread::ExitCode SDRThread::Entry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (freq_changed) {
|
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);
|
rtlsdr_read_sync(dev, buf, BUF_SIZE, &n_read);
|
||||||
|
|
||||||
if (!TestDestroy()) {
|
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++) {
|
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;
|
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;
|
// std::cout << "Time Slice: " << time_slice << std::endl;
|
||||||
if (!TestDestroy()) {
|
if (!TestDestroy()) {
|
||||||
wxThreadEvent event(wxEVT_THREAD, EVENT_SDR_INPUT);
|
SDRThreadIQData *iqData = new SDRThreadIQData(bandwidth,frequency,new_buffer);
|
||||||
event.SetPayload(new_buffer);
|
m_pQueue->sendIQData(SDRThreadTask::SDR_THREAD_DATA, iqData);
|
||||||
wxQueueEvent(m_pQueue->getHandler(), event.Clone());
|
|
||||||
} else {
|
|
||||||
delete new_buffer;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this->Yield();
|
this->Yield();
|
||||||
|
@ -26,10 +26,11 @@ SDRThreadTask SDRThreadQueue::pop() {
|
|||||||
return element;
|
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);
|
wxCommandEvent evt(wxEVT_THREAD, cmd);
|
||||||
evt.SetString(sArg);
|
|
||||||
evt.SetInt(iArg);
|
evt.SetClientData(data);
|
||||||
|
|
||||||
m_pParent->AddPendingEvent(evt);
|
m_pParent->AddPendingEvent(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
#include "SDRThreadTask.h"
|
#include "SDRThreadTask.h"
|
||||||
|
|
||||||
#include "wx/event.h"
|
#include "wx/event.h"
|
||||||
@ -13,7 +14,7 @@ public:
|
|||||||
SDRThreadQueue(wxEvtHandler* pParent);
|
SDRThreadQueue(wxEvtHandler* pParent);
|
||||||
|
|
||||||
void addTask(const SDRThreadTask& task, const SDR_PRIORITY& priority = SDR_PRIORITY_NORMAL);
|
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();
|
SDRThreadTask pop();
|
||||||
size_t stackSize();
|
size_t stackSize();
|
||||||
|
@ -1,12 +1,36 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#include "wx/string.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 {
|
class SDRThreadTask {
|
||||||
public:
|
public:
|
||||||
enum SDR_COMMAND {
|
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() :
|
SDRThreadTask() :
|
||||||
|
Loading…
Reference in New Issue
Block a user