Skip to content

fix(readers): enumerate libnfc ACR122 devices#842

Merged
wizzomafizzo merged 2 commits into
mainfrom
fix/issue-811-libnfc-acr122-enumeration
May 24, 2026
Merged

fix(readers): enumerate libnfc ACR122 devices#842
wizzomafizzo merged 2 commits into
mainfrom
fix/issue-811-libnfc-acr122-enumeration

Conversation

@wizzomafizzo
Copy link
Copy Markdown
Member

@wizzomafizzo wizzomafizzo commented May 24, 2026

Summary

  • enumerate concrete libnfc ACR122 connection strings instead of using only libnfcauto
  • skip already-connected ACR122 paths so multiple readers can connect independently
  • preserve underscored ACR122 libnfc driver names after config normalization

Fixes #811

Validated with go test ./pkg/readers/libnfc/ and golangci-lint run --fix pkg/readers/libnfc/.

Summary by CodeRabbit

  • Bug Fixes

    • Improved ACR122 reader detection with device-path filtering and deduplication; removed previous fallback behavior in certain detection paths
    • Added normalized handling for ACR122 USB and PCSC connection strings; trims trailing NUL bytes from libnfc-reported strings
  • Tests

    • Added comprehensive ACR122 detection tests covering selection, skipping already-connected devices, ignoring non-ACR122 entries, and fallback behavior
    • Extended connection-string normalization and end-to-end cases for ACR122 variants

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31dcdf7a-d7ec-4307-b222-69cb41b705ed

📥 Commits

Reviewing files that changed from the base of the PR and between 212be61 and 20c0336.

📒 Files selected for processing (2)
  • pkg/readers/libnfc/libnfc.go
  • pkg/readers/libnfc/libnfc_test.go

📝 Walkthrough

Walkthrough

This PR implements enumeration-based ACR122 device detection to resolve multiple-reader auto-detect issues. Reader.Detect queries libnfc for concrete ACR122 connections, deduplicates by derived paths, conditionally falls back to auto-open, and extends connection-string normalization for ACR122 USB/PCSC variants.

Changes

ACR122 Multi-Device Detection and Normalization

Layer / File(s) Summary
ACR122 Device Detection and Reader.Detect Integration
pkg/readers/libnfc/libnfc.go, pkg/readers/libnfc/libnfc_test.go
Reader.Detect now calls detectACR122Readers(connected) in both the ACR122-only and default branches. New helpers call nfc.ListDevices(), filter libnfc connection strings to acr122_usb:/acr122_pcsc:, derive a path component, skip already-connected paths, and return either a selected connection string, "" if libnfc reported ACR122 devices but none selectable, or fall back to autoConnStr only if libnfc reported no ACR122 entries. Tests in TestDetectACR122Device validate selection, deduplication, NUL trimming, and fallback behavior.
ACR122 Connection String Normalization
pkg/readers/libnfc/libnfc.go, pkg/readers/libnfc/libnfc_test.go
toLibnfcConnStr now converts internal acr122usb:acr122_usb: and acr122pcsc:acr122_pcsc:. Tests in TestToLibnfcConnStr and TestToLibnfcConnStrEndToEnd verify driver-name normalization and end-to-end libnfc-formatted connection strings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hop, hop, enumerate with glee,
Each ACR122 now finds its key,
Paths unrolled and NULs trimmed clean,
No more single-reader scene,
Little readers dance — hooray for me!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: enumerating libnfc ACR122 devices instead of relying on a single auto-detect path.
Linked Issues check ✅ Passed The pull request implements all core requirements from issue #811: enumerates concrete libnfc ACR122 connection strings, skips already-connected devices, and preserves driver names.
Out of Scope Changes check ✅ Passed All changes are directly scoped to ACR122 device enumeration logic and related test coverage; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-811-libnfc-acr122-enumeration

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/readers/libnfc/libnfc_test.go`:
- Around line 482-535: Add a regression test for the branch where ACR122 devices
are enumerated but every ACR122 path is already present in connected (expect
""), and fix the "auto already connected" case to use the same driver:path
string format the autodetect contract uses instead of raw autoConnStr; update
the table in TestDetectACR122Device (affecting the test cases that call
detectACR122Device and reference autoConnStr) by adding a case with devices like
"acr122_usb:003:004" and connected containing that same concrete path(s), and
change the existing auto-connected case to pass the driver-prefixed connection
string form rather than autoConnStr so it matches detectACR122Device's input
format.

In `@pkg/readers/libnfc/libnfc.go`:
- Around line 659-676: The current detectACR122Device loop calls
fallbackAutoACR122(connected) unconditionally when no new connStr is returned,
which causes a fallback to "libnfcauto:" even if ACR122 devices were enumerated
but skipped because their paths are already connected; modify detectACR122Device
to track whether any ACR122 connStrs were seen (use isACR122ConnStr(connStr))
and only call fallbackAutoACR122(connected) when none were found; if ACR122
devices existed but were all skipped due to
isConnectedPath(connectionPath(connStr)), return "" instead of falling back.
Ensure the same change is applied to the analogous block referenced in lines
678-683.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9b58b4d7-3058-4980-b921-37e2d17488e1

📥 Commits

Reviewing files that changed from the base of the PR and between 9c4dd2b and 212be61.

📒 Files selected for processing (2)
  • pkg/readers/libnfc/libnfc.go
  • pkg/readers/libnfc/libnfc_test.go

Comment thread pkg/readers/libnfc/libnfc_test.go
Comment thread pkg/readers/libnfc/libnfc.go
@sentry
Copy link
Copy Markdown

sentry Bot commented May 24, 2026

Codecov Report

❌ Patch coverage is 75.60976% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/readers/libnfc/libnfc.go 75.60% 9 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@wizzomafizzo wizzomafizzo merged commit c7a2dfd into main May 24, 2026
12 checks passed
@wizzomafizzo wizzomafizzo deleted the fix/issue-811-libnfc-acr122-enumeration branch May 24, 2026 10:42
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.

MiSTer: multiple ACR122U readers only connects one via libnfc auto-detect

1 participant