Skip to content
Snippets Groups Projects
Commit b90f9c9e authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-271: Initialise default parameters before starting UDP receiver thread to...

L2SS-271: Initialise default parameters before starting UDP receiver thread to avoid a race condition in which the UDP packets are processed before the default parameter list is initialised.
parent 7374e588
No related branches found
No related tags found
1 merge request!93L2SS-271: Emergency patches
...@@ -23,7 +23,13 @@ class StatisticsCollector(Thread): ...@@ -23,7 +23,13 @@ class StatisticsCollector(Thread):
self.queue = queue self.queue = queue
self.last_packet = None self.last_packet = None
self.parameters = { self.parameters = self._default_parameters()
super().__init__()
self.start()
def _default_parameters(self):
return {
"nof_packets": numpy.uint64(0), "nof_packets": numpy.uint64(0),
# Packet count for packets that could not be parsed # Packet count for packets that could not be parsed
...@@ -33,9 +39,6 @@ class StatisticsCollector(Thread): ...@@ -33,9 +39,6 @@ class StatisticsCollector(Thread):
"last_invalid_packet": numpy.zeros((9000,), dtype=numpy.uint8), "last_invalid_packet": numpy.zeros((9000,), dtype=numpy.uint8),
} }
super().__init__()
self.start()
def run(self): def run(self):
logger.info("Starting statistics thread") logger.info("Starting statistics thread")
...@@ -54,7 +57,7 @@ class StatisticsCollector(Thread): ...@@ -54,7 +57,7 @@ class StatisticsCollector(Thread):
except Exception as e: except Exception as e:
logger.exception("Could not parse statistics UDP packet") logger.exception("Could not parse statistics UDP packet")
self.parameters["last_invalid_packet"] = numpy.frombuffer(packet, dtype=numpy.uint8) self.parameters["last_invalid_packet"] = numpy.frombuffer(self.last_packet, dtype=numpy.uint8)
self.parameters["nof_invalid_packets"] += numpy.uint64(1) self.parameters["nof_invalid_packets"] += numpy.uint64(1)
logger.info("Stopped statistics thread") logger.info("Stopped statistics thread")
...@@ -92,10 +95,10 @@ class SSTCollector(StatisticsCollector): ...@@ -92,10 +95,10 @@ class SSTCollector(StatisticsCollector):
# Maximum number of subbands we support (used to determine array sizes) # Maximum number of subbands we support (used to determine array sizes)
MAX_SUBBANDS = 512 MAX_SUBBANDS = 512
def __init__(self, queue): def _default_parameters(self):
super().__init__(queue) defaults = super()._default_parameters()
self.parameters.extend({ defaults.update({
# Number of packets received so far that we could parse correctly and do not have a payload error # 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), "nof_valid_payloads": numpy.zeros((self.MAX_INPUTS,), dtype=numpy.uint64),
...@@ -108,6 +111,8 @@ class SSTCollector(StatisticsCollector): ...@@ -108,6 +111,8 @@ class SSTCollector(StatisticsCollector):
"integration_intervals": numpy.zeros((self.MAX_INPUTS,), dtype=numpy.float32), "integration_intervals": numpy.zeros((self.MAX_INPUTS,), dtype=numpy.float32),
}) })
return defaults
def process_packet(self, packet): def process_packet(self, packet):
fields = SSTPacket(packet) fields = SSTPacket(packet)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment