1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00

Compare commits

...

6 Commits

Author SHA1 Message Date
f4exb
1ef45efc4a use inline instead of static for code that is header only 2022-03-03 23:24:31 +01:00
f4exb
22381c5dbc ValueDialZ: fix find exponent. Fixes #1158 2022-03-03 23:23:54 +01:00
Edouard Griffiths
9a733527bb
Merge pull request #1172 from srcejon/fix_1161_sdrplay
SDRplayInput - Ensure decimation length is power of two
2022-03-03 21:04:55 +01:00
Edouard Griffiths
36876c053f
Merge pull request #1171 from srcejon/fix_1153
Rotator controller - Open/close serial ports in worker thread.
2022-03-03 19:06:52 +01:00
Jon Beniston
84865a6f8e SDRplayInput - Use buffer to ensure lenght of data passed to decimators is always a power of two. 2022-03-03 15:04:59 +00:00
Jon Beniston
994cadc91f Open/close serial ports in worker thread. Fix for #1153 2022-03-03 11:06:18 +00:00
6 changed files with 50 additions and 17 deletions

View File

@ -45,8 +45,6 @@ GS232ControllerWorker::GS232ControllerWorker() :
m_spidStatusSent(false),
m_rotCtlDReadAz(false)
{
connect(&m_pollTimer, SIGNAL(timeout()), this, SLOT(update()));
m_pollTimer.start(1000);
}
GS232ControllerWorker::~GS232ControllerWorker()
@ -69,6 +67,15 @@ bool GS232ControllerWorker::startWork()
{
QMutexLocker mutexLocker(&m_mutex);
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
connect(thread(), SIGNAL(started()), this, SLOT(started()));
connect(thread(), SIGNAL(finished()), this, SLOT(finished()));
m_running = true;
return m_running;
}
// startWork() is called from main thread. Serial ports on Linux need to be opened/closed on worker thread
void GS232ControllerWorker::started()
{
connect(&m_serialPort, &QSerialPort::readyRead, this, &GS232ControllerWorker::readData);
connect(&m_socket, &QTcpSocket::readyRead, this, &GS232ControllerWorker::readData);
if (m_settings.m_connection == GS232ControllerSettings::TCP) {
@ -76,21 +83,29 @@ bool GS232ControllerWorker::startWork()
} else {
m_device = openSerialPort(m_settings);
}
m_running = true;
return m_running;
connect(&m_pollTimer, SIGNAL(timeout()), this, SLOT(update()));
m_pollTimer.start(1000);
disconnect(thread(), SIGNAL(started()), this, SLOT(started()));
}
void GS232ControllerWorker::stopWork()
{
QMutexLocker mutexLocker(&m_mutex);
disconnect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
}
void GS232ControllerWorker::finished()
{
// Close serial port as USB/controller activity can create RFI
if (m_device && m_device->isOpen()) {
m_device->close();
}
disconnect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
disconnect(&m_serialPort, &QSerialPort::readyRead, this, &GS232ControllerWorker::readData);
disconnect(&m_socket, &QTcpSocket::readyRead, this, &GS232ControllerWorker::readData);
m_pollTimer.stop();
disconnect(&m_pollTimer, SIGNAL(timeout()), this, SLOT(update()));
m_running = false;
disconnect(thread(), SIGNAL(finished()), this, SLOT(finished()));
}
void GS232ControllerWorker::handleInputMessages()

View File

@ -95,6 +95,8 @@ private:
void setAzimuthElevation(float azimuth, float elevation);
private slots:
void started();
void finished();
void handleInputMessages();
void readData();
void update();

View File

@ -22,6 +22,7 @@
#include <thread>
#include "sdrplayv3thread.h"
#include "dsp/samplesinkfifo.h"
#include "util/poweroftwo.h"
#include <QDebug>
@ -34,7 +35,8 @@ SDRPlayV3Thread::SDRPlayV3Thread(sdrplay_api_DeviceT* dev, SampleSinkFifo* sampl
m_samplerate(2000000),
m_log2Decim(0),
m_fcPos(0),
m_iqOrder(true)
m_iqOrder(true),
m_iqCount(0)
{
}
@ -134,27 +136,37 @@ void SDRPlayV3Thread::callbackHelper(short *xi, short *xq, sdrplay_api_StreamCbP
(void) params;
(void) reset;
SDRPlayV3Thread* thread = (SDRPlayV3Thread*) ctx;
qint16 iq[8192];
if (params->rfChanged)
thread->m_rfChanged = params->rfChanged;
if (thread->m_running)
{
if (numSamples > 8192)
qCritical() << "SDRPlayV3Thread::callbackHelper: IQ buffer too small: " << numSamples;
// Interleave samples
for (int i = 0; i < (int)numSamples; i++)
{
iq[i*2] = xi[i];
iq[i*2+1] = xq[i];
thread->m_iq[thread->m_iqCount+i*2] = xi[i];
thread->m_iq[thread->m_iqCount+i*2+1] = xq[i];
}
thread->m_iqCount += numSamples * 2;
if (thread->m_iqCount > 8192) {
qCritical() << "SDRPlayV3Thread::callbackHelper: IQ buffer too small: " << numSamples;
}
// Decimators require length to be a power of 2
int iqLen = lowerPowerOfTwo(thread->m_iqCount);
if (thread->m_iqOrder) {
thread->callbackIQ(iq, numSamples*2);
thread->callbackIQ(thread->m_iq, iqLen);
} else {
thread->callbackQI(iq, numSamples*2);
thread->callbackQI(thread->m_iq, iqLen);
}
// Shuffle buffer up
int iqRemaining = thread->m_iqCount - iqLen;
memmove(thread->m_iq, &thread->m_iq[iqLen], iqRemaining * sizeof(qint16));
thread->m_iqCount = iqRemaining;
}
}

View File

@ -60,6 +60,9 @@ private:
int m_fcPos;
bool m_iqOrder;
qint16 m_iq[8192];
int m_iqCount;
int m_rfChanged;
static const unsigned int m_rfChangedTimeout = 500;

View File

@ -22,14 +22,14 @@
// Is x a power of two
// From: https://stackoverflow.com/questions/600293/how-to-check-if-a-number-is-a-power-of-2
static bool isPowerOfTwo(uint32_t x)
inline bool isPowerOfTwo(uint32_t x)
{
return (x & (x - 1)) == 0;
}
// Calculate next power of 2 lower than x
// From: https://stackoverflow.com/questions/2679815/previous-power-of-2
static uint32_t lowerPowerOfTwo(uint32_t x)
inline uint32_t lowerPowerOfTwo(uint32_t x)
{
x = x | (x >> 1);
x = x | (x >> 2);

View File

@ -173,7 +173,8 @@ quint64 ValueDialZ::findExponent(int digit)
for (int i = s+1; i < d+s; i++)
{
if ((i%4 == 0) || (m_positiveOnly && (i == d+s-1))) { // non digit positions
// if ((i%4 == 0) || (m_positiveOnly && (i == d+s-1))) { // non digit positions
if (i%4 == 0) {
continue;
}