Documentation
¶
Overview ¶
Package bacnet provides transport-neutral BACnet leaf types and helpers.
This package holds addresses, object/property identifiers, application values, decode limits and error sentinels. It does not open sockets and does not import BVLC, NPDU, APDU, service or client packages.
Wire codecs live in sibling packages (bvlc, npdu, apdu). The client runtime composes those layers. BACnet/IP endpoints live in package bip.
Horizon 1 targets a BACnet/IP IPv4 supervisory client developed against ANSI/ASHRAE 135-2024 (Protocol Revision 31 baseline). The client adapts to known remote capabilities and does not require Revision 31 features from remote devices.
Out of scope for Horizon 1:
- native MS/TP, BACnet/IPv6, BACnet/SC
- full BBMD server / multi-BBMD failover
- full BACnet server/device object model
- alarms, schedules, trends, WritePropertyMultiple
Status: early v0.x production-candidate — Horizon 1 wire/runtime P0 closed with software-oracle interop evidence. Not production-usable until the real-device gate (≥2 independent devices) is closed.
Index ¶
- Constants
- Variables
- func AppendApplicationValue(dst []byte, v ApplicationValue) ([]byte, error)
- func AppendContextBitString(dst []byte, tagNumber uint8, v BitString) ([]byte, error)
- func AppendContextBool(dst []byte, tagNumber uint8, v bool) ([]byte, error)
- func AppendContextCharacterString(dst []byte, tagNumber uint8, v CharacterString) ([]byte, error)
- func AppendContextNull(dst []byte, tagNumber uint8) ([]byte, error)
- func AppendContextObjectID(dst []byte, tagNumber uint8, id ObjectIdentifier) ([]byte, error)
- func AppendContextSigned(dst []byte, tagNumber uint8, v int64) ([]byte, error)
- func AppendContextTagged(dst []byte, tagNumber uint8, body []Element) ([]byte, error)
- func AppendContextTime(dst []byte, tagNumber uint8, t Time) ([]byte, error)
- func AppendContextUnsigned(dst []byte, tagNumber uint8, v uint64) ([]byte, error)
- func AppendObjectIdentifier(dst []byte, id ObjectIdentifier) ([]byte, error)
- func AppendTag(dst []byte, el Element) ([]byte, error)
- func AsBool(v ApplicationValue) (bool, error)
- func AsEnumerated(v ApplicationValue) (uint32, error)
- func AsReal(v ApplicationValue) (float32, error)
- func AsUnsigned(v ApplicationValue) (uint64, error)
- func ContextBool(el Element) (bool, error)
- func ContextSigned(el Element) (int64, error)
- func ContextUnsigned(el Element) (uint64, error)
- func DecodeBACnetError(elements []Element) (class, code uint16, err error)
- func EncodeBACnetError(dst []byte, class, code uint16) ([]byte, error)
- func EncodeObjectIdentifier(id ObjectIdentifier) (uint32, error)
- func IsContextConstructed(el Element) bool
- type APDUTooLargeError
- type AbortError
- type Address
- type AddressScope
- type ApplicationTag
- type ApplicationValue
- func BoolValue(b bool) ApplicationValue
- func DoubleValue(f float64) ApplicationValue
- func EnumValue(e uint32) ApplicationValue
- func NullValue() ApplicationValue
- func ObjectIDValue(id ObjectIdentifier) ApplicationValue
- func ParseApplicationValue(data []byte, limits DecodeLimits) (ApplicationValue, int, error)
- func RealValue(f float32) ApplicationValue
- func SignedValue(s int64) ApplicationValue
- func UnsignedValue(u uint64) ApplicationValue
- type BitString
- type CharacterString
- type Date
- type DecodeLimits
- type Element
- type ErrorResponse
- type MAC
- type ObjectIdentifier
- type ObjectType
- type OutcomeUnknownError
- type PropertyIdentifier
- type PropertyReference
- type RejectError
- type Time
- type ValueKind
Examples ¶
Constants ¶
const ArrayAll uint32 = 0xFFFFFFFF
ArrayAll selects all array elements.
const MaxMACLength = 7
MaxMACLength is the maximum BACnet MAC length retained for Horizon 1 addressing (covers BACnet/IP 6-octet MAC and common shorter MACs).
const MaxObjectInstance = 0x3FFFFF
MaxObjectInstance is the largest valid object instance (22 bits).
Variables ¶
var ( ErrClosed = errors.New("bacnet: client closed") ErrTimeout = errors.New("bacnet: request timeout") ErrTransactionCapacity = errors.New("bacnet: transaction capacity exhausted") ErrMalformed = errors.New("bacnet: malformed encoding") ErrUnsupported = errors.New("bacnet: unsupported") ErrResponseSourceMismatch = errors.New("bacnet: response source mismatch") ErrProtocolViolation = errors.New("bacnet: protocol violation") ErrAPDUTooLarge = errors.New("bacnet: APDU exceeds remote capability") ErrTrailingData = errors.New("bacnet: unexpected trailing data") ErrLimitExceeded = errors.New("bacnet: decode limit exceeded") ErrDeliveryDropped = errors.New("bacnet: delivery dropped") // ErrDeviceManagementDisabled is returned when DeviceCommunicationControl // or ReinitializeDevice is called without WithDeviceManagementEnabled. ErrDeviceManagementDisabled = errors.New("bacnet: device management API disabled") )
Local/runtime sentinels.
Functions ¶
func AppendApplicationValue ¶
func AppendApplicationValue(dst []byte, v ApplicationValue) ([]byte, error)
AppendApplicationValue appends a deterministic application-tagged encoding.
func AppendContextBitString ¶ added in v0.2.0
AppendContextBitString appends a context-tagged bit string.
func AppendContextBool ¶
AppendContextBool appends a context-tagged BOOLEAN as one value octet (0 or 1).
func AppendContextCharacterString ¶ added in v0.2.0
func AppendContextCharacterString(dst []byte, tagNumber uint8, v CharacterString) ([]byte, error)
AppendContextCharacterString appends a context-tagged character string.
func AppendContextNull ¶
AppendContextNull appends a context-tagged Null.
func AppendContextObjectID ¶
func AppendContextObjectID(dst []byte, tagNumber uint8, id ObjectIdentifier) ([]byte, error)
AppendContextObjectID appends a context-tagged object identifier.
func AppendContextSigned ¶ added in v0.2.0
AppendContextSigned appends a context-tagged signed integer.
func AppendContextTagged ¶
AppendContextTagged appends opening tag, body tags, and closing tag.
func AppendContextTime ¶ added in v0.2.0
AppendContextTime appends a context-tagged Time (4 octets).
func AppendContextUnsigned ¶
AppendContextUnsigned appends a context-tagged unsigned integer.
func AppendObjectIdentifier ¶
func AppendObjectIdentifier(dst []byte, id ObjectIdentifier) ([]byte, error)
AppendObjectIdentifier appends the 4-octet encoding to dst.
func AsEnumerated ¶
func AsEnumerated(v ApplicationValue) (uint32, error)
AsEnumerated converts an Enumerated value to uint32.
func AsReal ¶
func AsReal(v ApplicationValue) (float32, error)
AsReal converts a Real or Double value to float32.
func AsUnsigned ¶
func AsUnsigned(v ApplicationValue) (uint64, error)
AsUnsigned converts an Unsigned or Enumerated value to uint64.
func ContextBool ¶
ContextBool extracts a context-tagged BOOLEAN (exactly one octet 0 or 1).
func ContextSigned ¶ added in v0.2.0
ContextSigned extracts a signed integer from a context primitive element.
func ContextUnsigned ¶
ContextUnsigned extracts an unsigned from a context primitive element.
func DecodeBACnetError ¶
DecodeBACnetError parses a BACnet-Error structure.
Two encodings appear on the wire:
- Context [0] class / [1] code (unsigned or enumerated content) — used by this library's encoder and some goldens;
- Application ENUMERATED class then ENUMERATED code — used by bacnet-stack and BACpypes3 Error PDUs and RPM propertyAccessError.
func EncodeBACnetError ¶
EncodeBACnetError encodes Error Class/Code as context [0]/[1].
func EncodeObjectIdentifier ¶
func EncodeObjectIdentifier(id ObjectIdentifier) (uint32, error)
EncodeObjectIdentifier packs type and instance into a 4-octet value.
func IsContextConstructed ¶
IsContextConstructed reports a context-tagged constructed (open/close) value.
Types ¶
type APDUTooLargeError ¶
APDUTooLargeError reports a request that would exceed the remote max APDU without permitted segmentation.
func (*APDUTooLargeError) Error ¶
func (e *APDUTooLargeError) Error() string
func (*APDUTooLargeError) Unwrap ¶
func (e *APDUTooLargeError) Unwrap() error
type AbortError ¶
AbortError is a remote BACnet Abort PDU.
func (*AbortError) Error ¶
func (e *AbortError) Error() string
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
Address is a data-link-independent BACnet network address.
Example ¶
package main
import (
"fmt"
"github.com/otfabric/go-bacnet"
)
func main() {
mac := bacnet.MustMAC([]byte{192, 168, 1, 10, 0xBA, 0xC0})
local := bacnet.LocalStation(mac)
remote := bacnet.RemoteStation(2, mac)
fmt.Println(local.Scope() == bacnet.AddressLocalStation)
fmt.Println(remote.Network())
fmt.Println(bacnet.GlobalBroadcast().IsBroadcast())
}
Output: true 2 true
func GlobalBroadcast ¶
func GlobalBroadcast() Address
GlobalBroadcast returns the BACnet global broadcast address.
func LocalBroadcast ¶
func LocalBroadcast() Address
LocalBroadcast returns a local broadcast address.
func LocalStation ¶
LocalStation returns a local unicast BACnet address.
func RemoteBroadcast ¶
RemoteBroadcast returns a remote broadcast on network.
func RemoteStation ¶
RemoteStation returns a remote unicast address on network.
func (Address) IsBroadcast ¶
IsBroadcast reports whether the address is any broadcast form.
type AddressScope ¶
type AddressScope uint8
AddressScope classifies a BACnet network address.
const ( AddressLocalStation AddressScope = iota AddressLocalBroadcast AddressRemoteStation AddressRemoteBroadcast AddressGlobalBroadcast )
type ApplicationTag ¶
type ApplicationTag uint8
ApplicationTag numbers for BACnet application-tagged values.
const ( TagNull ApplicationTag = iota TagBoolean TagUnsigned TagSigned TagReal TagDouble TagOctetString TagCharacterString TagBitString TagEnumerated TagDate TagTime TagObjectIdentifier TagReserved13 TagReserved14 TagReserved15 )
type ApplicationValue ¶
type ApplicationValue struct {
Kind ValueKind
Boolean bool
Unsigned uint64
Signed int64
Real float32
Double float64
OctetString []byte
Character CharacterString
BitString BitString
Enumerated uint32
Date Date
Time Time
ObjectID ObjectIdentifier
// Constructed / context nesting.
Elements []Element
}
ApplicationValue is a generic decoded BACnet application value.
OctetString and BitString.Bytes may alias parse input unless Clone is used. Runtime storage beyond packet processing must call Clone.
Example (Helpers) ¶
package main
import (
"fmt"
"github.com/otfabric/go-bacnet"
)
func main() {
v := bacnet.RealValue(21.5)
f, err := bacnet.AsReal(v)
if err != nil {
fmt.Println("err", err)
return
}
fmt.Println(v.Kind == bacnet.ValueReal)
fmt.Printf("%.1f\n", f)
id := bacnet.ObjectIdentifier{Type: bacnet.ObjectTypeAnalogInput, Instance: 1}
oid := bacnet.ObjectIDValue(id)
got, err := bacnet.AsObjectID(oid)
if err != nil {
fmt.Println("err", err)
return
}
fmt.Println(got.String())
}
Output: true 21.5 0:1
func BoolValue ¶
func BoolValue(b bool) ApplicationValue
BoolValue returns a Boolean application value.
func DoubleValue ¶
func DoubleValue(f float64) ApplicationValue
DoubleValue returns a Double application value.
func EnumValue ¶
func EnumValue(e uint32) ApplicationValue
EnumValue returns an Enumerated application value.
func ObjectIDValue ¶
func ObjectIDValue(id ObjectIdentifier) ApplicationValue
ObjectIDValue returns an ObjectIdentifier application value.
func ParseApplicationValue ¶
func ParseApplicationValue(data []byte, limits DecodeLimits) (ApplicationValue, int, error)
ParseApplicationValue parses a single application-tagged value.
func RealValue ¶
func RealValue(f float32) ApplicationValue
RealValue returns a Real application value.
func SignedValue ¶
func SignedValue(s int64) ApplicationValue
SignedValue returns a Signed application value.
func UnsignedValue ¶
func UnsignedValue(u uint64) ApplicationValue
UnsignedValue returns an Unsigned application value.
func (ApplicationValue) Clone ¶
func (v ApplicationValue) Clone() ApplicationValue
Clone returns a deep copy that owns all byte slices.
func (ApplicationValue) TagNumber ¶
func (v ApplicationValue) TagNumber() ApplicationTag
TagNumber returns the application tag for primitive kinds.
type BitString ¶
BitString holds a BACnet bit string.
func ContextBitString ¶ added in v0.2.0
ContextBitString extracts a bit string from a context primitive element.
type CharacterString ¶
CharacterString holds a BACnet character string with encoding byte.
func ContextCharacterString ¶ added in v0.2.0
func ContextCharacterString(el Element) (CharacterString, error)
ContextCharacterString extracts a character string from a context primitive.
type Date ¶
type Date struct {
Year uint8 // years since 1900; 0xFF = unspecified
Month uint8
Day uint8
Weekday uint8
}
Date is a BACnet date (year offset from 1900, month, day, weekday).
type DecodeLimits ¶
type DecodeLimits struct {
MaxDatagramSize int
MaxAPDUSize int
MaxConstructedDepth int
MaxElements int
MaxOctetStringLength int
MaxCharacterLength int
MaxBitStringBits int
MaxSegments int
MaxReassembledAPDU int
}
DecodeLimits bounds parser and reassembly allocations. Application-configured hard bounds win over peer-advertised maxima.
func DefaultDecodeLimits ¶
func DefaultDecodeLimits() DecodeLimits
DefaultDecodeLimits returns conservative Horizon 1 defaults.
func (DecodeLimits) Normalize ¶
func (l DecodeLimits) Normalize() DecodeLimits
Normalize returns limits with zeros replaced by defaults.
type Element ¶
type Element struct {
Context bool
TagNumber uint8
Opening bool
Closing bool
Value ApplicationValue
}
Element is a generic BACnet tag element (application or context).
func ParseSequence ¶
ParseSequence parses a sequence of tags until data is exhausted or a closing tag matching closeTag is seen (if closeTag >= 0). Consumed length is returned. Nested opening/closing pairs become ValueConstructed elements (Opening=false).
type ErrorResponse ¶
ErrorResponse is a remote BACnet Error PDU.
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error() string
type MAC ¶
type MAC struct {
// contains filtered or unexported fields
}
MAC is an immutable, comparable BACnet MAC address.
type ObjectIdentifier ¶
type ObjectIdentifier struct {
Type ObjectType
Instance uint32
}
ObjectIdentifier identifies a BACnet object.
func AsObjectID ¶
func AsObjectID(v ApplicationValue) (ObjectIdentifier, error)
AsObjectID converts an ObjectIdentifier value.
func ContextObjectID ¶
func ContextObjectID(el Element) (ObjectIdentifier, error)
ContextObjectID extracts an object identifier from a context primitive.
func DecodeObjectIdentifier ¶
func DecodeObjectIdentifier(v uint32) ObjectIdentifier
DecodeObjectIdentifier unpacks a 4-octet object identifier.
func (ObjectIdentifier) String ¶
func (id ObjectIdentifier) String() string
String returns Type:Instance.
type ObjectType ¶
type ObjectType uint16
ObjectType is a BACnet object type (standard or proprietary).
const ( ObjectTypeAnalogInput ObjectType = 0 ObjectTypeAnalogOutput ObjectType = 1 ObjectTypeAnalogValue ObjectType = 2 ObjectTypeBinaryInput ObjectType = 3 ObjectTypeBinaryOutput ObjectType = 4 ObjectTypeBinaryValue ObjectType = 5 ObjectTypeCalendar ObjectType = 6 ObjectTypeCommand ObjectType = 7 ObjectTypeDevice ObjectType = 8 ObjectTypeEventEnrollment ObjectType = 9 ObjectTypeFile ObjectType = 10 ObjectTypeGroup ObjectType = 11 ObjectTypeLifeSafetyPoint ObjectType = 21 ObjectTypeLifeSafetyZone ObjectType = 22 ObjectTypeMultiStateInput ObjectType = 13 ObjectTypeNotificationClass ObjectType = 15 ObjectTypeMultiStateValue ObjectType = 19 ObjectTypeTrendLog ObjectType = 20 ObjectTypeAuditLog ObjectType = 61 )
Common standard object types (ASHRAE 135).
type OutcomeUnknownError ¶
OutcomeUnknownError indicates a request may have been executed remotely but no definitive response was observed (typical after a write send without ACK).
func (*OutcomeUnknownError) Error ¶
func (e *OutcomeUnknownError) Error() string
func (*OutcomeUnknownError) Unwrap ¶
func (e *OutcomeUnknownError) Unwrap() error
type PropertyIdentifier ¶
type PropertyIdentifier uint32
PropertyIdentifier is a BACnet property identifier (standard or proprietary).
const ( PropertyObjectIdentifier PropertyIdentifier = 75 PropertyObjectName PropertyIdentifier = 77 PropertyObjectType PropertyIdentifier = 79 PropertyPresentValue PropertyIdentifier = 85 PropertyPriorityArray PropertyIdentifier = 87 PropertyStatusFlags PropertyIdentifier = 111 PropertySystemStatus PropertyIdentifier = 112 PropertyVendorIdentifier PropertyIdentifier = 120 PropertyVendorName PropertyIdentifier = 121 PropertyModelName PropertyIdentifier = 70 PropertyProtocolVersion PropertyIdentifier = 98 PropertyProtocolRevision PropertyIdentifier = 139 PropertyMaxAPDULength PropertyIdentifier = 62 PropertySegmentation PropertyIdentifier = 107 PropertyDescription PropertyIdentifier = 28 PropertyUnits PropertyIdentifier = 117 PropertyRelinquishDefault PropertyIdentifier = 104 PropertyLogBuffer PropertyIdentifier = 131 )
Common property identifiers.
type PropertyReference ¶
type PropertyReference struct {
Identifier PropertyIdentifier
ArrayIndex *uint32 // nil means the entire property; ArrayAll means all elements
}
PropertyReference identifies a property, optionally with an array index.
func (PropertyReference) Equal ¶
func (p PropertyReference) Equal(o PropertyReference) bool
Equal reports whether p and o identify the same property reference.
type RejectError ¶
RejectError is a remote BACnet Reject PDU.
func (*RejectError) Error ¶
func (e *RejectError) Error() string
type Time ¶
Time is a BACnet time.
func ContextTime ¶ added in v0.2.0
ContextTime extracts a Time from a context primitive element.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apdu implements BACnet Application Protocol Data Unit framing.
|
Package apdu implements BACnet Application Protocol Data Unit framing. |
|
Package bip provides BACnet/IP data-link endpoint types.
|
Package bip provides BACnet/IP data-link endpoint types. |
|
Package bvlc implements BACnet Virtual Link Control (BACnet/IP) framing.
|
Package bvlc implements BACnet Virtual Link Control (BACnet/IP) framing. |
|
Package client implements a BACnet/IP supervisory client runtime.
|
Package client implements a BACnet/IP supervisory client runtime. |
|
cmd
|
|
|
bacnetctl
command
Command bacnetctl is a small BACnet/IP utility for decode, discover, read and write.
|
Command bacnetctl is a small BACnet/IP utility for decode, discover, read and write. |
|
examples
|
|
|
events
command
Command events listens for inbound EventNotification PDUs and prints typed NotificationParameters when recognized (for example change-of-state).
|
Command events listens for inbound EventNotification PDUs and prints typed NotificationParameters when recognized (for example change-of-state). |
|
read-range
command
Command read-range demonstrates Client.ReadRange against a Trend Log Log_Buffer, including typed BACnetLogRecord decode when the peer returns well-formed records.
|
Command read-range demonstrates Client.ReadRange against a Trend Log Log_Buffer, including typed BACnetLogRecord decode when the peer returns well-formed records. |
|
who-has
command
Command who-has demonstrates SendWhoHas / DiscoverObjects and the object observation registry.
|
Command who-has demonstrates SendWhoHas / DiscoverObjects and the object observation registry. |
|
write-multiple
command
Command write-multiple demonstrates Client.WritePropertyMultiple.
|
Command write-multiple demonstrates Client.WritePropertyMultiple. |
|
internal
|
|
|
clock
Package clock provides an injectable clock for deterministic lifecycle tests.
|
Package clock provides an injectable clock for deterministic lifecycle tests. |
|
diag
Package diag defines an optional diagnostic sink.
|
Package diag defines an optional diagnostic sink. |
|
fixtures
Package fixtures loads bacnet-interop corpus metadata for unit tests.
|
Package fixtures loads bacnet-interop corpus metadata for unit tests. |
|
virtual
Package virtual provides an in-memory BACnet/IP transport for deterministic tests.
|
Package virtual provides an in-memory BACnet/IP transport for deterministic tests. |
|
Package npdu implements BACnet Network Layer Protocol Data Units.
|
Package npdu implements BACnet Network Layer Protocol Data Units. |