diff --git a/plugins/samplesource/perseus/perseusthread.cpp b/plugins/samplesource/perseus/perseusthread.cpp new file mode 100644 index 000000000..eff34912c --- /dev/null +++ b/plugins/samplesource/perseus/perseusthread.cpp @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include "perseusthread.h" + +void PerseusThread::run() +{ + m_running = true; + m_startWaiter.wakeAll(); + + int rc = perseus_start_async_input(m_dev, 6*1024, rx_callback, 0); + + if (rc < 0) { + qCritical("PerseusThread::run: failed to start Perseus Rx: %s", perseus_errorstr()); + } + else + { + while (m_running) { + sleep(1); + } + } + + rc = perseus_stop_async_input(m_dev); + + if (rc < 0) { + qCritical("PerseusThread::run: failed to stop Perseus Rx: %s", perseus_errorstr()); + } else { + qDebug("PerseusThread::run: stopped Perseus Rx"); + } + + m_running = false; +} + +void PerseusThread::callback(const uint8_t* buf, qint32 len) +{ + +} + +int PerseusThread::rx_callback(void *buf, int buf_size, void *extra) +{ + qint32 nbIAndQ = buf_size / 3; // 3 bytes per I or Q + m_this->callback((uint8_t*) buf, nbIAndQ); +} + diff --git a/plugins/samplesource/perseus/perseusthread.h b/plugins/samplesource/perseus/perseusthread.h new file mode 100644 index 000000000..2929dd4dd --- /dev/null +++ b/plugins/samplesource/perseus/perseusthread.h @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSTHREAD_H_ +#define PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSTHREAD_H_ + +#include +#include +#include +#include "perseus-sdr.h" + +//#define PERSEUS_NBSAMPLES = 1024 // Number of I/Q samples in each callback from Perseus +//#define PERSEUS_BLOCKSIZE = 6*PERSEUS_NBSAMPLES // Perseus sends 2*3 bytes samples + +class PerseusThread : public QThread { + Q_OBJECT + +public: + PerseusThread(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0); + ~PerseusThread(); + + void startWork(); + void stopWork(); + void setSamplerate(uint32_t samplerate); + void setLog2Decimation(unsigned int log2_decim); + +private: + QMutex m_startWaitMutex; + QWaitCondition m_startWaiter; + bool m_running; + + perseus_descr* m_dev; + qint32 m_buf[2*1024]; + SampleVector m_convertBuffer; + SampleSinkFifo* m_sampleFifo; + + int m_samplerate; + unsigned int m_log2Decim; + static PerseusThread *m_this; + + Decimators m_decimators; + + void run(); + void callback(const uint8_t* buf, qint32 len); // inner call back + static int rx_callback(void *buf, int buf_size, void *extra); // call back from Perseus +}; + +#endif /* PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSTHREAD_H_ */