From 3307512874c40914e3c318227337bdc74646c001 Mon Sep 17 00:00:00 2001 From: danielhrisca Date: Fri, 8 May 2020 09:03:20 +0300 Subject: [PATCH] fixes #362 handle the case of wrong TX/MD link --- asammdf/blocks/mdf_v4.py | 14 ++++++++------ asammdf/blocks/utils.py | 16 ++++++++++++++-- asammdf/gui/widgets/plot_standalone.py | 19 ++++++++++--------- asammdf/signal.py | 1 + asammdf/version.py | 2 +- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/asammdf/blocks/mdf_v4.py b/asammdf/blocks/mdf_v4.py index cd3743ec4..84db33daf 100755 --- a/asammdf/blocks/mdf_v4.py +++ b/asammdf/blocks/mdf_v4.py @@ -6179,7 +6179,7 @@ def _get_structure( )[0] channel_values[i].append(vals) if master_is_required: - timestamps.append(self.get_master(gp_nr, fragment,)) + timestamps.append(self.get_master(gp_nr, fragment, one_piece=True)) if channel_invalidation_present: invalidation_bits.append( self.get_invalidation_bits(gp_nr, channel, fragment) @@ -6494,7 +6494,7 @@ def _get_array( vals = fromarrays(arrays, dtype(types)) if master_is_required: - timestamps.append(self.get_master(gp_nr, fragment)) + timestamps.append(self.get_master(gp_nr, fragment, one_piece=True)) if channel_invalidation_present: invalidation_bits.append( self.get_invalidation_bits(gp_nr, channel, fragment) @@ -6619,7 +6619,7 @@ def _get_scalar( vals += offset if master_is_required: - timestamps.append(self.get_master(gp_nr, fragment)) + timestamps.append(self.get_master(gp_nr, fragment, record_offset=offset, record_count=_count, one_piece=True)) if channel_invalidation_present: invalidation_bits.append( self.get_invalidation_bits(gp_nr, channel, fragment) @@ -6782,7 +6782,11 @@ def _get_scalar( vals = vals.astype(channel_dtype) if master_is_required: - timestamps = self.get_master(gp_nr, fragment, one_piece=True) + timestamps = self.get_master( + gp_nr, + fragment, + one_piece=True + ) else: timestamps = None @@ -7655,7 +7659,6 @@ def get_master( if time_ch_nr is None: if record_size: - offset = offset // record_size t = arange(cycles_nr, dtype=float64) t += offset else: @@ -7670,7 +7673,6 @@ def get_master( metadata = (time_name, time_ch.sync_type) if time_ch.channel_type == v4c.CHANNEL_TYPE_VIRTUAL_MASTER: - offset = offset // record_size time_a = time_conv["a"] time_b = time_conv["b"] t = arange(cycles_nr, dtype=float64) diff --git a/asammdf/blocks/utils.py b/asammdf/blocks/utils.py index f22ee3a47..09bec0edf 100644 --- a/asammdf/blocks/utils.py +++ b/asammdf/blocks/utils.py @@ -182,10 +182,16 @@ def get_text_v3(address, stream, mapped=False, decode=True): return "" if decode else b"" if mapped: + block_id = stream[address: address+2] + if block_id != b'TX': + return "" if decode else b"" (size,) = UINT16_uf(stream, address + 2) text_bytes = stream[address + 4 : address + size].strip(b" \r\t\n\0") else: - stream.seek(address + 2) + stream.seek(address) + block_id = stream.read(2) + if block_id != b'TX': + return "" if decode else b"" size = UINT16_u(stream.read(2))[0] - 4 text_bytes = stream.read(size).strip(b" \r\t\n\0") if decode: @@ -221,10 +227,16 @@ def get_text_v4(address, stream, mapped=False, decode=True): return "" if decode else b"" if mapped: + block_id = stream[address: address+4] + if block_id not in (b'##TX', b'##MD'): + return "" if decode else b"" (size,) = UINT64_uf(stream, address + 8) text_bytes = stream[address + 24 : address + size].strip(b" \r\t\n\0") else: - stream.seek(address + 8) + stream.seek(address) + block_id = stream.read(8)[:4] + if block_id not in (b'##TX', b'##MD'): + return "" if decode else b"" size, _ = TWO_UINT64_u(stream.read(16)) text_bytes = stream.read(size - 24).strip(b" \r\t\n\0") if decode: diff --git a/asammdf/gui/widgets/plot_standalone.py b/asammdf/gui/widgets/plot_standalone.py index 61164e592..270a23a39 100644 --- a/asammdf/gui/widgets/plot_standalone.py +++ b/asammdf/gui/widgets/plot_standalone.py @@ -35,6 +35,15 @@ def __init__(self, signals, *args, **kwargs): self.setMenuBar(self.menubar) self._settings = QtCore.QSettings() + self.with_dots = self._settings.value("dots", False, type=bool) + + if not isinstance(signals, (list, tuple)): + signals = [ + signals, + ] + + self.plot = Plot(signals, self.with_dots) + self._light_palette = self.palette() menu = QtWidgets.QMenu("Settings", self.menubar) @@ -339,15 +348,6 @@ def __init__(self, signals, *args, **kwargs): open_group.addAction(action) menu.addActions(open_group.actions()) - self.with_dots = self._settings.value("dots", False, type=bool) - - if not isinstance(signals, (list, tuple)): - signals = [ - signals, - ] - - self.plot = Plot(signals, self.with_dots) - self.setCentralWidget(self.plot) icon = QtGui.QIcon() @@ -385,6 +385,7 @@ def set_plot_xaxis(self, option): fmt = "time" plot = self.plot + plot.plot.x_axis.format = fmt plot.plot.x_axis.updateAutoSIPrefix() if plot.plot.cursor1 is not None: diff --git a/asammdf/signal.py b/asammdf/signal.py index c91b1451e..dcdedfb58 100644 --- a/asammdf/signal.py +++ b/asammdf/signal.py @@ -174,6 +174,7 @@ def plot(self, validate=True): return except: + print(format_exc()) try: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d diff --git a/asammdf/version.py b/asammdf/version.py index f779a3e8d..e1b7dea9b 100644 --- a/asammdf/version.py +++ b/asammdf/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- """ asammdf version module """ -__version__ = "5.20.3" +__version__ = "5.20.4"