mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 09:48:45 -05:00
Morse Decoder: adeed scope and set bytes block size appropriately plus minor changes
This commit is contained in:
parent
31274b1227
commit
1edaa0d98a
@ -128,9 +128,13 @@ void MorseDecoder::start()
|
|||||||
m_state = StRunning;
|
m_state = StRunning;
|
||||||
m_thread->start();
|
m_thread->start();
|
||||||
|
|
||||||
MorseDecoderWorker::MsgConfigureMorseDecoderWorker *msg
|
MorseDecoderWorker::MsgConfigureMorseDecoderWorker *msgConfigure
|
||||||
= MorseDecoderWorker::MsgConfigureMorseDecoderWorker::create(m_settings, QList<QString>(), true);
|
= MorseDecoderWorker::MsgConfigureMorseDecoderWorker::create(m_settings, QList<QString>(), true);
|
||||||
m_worker->getInputMessageQueue()->push(msg);
|
m_worker->getInputMessageQueue()->push(msgConfigure);
|
||||||
|
|
||||||
|
MorseDecoderWorker::MsgConfigureSampleRate *msgSampleRate
|
||||||
|
= MorseDecoderWorker::MsgConfigureSampleRate::create(m_sampleRate);
|
||||||
|
m_worker->getInputMessageQueue()->push(msgSampleRate);
|
||||||
|
|
||||||
if (m_dataPipe)
|
if (m_dataPipe)
|
||||||
{
|
{
|
||||||
@ -217,6 +221,7 @@ bool MorseDecoder::handleMessage(const Message& cmd)
|
|||||||
if (report.getChannelAPI() == m_selectedChannel)
|
if (report.getChannelAPI() == m_selectedChannel)
|
||||||
{
|
{
|
||||||
m_sampleRate = report.getSampleRate();
|
m_sampleRate = report.getSampleRate();
|
||||||
|
qDebug("MorseDecoder::handleMessage: MainCore::MsgChannelDemodReport: %d S/s", m_sampleRate);
|
||||||
|
|
||||||
if (m_running) {
|
if (m_running) {
|
||||||
m_worker->applySampleRate(m_sampleRate);
|
m_worker->applySampleRate(m_sampleRate);
|
||||||
|
@ -196,7 +196,7 @@ MorseDecoderGUI::MorseDecoderGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISe
|
|||||||
m_scopeVis = m_morseDecoder->getScopeVis();
|
m_scopeVis = m_morseDecoder->getScopeVis();
|
||||||
m_scopeVis->setGLScope(ui->glScope);
|
m_scopeVis->setGLScope(ui->glScope);
|
||||||
ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope);
|
ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope);
|
||||||
m_scopeVis->setLiveRate(1484/4.7488);
|
m_scopeVis->setLiveRate(4800); // 1 second
|
||||||
|
|
||||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
|
||||||
connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
||||||
|
@ -270,16 +270,26 @@ QString MorseDecoderSettings::formatText(const QString& text)
|
|||||||
{
|
{
|
||||||
// Format text
|
// Format text
|
||||||
QString showText = text.simplified();
|
QString showText = text.simplified();
|
||||||
|
QString spaceFirst;
|
||||||
|
QString spaceLast;
|
||||||
|
|
||||||
if (text.size() > 3)
|
if (text.size() >= 2)
|
||||||
{
|
{
|
||||||
if (text.right(1)[0].isSpace()) {
|
if (text.right(1)[0].isSpace()) {
|
||||||
showText.append(text.right(1));
|
spaceLast = text.right(1);
|
||||||
}
|
}
|
||||||
if (text.left(1)[0].isSpace()) {
|
if (text.left(1)[0].isSpace()) {
|
||||||
showText = text.left(1) + showText;
|
spaceFirst = text.left(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (spaceFirst.size() != 0) {
|
||||||
|
showText = spaceFirst + showText;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spaceLast.size() != 0) {
|
||||||
|
showText.append(spaceLast);
|
||||||
|
}
|
||||||
|
|
||||||
return showText;
|
return showText;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "morsedecoderworker.h"
|
#include "morsedecoderworker.h"
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(MorseDecoderWorker::MsgConfigureMorseDecoderWorker, Message)
|
MESSAGE_CLASS_DEFINITION(MorseDecoderWorker::MsgConfigureMorseDecoderWorker, Message)
|
||||||
|
MESSAGE_CLASS_DEFINITION(MorseDecoderWorker::MsgConfigureSampleRate, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(MorseDecoderWorker::MsgConnectFifo, Message)
|
MESSAGE_CLASS_DEFINITION(MorseDecoderWorker::MsgConnectFifo, Message)
|
||||||
|
|
||||||
MorseDecoderWorker::MorseDecoderWorker() :
|
MorseDecoderWorker::MorseDecoderWorker() :
|
||||||
@ -92,42 +93,17 @@ void MorseDecoderWorker::feedPart(
|
|||||||
DataFifo::DataType dataType
|
DataFifo::DataType dataType
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if (dataType != DataFifo::DataTypeI16) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int countBytes = end - begin;
|
int countBytes = end - begin;
|
||||||
int bytesLeft = m_bytesBufferSize - m_bytesBufferCount;
|
int bytesLeft = m_bytesBufferSize - m_bytesBufferCount;
|
||||||
|
|
||||||
if (dataType == DataFifo::DataTypeCI16) // (re, im) -> one sample conversion
|
if (countBytes > m_bytesBufferSize) {
|
||||||
{
|
return;
|
||||||
countBytes /= 2;
|
|
||||||
|
|
||||||
if (countBytes != m_convBuffer.size()) {
|
|
||||||
m_convBuffer.resize(countBytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t *s = (int16_t*) begin;
|
|
||||||
int16_t *b = (int16_t*) m_convBuffer.begin();
|
|
||||||
|
|
||||||
for (int is = 0; is < countBytes; is++)
|
|
||||||
{
|
|
||||||
int32_t re = s[2*is];
|
|
||||||
int32_t im = s[2*is+1];
|
|
||||||
b[is] = (int16_t) ((re+im) / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (countBytes >= bytesLeft)
|
|
||||||
{
|
|
||||||
std::copy(m_convBuffer.begin(), m_convBuffer.begin() + bytesLeft, m_bytesBuffer.begin() + m_bytesBufferCount); // fill buffer
|
|
||||||
int unprocessedBytes = processBuffer(m_convBuffer, countBytes);
|
|
||||||
std::copy(m_convBuffer.begin() + bytesLeft - unprocessedBytes, m_convBuffer.end(), m_bytesBuffer.begin());
|
|
||||||
m_bytesBufferCount = bytesLeft + unprocessedBytes;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::copy(m_convBuffer.begin(), m_convBuffer.end(), m_bytesBuffer.begin() + m_bytesBufferCount);
|
|
||||||
m_bytesBufferCount += countBytes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (countBytes >= bytesLeft)
|
if (countBytes >= bytesLeft)
|
||||||
{
|
{
|
||||||
std::copy(begin, begin + bytesLeft, m_bytesBuffer.begin() + m_bytesBufferCount); // fill buffer
|
std::copy(begin, begin + bytesLeft, m_bytesBuffer.begin() + m_bytesBufferCount); // fill buffer
|
||||||
@ -141,7 +117,6 @@ void MorseDecoderWorker::feedPart(
|
|||||||
m_bytesBufferCount += countBytes;
|
m_bytesBufferCount += countBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int MorseDecoderWorker::processBuffer(QByteArray& bytesBuffer, int countBytes)
|
int MorseDecoderWorker::processBuffer(QByteArray& bytesBuffer, int countBytes)
|
||||||
{
|
{
|
||||||
@ -203,27 +178,31 @@ int MorseDecoderWorker::processBuffer(QByteArray& bytesBuffer, int countBytes)
|
|||||||
int traceSize = m_ggMorse->takeSignalF(trace);
|
int traceSize = m_ggMorse->takeSignalF(trace);
|
||||||
std::vector<float> thresholds;
|
std::vector<float> thresholds;
|
||||||
int thrSize = m_ggMorse->takeThresholdF(thresholds);
|
int thrSize = m_ggMorse->takeThresholdF(thresholds);
|
||||||
qDebug("MorseDecoderWorker::processBuffer: traceSize: %d thrSize: %d", traceSize, thrSize);
|
// qDebug("MorseDecoderWorker::processBuffer: traceSize: %d thrSize: %d", traceSize, thrSize);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int d = (traceSize / thrSize) + 1;
|
float ftrace = traceSize / 4800.0f; // interpolation to scope basic trace size
|
||||||
|
float fthres = thrSize / 4800.0f;
|
||||||
|
|
||||||
if (traceSize != 0)
|
if (traceSize != 0)
|
||||||
{
|
{
|
||||||
SampleVector strace;
|
SampleVector strace;
|
||||||
strace.resize(traceSize);
|
strace.resize(4800, 0);
|
||||||
std::transform(
|
std::for_each(
|
||||||
trace.begin(),
|
|
||||||
trace.end(),
|
|
||||||
strace.begin(),
|
strace.begin(),
|
||||||
[&](float& t) {
|
strace.end(),
|
||||||
float im = thresholds[i/d];
|
[&](Sample& s)
|
||||||
|
{
|
||||||
|
int itrace = ftrace * i;
|
||||||
|
int ithres = fthres * i;
|
||||||
|
float re = trace[itrace];
|
||||||
|
float im = thresholds[ithres];
|
||||||
i++;
|
i++;
|
||||||
return Sample(t*SDR_RX_SCALEF, im*SDR_RX_SCALEF);
|
s = Sample(re*SDR_RX_SCALEF, im*SDR_RX_SCALEF);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
std::vector<SampleVector::const_iterator> vbegin;
|
std::vector<SampleVector::const_iterator> vbegin;
|
||||||
vbegin.push_back(strace.begin());
|
vbegin.push_back(strace.begin());
|
||||||
m_scopeVis->feed(vbegin, traceSize);
|
m_scopeVis->feed(vbegin, 4800);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,6 +234,15 @@ bool MorseDecoderWorker::handleMessage(const Message& cmd)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (MsgConfigureSampleRate::match(cmd))
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
MsgConfigureSampleRate& cfg = (MsgConfigureSampleRate&) cmd;
|
||||||
|
qDebug("MorseDecoderWorker::handleMessage: MsgConfigureSampleRate");
|
||||||
|
applySampleRate(cfg.getSampleRate());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else if (MsgConnectFifo::match(cmd))
|
else if (MsgConnectFifo::match(cmd))
|
||||||
{
|
{
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
@ -323,14 +311,18 @@ void MorseDecoderWorker::applySettings(const MorseDecoderSettings& settings, con
|
|||||||
|
|
||||||
void MorseDecoderWorker::applySampleRate(int sampleRate)
|
void MorseDecoderWorker::applySampleRate(int sampleRate)
|
||||||
{
|
{
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
|
||||||
m_sinkSampleRate = sampleRate;
|
m_sinkSampleRate = sampleRate;
|
||||||
m_ggMorseParameters->sampleRateInp = sampleRate;
|
m_ggMorseParameters->sampleRateInp = sampleRate;
|
||||||
int ggMorseBlockSize = (sampleRate / GGMorse::kBaseSampleRate)*GGMorse::kDefaultSamplesPerFrame;
|
int ggMorseBlockSize = (sampleRate / GGMorse::kBaseSampleRate)*GGMorse::kDefaultSamplesPerFrame;
|
||||||
// m_bytesBufferSize = (GGMorse::kBaseSampleRate/GGMorse::kDefaultSamplesPerFrame)*ggMorseBlockSize*10; // ~5s
|
m_bytesBufferSize = 64*ggMorseBlockSize*2;
|
||||||
m_bytesBufferSize = sampleRate*9.4976; // + ggMorseBlockSize;
|
|
||||||
m_bytesBuffer.resize(m_bytesBufferSize);
|
m_bytesBuffer.resize(m_bytesBufferSize);
|
||||||
m_bytesBufferCount = 0;
|
m_bytesBufferCount = 0;
|
||||||
|
float seconds = m_bytesBufferSize/(sampleRate*2.0f);
|
||||||
|
|
||||||
|
if (m_scopeVis) {
|
||||||
|
m_scopeVis->setLiveRate(4800/seconds);
|
||||||
|
}
|
||||||
|
|
||||||
qDebug("MorseDecoderWorker::applySampleRate: m_sinkSampleRate: %d ggMorseBlockSize: %d m_bytesBufferSize: %d",
|
qDebug("MorseDecoderWorker::applySampleRate: m_sinkSampleRate: %d ggMorseBlockSize: %d m_bytesBufferSize: %d",
|
||||||
m_sinkSampleRate, ggMorseBlockSize, m_bytesBufferSize);
|
m_sinkSampleRate, ggMorseBlockSize, m_bytesBufferSize);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,26 @@ public:
|
|||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MsgConfigureSampleRate : public Message {
|
||||||
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
public:
|
||||||
|
int getSampleRate() const { return m_sampleRate; }
|
||||||
|
|
||||||
|
static MsgConfigureSampleRate* create(int sampleRate)
|
||||||
|
{
|
||||||
|
return new MsgConfigureSampleRate(sampleRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_sampleRate;
|
||||||
|
|
||||||
|
MsgConfigureSampleRate(int sampleRate) :
|
||||||
|
Message(),
|
||||||
|
m_sampleRate(sampleRate)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
class MsgConnectFifo : public Message {
|
class MsgConnectFifo : public Message {
|
||||||
MESSAGE_CLASS_DECLARATION
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user