From 596efeba4762e95e133f1ffe58c08f03519fd517 Mon Sep 17 00:00:00 2001 From: cortadocodes Date: Tue, 29 Mar 2022 13:25:33 +0100 Subject: [PATCH 1/5] FIX: Update handles in the parser process instead of reader process --- data_gateway/packet_reader.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data_gateway/packet_reader.py b/data_gateway/packet_reader.py index f0dc2822..2f0716dc 100644 --- a/data_gateway/packet_reader.py +++ b/data_gateway/packet_reader.py @@ -89,10 +89,6 @@ def read_packets(self, serial_port, packet_queue, stop_signal): length = int.from_bytes(serial_port.read(), self.config.endian) packet = serial_port.read(length) - if packet_type == str(self.config.type_handle_def): - self.update_handles(packet) - continue - # Check for bytes in serial input buffer. A full buffer results in overflow. if serial_port.in_waiting == self.config.serial_buffer_rx_size: logger.warning("Serial port buffer is full - buffer overflow may occur, resulting in data loss.") @@ -173,6 +169,10 @@ def parse_packets(self, packet_queue, stop_signal, stop_when_no_more_data_after= logger.error("Received packet with unknown type: %s", packet_type) continue + if packet_type == str(self.config.type_handle_def): + self.update_handles(packet) + continue + if len(packet) == 244: # If the full data payload is received, proceed parsing it timestamp = int.from_bytes(packet[240:244], self.config.endian, signed=False) / (2 ** 16) From 1cb6b7bab4144a6662483af370cb87db6ed3e185 Mon Sep 17 00:00:00 2001 From: cortadocodes Date: Tue, 29 Mar 2022 13:28:05 +0100 Subject: [PATCH 2/5] OPS: Increase version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e8232401..43aa7979 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name="data_gateway", - version="0.11.5", + version="0.11.6", install_requires=[ "click>=7.1.2", "pyserial==3.5", From 9ddfe4113eab2e0e6d771954b3e44fc595f5aac9 Mon Sep 17 00:00:00 2001 From: Juri Date: Wed, 30 Mar 2022 12:59:48 +0200 Subject: [PATCH 3/5] FIX: Update Handles before checking them --- data_gateway/packet_reader.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data_gateway/packet_reader.py b/data_gateway/packet_reader.py index 2f0716dc..7b7746ff 100644 --- a/data_gateway/packet_reader.py +++ b/data_gateway/packet_reader.py @@ -165,14 +165,14 @@ def parse_packets(self, packet_queue, stop_signal, stop_when_no_more_data_after= break continue - if packet_type not in self.handles: - logger.error("Received packet with unknown type: %s", packet_type) - continue - if packet_type == str(self.config.type_handle_def): self.update_handles(packet) continue + if packet_type not in self.handles: + logger.error("Received packet with unknown type: %s", packet_type) + continue + if len(packet) == 244: # If the full data payload is received, proceed parsing it timestamp = int.from_bytes(packet[240:244], self.config.endian, signed=False) / (2 ** 16) From 1949e25f41106b57dd8b2e5282edd8a25bac6809 Mon Sep 17 00:00:00 2001 From: Juri Date: Wed, 30 Mar 2022 13:21:59 +0200 Subject: [PATCH 4/5] FIX: Remove packet type check on calculate offset call --- data_gateway/packet_reader.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/data_gateway/packet_reader.py b/data_gateway/packet_reader.py index 7b7746ff..cde4bff4 100644 --- a/data_gateway/packet_reader.py +++ b/data_gateway/packet_reader.py @@ -517,10 +517,8 @@ def _timestamp_and_persist_data(self, data, sensor_name, timestamp, period): # The first time this method runs, calculate the offset between the last timestamp of the first sample and the # UTC time now. Store it as the `sensor_time_offset` metadata in the windows. - if sensor_name == "Constat": - logger.debug("Constat packet: %d" % timestamp) - if time and self.sensor_time_offset is None: - self._calculate_and_store_sensor_timestamp_offset(time) + if time and self.sensor_time_offset is None: + self._calculate_and_store_sensor_timestamp_offset(time) def _calculate_and_store_sensor_timestamp_offset(self, timestamp): """Calculate the offset between the given timestamp and the UTC time now, storing it in the metadata of the From 9e1cc8f52f697692bb89bcf1d69bd168f29d143e Mon Sep 17 00:00:00 2001 From: Juri Date: Wed, 30 Mar 2022 13:21:59 +0200 Subject: [PATCH 5/5] FIX: Revert previous commit This reverts commit 1949e25f41106b57dd8b2e5282edd8a25bac6809. --- data_gateway/packet_reader.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data_gateway/packet_reader.py b/data_gateway/packet_reader.py index cde4bff4..7b7746ff 100644 --- a/data_gateway/packet_reader.py +++ b/data_gateway/packet_reader.py @@ -517,8 +517,10 @@ def _timestamp_and_persist_data(self, data, sensor_name, timestamp, period): # The first time this method runs, calculate the offset between the last timestamp of the first sample and the # UTC time now. Store it as the `sensor_time_offset` metadata in the windows. - if time and self.sensor_time_offset is None: - self._calculate_and_store_sensor_timestamp_offset(time) + if sensor_name == "Constat": + logger.debug("Constat packet: %d" % timestamp) + if time and self.sensor_time_offset is None: + self._calculate_and_store_sensor_timestamp_offset(time) def _calculate_and_store_sensor_timestamp_offset(self, timestamp): """Calculate the offset between the given timestamp and the UTC time now, storing it in the metadata of the