driver

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxGlobalReconnectRate = 10
)

Functions

func RegisterDriver

func RegisterDriver(name string, factory Factory)

RegisterDriver registers a driver factory for a given protocol name

Types

type BACnetAddressNotifier added in v0.0.7

type BACnetAddressNotifier interface {
	OnBACnetAddressDiscovered(deviceKey, ip string, port int)
}

BACnetAddressNotifier receives runtime BACnet address updates (e.g. UDP port change after reboot).

type BACnetAddressNotifySetter added in v0.0.7

type BACnetAddressNotifySetter interface {
	SetBACnetAddressNotifier(BACnetAddressNotifier)
}

BACnetAddressNotifySetter allows wiring a notifier into the BACnet driver.

type ConnState

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

func (ConnState) String

func (s ConnState) String() string

type ConnectFunc added in v0.0.7

type ConnectFunc func(ctx context.Context) error

ConnectFunc performs a single connection attempt (dial/open). Retry/backoff is owned exclusively by ConnectionManager.EnsureConnected.

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) EnsureConnected added in v0.0.7

func (cm *ConnectionManager) EnsureConnected(ctx context.Context, connect ConnectFunc) error

EnsureConnected is the single entry point for synchronous reconnect with backoff, cooldown, and global rate limiting.

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) ScheduleAsyncTask added in v0.0.7

func (cm *ConnectionManager) ScheduleAsyncTask(parentCtx context.Context, timeout time.Duration, task func(context.Context) error)

ScheduleAsyncTask runs a one-shot async operation under the same single-flight guard as ScheduleReconnect, without requiring a disconnected connection state. Use for device-level recovery probes while the channel remains connected.

func (*ConnectionManager) ScheduleReconnect added in v0.0.7

func (cm *ConnectionManager) ScheduleReconnect(parentCtx context.Context, timeout time.Duration, connect ConnectFunc)

ScheduleReconnect starts an asynchronous reconnect guarded by single-flight. Duplicate calls while a reconnect is in progress are ignored.

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)

func (*ConnectionManager) StartBackgroundLoop added in v0.0.7

func (cm *ConnectionManager) StartBackgroundLoop(fn func(context.Context))

StartBackgroundLoop runs fn in a single managed goroutine until StopBackgroundLoop is called or the parent context passed to fn is cancelled via StopBackgroundLoop. Only one background loop may run per ConnectionManager.

func (*ConnectionManager) StopBackgroundLoop added in v0.0.7

func (cm *ConnectionManager) StopBackgroundLoop()

StopBackgroundLoop cancels and waits for the managed background goroutine to exit.

type DeviceCollectionResetter added in v0.0.7

type DeviceCollectionResetter interface {
	ResetDeviceCollection(deviceID string)
}

DeviceCollectionResetter is optional. Drivers that cache per-device collection state (e.g. OPC UA subscriptions) should implement it so ScanEngine can drop stale state when points are added, removed, or the device is re-registered.

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

Directories

Path Synopsis
tsm
Package ethercat implements EtherCAT master driver for EdgeX gateway.
Package ethercat implements EtherCAT master driver for EdgeX gateway.

Jump to

Keyboard shortcuts

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