device

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package device is the BACnet device (server) role over BACnet/IP: a Device object and an object table served to other BACnet clients with Who-Is and Who-Has, ReadProperty and ReadPropertyMultiple (array indexes, ALL, REQUIRED and OPTIONAL), WriteProperty and WritePropertyMultiple (priority arrays of commandable objects), SubscribeCOV with confirmed and unconfirmed notifications and lifetimes, and segmentation of answers and of requests (clause 5.4). Clauses cited are of ANSI/ASHRAE 135-2024.

Index

Constants

View Source
const (
	PropAPDUTimeout          = 11
	PropAppSoftwareVersion   = 12
	PropDeviceAddressBinding = 30
	PropFirmwareRevision     = 44
	PropMaxAPDU              = 62
	PropModelName            = 70
	PropNumberOfAPDURetries  = 73
	PropObjectIdentifier     = 75
	PropObjectList           = 76
	PropObjectName           = 77
	PropObjectType           = 79
	PropPriorityArray        = 87
	PropProtocolObjectTypes  = 96
	PropProtocolServices     = 97
	PropProtocolVersion      = 98
	PropRelinquishDefault    = 104
	PropSegmentation         = 107
	PropSystemStatus         = 112
	PropVendorIdentifier     = 120
	PropVendorName           = 121
	PropProtocolRevision     = 139
	PropDatabaseRevision     = 155
	PropDescription          = 28
	PropEventState           = 36
)

Property identifiers the device serves itself (clause 12, 21).

View Source
const (
	ClassObject       = 1
	ClassProperty     = 2
	ClassServices     = 5
	CodeUnknownObject = 31
	CodeUnknownProp   = 32
	CodeWriteDenied   = 40
	CodeInvalidIndex  = 42
	CodeTypeMismatch  = 9 // invalid-data-type
	CodeValueRange    = 37
	CodeNotArray      = 50 // property-is-not-an-array
	CodeOther         = 0
)

Error classes and codes (clause 18) the device answers with.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Instance   uint32 // device instance, 0 to 4194302
	Name       string
	VendorID   uint16
	VendorName string
	ModelName  string
	Firmware   string
	Software   string
	// MaxAPDU is the largest APDU the device accepts and sends (50 to
	// 1476; default 1476).
	MaxAPDU int
	// Window is the window the device proposes for segmented answers
	// (default 4); MaxSegments the most segments it sends (default 64).
	Window      byte
	MaxSegments int
	// SegmentTimeout and SegmentRetries govern segmented transfers
	// (default 2 s, 3).
	SegmentTimeout time.Duration
	SegmentRetries int
	// OnWrite, when set, sees every accepted write before it is stored; a
	// non-nil error (an *Error for a chosen class and code) refuses it.
	OnWrite func(o bacnet.ObjectID, prop uint32, index int, value any, priority int) error
	Logger  *slog.Logger
}

Config sets up a Device.

type Device

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

Device is a BACnet/IP device. Its methods are safe for concurrent use.

func New

func New(cfg Config) *Device

New makes a Device with its Device object; AddObject adds the others.

func (*Device) AddObject

func (d *Device) AddObject(o *Object)

AddObject adds (or replaces) an object; a Commandable object's relinquish default is its Props[PropRelinquishDefault], or its Props[PropPresentValue] when that is set instead.

func (*Device) Attach

func (d *Device) Attach(c *bacnet.Client)

Attach serves the device on a bacnet.Client's data link instead of its own UDP socket: BACnet/IP, BACnet/IPv6 (NewClient6) or BACnet/SC (NewClientSC), so one port is both a client and a device. The client segments the answers and reassembles segmented requests itself. An OnUnconfirmed hook set before Attach still runs. Call it before the client's Serve.

func (*Device) Close

func (d *Device) Close()

Close stops serving.

func (*Device) Get

func (d *Device) Get(id bacnet.ObjectID, prop uint32) (any, bool)

Get returns a property's value as a client reads it.

func (*Device) Handle

func (d *Device) Handle(a bacnet.APDU, src string, out Out) []byte

Handle answers one unsegmented confirmed request: the APDU to send back (a Complex-ACK the caller may segment), or nil.

func (*Device) IAm

func (d *Device) IAm(broadcast *net.UDPAddr) error

IAm announces the device by a local broadcast to port 47808 of broadcast (for example 255.255.255.255 or a subnet's address).

func (*Device) ID

func (d *Device) ID() bacnet.ObjectID

ID is the Device object's identifier.

func (*Device) Listen

func (d *Device) Listen(addr string) (*net.UDPAddr, error)

Listen serves BACnet/IP on a UDP address ("0.0.0.0:47808") in the background and returns the bound address.

func (*Device) Set

func (d *Device) Set(id bacnet.ObjectID, prop uint32, v any) error

Set changes a property (present-value of a Commandable object: its relinquish default) and sends COV notifications when it is present-value or status-flags.

type Error

type Error struct{ Class, Code uint32 }

Error is a BACnet error class and code returned by an OnWrite hook.

func (*Error) Error

func (e *Error) Error() string

type Object

type Object struct {
	ID   bacnet.ObjectID
	Name string
	// Props are the object's other properties: values Enc.App encodes, or
	// []any for arrays and lists.
	Props map[uint32]any
	// Writable are the properties other devices may write (present-value
	// of a Commandable object always is).
	Writable map[uint32]bool
	// Commandable objects take writes of present-value at a priority
	// (clause 19.2): the present value is the first non-NULL slot of the
	// priority array, or the relinquish default.
	Commandable bool
	// contains filtered or unexported fields
}

Object is one object the device serves. Present-value, priority-array and relinquish-default are kept for a Commandable object; every other property is in Props. Object-identifier, object-name and object-type are answered from ID and Name.

type Out

type Out func(apdu []byte, expectReply bool) error

Out sends an APDU back to a requester over whatever data link it came by; expectReply marks a confirmed request.

Jump to

Keyboard shortcuts

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