From d2c3985de0361b61959c493ff8d67d7f65b7cd0d Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 21 Aug 2018 08:51:10 +0200 Subject: [PATCH] SDRdaemon: UDP channel sink (2) --- sdrdaemon/channel/sdrdaemonchannelsink.cpp | 58 +++++++++++++++++++++- sdrdaemon/channel/sdrdaemonchannelsink.h | 4 ++ sdrdaemon/channel/sdrdaemondatablock.h | 2 +- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.cpp b/sdrdaemon/channel/sdrdaemonchannelsink.cpp index 1cf840aec..b34f18c63 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsink.cpp +++ b/sdrdaemon/channel/sdrdaemonchannelsink.cpp @@ -20,6 +20,11 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include + #include "util/simpleserializer.h" #include "dsp/threadedbasebandsamplesink.h" #include "dsp/downchannelizer.h" @@ -59,12 +64,63 @@ SDRDaemonChannelSink::~SDRDaemonChannelSink() void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused))) { - qDebug("SDRDaemonChannelSink::feed: received %d samples", (int) (end - begin)); + SampleVector::const_iterator it = begin; + + while (it != end) + { + int inSamplesIndex = it - begin; + int inRemainingSamples = end - it; + + if (m_txBlockIndex == 0) + { + struct timeval tv; + SDRDaemonMetaDataFEC metaData; + gettimeofday(&tv, 0); + + metaData.m_centerFrequency = 0; // TODO + metaData.m_sampleRate = 48000; // TODO + metaData.m_sampleBytes = SDR_RX_SAMP_SZ/8; + metaData.m_sampleBits = SDR_RX_SAMP_SZ; + metaData.m_nbOriginalBlocks = SDRDaemonNbOrginalBlocks; + metaData.m_nbFECBlocks = 8; // TODO + metaData.m_tv_sec = tv.tv_sec; + metaData.m_tv_usec = tv.tv_usec; + + boost::crc_32_type crc32; + crc32.process_bytes(&metaData, 20); + metaData.m_crc32 = crc32.checksum(); + SDRDaemonSuperBlock& superBlock = m_dataBlock.m_superBlocks[0]; // first block + + memset((void *) &superBlock, 0, SDRDaemonUdpSize); + + superBlock.m_header.m_frameIndex = m_frameCount; + superBlock.m_header.m_blockIndex = m_txBlockIndex; + memcpy((void *) &superBlock.m_protectedBlock, (const void *) &metaData, sizeof(SDRDaemonMetaDataFEC)); + + if (!(metaData == m_currentMetaFEC)) + { + qDebug() << "SDRDaemonChannelSink::feed: meta: " + << "|" << metaData.m_centerFrequency + << ":" << metaData.m_sampleRate + << ":" << (int) (metaData.m_sampleBytes & 0xF) + << ":" << (int) metaData.m_sampleBits + << "|" << (int) metaData.m_nbOriginalBlocks + << ":" << (int) metaData.m_nbFECBlocks + << "|" << metaData.m_tv_sec + << ":" << metaData.m_tv_usec; + + m_currentMetaFEC = metaData; + } + + m_txBlockIndex = 1; // next Tx block with data + } + } } void SDRDaemonChannelSink::start() { qDebug("SDRDaemonChannelSink::start"); + memset((void *) &m_currentMetaFEC, 0, sizeof(SDRDaemonMetaDataFEC)); if (m_running) { stop(); } m_sinkThread = new SDRDaemonChannelSinkThread(&m_dataQueue, m_cm256p); m_running = true; diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.h b/sdrdaemon/channel/sdrdaemonchannelsink.h index 25abbf181..e9e49e4f5 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsink.h +++ b/sdrdaemon/channel/sdrdaemonchannelsink.h @@ -28,6 +28,7 @@ #include "dsp/basebandsamplesink.h" #include "channel/channelsinkapi.h" #include "channel/sdrdaemondataqueue.h" +#include "channel/sdrdaemondatablock.h" class DeviceSourceAPI; class ThreadedBasebandSampleSink; @@ -70,6 +71,9 @@ private: int m_txBlockIndex; //!< Current index in blocks to transmit in the Tx row uint16_t m_frameCount; //!< transmission frame count int m_sampleIndex; //!< Current sample index in protected block data + SDRDaemonSuperBlock m_superBlock; + SDRDaemonMetaDataFEC m_currentMetaFEC; + SDRDaemonDataBlock m_dataBlock; }; #endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ */ diff --git a/sdrdaemon/channel/sdrdaemondatablock.h b/sdrdaemon/channel/sdrdaemondatablock.h index 35f9f06f7..422148ccd 100644 --- a/sdrdaemon/channel/sdrdaemondatablock.h +++ b/sdrdaemon/channel/sdrdaemondatablock.h @@ -46,7 +46,7 @@ struct SDRDaemonMetaDataFEC bool operator==(const SDRDaemonMetaDataFEC& rhs) { - return (memcmp((const void *) this, (const void *) &rhs, 16) == 0); // Only the 16 first bytes are relevant + return (memcmp((const void *) this, (const void *) &rhs, 12) == 0); // Only the 12 first bytes are relevant } void init()