From 8ed941ad6abbd0e3b613a72a8638849844c57fa0 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Mon, 21 Jun 2021 10:20:03 +0200
Subject: [PATCH] L2SS-244: Record the last packet that was marked invalid, for
 debugging purposes.

---
 devices/SST.py                |  2 ++
 devices/clients/sst_client.py | 14 ++++++--------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/devices/SST.py b/devices/SST.py
index 1e17edbde..36b21444e 100644
--- a/devices/SST.py
+++ b/devices/SST.py
@@ -64,6 +64,8 @@ class SST(hardware_device):
 
     # number of invalid (non-SST) packets received
     nof_invalid_packets_R   = attribute_wrapper(comms_annotation={"type": "sst", "parameter": "nof_invalid_packets"}, datatype=numpy.uint64)
+    # last packet that could not be parsed
+    last_invalid_packet_R   = attribute_wrapper(comms_annotation={"type": "sst", "parameter": "last_invalid_packet"}, dims=(9000,), datatype=numpy.uint8)
     # number of packets with valid payloads
     nof_valid_payloads_R    = attribute_wrapper(comms_annotation={"type": "sst", "parameter": "nof_valid_payloads"}, dims=(SST_collector.MAX_INPUTS,), datatype=numpy.uint64)
     # number of packets with invalid payloads
diff --git a/devices/clients/sst_client.py b/devices/clients/sst_client.py
index 18d17276c..919f2f604 100644
--- a/devices/clients/sst_client.py
+++ b/devices/clients/sst_client.py
@@ -229,6 +229,9 @@ class SST_collector(Thread):
             # Packet count for packets that could not be parsed as SSTs
             "nof_invalid_packets":   numpy.uint64(0),
 
+            # Full contents of the latest packet we deemed invalid.
+            "last_invalid_packet":   numpy.zeros((9000,), dtype=numpy.uint8),
+
             # Number of packets received so far that we could parse correctly and do not have a payload error
             "nof_valid_payloads":    numpy.zeros((self.MAX_INPUTS,), dtype=numpy.uint64),
 
@@ -280,18 +283,12 @@ class SST_collector(Thread):
         self.parameters["nof_packets"] += numpy.uint64(1)
 
         try:
-            try:
-                fields = SSTPacket(packet)
-            except ValueError:
-                # not an SST packet
-                self.parameters["nof_invalid_packets"] += numpy.uint64(1)
-                return
+            fields = SSTPacket(packet)
 
             # determine which input this packet contains data for
             if fields.signal_input_index >= self.MAX_INPUTS:
                 # packet describes an input that is out of bounds for us
-                self.parameters["nof_invalid_packets"] += numpy.uint64(1)
-                return
+                raise ValueError("Packet describes input %d, but we are limited to describing MAX_INPUTS=%d" % (fields.signal_input_index, self.MAX_INPUTS))
 
             input_index = fields.signal_input_index
 
@@ -310,3 +307,4 @@ class SST_collector(Thread):
             logging.exception("Could not parse SST UDP packet")
 
             self.parameters["nof_invalid_packets"] += numpy.uint64(1)
+            self.parameters["last_packet"]         = numpy.frombuffer(packet, dtype=numpy.uint8)
-- 
GitLab