Repository navigation
Description
What happens
J1939Parser::getPgn (j1939_parser/j1939_parser.cpp) looks up frame_.canID() and, on a miss, frame_.pgn_.
J1939_frame::canID() packs priority, data page, PF, PS or destination, source address, and CAN_EFF_FLAG when extended_ is set. A live frame almost never equals the key the compiler stored. The test GetPgnFallsBackToPgnKeyLookup documents this: the CAN-id probe is expected to miss, and the PGN probe is what hits.
DbcParser::removeDuplicates (j1939_parser/dbc_parser/dbc_parser.cpp) then builds those keys with a different rule than the lookup:
- Extended ids are grouped by PGN. A PGN that has a single layout is reinserted under the bare PGN, with SA cleared (
Message::generalized). - A PGN with several different layouts is reinserted under each message's CAN id. The first message in the group was already replaced by its generalized form, so its key has SA 0 and whatever priority
setFromextracted. Later messages keep the DBC CAN id, including priority, SA, and the extended-frame bit. - A PGN key is also inserted, but only for the first variant whose DLC is exactly 8. If every variant has some other DLC, there is no PGN key at all.
So a frame decodes only when its priority and source address happen to match the DBC, or when a PGN key was created as a side effect of the DLC-8 rule. Two ECUs sending the same PGN at different priorities, or a 16-byte DM1 next to an 8-byte variant, fall through to toStringRawFrame.
Standard (11-bit) ids skip this dedup. They stay under the raw BO_ id. setFrom still slices that id as a 29-bit J1939 id, so the fallback find(pgn_) can run against a meaningless PGN.
Also wrong in the equality used to collapse rows
Signal::operator== compares start bit, length, scale, offset, sign, min, max, and enums. It does not compare little_endian_. Two layouts that differ only in byte order are treated as the same message and one is discarded.
Message::operator== ignores source address on purpose, but combined with the key rules above the surviving row is not reliably findable.
Expected rule
Identity of an extended message is the PGN plus, only when the DBC really has two layouts, the source address. Priority and CAN_EFF_FLAG are not part of the key. DLC is not a tie-break for which row is the generic one.
The plain-C database proposed in the companion issue encodes that rule in the table (pgn, sa_mask, sa) so lookup is one binary search with a documented tie-break, not two map probes.
Tests to add
- Same PGN, two source addresses, identical signals, different priority bits in the
BO_id: one row, found for both source addresses and any priority. - Same PGN, different signals: both rows kept, a frame from SA A does not decode with SA B's layout, and a third SA misses rather than silently using whichever row happened to have DLC 8.
- Two signals equal except
@0vs@1: not collapsed. - An 11-bit id is found by
can_id & 0x7FFand is not also matched as a J1939 PGN.
Activity
ip332 commentedon Nov 19, 2026
Fixed in #10.
Extended identity is the PGN, plus the source address only when that PGN has two layouts. Priority is ignored.
BA_ "J1939Default"chooses the generic row when layouts differ, and DLC is not the tie-break.@0and@1are different layouts. An 11-bit id is found withcan_id & 0x7FF.