From 62ecc7ac65881e73947727d7bbc86d5c82b903bb Mon Sep 17 00:00:00 2001
From: Alexander van Amesfoort <amesfoort@astron.nl>
Date: Mon, 18 Jan 2016 16:54:04 +0000
Subject: [PATCH] Task #8990: TBB_Writer: Use proper constant for invalid sb
 storage idx, and add some comments. No change to program logic.

---
 RTCP/Cobalt/OutputProc/src/TBB_Writer.cc | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/RTCP/Cobalt/OutputProc/src/TBB_Writer.cc b/RTCP/Cobalt/OutputProc/src/TBB_Writer.cc
index e61e081de35..e0c09a301cb 100644
--- a/RTCP/Cobalt/OutputProc/src/TBB_Writer.cc
+++ b/RTCP/Cobalt/OutputProc/src/TBB_Writer.cc
@@ -64,6 +64,7 @@
 #define TBB_SPECTRAL_MODE                       2
 
 #define RSP_NR_SUBBANDS                         512
+#define INVALID_SUBBAND_STORAGE_INDEX           UINT_MAX
 
 namespace LOFAR
 {
@@ -238,6 +239,7 @@ namespace LOFAR
       /*
        * Out-of-order or duplicate frames are very unlikely in the LOFAR TBB setup,
        * but let us know if it ever happens, then we will adapt this code and appendFlags().
+       * Update: it happens when data is dumped (incorrectly) across the frozen TBB write pointer. (TODO: deal with this one time data shift)
        */
       if (frame.header.time < itsTime || (frame.header.time == itsTime && frame.header.sampleNr < itsExpSampleNr)) {
         LOG_WARN_STR("TBB: Unhandled out-of-order or duplicate frame: " <<
@@ -273,7 +275,7 @@ namespace LOFAR
 
       /*
        * On a data checksum error, flag these samples.
-       * Flag zeroed payloads too, as incredibly unlikely to be correct, but not rejected by crc32tbb.
+       * Flag zeroed payloads too, as incredibly unlikely to be correct (unless wave generator used and set to zero amp (pointless)), but not rejected by crc32tbb.
        */
       if (!crc32tbb(&frame.payload, frame.header.nOfSamplesPerFrame)) {
         appendFlags(offset, frame.header.nOfSamplesPerFrame);
@@ -297,6 +299,7 @@ namespace LOFAR
       /*
        * Out-of-order or duplicate frames are very unlikely in the LOFAR TBB setup,
        * but let us know if it ever happens, then we will adapt this code and appendFlags().
+       * Update: it happens when data is dumped (incorrectly) across the frozen TBB write pointer. (TODO: deal with this one time data shift)
        */
       uint32_t sliceNr = frame.header.bandSliceNr >> TBB_SLICE_NR_SHIFT; // cannot sanitize fully: too large values indicate lost data: flag
       if (frame.header.time < itsTime || (frame.header.time == itsTime && sliceNr < itsExpSliceNr)) {
@@ -329,7 +332,7 @@ namespace LOFAR
 
       /*
        * On a data checksum error, flag these samples.
-       * Flag zeroed payloads too, as incredibly unlikely to be correct, but not rejected by crc32tbb.
+       * Flag zeroed payloads too, as incredibly unlikely to be correct (unless wave generator used and set to zero amp (pointless)), but not rejected by crc32tbb.
        *
        * TBB Design Doc states the crc32 is computed for transient data only, but it is also valid for spectral data.
        * Except that it looks invalid for the first spectral frame each second, so skip checking those. // TODO: enable 'sliceNr != 0 && ' below after verifying with recent real data
@@ -595,7 +598,7 @@ namespace LOFAR
         }
 
         // "Invert" tbbSubbandList, such that we can later simply lookup where to store a subband.
-        info.storageIndices.resize(RSP_NR_SUBBANDS, (unsigned)-1);
+        info.storageIndices.resize(RSP_NR_SUBBANDS, INVALID_SUBBAND_STORAGE_INDEX); // TODO: check for the invalid idx at frame rx
         for (unsigned i = 0; i < tbbSubbandList.size(); ++i) {
           unsigned sbNr = tbbSubbandList[i];
           if (sbNr >= RSP_NR_SUBBANDS) {
-- 
GitLab