mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-23 04:08:36 -05:00
Simplify SDRPostThread: no longer binding methods, directly use the true list of demodulators
This commit is contained in:
parent
a8f8f4a7e2
commit
37712c7a81
@ -2273,7 +2273,7 @@ bool AppFrame::loadSession(std::string fileName) {
|
||||
}
|
||||
|
||||
if (demodsLoaded.size()) {
|
||||
wxGetApp().bindDemodulators(demodsLoaded);
|
||||
wxGetApp().notifyDemodulatorsChanged();
|
||||
}
|
||||
|
||||
} // if l.rootNode()->hasAnother("demodulators")
|
||||
|
@ -828,16 +828,9 @@ SDRThread *CubicSDR::getSDRThread() {
|
||||
}
|
||||
|
||||
|
||||
void CubicSDR::bindDemodulator(DemodulatorInstancePtr demod) {
|
||||
if (!demod) {
|
||||
return;
|
||||
}
|
||||
sdrPostThread->bindDemodulator(demod);
|
||||
}
|
||||
void CubicSDR::notifyDemodulatorsChanged() {
|
||||
|
||||
void CubicSDR::bindDemodulators(const std::vector<DemodulatorInstancePtr>& demods) {
|
||||
|
||||
sdrPostThread->bindDemodulators(demods);
|
||||
sdrPostThread->notifyDemodulatorsChanged();
|
||||
}
|
||||
|
||||
long long CubicSDR::getSampleRate() {
|
||||
@ -849,7 +842,7 @@ void CubicSDR::removeDemodulator(DemodulatorInstancePtr demod) {
|
||||
return;
|
||||
}
|
||||
demod->setActive(false);
|
||||
sdrPostThread->removeDemodulator(demod);
|
||||
sdrPostThread->notifyDemodulatorsChanged();
|
||||
wxGetApp().getAppFrame()->notifyUpdateModemProperties();
|
||||
}
|
||||
|
||||
|
@ -121,8 +121,8 @@ public:
|
||||
SDRPostThread *getSDRPostThread();
|
||||
SDRThread *getSDRThread();
|
||||
|
||||
void bindDemodulator(DemodulatorInstancePtr demod);
|
||||
void bindDemodulators(const std::vector<DemodulatorInstancePtr>& demods);
|
||||
void notifyDemodulatorsChanged();
|
||||
|
||||
void removeDemodulator(DemodulatorInstancePtr demod);
|
||||
|
||||
void setFrequencySnap(int snap);
|
||||
|
@ -85,10 +85,10 @@ DemodulatorInstance::DemodulatorInstance() {
|
||||
DemodulatorInstance::~DemodulatorInstance() {
|
||||
|
||||
//now that DemodulatorInstance are managed through shared_ptr, we
|
||||
//should enter here ONLY when it is no longer used by any piece of code, anywahere.
|
||||
//should enter here ONLY when it is no longer used by any piece of code, anywhere.
|
||||
//so active wait on IsTerminated(), then die.
|
||||
#define TERMINATION_SPIN_WAIT_MS (20)
|
||||
#define MAX_WAIT_FOR_TERMINATION_MS (1000.0)
|
||||
#define MAX_WAIT_FOR_TERMINATION_MS (3000.0)
|
||||
//this is a stupid busy plus sleep loop
|
||||
int nbCyclesToWait = (MAX_WAIT_FOR_TERMINATION_MS / TERMINATION_SPIN_WAIT_MS) + 1;
|
||||
int currentCycle = 0;
|
||||
|
@ -9,9 +9,6 @@
|
||||
//50 ms
|
||||
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
|
||||
|
||||
//1s
|
||||
#define MAX_BLOCKING_DURATION_MICROS (1000 * 1000)
|
||||
|
||||
DemodulatorWorkerThread::DemodulatorWorkerThread() : IOThread(),
|
||||
commandQueue(nullptr), resultQueue(nullptr), cModem(nullptr), cModemKit(nullptr) {
|
||||
}
|
||||
@ -111,7 +108,7 @@ void DemodulatorWorkerThread::run() {
|
||||
result.modemName = cModemName;
|
||||
|
||||
//VSO: blocking push
|
||||
resultQueue->push(result, MAX_BLOCKING_DURATION_MICROS, "resultQueue");
|
||||
resultQueue->push(result);
|
||||
}
|
||||
}
|
||||
// std::cout << "Demodulator worker thread done." << std::endl;
|
||||
|
@ -845,7 +845,7 @@ void BookmarkView::activateBookmark(BookmarkEntryPtr bmEnt) {
|
||||
|
||||
matchingDemod = wxGetApp().getDemodMgr().loadInstance(bmEnt->node);
|
||||
matchingDemod->run();
|
||||
wxGetApp().bindDemodulator(matchingDemod);
|
||||
wxGetApp().notifyDemodulatorsChanged();
|
||||
}
|
||||
|
||||
matchingDemod->setActive(true);
|
||||
|
@ -36,41 +36,12 @@ SDRPostThread::SDRPostThread() : IOThread(), buffers("SDRPostThreadBuffers"), vi
|
||||
SDRPostThread::~SDRPostThread() {
|
||||
}
|
||||
|
||||
void SDRPostThread::bindDemodulator(DemodulatorInstancePtr demod) {
|
||||
void SDRPostThread::notifyDemodulatorsChanged() {
|
||||
|
||||
std::lock_guard < std::mutex > lock(busy_demod);
|
||||
|
||||
demodulators.push_back(demod);
|
||||
doRefresh.store(true);
|
||||
|
||||
}
|
||||
|
||||
void SDRPostThread::bindDemodulators(const std::vector<DemodulatorInstancePtr >& demods) {
|
||||
|
||||
std::lock_guard < std::mutex > lock(busy_demod);
|
||||
|
||||
for (auto di : demods) {
|
||||
demodulators.push_back(di);
|
||||
doRefresh.store(true);
|
||||
}
|
||||
}
|
||||
|
||||
void SDRPostThread::removeDemodulator(DemodulatorInstancePtr demod) {
|
||||
if (!demod) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard < std::mutex > lock(busy_demod);
|
||||
|
||||
auto it = std::find(demodulators.begin(), demodulators.end(), demod);
|
||||
|
||||
if (it != demodulators.end()) {
|
||||
demodulators.erase(it);
|
||||
doRefresh.store(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SDRPostThread::initPFBChannelizer() {
|
||||
// std::cout << "Initializing post-process FIR polyphase filterbank channelizer with " << numChannels << " channels." << std::endl;
|
||||
if (channelizer) {
|
||||
@ -93,6 +64,9 @@ void SDRPostThread::updateActiveDemodulators() {
|
||||
|
||||
long long centerFreq = wxGetApp().getFrequency();
|
||||
|
||||
//retreive the current list of demodulators:
|
||||
auto demodulators = wxGetApp().getDemodMgr().getDemodulators();
|
||||
|
||||
for (auto demod : demodulators) {
|
||||
|
||||
// not in range?
|
||||
@ -189,9 +163,8 @@ void SDRPostThread::run() {
|
||||
if (!iqDataInQueue->pop(data_in, HEARTBEAT_CHECK_PERIOD_MICROS)) {
|
||||
continue;
|
||||
}
|
||||
// std::lock_guard < std::mutex > lock(data_in->m_mutex);
|
||||
|
||||
std::lock_guard < std::mutex > lock(busy_demod);
|
||||
bool doUpdate = false;
|
||||
|
||||
if (data_in && data_in->data.size()) {
|
||||
if(data_in->numChannels > 1) {
|
||||
@ -201,7 +174,6 @@ void SDRPostThread::run() {
|
||||
}
|
||||
}
|
||||
|
||||
bool doUpdate = false;
|
||||
for (size_t j = 0; j < nRunDemods; j++) {
|
||||
DemodulatorInstancePtr demod = runDemods[j];
|
||||
if (abs(frequency - demod->getFrequency()) > (sampleRate / 2)) {
|
||||
@ -210,7 +182,7 @@ void SDRPostThread::run() {
|
||||
}
|
||||
|
||||
//Only update the list of demodulators here
|
||||
if (doUpdate) {
|
||||
if (doUpdate || doRefresh) {
|
||||
updateActiveDemodulators();
|
||||
}
|
||||
} //end while
|
||||
@ -259,9 +231,9 @@ void SDRPostThread::runSingleCH(SDRThreadIQData *data_in) {
|
||||
}
|
||||
|
||||
size_t refCount = nRunDemods;
|
||||
bool doIQDataOut = (iqDataOutQueue != NULL && !iqDataOutQueue->full());
|
||||
bool doIQDataOut = (iqDataOutQueue != nullptr && !iqDataOutQueue->full());
|
||||
bool doDemodVisOut = (nRunDemods && iqActiveDemodVisualQueue != NULL && !iqActiveDemodVisualQueue->full());
|
||||
bool doVisOut = (iqVisualQueue != NULL && !iqVisualQueue->full());
|
||||
bool doVisOut = (iqVisualQueue != nullptr && !iqVisualQueue->full());
|
||||
|
||||
if (doIQDataOut) {
|
||||
refCount++;
|
||||
@ -290,22 +262,26 @@ void SDRPostThread::runSingleCH(SDRThreadIQData *data_in) {
|
||||
|
||||
if (doDemodVisOut) {
|
||||
//VSO: blocking push
|
||||
iqActiveDemodVisualQueue->push(demodDataOut, MAX_BLOCKING_DURATION_MICROS, "runSingleCH() iqActiveDemodVisualQueue");
|
||||
iqActiveDemodVisualQueue->push(demodDataOut);
|
||||
}
|
||||
|
||||
if (doIQDataOut) {
|
||||
//VSO: blocking push
|
||||
iqDataOutQueue->push(demodDataOut, MAX_BLOCKING_DURATION_MICROS,"runSingleCH() iqDataOutQueue");
|
||||
iqDataOutQueue->push(demodDataOut);
|
||||
}
|
||||
|
||||
if (doVisOut) {
|
||||
//VSO: blocking push
|
||||
iqVisualQueue->push(demodDataOut, MAX_BLOCKING_DURATION_MICROS, "runSingleCH() iqVisualQueue");
|
||||
iqVisualQueue->push(demodDataOut);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nRunDemods; i++) {
|
||||
//VSO: blocking push
|
||||
runDemods[i]->getIQInputDataPipe()->push(demodDataOut, MAX_BLOCKING_DURATION_MICROS, "runSingleCH() runDemods[i]->getIQInputDataPipe()");
|
||||
//VSO: timed-push
|
||||
if (!runDemods[i]->getIQInputDataPipe()->push(demodDataOut, MAX_BLOCKING_DURATION_MICROS, "runSingleCH() runDemods[i]->getIQInputDataPipe()")) {
|
||||
//some runDemods are no longer there, bail out from runSingleCH() entirely.
|
||||
doRefresh = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -342,11 +318,11 @@ void SDRPostThread::runPFBCH(SDRThreadIQData *data_in) {
|
||||
iqDataOut->data.assign(data_in->data.begin(), data_in->data.begin() + dataSize);
|
||||
|
||||
//VSO: blocking push
|
||||
iqDataOutQueue->push(iqDataOut, MAX_BLOCKING_DURATION_MICROS, "runPFBCH() iqDataOutQueue");
|
||||
iqDataOutQueue->push(iqDataOut);
|
||||
|
||||
if (doVis) {
|
||||
//VSO: blocking push
|
||||
iqVisualQueue->push(iqDataOut, MAX_BLOCKING_DURATION_MICROS, "runPFBCH() iqVisualQueue");
|
||||
iqVisualQueue->push(iqDataOut);
|
||||
}
|
||||
}
|
||||
|
||||
@ -442,16 +418,20 @@ void SDRPostThread::runPFBCH(SDRThreadIQData *data_in) {
|
||||
|
||||
if (doDemodVis) {
|
||||
//VSO: blocking push
|
||||
iqActiveDemodVisualQueue->push(demodDataOut, MAX_BLOCKING_DURATION_MICROS, "runPFBCH() iqActiveDemodVisualQueue");
|
||||
iqActiveDemodVisualQueue->push(demodDataOut);
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < nRunDemods; j++) {
|
||||
if (demodChannel[j] == i) {
|
||||
|
||||
//VSO: blocking push
|
||||
runDemods[j]->getIQInputDataPipe()->push(demodDataOut, MAX_BLOCKING_DURATION_MICROS, "runPFBCH() demod->getIQInputDataPipe()");
|
||||
//VSO: timed- push
|
||||
if (!runDemods[j]->getIQInputDataPipe()->push(demodDataOut, MAX_BLOCKING_DURATION_MICROS, "runPFBCH() runDemods[j]->getIQInputDataPipe()")) {
|
||||
//Some runDemods are no longer there, bail out from runPFBCH() entirely.
|
||||
doRefresh = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} //end for
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,7 @@ public:
|
||||
SDRPostThread();
|
||||
~SDRPostThread();
|
||||
|
||||
void bindDemodulator(DemodulatorInstancePtr demod);
|
||||
void bindDemodulators(const std::vector<DemodulatorInstancePtr>& demods);
|
||||
void removeDemodulator(DemodulatorInstancePtr demod);
|
||||
void notifyDemodulatorsChanged();
|
||||
|
||||
virtual void run();
|
||||
virtual void terminate();
|
||||
@ -28,12 +26,6 @@ protected:
|
||||
DemodulatorThreadInputQueuePtr iqVisualQueue;
|
||||
DemodulatorThreadInputQueuePtr iqActiveDemodVisualQueue;
|
||||
|
||||
//protects access to demodulators lists and such
|
||||
std::mutex busy_demod;
|
||||
std::vector<DemodulatorInstancePtr> demodulators;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void initPFBChannelizer();
|
||||
|
@ -729,7 +729,7 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) {
|
||||
demod->writeModemSettings(mgr->getLastModemSettings(mgr->getLastDemodulatorType()));
|
||||
demod->run();
|
||||
|
||||
wxGetApp().bindDemodulator(demod);
|
||||
wxGetApp().notifyDemodulatorsChanged();
|
||||
DemodulatorThread::releaseSquelchLock(nullptr);
|
||||
}
|
||||
|
||||
@ -829,7 +829,7 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) {
|
||||
|
||||
demod->run();
|
||||
|
||||
wxGetApp().bindDemodulator(demod);
|
||||
wxGetApp().notifyDemodulatorsChanged();
|
||||
}
|
||||
|
||||
if (demod == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user