From 6691a926f16cc59412e5ce36830336f64d6369d8 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 20 Aug 2018 08:41:54 +0200 Subject: [PATCH] SDRdaemon: data block definitions --- sdrdaemon/channel/sdrdaemondatablock.h | 100 +++++++++++++++++++++++++ sdrdaemon/channel/sdrdaemondataqueue.h | 55 ++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 sdrdaemon/channel/sdrdaemondatablock.h create mode 100644 sdrdaemon/channel/sdrdaemondataqueue.h diff --git a/sdrdaemon/channel/sdrdaemondatablock.h b/sdrdaemon/channel/sdrdaemondatablock.h new file mode 100644 index 000000000..6d3c93de1 --- /dev/null +++ b/sdrdaemon/channel/sdrdaemondatablock.h @@ -0,0 +1,100 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB. // +// // +// SDRdaemon sink channel (Rx) data block // +// // +// SDRdaemon is a detached SDR front end that handles the interface with a // +// physical device and sends or receives the I/Q samples stream to or from a // +// SDRangel instance via UDP. It is controlled via a Web REST API. // +// // +// 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 SDRDAEMON_CHANNEL_SDRDAEMONDATABLOCK_H_ +#define SDRDAEMON_CHANNEL_SDRDAEMONDATABLOCK_H_ + +#include +#include +#include "dsp/dsptypes.h" + +#define UDPSINKFEC_UDPSIZE 512 +#define UDPSINKFEC_NBORIGINALBLOCKS 128 +#define UDPSINKFEC_NBTXBLOCKS 8 + +namespace SDRDaemon { + +#pragma pack(push, 1) +struct MetaDataFEC +{ + uint32_t m_centerFrequency; //!< 4 center frequency in kHz + uint32_t m_sampleRate; //!< 8 sample rate in Hz + uint8_t m_sampleBytes; //!< 9 MSB(4): indicators, LSB(4) number of bytes per sample + uint8_t m_sampleBits; //!< 10 number of effective bits per sample + uint8_t m_nbOriginalBlocks; //!< 11 number of blocks with original (protected) data + uint8_t m_nbFECBlocks; //!< 12 number of blocks carrying FEC + uint32_t m_tv_sec; //!< 16 seconds of timestamp at start time of super-frame processing + uint32_t m_tv_usec; //!< 20 microseconds of timestamp at start time of super-frame processing + uint32_t m_crc32; //!< 24 CRC32 of the above + + bool operator==(const MetaDataFEC& rhs) + { + return (memcmp((const void *) this, (const void *) &rhs, 12) == 0); // Only the 12 first bytes are relevant + } + + void init() + { + memset((void *) this, 0, sizeof(MetaDataFEC)); + m_nbFECBlocks = -1; + } +}; + +struct Header +{ + uint16_t m_frameIndex; + uint8_t m_blockIndex; + uint8_t m_filler; +}; + +static const int samplesPerBlock = (UDPSINKFEC_UDPSIZE - sizeof(Header)) / sizeof(Sample); + +struct ProtectedBlock +{ + Sample m_samples[samplesPerBlock]; +}; + +struct SuperBlock +{ + Header m_header; + ProtectedBlock m_protectedBlock; +}; +#pragma pack(pop) + +struct TxControlBlock +{ + bool m_processed; + uint16_t m_frameIndex; + int m_nbBlocksFEC; + int m_txDelay; +}; + +class DataBlock +{ + SuperBlock m_superBlock; + TxControlBlock m_controlBlock; +}; + +} // namespace SDRDaemon + + + +#endif /* SDRDAEMON_CHANNEL_SDRDAEMONDATABLOCK_H_ */ diff --git a/sdrdaemon/channel/sdrdaemondataqueue.h b/sdrdaemon/channel/sdrdaemondataqueue.h new file mode 100644 index 000000000..d83346ad1 --- /dev/null +++ b/sdrdaemon/channel/sdrdaemondataqueue.h @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB. // +// // +// SDRdaemon sink channel (Rx) data blocks queue // +// // +// SDRdaemon is a detached SDR front end that handles the interface with a // +// physical device and sends or receives the I/Q samples stream to or from a // +// SDRangel instance via UDP. It is controlled via a Web REST API. // +// // +// 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 SDRDAEMON_CHANNEL_SDRDAEMONDATAQUEUE_H_ +#define SDRDAEMON_CHANNEL_SDRDAEMONDATAQUEUE_H_ + +#include + +class DataBlock; + +namespace SDRDaemon { + +class DataQueue : public QObject { + Q_OBJECT + +public: + DataQueue(QObject* parent = NULL); + ~DataQueue(); + + void push(DataBlock* message, bool emitSignal = true); //!< Push daa block onto queue + DataBlock* pop(); //!< Pop message from queue + + int size(); //!< Returns queue size + void clear(); //!< Empty queue + +signals: + void dataBlockEnqueued(); + +private: + QMutex m_lock; + QQueue m_queue; +}; + +} // namespace SDRDaemon + +#endif /* SDRDAEMON_CHANNEL_SDRDAEMONDATAQUEUE_H_ */