diff --git a/RTCP/Cobalt/OutputProc/src/TBB_Frame.cc b/RTCP/Cobalt/OutputProc/src/TBB_Frame.cc index 0f592b2be2fe1eeadd663405d351f5fb0f7998ca..49b1190b898dfb1625dc48dcdc6cf56b47a1f2fa 100644 --- a/RTCP/Cobalt/OutputProc/src/TBB_Frame.cc +++ b/RTCP/Cobalt/OutputProc/src/TBB_Frame.cc @@ -52,7 +52,7 @@ namespace LOFAR const unsigned TBB_Frame::spectralFrameSize = sizeof(TBB_Header) + MAX_TBB_SPECTRAL_NSAMPLES * sizeof(std::complex< int16_t >) + /*crc32:*/sizeof(uint32_t); - unsigned TBB_Header::getFirstBandSelNr() const + uint32_t TBB_Header::getFirstBandSelNr() const { //TODO: implement like https://github.com/liamconnor/tbb-tools/blob/master/read_tbb_data.py#L157 //for now, just return 0 to test the signal path diff --git a/RTCP/Cobalt/OutputProc/src/TBB_Frame.h b/RTCP/Cobalt/OutputProc/src/TBB_Frame.h index 983e85c5d0aef1c6829285295a8fb0dbb3dc0d19..092fda7ae86ecd68dbc5138899cd77d4f389381a 100644 --- a/RTCP/Cobalt/OutputProc/src/TBB_Frame.h +++ b/RTCP/Cobalt/OutputProc/src/TBB_Frame.h @@ -30,13 +30,32 @@ namespace LOFAR { - namespace Cobalt - { - /** - * This reflects the fact that LOFAR's TBB boards can produce spectral - * time series for a maximum of 487 frequency bands. - */ - const uint32_t MAX_TBB_SPECTRAL_SUBBANDS{487U}; + namespace Cobalt + { + /** + * This reflects the fact that LOFAR's TBB boards can produce spectral + * time series for a maximum of 487 frequency bands. + */ + const uint32_t MAX_TBB_SPECTRAL_SUBBANDS{487U}; + /** + * The bit shift and mask for the uint32_t in the TBB frame header that + * represent the slice and band numbers. + */ + const uint32_t TBB_SLICE_NR_SHIFT{10U}; + const uint32_t TBB_BAND_NR_MASK{((1U << TBB_SLICE_NR_SHIFT) - 1U)}; + + /** + * For transient, TBB always sends sends 1024 samples per frame (from the + * spec and seen in data). + * For spectral, it depends on the nr of subbands (max is equal to + * MAX_TBB_SPECTRAL_NSAMPLES). + */ + // RSP FFT block size in samples (complex 16 bit value) + const uint32_t SPECTRAL_TRANSFORM_SIZE{1024U}; + // equal to nr bits in TBB_Header::bandSel[] + const uint32_t RSP_NR_SUBBANDS{(SPECTRAL_TRANSFORM_SIZE / 2U)}; + // for spectral it depends on #subbands + const uint32_t DEFAULT_TBB_TRANSIENT_NSAMPLES{1024U}; /* * Incoming UDP frame format. @@ -69,8 +88,6 @@ namespace LOFAR uint32_t sampleNr; uint32_t bandSliceNr; // in spectral mode: bandNr[9:0] and sliceNr[31:10] }; -#define TBB_SLICE_NR_SHIFT 10 -#define TBB_BAND_NR_MASK ((1 << TBB_SLICE_NR_SHIFT) - 1) uint16_t nOfSamplesPerFrame; // Total number of samples in the frame payload uint16_t nOfFreqBands; // Number of frequency bands for each spectrum in spectral mode. Is set to 0 for transient mode. Descriptive for this packet's payload. @@ -82,42 +99,36 @@ namespace LOFAR // Returns lowest band nr bit set in bandSel, or RSP_NR_SUBBANDS if not found. - unsigned getFirstBandSelNr() const; + uint32_t getFirstBandSelNr() const; std::string to_string() const; }; - struct TBB_Payload { - /* - * In transient mode, a sample is a signed 12 bit integer. In spectral mode, it is a complex int16_t. - * In the TBBs, transient samples are packed (2 samples per 3 bytes) with the checksum all the way at the end. This changes on transfer. - * - * TBB stores a frame in 2040 bytes (actually, 2048 with preamble and gaps). It sends a frame at a time, so derive our max from it. - * - * In spectral mode the frame size is only 2012 bytes! - */ -#define MAX_TBB_DATA_SIZE_SPECTRAL_MODE (2012 - sizeof(TBB_Header) - sizeof(uint32_t)) -#define MAX_TBB_DATA_SIZE_TRANSIENT_MODE (2040 - sizeof(TBB_Header) - sizeof(uint32_t)) // 1948: TBB frame size without header and payload crc32. - -#define MAX_TBB_TRANSIENT_NSAMPLES (MAX_TBB_DATA_SIZE_TRANSIENT_MODE / 3 * 2) // 1298 (.666: 1 byte padding when indeed 1298 samples would ever be stored in TBB) -#define MAX_TBB_SPECTRAL_NSAMPLES (MAX_TBB_DATA_SIZE_SPECTRAL_MODE / (2 * sizeof(int16_t))) // 487 + /* + * In transient mode, a sample is a signed 12 bit integer. In spectral mode, it is a complex int16_t. + * In the TBBs, transient samples are packed (2 samples per 3 bytes) with the checksum all the way at the end. This changes on transfer. + * + * TBB stores a frame in 2040 bytes (actually, 2048 with preamble and gaps). It sends a frame at a time, so derive our max from it. + * + * In spectral mode the frame size is only 2012 bytes! + */ + const uint32_t MAX_TBB_DATA_SIZE_SPECTRAL_MODE{(2012 - sizeof(TBB_Header) - sizeof(uint32_t))}; + // 1948: TBB frame size without header and payload crc32. + const uint32_t MAX_TBB_DATA_SIZE_TRANSIENT_MODE{(2040 - sizeof(TBB_Header) - sizeof(uint32_t))}; + // 1298 (.666: 1 byte padding when indeed 1298 samples would ever be stored in TBB) + const uint32_t MAX_TBB_TRANSIENT_NSAMPLES{(MAX_TBB_DATA_SIZE_TRANSIENT_MODE / 3 * 2)}; + // Is 480: + const uint32_t MAX_TBB_SPECTRAL_NSAMPLES{(MAX_TBB_DATA_SIZE_SPECTRAL_MODE / (2 * sizeof(int16_t)))}; + struct TBB_Payload { // Unpacked, sign-extended (for transient) samples without padding, i.e. as received. // Frames might not be full; the doc says the crc32 is always sent right after (no padding), // so we include the crc32 in 'data', but note that the crc32 is a little endian uint32_t, hence ' + 2'. union { int16_t data[MAX_TBB_TRANSIENT_NSAMPLES]; - int16_t spectralData[MAX_TBB_SPECTRAL_NSAMPLES + 2][2]; + int16_t spectralData[MAX_TBB_SPECTRAL_NSAMPLES + 2U][2]; }; - - // For transient, TBB always sends sends 1024 samples per frame (from the spec and seen in data). - // For spectral, it depends on the nr of subbands (max is equal to MAX_TBB_SPECTRAL_NSAMPLES). - -#define SPECTRAL_TRANSFORM_SIZE 1024 // RSP FFT block size in samples (complex 16 bit value) -#define RSP_NR_SUBBANDS (SPECTRAL_TRANSFORM_SIZE / 2) // equal to nr bits in TBB_Header::bandSel[] - -#define DEFAULT_TBB_TRANSIENT_NSAMPLES 1024 // for spectral it depends on #subbands }; struct TBB_Frame {