88import struct
99import warnings
1010from datetime import datetime , timezone
11- from typing import Tuple
11+ from typing import Tuple , Union
1212
1313import numpy as np
1414
@@ -52,8 +52,8 @@ def unpack_sbd(file_name: str, file_content: bytes) -> Tuple:
5252 sensor_type = get_sensor_type (file_content )
5353
5454 if sensor_type :
55- payload_struct = get_sensor_type_definition (sensor_type )
5655 file_size = len (file_content )
56+ payload_struct = get_sensor_type_definition (sensor_type , file_size )
5757 expected_file_size = struct .calcsize (payload_struct )
5858 if file_size == expected_file_size :
5959 data = struct .unpack (payload_struct , file_content )
@@ -70,10 +70,14 @@ def unpack_sbd(file_name: str, file_content: bytes) -> Tuple:
7070 error_message ['error' ] = _rstrip_null (file_content ) # decode('ascii')
7171
7272 if data :
73- if sensor_type == 51 :
73+ if sensor_type == '51' :
7474 swift = unpack_sensor_type_51 (data )
75- elif sensor_type == 52 :
75+ elif sensor_type == '52' :
7676 swift = unpack_sensor_type_52 (data )
77+ elif sensor_type == '53' :
78+ swift = {} # TODO: ignore for now, but implement later
79+ elif sensor_type == '54' :
80+ swift = {} # TODO: ignore for now, but implement later
7781 else :
7882 raise NotImplementedError (f'The specified sensor type '
7983 f'({ sensor_type } ) is not supported.' )
@@ -83,7 +87,7 @@ def unpack_sbd(file_name: str, file_content: bytes) -> Tuple:
8387 return swift , error_message
8488
8589
86- def get_sensor_type (file_content : bytes ) -> int :
90+ def get_sensor_type (file_content : bytes ) -> Union [ str , None ] :
8791 """
8892 Determine sensor type from an SBD message.
8993
@@ -96,13 +100,13 @@ def get_sensor_type(file_content: bytes) -> int:
96100 file_content (bytes): binary SBD message
97101
98102 Returns:
99- (int ): int corresponding to sensor type
103+ (str ): str corresponding to sensor type
100104 """
101105 payload_type = \
102106 file_content [PAYLOAD_START :PAYLOAD_START + 1 ].decode (errors = 'replace' )
103107
104108 if payload_type == PAYLOAD_TYPE :
105- sensor_type = ord (file_content [PAYLOAD_START + 1 :PAYLOAD_START + 2 ])
109+ sensor_type = str ( ord (file_content [PAYLOAD_START + 1 :PAYLOAD_START + 2 ]) )
106110 else :
107111 sensor_type = None
108112
0 commit comments