1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05:00

Have a specialized class for UDP output (debug purpose)

This commit is contained in:
f4exb 2015-12-12 23:01:46 +01:00
parent 1be47adfef
commit 74e338f092
3 changed files with 104 additions and 44 deletions

81
include/util/udpsink.h Normal file
View File

@ -0,0 +1,81 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 F4EXB //
// written by Edouard Griffiths //
// //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_UTIL_UDPSINK_H_
#define INCLUDE_UTIL_UDPSINK_H_
#include <QObject>
#include <QUdpSocket>
#include <QHostAddress>
template<typename T>
class UDPSink
{
public:
UDPSink(QObject *parent, unsigned int udpSize, unsigned int port) :
m_udpSize(udpSize),
m_address(QHostAddress::LocalHost),
m_port(port),
m_sampleBufferIndex(0)
{
m_sampleBuffer = new T[m_udpSize];
m_socket = new QUdpSocket(parent);
}
UDPSink (QObject *parent, unsigned int udpSize, QHostAddress& address, unsigned int port) :
m_udpSize(udpSize),
m_address(address),
m_port(port),
m_sampleBufferIndex(0)
{
m_sampleBuffer = new T[m_udpSize];
m_socket = new QUdpSocket(parent);
}
~UDPSink()
{
delete[] m_sampleBuffer;
delete m_socket;
}
void write(T sample)
{
m_sampleBuffer[m_sampleBufferIndex] = sample;
if (m_sampleBufferIndex < m_udpSize)
{
m_sampleBufferIndex++;
}
else
{
m_socket->writeDatagram((const char*)&m_sampleBuffer[0], (qint64 ) (m_udpSize * sizeof(T)), m_address, m_port);
m_sampleBufferIndex = 0;
}
}
private:
unsigned int m_udpSize;
QHostAddress m_address;
unsigned int m_port;
QUdpSocket *m_socket;
T *m_sampleBuffer;;
int m_sampleBufferIndex;
};
#endif /* INCLUDE_UTIL_UDPSINK_H_ */

View File

@ -26,7 +26,8 @@ const Real RDSDemod::m_pllBeta = 50;
const int RDSDemod::m_udpSize = 1472;
const Real RDSDemod::m_fsc = 1187.5;
RDSDemod::RDSDemod()
RDSDemod::RDSDemod() :
m_udpDebug(this, 1472, 9995)
{
m_srate = 250000;
@ -35,29 +36,19 @@ RDSDemod::RDSDemod()
m_parms.clock_phi = 0;
m_parms.prev_clock_phi = 0;
m_parms.lo_clock = 0;
m_parms.prevclock = 0;
m_parms.prev_lo_clock = 0;
m_parms.prev_bb = 0;
m_parms.d_phi_sc = 0;
m_parms.d_cphi = 0;
m_parms.acc = 0;
m_parms.subcarr_sample = 0;
m_parms.c = 0;
m_parms.fmfreq = 0;
m_parms.bytesread;
m_parms.numsamples = 0;
m_parms.loop_out = 0;
m_parms.prev_loop = 0;
m_parms.prev_acc = 0;
m_parms.counter = 0;
m_parms.reading_frame = 0;
m_socket = new QUdpSocket(this);
m_sampleBufferIndex = 0;
}
RDSDemod::~RDSDemod()
{
delete m_socket;
//delete m_socket;
}
void RDSDemod::setSampleRate(int srate) /// FIXME: fix rate for now
@ -66,17 +57,7 @@ void RDSDemod::setSampleRate(int srate) /// FIXME: fix rate for now
void RDSDemod::process(Real demod, Real pilot)
{
m_sampleBuffer[m_sampleBufferIndex] = m_parms.lo_clock * m_parms.subcarr_bb[0]; // UDP debug
if (m_sampleBufferIndex < m_udpSize)
{
m_sampleBufferIndex++;
}
else
{
m_socket->writeDatagram((const char*)&m_sampleBuffer[0], (qint64 ) (m_udpSize * sizeof(Real)), QHostAddress::LocalHost, 9995);
m_sampleBufferIndex = 0;
}
m_udpDebug.write(m_parms.lo_clock * m_parms.subcarr_bb[0]);
// Subcarrier downmix & phase recovery
@ -84,6 +65,14 @@ void RDSDemod::process(Real demod, Real pilot)
// 1187.5 Hz clock
/*
if (m_parms.subcarr_phi > 1e9) // ~ every 37 hours => not really useful
{
qDebug("RDSDemod::process: reset 1187.5 Hz clock");
m_parms.subcarr_phi = 0;
m_parms.clock_offset = 0;
}*/
m_parms.subcarr_phi += (2 * M_PI * m_fsc) / (Real) m_srate;
m_parms.clock_phi = m_parms.subcarr_phi + m_parms.clock_offset;
@ -110,13 +99,13 @@ void RDSDemod::process(Real demod, Real pilot)
/* biphase symbol integrate & dump */
m_parms.acc += m_parms.subcarr_bb[0] * m_parms.lo_clock;
if (sign(m_parms.lo_clock) != sign(m_parms.prevclock))
if (sign(m_parms.lo_clock) != sign(m_parms.prev_lo_clock))
{
biphase(m_parms.acc, m_parms.clock_phi - m_parms.prev_clock_phi);
m_parms.acc = 0;
}
m_parms.prevclock = m_parms.lo_clock;
m_parms.prev_lo_clock = m_parms.lo_clock;
}
m_parms.numsamples++;

View File

@ -20,8 +20,7 @@
#define PLUGINS_CHANNEL_BFM_RDSDEMOD_H_
#include <QObject>
#include <QHostAddress>
#include <QUdpSocket>
#include "util/udpsink.h"
#include "dsp/dsptypes.h"
@ -45,24 +44,17 @@ private:
struct
{
double subcarr_phi;
double subcarr_bb[2];
Real subcarr_bb[2];
double clock_offset;
double clock_phi;
double prev_clock_phi;
double lo_clock;
double prevclock;
double prev_bb;
double d_phi_sc;
Real lo_clock;
Real prev_lo_clock;
Real prev_bb;
double d_cphi;
double acc;
double subcarr_sample;
int c;
int fmfreq;
int bytesread;
Real acc;
int numsamples;
double loop_out;
double prev_loop;
double prev_acc;
Real prev_acc;
int counter;
int reading_frame;
int tot_errs[2];
@ -76,9 +68,7 @@ private:
int m_srate;
QUdpSocket *m_socket;
Real m_sampleBuffer[1<<12];
int m_sampleBufferIndex;
UDPSink<Real> m_udpDebug;
static const int m_udpSize;
static const Real m_pllBeta;