From 2f85e1aaf8335158f63c179216c8119fdc3c60ba Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Tue, 15 Jun 2021 18:26:21 +0200 Subject: [PATCH] L2SS-244: Fields are all big endian. --- devices/clients/StatisticsPacket.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/devices/clients/StatisticsPacket.py b/devices/clients/StatisticsPacket.py index f97ac128c..8f21128c2 100644 --- a/devices/clients/StatisticsPacket.py +++ b/devices/clients/StatisticsPacket.py @@ -68,13 +68,13 @@ class StatisticsPacket(object): def observation_id(self) -> int: """ Return the ID of the observation running when this packet was generated. """ - return unpack("<I",self.packet[2:6])[0] + return unpack(">I",self.packet[2:6])[0] @property def station_id(self) -> int: """ Return the number of the station this packet was generated on. """ - return unpack("<H",self.packet[6:8])[0] + return unpack(">H",self.packet[6:8])[0] @property def source_info(self) -> int: @@ -94,7 +94,7 @@ class StatisticsPacket(object): reserved: reserved bits gn_index: global index of FPGA that emitted this packet. """ - bits = unpack("<H",self.packet[8:10])[0] + bits = unpack(">H",self.packet[8:10])[0] return { "_raw": bits, @@ -123,8 +123,8 @@ class StatisticsPacket(object): def integration_interval_raw(self) -> int: """ Returns the integration interval, in blocks. """ - # This field is 3 bytes, little endian, so we need to append a 0 to parse it as a 32-bit integer. - return unpack("<I", self.packet[11:14] + b'0')[0] + # This field is 3 bytes, big endian, so we need to prepend a 0 to parse it as a 32-bit integer. + return unpack(">I", b'0' + self.packet[11:14])[0] def integration_interval(self) -> float: """ Returns the integration interval, in seconds. """ @@ -136,7 +136,7 @@ class StatisticsPacket(object): def data_id_raw(self) -> int: """ Returns the generic data identifier. """ - return unpack("<I",self.packet[14:18])[0] + return unpack(">I",self.packet[14:18])[0] @property def sst_signal_input_index(self) -> int: @@ -180,25 +180,25 @@ class StatisticsPacket(object): @property def nof_signal_inputs(self) -> int: """ Number of inputs that were used for constructing the payload. """ - return unpack("<B",self.packet[18:19])[0] + return unpack(">B",self.packet[18:19])[0] @property def nof_bytes_per_statistic(self) -> int: """ Word size for the payload. """ - return unpack("<B",self.packet[19:20])[0] + return unpack(">B",self.packet[19:20])[0] @property def nof_statistics_per_packet(self) -> int: """ Number of data points in the payload. """ - return unpack("<H",self.packet[20:22])[0] + return unpack(">H",self.packet[20:22])[0] @property def block_period_raw(self) -> int: """ Return the block period, in nanoseconds. """ - return unpack("<H",self.packet[22:24])[0] + return unpack(">H",self.packet[22:24])[0] def block_period(self) -> float: """ Return the block period, in seconds. """ @@ -209,7 +209,7 @@ class StatisticsPacket(object): def block_serial_number(self) -> int: """ Block index since epoch (1970). """ - return unpack("<Q",self.packet[24:32])[0] + return unpack(">Q",self.packet[24:32])[0] def timestamp(self) -> datetime: """ Returns the timestamp of the data in this packet. @@ -271,7 +271,7 @@ class StatisticsPacket(object): # derive which and how many elements to read from the packet header bytecount_to_unsigned_struct_type = { 1: 'B', 2: 'H', 4: 'I', 8: 'Q' } - format_str = "<{}{}".format(self.nof_statistics_per_packet, bytecount_to_unsigned_struct_type[self.nof_bytes_per_statistic]) + format_str = ">{}{}".format(self.nof_statistics_per_packet, bytecount_to_unsigned_struct_type[self.nof_bytes_per_statistic]) return numpy.array(unpack(format_str, self.packet[32:32+calcsize(format_str)])) -- GitLab