detection

package
v0.22.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// TransportUART identifies UART/serial PN532 detection.
	TransportUART = "uart"
	// TransportSPI identifies SPI PN532 detection.
	TransportSPI = "spi"
	// TransportI2C identifies I2C PN532 detection. I2C probing can be unsafe on
	// some platforms, so it is not part of the default auto-detect transports.
	TransportI2C = "i2c"
)

Variables

View Source
var (
	// ErrNoDevicesFound indicates no PN532 devices were detected
	ErrNoDevicesFound = errors.New("no PN532 devices found")
	// ErrDetectionTimeout indicates detection timed out
	ErrDetectionTimeout = errors.New("detection timeout")
	// ErrUnsupportedPlatform indicates the platform doesn't support this detection method
	ErrUnsupportedPlatform = errors.New("platform not supported")
)

Errors

Functions

func ClearDetectionCache

func ClearDetectionCache()

ClearDetectionCache removes all cached detection results

func ClearDetectionCacheForTransport

func ClearDetectionCacheForTransport(transport string)

ClearDetectionCacheForTransport removes cached results for a specific transport

func DefaultBlocklist

func DefaultBlocklist() []string

DefaultBlocklist returns a list of known problematic USB devices that should not be probed during detection. Format: VID:PID in hexadecimal (case-insensitive).

func DefaultTransports added in v0.22.1

func DefaultTransports() []string

DefaultTransports returns the safe default transports used for auto-detect. SPI and I2C are intentionally excluded because probing shared buses may be unsafe on some platforms; include them explicitly when bus detection is wanted.

func IsBlocked

func IsBlocked(vidpid string, blocklist []string) bool

IsBlocked checks if a USB device is in the blocklist.

func IsPathIgnored added in v0.3.0

func IsPathIgnored(devicePath string, ignorePaths []string) bool

IsPathIgnored checks if a device path should be ignored. Supports exact path matching and normalized path comparison.

func ParseVIDPID

func ParseVIDPID(descriptor string) string

ParseVIDPID extracts VID:PID from various USB descriptor formats.

func RegisterDetector

func RegisterDetector(d Detector)

RegisterDetector adds a detector to the registry

Types

type Confidence

type Confidence int

Confidence represents the confidence level of device detection

const (
	// Low confidence - device might be PN532 (e.g., I2C ACK only)
	Low Confidence = iota
	// Medium confidence - device responds to basic commands
	Medium
	// High confidence - device confirmed as PN532
	High
)

type Detector

type Detector interface {
	// Detect searches for devices using the given options
	Detect(ctx context.Context, opts *Options) ([]DeviceInfo, error)
	// Transport returns the transport type this detector handles
	Transport() string
}

Detector interface for transport-specific device detection

type DeviceInfo

type DeviceInfo struct {
	// Additional metadata (e.g., VID:PID for USB devices)
	Metadata map[string]string
	// Transport type: "uart", "i2c", "spi"
	Transport string
	// Connection path (e.g., "/dev/ttyUSB0", "/dev/i2c-1")
	Path string
	// Human-readable device name
	Name string
	// Detection confidence level
	Confidence Confidence
}

DeviceInfo represents a detected PN532 device

func DetectAll

func DetectAll(ctx context.Context, opts *Options) ([]DeviceInfo, error)

DetectAll searches for PN532 devices with custom context

func (DeviceInfo) String

func (d DeviceInfo) String() string

String returns a human-readable representation of the device

type Mode

type Mode int

Mode represents the level of invasiveness for device detection

const (
	// Passive mode only checks device descriptors without any communication
	Passive Mode = iota
	// Safe mode performs minimal probing with GetFirmwareVersion command
	Safe
	// Full mode performs complete verification including SAM connection test
	Full
)

type Options

type Options struct {
	// USB VID:PID pairs to skip (e.g., ["1234:5678", "ABCD:EF01"])
	Blocklist []string
	// Device paths to explicitly ignore (e.g., ["/dev/ttyUSB0", "COM2"])
	IgnorePaths []string
	// Which transports to check. Empty means the safe default, UART only;
	// include TransportSPI or TransportI2C explicitly to opt into bus probing.
	Transports []string
	// Cache TTL duration
	CacheTTL time.Duration
	// Maximum time to wait for detection
	Timeout time.Duration
	// Detection invasiveness level
	Mode Mode
	// Enable result caching
	EnableCache bool
}

Options configures the detection behavior

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns sensible default detection options.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL