SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
remotedatareadqueue.h
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB. //
3 // //
4 // Remote sink channel (Rx) data blocks to read queue //
5 // //
6 // SDRangel can serve as a remote SDR front end that handles the interface //
7 // with a physical device and sends or receives the I/Q samples stream via UDP //
8 // to or from another SDRangel instance or any program implementing the same //
9 // protocol. The remote SDRangel is controlled via its Web REST API. //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation as version 3 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License V3 for more details. //
20 // //
21 // You should have received a copy of the GNU General Public License //
22 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
24 
25 #ifndef CHANNEL_REMOTEDATAREADQUEUE_H_
26 #define CHANNEL_REMOTEDATAREADQUEUE_H_
27 
28 #include <QQueue>
29 
30 #include "export.h"
31 
32 class RemoteDataBlock;
33 class Sample;
34 
36 {
37 public:
40 
41  void push(RemoteDataBlock* dataBlock);
42  RemoteDataBlock* pop();
43  void readSample(Sample& s, bool scaleForTx = false);
44  uint32_t length() const { return m_dataReadQueue.size(); }
45  uint32_t size() const { return m_maxSize; }
46  void setSize(uint32_t size);
47  uint32_t readSampleCount() const { return m_sampleCount; }
48 
49  static const uint32_t MinimumMaxSize;
50 
51 private:
52  QQueue<RemoteDataBlock*> m_dataReadQueue;
58  bool m_full;
59 
60  inline void convertDataToSample(Sample& s, uint32_t blockIndex, uint32_t sampleIndex, bool scaleForTx)
61  {
62  int sampleSize = m_dataBlock->m_superBlocks[blockIndex].m_header.m_sampleBytes * 2; // I/Q sample size in data block
63  int samplebits = m_dataBlock->m_superBlocks[blockIndex].m_header.m_sampleBits; // I or Q sample size in bits
64  int32_t iconv, qconv;
65 
66  if ((sizeof(Sample) == 4) && (sampleSize == 8)) // generally 24->16 bits
67  {
68  iconv = ((int32_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0];
69  qconv = ((int32_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+4]))[0];
70  iconv >>= scaleForTx ? (SDR_TX_SAMP_SZ-SDR_RX_SAMP_SZ) : (samplebits-SDR_RX_SAMP_SZ);
71  qconv >>= scaleForTx ? (SDR_TX_SAMP_SZ-SDR_RX_SAMP_SZ) : (samplebits-SDR_RX_SAMP_SZ);
72  s.setReal(iconv);
73  s.setImag(qconv);
74  }
75  else if ((sizeof(Sample) == 8) && (sampleSize == 4)) // generally 16->24 bits
76  {
77  iconv = ((int16_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0];
78  qconv = ((int16_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+2]))[0];
79  iconv <<= scaleForTx ? (SDR_TX_SAMP_SZ-samplebits) : (SDR_RX_SAMP_SZ-samplebits);
80  qconv <<= scaleForTx ? (SDR_TX_SAMP_SZ-samplebits) : (SDR_RX_SAMP_SZ-samplebits);
81  s.setReal(iconv);
82  s.setImag(qconv);
83  }
84  else if ((sampleSize == 4) || (sampleSize == 8)) // generally 16->16 or 24->24 bits
85  {
86  s = *((Sample*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]));
87  }
88  else // invalid size
89  {
90  s = Sample{0, 0};
91  }
92  }
93 };
94 
95 
96 
97 #endif /* CHANNEL_REMOTEDATAREADQUEUE_H_ */
short int16_t
Definition: rtptypes_win.h:43
uint32_t size() const
Returns queue size (max length)
RemoteSuperBlock * m_superBlocks
uint32_t m_sampleCount
use a counter capped below 2^31 as it is going to be converted to an int in the web interface ...
RemoteProtectedBlock m_protectedBlock
unsigned int uint32_t
Definition: rtptypes_win.h:46
uint32_t readSampleCount() const
Returns the absolute number of samples read.
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
bool m_full
full condition was hit
uint8_t buf[RemoteNbBytesPerBlock]
uint8_t m_sampleBytes
number of bytes per sample (2 or 4) for this block
void setImag(FixReal v)
Definition: dsptypes.h:59
int int32_t
Definition: rtptypes_win.h:45
#define SDR_TX_SAMP_SZ
Definition: dsptypes.h:38
uint32_t length() const
Returns queue length.
RemoteHeader m_header
void setReal(FixReal v)
Definition: dsptypes.h:58
RemoteDataBlock * m_dataBlock
void convertDataToSample(Sample &s, uint32_t blockIndex, uint32_t sampleIndex, bool scaleForTx)
#define SDRBASE_API
Definition: export.h:40
QQueue< RemoteDataBlock * > m_dataReadQueue
static const uint32_t MinimumMaxSize
uint8_t m_sampleBits
number of bits per sample