Problem
The current decodeCAN implementation reads raw bit values without performing CAN bit destuffing. Per the CAN 2.0 spec, after 5 consecutive bits of the same value, a complement (stuff) bit is inserted. The decoder must remove these stuff bits to correctly parse the arbitration, control, data, and CRC fields.
Impact
- Real CAN captures (e.g. the
can_mcp2515_125k_msg_222.sr fixture from sigrok-dumps) cannot be fully decoded — decodeCAN returns 0 frames.
autoDetectLaProtocol falls back to UART instead of CAN on real captures.
- Label-based detection (
inferDecoderDefaults with CAN_RX label) still works correctly.
Fix
Add a bit-destuffing pass in decodeCAN that:
- Tracks consecutive same-valued bits
- After 5 consecutive, skips the next stuff bit
- Uses destuffed bit stream for all field parsing (ID, RTR, IDE, DLC, data, CRC)
Test
The existing can_mcp2515_125k_msg_222.sr fixture (4 MS/s, 125 kbits, standard frame ID 222 with 5 data bytes) can be used to verify the fix. The test in sigrokFixtures.test.ts already checks label detection and signal activity — once destuffing is added, it should be extended to verify full frame decode.
Problem
The current
decodeCANimplementation reads raw bit values without performing CAN bit destuffing. Per the CAN 2.0 spec, after 5 consecutive bits of the same value, a complement (stuff) bit is inserted. The decoder must remove these stuff bits to correctly parse the arbitration, control, data, and CRC fields.Impact
can_mcp2515_125k_msg_222.srfixture from sigrok-dumps) cannot be fully decoded —decodeCANreturns 0 frames.autoDetectLaProtocolfalls back to UART instead of CAN on real captures.inferDecoderDefaultswithCAN_RXlabel) still works correctly.Fix
Add a bit-destuffing pass in
decodeCANthat:Test
The existing
can_mcp2515_125k_msg_222.srfixture (4 MS/s, 125 kbits, standard frame ID 222 with 5 data bytes) can be used to verify the fix. The test insigrokFixtures.test.tsalready checks label detection and signal activity — once destuffing is added, it should be extended to verify full frame decode.