Skip to content

Commit

Permalink
fixes #362
Browse files Browse the repository at this point in the history
handle the case of wrong TX/MD link
  • Loading branch information
danielhrisca committed May 8, 2020
1 parent 4633ea5 commit 3307512
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
14 changes: 8 additions & 6 deletions asammdf/blocks/mdf_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions asammdf/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 10 additions & 9 deletions asammdf/gui/widgets/plot_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions asammdf/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion asammdf/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
""" asammdf version module """

__version__ = "5.20.3"
__version__ = "5.20.4"

0 comments on commit 3307512

Please sign in to comment.