Skip to content

Revision code parsing for board detection#682

Merged
FDelporte merged 6 commits into
Pi4J:developfrom
pjbosco:revision-code-parsing-for-board-detection
Jun 30, 2026
Merged

Revision code parsing for board detection#682
FDelporte merged 6 commits into
Pi4J:developfrom
pjbosco:revision-code-parsing-for-board-detection

Conversation

@pjbosco

@pjbosco pjbosco commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Introduce RevisionCode, a parser for the Raspberry Pi 32-bit revision
code format (NOQuuuWuFMMMCCCCPPPPTTTTTTTTRRRR). Both new-style codes
(identified by bit 23) and old-style codes are supported. New-style
codes are decoded by extracting structured bit fields for memory size,
processor, and board type. Old-style codes are matched against known
revision code tables.

Update BoardModel.getByBoardCode() to attempt structured identification
via RevisionCode before falling back to legacy string matching. Add
BoardModel.getByRevisionCode(RevisionCode) which switches on the decoded
board type and, where necessary, disambiguates on PCB revision or memory
size.

This aligns board identification with the Raspberry Pi foundation's
recommended best practices for revision code usage
, ensuring that new
board revisions of existing types are identified correctly without
requiring a code change.

  • Add RevisionCode with nested MemorySize, Processor, and Type enums
  • Add RevisionCodeTest with full coverage of new-style and old-style
    parsing, field extraction, string input handling, and edge cases
  • Add BoardModel.getByRevisionCode(RevisionCode)
  • Add BoardModelTest cases for getByRevisionCode()
  • Update BoardModel.getByBoardCode() to delegate to RevisionCode and BoardModel.getByRevisionCode()

See discussion here: #679

pjbosco and others added 3 commits June 27, 2026 21:35
Introduce RevisionCode, a parser for the Raspberry Pi 32-bit revision
code format (NOQuuuWuFMMMCCCCPPPPTTTTTTTTRRRR). Both new-style codes
(identified by bit 23) and old-style codes are supported. New-style
codes are decoded by extracting structured bit fields for memory size,
processor, and board type. Old-style codes are matched against known
revision code tables.

Update BoardModel.getByBoardCode() to attempt structured identification
via RevisionCode before falling back to legacy string matching. Add
BoardModel.getByRevisionCode(RevisionCode) which switches on the decoded
board type and, where necessary, disambiguates on PCB revision or memory
size.

This aligns board identification with the Raspberry Pi foundation's
recommended best practices for revision code usage, ensuring that new
board revisions of existing types are identified correctly without
requiring a code change.

- Add RevisionCode with nested MemorySize, Processor, and Type enums
- Add RevisionCodeTest with full coverage of new-style and old-style
  parsing, field extraction, string input handling, and edge cases
- Update BoardModel.getByBoardCode() to delegate to RevisionCode
- Add BoardModel.getByRevisionCode(RevisionCode)
- Add BoardModelTest cases for getByRevisionCode()
@pjbosco

pjbosco commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Working on fixing the cognitive complexity/duplication called out by sonar.

pjbosco added 2 commits June 29, 2026 14:52
- extracting a common interface, RevisionCodeEnum`, for internal enumerations of RevisionCode
- creating a new fromNewStyleCode() method that generically returns an enum constant whose bit field value matches the extracted field of a new-style revision code based on a given shift and mask
- creating a new fromOldStyleCode() method that generically returns an enum constant whose old-style revision code list contains the given revision code
…detection' into revision-code-parsing-for-board-detection
@pjbosco

pjbosco commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Working on fixing the cognitive complexity/duplication called out by sonar.

I think I've got that fixed. Slight refactor on RevisionCode.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds structured parsing of Raspberry Pi 32-bit revision codes and uses the decoded fields to improve BoardModel detection, reducing reliance on hardcoded legacy string matching.

Changes:

  • Introduces RevisionCode with enums to decode new-style and old-style revision codes.
  • Adds BoardModel.getByRevisionCode(RevisionCode) and updates getByBoardCode() to prefer structured decoding before legacy lookup.
  • Adds/extends unit tests for revision-code parsing and board-model resolution.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
pi4j-core/src/main/java/com/pi4j/boardinfo/definition/RevisionCode.java New revision-code parser and field decoders (memory/processor/type/revision).
pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java Adds structured RevisionCode-based board detection and integrates it into getByBoardCode().
pi4j-core/src/test/java/com/pi4j/boardinfo/definition/RevisionCodeTest.java New tests covering parsing, field extraction, and edge cases.
pi4j-core/src/test/java/com/pi4j/boardinfo/definition/BoardModelTest.java Adds test cases for BoardModel.getByRevisionCode().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java Outdated
- Refactor RevisionCode.of(String) to do more initial checking on the given String.
- Update MemorySize.getOldStyleRevisionCodes(), Type.getOldStyleRevisionCodes(), and Processor.getOldStyleRevisionCodes() methods to return a copy of the internal array of each respective enum rather than a reference to the internal array itself.
- Fix formatting in BoardModel.getByBoardCode().
- Update RevisionCodeTest to more thoroughly test the RevisionCode class, especially around input validation for the of() method. Also added a test for the equals(), hashCode(), and toString() methods.
@FDelporte FDelporte merged commit 2a0c40d into Pi4J:develop Jun 30, 2026
5 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants