driver

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDriver

func RegisterDriver(name string, factory Factory)

RegisterDriver registers a driver factory for a given protocol name

Types

type ConnState

type ConnState int
const (
	StateDisconnected ConnState = iota
	StateConnecting
	StateConnected
	StateRetrying
	StateDead
)

func (ConnState) String

func (s ConnState) String() string

type ConnectionManager

type ConnectionManager struct {
	// contains filtered or unexported fields
}

func NewConnectionManager

func NewConnectionManager(driverName string) *ConnectionManager

func (*ConnectionManager) AttemptHalfOpen

func (cm *ConnectionManager) AttemptHalfOpen(success bool)

func (*ConnectionManager) CanRetry

func (cm *ConnectionManager) CanRetry() (canRetry bool, waitTime time.Duration)

func (*ConnectionManager) Close

func (cm *ConnectionManager) Close()

func (*ConnectionManager) GetState

func (cm *ConnectionManager) GetState() ConnState

func (*ConnectionManager) GetStatus

func (cm *ConnectionManager) GetStatus() (state ConnState, retryCount int, maxRetries int, coolDownRemaining time.Duration, lastSuccess time.Time)

func (*ConnectionManager) RecordFailure

func (cm *ConnectionManager) RecordFailure() (shouldRetry bool, backoff time.Duration)

func (*ConnectionManager) RecordSuccess

func (cm *ConnectionManager) RecordSuccess()

func (*ConnectionManager) ResetDaily

func (cm *ConnectionManager) ResetDaily()

func (*ConnectionManager) SetBackoffParams

func (cm *ConnectionManager) SetBackoffParams(base, max time.Duration, factor float64)

func (*ConnectionManager) SetMaxFailCount

func (cm *ConnectionManager) SetMaxFailCount(max int)

func (*ConnectionManager) SetMaxRetries

func (cm *ConnectionManager) SetMaxRetries(max int)

func (*ConnectionManager) SetState

func (cm *ConnectionManager) SetState(state ConnState)

type Driver

type Driver interface {
	Init(cfg model.DriverConfig) error
	Connect(ctx context.Context) error
	Disconnect() error
	ReadPoints(ctx context.Context, points []model.Point) (map[string]model.Value, error)
	WritePoint(ctx context.Context, point model.Point, value any) error
	Health() HealthStatus
	// SetSlaveID sets the slave/unit ID for protocols that support multiple slaves (optional)
	SetSlaveID(slaveID uint8) error
	// SetDeviceConfig sets device specific configuration (optional, for protocols needing per-device connection info like BACnet IP)
	SetDeviceConfig(config map[string]any) error

	// GetConnectionMetrics returns transport-level connection metrics
	GetConnectionMetrics() (connectionSeconds int64, reconnectCount int64, localAddr string, remoteAddr string, lastDisconnectTime time.Time)
}

Driver is the unified interface for all protocol drivers

func GetDriver

func GetDriver(name string) (Driver, bool)

GetDriver creates a new driver instance for the given protocol

type Factory

type Factory func() Driver

Factory function type for creating drivers

type HealthStatus

type HealthStatus int

HealthStatus represents the health of the driver connection

const (
	HealthStatusUnknown HealthStatus = iota
	HealthStatusGood
	HealthStatusBad
)

type ObjectScanner

type ObjectScanner interface {
	ScanObjects(ctx context.Context, config map[string]any) (any, error)
}

ObjectScanner is an optional interface for drivers that support object/point discovery on a device

type Scanner

type Scanner interface {
	Scan(ctx context.Context, params map[string]any) (any, error)
}

Scanner is an optional interface for drivers that support discovery

Jump to

Keyboard shortcuts

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