Skip to content

sym: use the longest Len of a multiplexed message - #879

Merged
andlaus merged 1 commit into
cantools:masterfrom
TheeCoderAhmed:fix/sym-multiplexed-len
Nov 4, 2026
Merged

andlaus merged 1 commit into
cantools:masterfrom
TheeCoderAhmed:fix/sym-multiplexed-len

Conversation

@TheeCoderAhmed

Copy link
Copy Markdown
Contributor

Fixes #148

A multiplexed SYM message can repeat its section with a different Len= for each multiplexer value:

[TestAlert]
ID=700h
Len=4
Mux=FSM 0,8 1
Var=alert1 unsigned 8,1

[TestAlert]
Len=8
Mux=TestMuxFloat 0,8 2
Var=value float 8,32

Loading this fails with The signal value does not fit in message TestAlert.

_load_message read Len only from the first section, the one with the ID. _load_muxed_message_signals merges the signals of every section with that name, so signals from the later sections were checked against the first section's length.

The message length is now the largest Len among the first section and the sections that continue it (same name, no ID). Non-multiplexed messages and sections without a Len read the same as before.

One behaviour change to check: a file whose first section is shorter than a later one now loads with the longer length, even if all its signals happened to fit the first. cantools keeps one length per message, so a short frame for the first multiplexer value now needs allow_truncated=True to decode.

What I ran:

  • the new test_multiplexed_sections_with_different_lengths_sym fails before the change and passes after it
  • pytest tests/test_database.py tests/test_convert.py tests/test_dump.py tests/test_list.py tests/test_database_merge.py tests/test_tester.py: 327 passed
  • ruff check src tests/test_database.py, and mypy on sym.py only

Not run: the rest of the test suite (command line, monitor, plot), tox, or the C code generation tests. I did not check the sample file in the PCAN Symbol Editor.

Each section of a multiplexed SYM message can state its own Len, but
only the Len of the first section was read. Signals from the later
sections were then checked against that length, so loading failed with
"The signal x does not fit in message y".

Take the largest Len of the first section and the sections continuing
it. Non-multiplexed messages and sections without a Len read as before.
@andlaus

andlaus commented Nov 4, 2026

Copy link
Copy Markdown
Member

I don't know much about the SYM format, but the reasoning here seems correct. (I trust that your LLM got the implementation right.) Merging, thanks!

@andlaus
andlaus merged commit 0497552 into cantools:master Nov 4, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiplexed signals counting size incorrectly

2 participants