Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateReaderID ¶ added in v2.9.0
GenerateReaderID creates a deterministic reader ID from driver name and a stable path. The ID format is "{driver}-{hash}" where hash is 8 lowercase base32 characters (40 bits) derived from SHA-256.
The stablePath should be something that persists across reboots when the hardware stays in the same port, such as:
- USB topology path (e.g., "1-2.3.1") for serial readers
- PCSC reader name for smart card readers
- File path for file-based readers
- Broker + topic for MQTT readers
Inputs are normalized (lowercased, path separators unified) to ensure consistent IDs across platforms. Same inputs always produce the same ID, enabling deterministic reader identification across service restarts.
func HasCapability ¶ added in v2.9.0
func HasCapability(r CapabilityProvider, capability Capability) bool
HasCapability checks if a reader has a specific capability.
func NormalizeDriverID ¶ added in v2.7.0
NormalizeDriverID removes underscores from driver IDs to provide backwards compatibility with the legacy underscore format (e.g., "simple_serial"). This allows both "simple_serial" and "simpleserial" to work interchangeably.
Types ¶
type Capability ¶
type Capability string
const ( CapabilityWrite Capability = "write" CapabilityDisplay Capability = "display" CapabilityRemovable Capability = "removable" )
type CapabilityProvider ¶ added in v2.9.0
type CapabilityProvider interface {
Capabilities() []Capability
}
CapabilityProvider is an interface for types that can report their capabilities. This allows capability checking without requiring the full Reader interface.
type DriverMetadata ¶
type Reader ¶
type Reader interface {
// Metadata returns static configuration for this driver.
Metadata() DriverMetadata
// IDs returns the device string prefixes supported by this reader.
IDs() []string
// Open any necessary connections to the device and start polling.
// Takes a device connection string and a channel to send scanned tokens.
Open(config.ReadersConnect, chan<- Scan) error
// Close any open connections to the device and stop polling.
Close() error
// Detect attempts to search for a connected device and returns the device
// connection string. If no device is found, an empty string is returned.
// Takes a list of currently connected device strings.
Detect([]string) string
// Path returns the connection path used to open this reader.
// This is the physical resource identifier (e.g., "/dev/ttyUSB0", PCSC
// reader name, MQTT broker URL) used to prevent multiple drivers from
// competing for the same device.
Path() string
// Connected returns true if the device is connected and active.
Connected() bool
// Info returns a string with information about the connected device.
Info() string
// Write sends a string to the device to be written to a token, if
// that device supports writing. Blocks until completion or timeout.
Write(string) (*tokens.Token, error)
// CancelWrite sends a request to cancel an active write request.
CancelWrite()
// Capabilities returns the list of capabilities supported by this reader.
Capabilities() []Capability
// OnMediaChange is called when the active media changes.
OnMediaChange(*models.ActiveMedia) error
// ReaderID returns a deterministic identifier for this reader instance.
// The ID is stable across service restarts when the hardware stays in
// the same port. Format: "{driver}-{hash16}" where hash16 is derived
// from stable hardware attributes like USB topology path.
ReaderID() string
}
func FilterByCapability ¶ added in v2.9.0
func FilterByCapability(rs []Reader, capability Capability) []Reader
FilterByCapability returns only the Readers that have the specified capability.
func SelectWriterPreferred ¶ added in v2.9.0
SelectWriterPreferred finds a write-capable reader, trying each preferred ID in order. Falls back to the first available write-capable reader if no preferences match.
Directories
¶
| Path | Synopsis |
|---|---|
|
shared
|
|
|
Package testutils provides common testing utilities for reader tests.
|
Package testutils provides common testing utilities for reader tests. |