@@ -80,6 +80,7 @@ def _read_struct(self, fmt, endian='<', data=None, always_tuple=False):
8080
8181 def _read_and_assert_crc (self , allow_zero = False ):
8282 # CRC Calculation is little endian from SDK
83+ # TODO - How to handle the case of unterminated file? Error out and have user retry with check_crc=false?
8384 crc_computed , crc_read = self ._crc .value , self ._read_struct (Crc .FMT )
8485 if not self .check_crc :
8586 return
@@ -132,7 +133,8 @@ def _parse_file_header(self):
132133 def _parse_message (self ):
133134 # When done, calculate the CRC and return None
134135 if self ._bytes_left <= 0 :
135- if not self ._complete :
136+ # Don't assert CRC if requested not
137+ if not self ._complete and self .check_crc :
136138 self ._read_and_assert_crc ()
137139
138140 if self ._file .tell () >= self ._filesize :
@@ -245,9 +247,14 @@ def _parse_raw_values_from_data_message(self, def_mesg):
245247 struct_fmt = str (int (field_def .size / base_type .size )) + base_type .fmt
246248
247249 # Extract the raw value, ask for a tuple if it's a byte type
248- raw_value = self ._read_struct (
249- struct_fmt , endian = def_mesg .endian , always_tuple = is_byte ,
250- )
250+ try :
251+ raw_value = self ._read_struct (
252+ struct_fmt , endian = def_mesg .endian , always_tuple = is_byte ,
253+ )
254+ except FitEOFError :
255+ # file was suddenly terminated, usually due to
256+ print ("File was terminated unexpectedly, some data will not be loaded." )
257+ break
251258
252259 # If the field returns with a tuple of values it's definitely an
253260 # oddball, but we'll parse it on a per-value basis it.
0 commit comments