8000 cdd: correct LINCOMP conversions and support packed integer containers by tomrford · Pull Request #59 · tomrford/gocan · GitHub
[go: up one dir, main page]

Skip to content

cdd: correct LINCOMP conversions and support packed integer containers - #59

Merged
tomrford merged 7 commits into
mainfrom
fix/cdd-lincomp-conversion
Sep 5, 2026
Merged

tomrford merged 7 commits into
mainfrom
fix/cdd-lincomp-conversion

Conversation

@tomrford
@tomrford tomrford commented Sep 5, 2026 •
Copy link
Copy Markdown
Owner

CDD LINCOMP decoding ignored div, so raw 502 with f=1, div=100, o=0 decoded as 502 and encoding 5.02 failed. STRUCT resolution also discarded the enclosing datatype and treated children as consecutive wire fields, losing the container's size and byte mapping.

Normalise LINCOMP to physical = (f/div)*raw + o and use the existing inverse codec. Preserve exact 64-bit integers for identity conversions, enforce optional limits against raw integers, and reject malformed/non-finite parameters, zero divisors, ambiguous declarations and empty representable ranges. Only an omitted divisor defaults to 1; negative divisors are accepted.

Retain STRUCT container metadata and position integer children from its logical least-significant bit. Apply atomic container byte order to the combined value; fixed one-byte arrays use most-significant-byte-first mapping unless the ReverseBitfieldBytes enumeration resolved within ECUDOC/DEFATTS/DATATYPEATTS (also accepting the explicit ReverseBitFieldBytes spelling, with duplicate declarations rejected) reverses the whole sequence. Explicit gaps and unused container space remain reserved: ignored when decoding and zero when encoding. Width checks protect neighbouring fields. Unresolved and overfull layouts fail explicitly.

Reference evidence and scope

  • The equation, divisor default and raw-limit semantics come from supplied transcriptions of installed Vector CANdelaStudio 9.1 and 17 English help. The offset is outside the division. Installed Vector ODX export documentation identifies a zero divisor as invalid input.
  • Packed positioning, enclosing datatype behaviour, byte reversal and reserved-bit rules come from the supplied CANdelaStudio 17 English help findings. Its 7-bit/2-bit diagram gives 00 7F for Motorola and 7F 00 for Intel. The independently calculated 7-bit/9-bit case gives 91 B5 and B5 91.
  • Fixtures and tests record this provenance. They are synthetic examples and independent arithmetic, not CANoe/CANalyzer execution results. No local Vector executable oracle was available.
  • The exact candela.dtd for 10.0.108 remains unavailable. These findings do not establish every XML attribute requirement. Missing factor/offset remain explicitly unsupported, without invented defaults. Zero-factor conversions need Vector's explicit inverse-value behaviour and remain unsupported rather than being classified as malformed.
  • Supported packed children are atomic signed/unsigned integers up to 64 bits, including choices and LINCOMP. Containers are fixed byte-aligned IDENT or TEXTTBL integer atoms up to 64 bits, or fixed one-byte IDENT integer/ASCII arrays. A TEXTTBL container contributes only its coded size and byte order; child values and labels use each child’s datatype. Nested bitfields are prohibited; child arrays, Unicode-array containers and other container types remain explicitly unsupported. Top-level unaligned fields remain unsupported.
  • Correct two synthetic fixtures that previously used untyped STRUCT as a grouping wrapper: give the one-byte sample its datatype, and express Nameplate's ordinary calibration fields as a top-level sequence. Missing STRUCT datatype references have dedicated rejection coverage.

Validation

  • Independent decode values and encode bytes cover divisors 10/100, non-unit factors with nonzero offsets, signed values, raw/range boundaries and exact 64-bit identity values.
  • Packed cases cover two 4-bit fields, consecutive 14-bit fields, crossing boundaries, mixed containers/ordinary fields, both byte orders, choices/scaling, reserved bits, payload lengths, reversal declarations/overrides, TEXTTBL containers with 2-bit/3-bit states and nonzero reserved response bits, and an unaligned 64-bit value spanning nine bytes.
  • go test -race ./... passed.
  • go vet ./... passed.
  • gofmt -l . produced no output; git diff --check passed.
  • Fresh independent adversarial review completed; both reported validation gaps were fixed and re-reviewed.
  • An additional fresh full-branch minimalism review found one redundant decoding pass for fields without raw limits. That pass now runs only when limits exist; the reviewer otherwise recommended retaining the implementation and tests.

Conversion handling and packed-field support are in separate commits, followed by focused validation and minimalism fixes.


Note

Medium Risk
Changes core CDD record encode/decode and on-wire layout for LINCOMP and STRUCT containers, which can alter bytes and decoded values for existing catalogs even though behavior is intended to match CANdelaStudio rules.

Overview
Fixes LINCOMP handling so physical values use (f/div)*raw + o (div defaults to 1), with stricter parsing and codec checks for raw limits (s/e), non-finite parameters, zero divisors, ambiguous COMP/CVALUETYPE, and empty representable ranges. Encode/decode now validate raw values against those limits when present.

STRUCT with a fixed byte-aligned IDENT or TEXTTBL container is resolved as a shared bitfield: children pack from the container LSB with container byte order, optional ReverseBitfieldBytes reversal for one-byte arrays, gaps/reserved bits ignored on decode and zeroed on encode. Record Encode/Decode route bitfield children through readPacked/writePacked and relax byte-alignment rules only inside bitfields.

Test fixtures drop invalid untyped STRUCT wrappers; large reference tests cover conversions, packing, reversal, and rejection cases.

Reviewed by Cursor Bugbot for commit db05544. Configure here.

@tomrford
tomrford commented Sep 5, 2026
Copy link
Copy Markdown
Owner Author

cursor review

8000

@cursor cursor Bot left a comment •
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tomrford
tomrford commented Sep 5, 2026
Copy link
Copy Markdown
Owner Author

cursor review

@cursor cursor Bot left a comment •
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tomrford
tomrford commented Sep 5, 2026
Copy link
Copy Markdown
Owner Author

cursor review

@cursor cursor Bot left a comment •
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tomrford
tomrford commented Sep 5, 2026
Copy link
Copy Markdown
Owner Author

cursor review

@cursor cursor Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit db05544. Configure here.

@tomrford
tomrford merged commit 7519a4a into main Sep 5, 2026
2 checks passed
@tomrford
tomrford deleted the fix/cdd-lincomp-conversion branch September 5, 2026 23:20
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.

1 participant

0