detection

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: LGPL-3.0 Imports: 7 Imported by: 1

Documentation

Overview

Package detection provides device detection and management functionality for PN532 devices

Index

Constants

This section is empty.

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 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(opts *Options) ([]DeviceInfo, error)

DetectAll searches for PN532 devices across all registered transports

func DetectAllContext

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

DetectAllContext 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 = all)
	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
Package i2c provides I2C device detection functionality for Linux systems
Package i2c provides I2C device detection functionality for Linux systems
Package spi provides SPI device detection and management functionality
Package spi provides SPI device detection and management functionality
Package uart provides UART device detection functionality
Package uart provides UART device detection functionality

Jump to

Keyboard shortcuts

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