2018-08-20 02:41:54 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef SDRDAEMON_CHANNEL_SDRDAEMONDATABLOCK_H_
|
|
|
|
#define SDRDAEMON_CHANNEL_SDRDAEMONDATABLOCK_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2018-08-21 11:23:48 -04:00
|
|
|
#include <algorithm>
|
2018-08-28 00:33:15 -04:00
|
|
|
#include <QString>
|
2018-08-20 02:41:54 -04:00
|
|
|
#include "dsp/dsptypes.h"
|
|
|
|
|
|
|
|
#define UDPSINKFEC_UDPSIZE 512
|
|
|
|
#define UDPSINKFEC_NBORIGINALBLOCKS 128
|
2018-08-20 08:05:27 -04:00
|
|
|
//#define UDPSINKFEC_NBTXBLOCKS 8
|
2018-08-20 02:41:54 -04:00
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
2018-08-20 08:05:27 -04:00
|
|
|
struct SDRDaemonMetaDataFEC
|
2018-08-20 02:41:54 -04:00
|
|
|
{
|
|
|
|
uint32_t m_centerFrequency; //!< 4 center frequency in kHz
|
|
|
|
uint32_t m_sampleRate; //!< 8 sample rate in Hz
|
2018-09-12 18:31:49 -04:00
|
|
|
uint8_t m_sampleBytes; //!< 9 4 LSB: number of bytes per sample (2 or 4)
|
2018-08-21 10:04:10 -04:00
|
|
|
uint8_t m_sampleBits; //!< 10 number of effective bits per sample (deprecated)
|
2018-08-20 19:36:39 -04:00
|
|
|
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
|
2018-08-20 02:41:54 -04:00
|
|
|
|
2018-08-20 08:05:27 -04:00
|
|
|
bool operator==(const SDRDaemonMetaDataFEC& rhs)
|
2018-08-20 02:41:54 -04:00
|
|
|
{
|
2018-08-21 02:51:10 -04:00
|
|
|
return (memcmp((const void *) this, (const void *) &rhs, 12) == 0); // Only the 12 first bytes are relevant
|
2018-08-20 02:41:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
2018-08-21 11:23:48 -04:00
|
|
|
m_centerFrequency = 0;
|
|
|
|
m_sampleRate = 0;
|
|
|
|
m_sampleBytes = 0;
|
|
|
|
m_sampleBits = 0;
|
|
|
|
m_nbOriginalBlocks = 0;
|
2018-08-26 19:09:12 -04:00
|
|
|
m_nbFECBlocks = 0;
|
2018-08-21 11:23:48 -04:00
|
|
|
m_tv_sec = 0;
|
|
|
|
m_tv_usec = 0;
|
|
|
|
m_crc32 = 0;
|
2018-08-20 02:41:54 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-20 08:05:27 -04:00
|
|
|
struct SDRDaemonHeader
|
2018-08-20 02:41:54 -04:00
|
|
|
{
|
|
|
|
uint16_t m_frameIndex;
|
|
|
|
uint8_t m_blockIndex;
|
2018-09-12 18:31:49 -04:00
|
|
|
uint8_t m_sampleBytes; //!< number of bytes per sample (2 or 4) for this block
|
|
|
|
uint8_t m_sampleBits; //!< number of bits per sample
|
2018-08-20 02:41:54 -04:00
|
|
|
uint8_t m_filler;
|
2018-09-12 18:31:49 -04:00
|
|
|
uint16_t m_filler2;
|
2018-08-21 11:23:48 -04:00
|
|
|
|
2018-08-22 17:16:08 -04:00
|
|
|
void init()
|
2018-08-21 11:23:48 -04:00
|
|
|
{
|
|
|
|
m_frameIndex = 0;
|
|
|
|
m_blockIndex = 0;
|
2018-09-12 18:31:49 -04:00
|
|
|
m_sampleBytes = 2;
|
|
|
|
m_sampleBits = 16;
|
2018-08-21 11:23:48 -04:00
|
|
|
m_filler = 0;
|
2018-09-09 20:52:36 -04:00
|
|
|
m_filler2 = 0;
|
2018-08-22 17:16:08 -04:00
|
|
|
}
|
2018-08-20 02:41:54 -04:00
|
|
|
};
|
|
|
|
|
2018-08-20 08:05:27 -04:00
|
|
|
static const int SDRDaemonUdpSize = UDPSINKFEC_UDPSIZE;
|
|
|
|
static const int SDRDaemonNbOrginalBlocks = UDPSINKFEC_NBORIGINALBLOCKS;
|
2018-09-10 12:52:40 -04:00
|
|
|
static const int SDRDaemonNbBytesPerBlock = UDPSINKFEC_UDPSIZE - sizeof(SDRDaemonHeader);
|
2018-08-20 02:41:54 -04:00
|
|
|
|
2018-08-20 08:05:27 -04:00
|
|
|
struct SDRDaemonProtectedBlock
|
2018-08-20 02:41:54 -04:00
|
|
|
{
|
2018-09-10 12:52:40 -04:00
|
|
|
uint8_t buf[SDRDaemonNbBytesPerBlock];
|
2018-08-21 11:23:48 -04:00
|
|
|
|
|
|
|
void init() {
|
2018-09-10 12:52:40 -04:00
|
|
|
std::fill(buf, buf+SDRDaemonNbBytesPerBlock, 0);
|
2018-08-21 11:23:48 -04:00
|
|
|
}
|
2018-08-20 02:41:54 -04:00
|
|
|
};
|
|
|
|
|
2018-08-20 08:05:27 -04:00
|
|
|
struct SDRDaemonSuperBlock
|
2018-08-20 02:41:54 -04:00
|
|
|
{
|
2018-08-20 08:05:27 -04:00
|
|
|
SDRDaemonHeader m_header;
|
|
|
|
SDRDaemonProtectedBlock m_protectedBlock;
|
2018-08-21 11:23:48 -04:00
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
m_header.init();
|
|
|
|
m_protectedBlock.init();
|
|
|
|
}
|
2018-08-20 02:41:54 -04:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2018-08-20 08:05:27 -04:00
|
|
|
struct SDRDaemonTxControlBlock
|
2018-08-20 02:41:54 -04:00
|
|
|
{
|
2018-08-21 08:00:56 -04:00
|
|
|
bool m_complete;
|
2018-08-20 02:41:54 -04:00
|
|
|
bool m_processed;
|
|
|
|
uint16_t m_frameIndex;
|
|
|
|
int m_nbBlocksFEC;
|
|
|
|
int m_txDelay;
|
2018-08-22 17:16:08 -04:00
|
|
|
QString m_dataAddress;
|
|
|
|
uint16_t m_dataPort;
|
2018-08-21 08:00:56 -04:00
|
|
|
|
|
|
|
SDRDaemonTxControlBlock() {
|
|
|
|
m_complete = false;
|
|
|
|
m_processed = false;
|
|
|
|
m_frameIndex = 0;
|
|
|
|
m_nbBlocksFEC = 0;
|
|
|
|
m_txDelay = 100;
|
2018-08-22 17:16:08 -04:00
|
|
|
m_dataAddress = "127.0.0.1";
|
|
|
|
m_dataPort = 9090;
|
2018-08-21 08:00:56 -04:00
|
|
|
}
|
2018-08-20 02:41:54 -04:00
|
|
|
};
|
|
|
|
|
2018-08-26 19:09:12 -04:00
|
|
|
struct SDRDaemonRxControlBlock
|
|
|
|
{
|
|
|
|
int m_blockCount; //!< number of blocks received for this frame
|
|
|
|
int m_originalCount; //!< number of original blocks received
|
|
|
|
int m_recoveryCount; //!< number of recovery blocks received
|
|
|
|
bool m_metaRetrieved; //!< true if meta data (block zero) was retrieved
|
|
|
|
int m_frameIndex; //!< this frame index or -1 if unset
|
|
|
|
|
|
|
|
SDRDaemonRxControlBlock() {
|
|
|
|
m_blockCount = 0;
|
|
|
|
m_originalCount = 0;
|
|
|
|
m_recoveryCount = 0;
|
|
|
|
m_metaRetrieved = false;
|
|
|
|
m_frameIndex = -1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-20 08:05:27 -04:00
|
|
|
class SDRDaemonDataBlock
|
2018-08-20 02:41:54 -04:00
|
|
|
{
|
2018-08-20 08:05:27 -04:00
|
|
|
public:
|
2018-08-21 11:23:48 -04:00
|
|
|
SDRDaemonDataBlock() {
|
|
|
|
m_superBlocks = new SDRDaemonSuperBlock[256];
|
|
|
|
}
|
|
|
|
~SDRDaemonDataBlock() {
|
|
|
|
delete[] m_superBlocks;
|
|
|
|
}
|
2018-08-26 19:09:12 -04:00
|
|
|
SDRDaemonTxControlBlock m_txControlBlock;
|
|
|
|
SDRDaemonRxControlBlock m_rxControlBlock;
|
2018-08-21 11:23:48 -04:00
|
|
|
SDRDaemonSuperBlock *m_superBlocks;
|
2018-08-20 02:41:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SDRDAEMON_CHANNEL_SDRDAEMONDATABLOCK_H_ */
|