def _open_file(self): """Open the configured file for processing""" file_opened = False while not self.stop_reading.isSet(): if dltlib.dlt_file_open(ctypes.byref(self), self.filename, self.verbose) >= DLT_RETURN_OK: file_opened = True break if not self.live_run: break time.sleep(0.5) if not file_opened: logger.error("DLT FILE OPEN FAILED - Analysis will not be performed") raise IOError(cDLT_FILE_NOT_OPEN_ERROR)
def generate_index(self): """Generate an index for the loaded DLT file :returns: True if file had been previously read and the index is successfully generated, otherwise False :rtype: bool """ if not self.filename: return False self.indexed = False if dltlib.dlt_file_open(ctypes.byref(self), self.filename, self.verbose) >= DLT_RETURN_OK: # load, analyse data file and create index list if self.file_length == 0: raise IOError(DLT_EMPTY_FILE_ERROR) while self.file_position < self.file_length: ret = dltlib.dlt_file_read(ctypes.byref(self), self.verbose) if ret < DLT_RETURN_OK: # - This can happen if either the frame's storage # header could not be read correctly or the frame is # corrupt. If the frame's storage header could not # be read correctly we try to get the next storage # header and continue indexing next_header_position = self._find_next_header() if next_header_position: if self.file_position == next_header_position: # pylint: disable=no-else-break # - This this implies that dltlib.dlt_read_file() # returned due to an error other than invalid storage # header because we already were at the correct # header_position in the last iteration. So, we # need to break out of the read/index loop. break else: self.file_position = next_header_position self.corrupt_msg_count += 1 else: break self.indexed = True else: raise IOError(cDLT_FILE_NOT_OPEN_ERROR) return self.indexed