Skip to content

Commit

Permalink
Improving signal overlapping error message (#137)
Browse files Browse the repository at this point in the history
* Better message when signals overlap or are outside the frame
  • Loading branch information
c4deszes authored Apr 28, 2024
1 parent 8a38dc2 commit fbf34fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.25.0] - 2024-04-28

### Changed

- Signals overlapping error message now includes relevant information

## [0.24.0] - 2024-02-22

### Changed
Expand Down
9 changes: 6 additions & 3 deletions ldfparser/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ def __init__(self, frame_id: int, name: str, length: int, signals: Dict[int, 'Li
self.publisher = None
self.length = length
self.signal_map = sorted(signals.items(), key=lambda x: x[0])
self._packer = LinUnconditionalFrame._frame_pattern(self.length, self.signal_map, pad_with_zero)
self._packer = LinUnconditionalFrame._frame_pattern(self.name, self.length, self.signal_map, pad_with_zero)

@staticmethod
def _frame_pattern(
frame_name: str,
frame_size: int,
signals: List[Tuple[int, 'LinSignal']],
pad_with_zero: bool = True,
Expand Down Expand Up @@ -89,21 +90,23 @@ def _frame_pattern(
pattern = "<"
frame_bits = frame_size * 8
frame_offset = 0
prev_signal = None
padding_value = "p" if pad_with_zero else "P"
for (offset, signal) in signals:
if offset < frame_offset:
raise ValueError(f"{signal} is overlapping ")
raise ValueError(f"{frame_name}: {signal.name} at bit {offset} is overlapping {prev_signal.name}")
if offset != frame_offset:
padding = offset - frame_offset
pattern += f"{padding_value}{padding}"
frame_offset += padding
if frame_offset + signal.width > frame_bits:
raise ValueError(f"{signal} with offset {offset} spans outside frame!")
raise ValueError(f"{frame_name}: {signal.name} at bit {offset} spans outside frame!")
if signal.is_array():
pattern += "u8" * int(signal.width / 8)
else:
pattern += f"u{signal.width}"
frame_offset += signal.width
prev_signal = signal
if frame_offset < frame_bits:
pattern += f"{padding_value}{frame_bits - frame_offset}"
return bitstruct.compile(pattern)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
version = 0.24.0
version = 0.25.0

0 comments on commit fbf34fe

Please sign in to comment.