Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving signal overlapping error message #137

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading