-
-
Notifications
You must be signed in to change notification settings - Fork 24
feat(readers): stable reader IDs and improved management #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add GetUSBTopologyPath helper that resolves device paths to their physical USB port topology (e.g., "1-2.3"). This provides stable device identification that survives reboots, useful for persistent reader identification. Platform implementations: - Linux: Uses sysfs to resolve device major/minor to USB topology - Windows: Uses SetupAPI to extract USBROOT/USB port segments - Darwin: Uses IOKit to traverse USB device hierarchy
Reduce hash portion from 26 to 8 base32 characters for improved readability while maintaining sufficient uniqueness for local device identification. 40 bits provides ~1 trillion combinations, far exceeding practical collision risk for per-system reader counts. Example: pn532-jbsxmwkziaxvk3dfjbsxmwkz → pn532-ujqixjv6
When readers were unplugged, they remained in the readers list indefinitely because Connected() continued to return true even after the underlying connection failed. PN532: - Add `connected` bool field that tracks session lifecycle - Set to true before session starts, false when session exits (via defer) - Update Connected() to check this field instead of context state LibNFC: - Update Connected() to check `polling` flag (already set false on I/O errors) - Matches pattern used by other serial-based readers Also upgrades go-pn532 v0.14.0 → v0.15.0 which fixes polling loops to exit on fatal I/O errors instead of retrying forever.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Achieves 100% test coverage on all functions in autodetect.go including: - Connected/failed map operations with driver ID normalization - Detection flow with various driver enable/auto-detect states - Connection success, open errors, and connection failures - Close error handling in multiple contexts - Logging with state changes and heartbeats - Concurrent access safety - Exclude list handling for connected reader paths
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Major improvements to reader management with stable, persistent reader IDs and better lifecycle handling.
Key Changes
Stable Reader IDs
/dev/ttyUSB0→/dev/ttyUSB1)pkg/readers/identity.gowithGenerateReaderID()functionReader Capabilities System
pkg/readers/capabilities.godefining reader capabilitiesCapabilityRemovable,CapabilityWrite, etc.Disconnection Detection Fix
connectedbool to PN532 that tracks session lifecycleConnected()to checkpollingflagAPI Changes
ReaderInforesponse addsreaderId(stable) anddriverfieldsTokenResponseaddsreaderIdfieldreaders.writeandreaders.write.cancelaccept optionalreaderIdparam to target specific readerFiles Changed
pkg/helpers/usb_{linux,darwin,windows}.go- USB topology resolutionpkg/readers/identity.go- Reader ID generationpkg/readers/capabilities.go- Capabilities systempkg/readers/*.go- All drivers updated withReaderID()methodpkg/api/models/*.go- New fields in params and responsespkg/api/methods/readers.go- Refactored to use new reader selectionpkg/service/readers.go- Reader management updates