bacnet

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeviceStateOnline   = 0
	DeviceStateUnstable = 1
	DeviceStateOffline  = 2
	DeviceStateIsolated = 3
)
View Source
const ArrayAll = 0xFFFFFFFF

ArrayAll is used when reading/writing to a property to read/write the entire array

Variables

This section is empty.

Functions

func NewBACnetDriver

func NewBACnetDriver() drv.Driver

Types

type BACnetDriver

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

func (*BACnetDriver) Connect

func (d *BACnetDriver) Connect(ctx context.Context) error

func (*BACnetDriver) Disconnect

func (d *BACnetDriver) Disconnect() error

func (*BACnetDriver) GetConnectionMetrics

func (d *BACnetDriver) GetConnectionMetrics() (connectionSeconds int64, reconnectCount int64, localAddr string, remoteAddr string, lastDisconnectTime time.Time)

func (*BACnetDriver) GetMetrics

func (d *BACnetDriver) GetMetrics() model.ChannelMetrics

GetMetrics 返回BACnet驱动的详细指标

func (*BACnetDriver) Health

func (d *BACnetDriver) Health() drv.HealthStatus

func (*BACnetDriver) Init

func (d *BACnetDriver) Init(config model.DriverConfig) error

func (*BACnetDriver) ReadPoints

func (d *BACnetDriver) ReadPoints(ctx context.Context, points []model.Point) (map[string]model.Value, error)

func (*BACnetDriver) Scan

func (d *BACnetDriver) Scan(ctx context.Context, params map[string]any) (any, error)

Scan performs BACnet device discovery using a four-strategy progressive approach aligned with the reference test report (策略1→策略4):

  • 策略1: 标准广播 WhoIs (255.255.255.255:47808)
  • 策略2: 子网广播 WhoIs (computed from localIP/subnetCIDR)
  • 策略3: 单播探测 (target_ip + multi-port ReadProperty)
  • 策略4: 最终确认 (逐设备 ReadProperty ObjectName)

Params:

  • interface_ip: local NIC IP to bind UDP socket (e.g. "192.168.3.230")
  • target_ip: remote target IP to scan (e.g. "192.168.3.115"); if empty, broadcast
  • mode: "deep"/"full" for object scan on discovered devices
  • device_id: if set, triggers ScanObjects instead of device discovery

func (*BACnetDriver) ScanObjects

func (d *BACnetDriver) ScanObjects(ctx context.Context, config map[string]any) (any, error)

ScanObjects implements ObjectScanner interface ScanObjects 实现 ObjectScanner 接口,扫描设备下的 BACnet 对象

func (*BACnetDriver) ScheduleReconnect added in v0.0.9

func (d *BACnetDriver) ScheduleReconnect(ctx context.Context, timeout time.Duration)

ScheduleReconnect schedules a reconnection attempt for the BACnet driver.

func (*BACnetDriver) SetBACnetAddressNotifier added in v0.0.7

func (d *BACnetDriver) SetBACnetAddressNotifier(notifier drv.BACnetAddressNotifier)

func (*BACnetDriver) SetDeviceConfig

func (d *BACnetDriver) SetDeviceConfig(config map[string]any) error

func (*BACnetDriver) SetSlaveID

func (d *BACnetDriver) SetSlaveID(slaveID uint8) error

func (*BACnetDriver) WritePoint

func (d *BACnetDriver) WritePoint(ctx context.Context, point model.Point, value any) error

type DeviceConfig

type DeviceConfig struct {
	DeviceID int
	IP       string
	Port     int
}

type DeviceContext

type DeviceContext struct {
	Device              btypes.Device
	Scheduler           *PointScheduler
	Config              DeviceConfig
	DeviceKey           string
	LastDiscovery       time.Time
	State               int
	ConsecutiveFailures int
	IsolationUntil      time.Time
	IsolationCount      int
	LastValues          map[string]model.Value
	CacheMu             sync.RWMutex
	ReadMu              sync.Mutex
	// contains filtered or unexported fields
}

type ObjectResult

type ObjectResult struct {
	Type         string `json:"type"`
	Instance     int    `json:"instance"`
	Name         string `json:"name,omitempty"`
	Description  string `json:"description,omitempty"`
	Units        string `json:"units,omitempty"`
	PresentValue any    `json:"present_value,omitempty"`
	StatusFlags  string `json:"status_flags,omitempty"`
	Reliability  string `json:"reliability,omitempty"`
	Writable     bool   `json:"writable"`
	DiffStatus   string `json:"diff_status"` // new, existing, removed
}

type PointRuntime

type PointRuntime struct {
	Point         model.Point
	FailCount     int
	LastSuccess   time.Time
	State         string // OK, SKIPPED
	CooldownUntil time.Time
}

PointRuntime Runtime state of a point

type PointScheduler

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

PointScheduler implements the scheduling logic for BACnet points

func NewPointScheduler

func NewPointScheduler(client bacnetlib.Client, targetDevice btypes.Device, groupThreshold uint16, instructionInterval time.Duration, cooldownDuration time.Duration, useDataformat bool) *PointScheduler

func (*PointScheduler) Read

func (s *PointScheduler) Read(ctx context.Context, points []model.Point) (map[string]model.Value, error)

func (*PointScheduler) Write

func (s *PointScheduler) Write(ctx context.Context, writes []PointWriteRequest) error

type PointWriteRequest

type PointWriteRequest struct {
	Point    model.Point
	Value    any
	Priority *uint8
}

PointWriteRequest represents a request to write a value to a point

type ScanResult

type ScanResult struct {
	DeviceID        int    `json:"device_id"`
	IP              string `json:"ip"`
	Port            int    `json:"port"`
	Network         uint16 `json:"network_number"`
	VendorID        uint32 `json:"vendor_id"`
	VendorName      string `json:"vendor_name"`
	ModelName       string `json:"model_name"`
	ObjectName      string `json:"object_name"`
	MaxAPDU         uint32 `json:"max_apdu"`
	Segmentation    uint32 `json:"segmentation"`
	Status          string `json:"status"`
	DiffStatus      string `json:"diff_status,omitempty"` // new, existing
	Step1Verified   bool   `json:"step1_verified"`
	Step2Discovered bool   `json:"step2_discovered"`
	DiscoveryPhase  string `json:"discovery_phase"` // preconfigured, broadcast, both
}

Jump to

Keyboard shortcuts

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