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
- type Config
- type Device
- func (d *Device) AddObject(o *Object)
- func (d *Device) Attach(c *bacnet.Client)
- func (d *Device) Close()
- func (d *Device) Get(id bacnet.ObjectID, prop uint32) (any, bool)
- func (d *Device) Handle(a bacnet.APDU, src string, out Out) []byte
- func (d *Device) IAm(broadcast *net.UDPAddr) error
- func (d *Device) ID() bacnet.ObjectID
- func (d *Device) Listen(addr string) (*net.UDPAddr, error)
- func (d *Device) Set(id bacnet.ObjectID, prop uint32, v any) error
- type Error
- type Object
- type Out
Constants ¶
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).
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 (*Device) AddObject ¶
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 ¶
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) Handle ¶
Handle answers one unsegmented confirmed request: the APDU to send back (a Complex-ACK the caller may segment), or nil.
func (*Device) IAm ¶
IAm announces the device by a local broadcast to port 47808 of broadcast (for example 255.255.255.255 or a subnet's address).
type Error ¶
type Error struct{ Class, Code uint32 }
Error is a BACnet error class and code returned by an OnWrite hook.
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.