-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathencoding.go
More file actions
111 lines (78 loc) · 2.9 KB
/
encoding.go
File metadata and controls
111 lines (78 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package bacnet
import (
"github.com/ulbios/bacnet/plumbing"
"github.com/ulbios/bacnet/services"
)
const (
DEFAULT_ACCEPTED_SIZE = 1024
DEFAULT_SEGMENTATION_SUPPORT = 0x3 // No segmentation
)
func NewWhois() ([]byte, error) {
bvlc := plumbing.NewBVLC(plumbing.BVLCFuncBroadcast)
npdu := plumbing.NewNPDU(false, false, false, false)
u := services.NewUnconfirmedWhoIs(bvlc, npdu)
return u.MarshalBinary()
}
func NewIAm(deviceId uint32, vendorId uint16) ([]byte, error) {
bvlc := plumbing.NewBVLC(plumbing.BVLCFuncBroadcast)
npdu := plumbing.NewNPDU(false, true, false, false)
npdu.DNET = 0xFFFF
npdu.DLEN = 0
npdu.Hop = 0xFF
u := services.NewUnconfirmedIAm(bvlc, npdu)
u.APDU.Objects = services.IAmObjects(deviceId,
DEFAULT_ACCEPTED_SIZE, DEFAULT_SEGMENTATION_SUPPORT, vendorId)
u.SetLength()
return u.MarshalBinary()
}
func NewCACK(service uint8, objectType uint16, instN uint32, propertyId uint8, value float32) ([]byte, error) {
bvlc := plumbing.NewBVLC(plumbing.BVLCFuncUnicast)
npdu := plumbing.NewNPDU(false, false, false, false)
c := services.NewComplexACK(bvlc, npdu)
c.APDU.Service = service
c.APDU.InvokeID = 1
c.APDU.Objects = services.ComplexACKObjects(objectType, instN, propertyId, value)
c.SetLength()
return c.MarshalBinary()
}
func NewSACK(service uint8) ([]byte, error) {
bvlc := plumbing.NewBVLC(plumbing.BVLCFuncUnicast)
npdu := plumbing.NewNPDU(false, false, false, false)
s := services.NewSimpleACK(bvlc, npdu)
s.APDU.Service = service
s.APDU.InvokeID = 1
s.SetLength()
return s.MarshalBinary()
}
func NewError(service, errorClass, errorCode uint8) ([]byte, error) {
bvlc := plumbing.NewBVLC(plumbing.BVLCFuncUnicast)
npdu := plumbing.NewNPDU(false, false, false, false)
e := services.NewError(bvlc, npdu)
e.APDU.Service = service
e.APDU.InvokeID = 1
e.APDU.Objects = services.ErrorObjects(errorClass, errorCode)
e.SetLength()
return e.MarshalBinary()
}
func NewReadProperty(objectType uint16, instanceNumber uint32, propertyId uint8) ([]byte, error) {
bvlc := plumbing.NewBVLC(plumbing.BVLCFuncUnicast)
npdu := plumbing.NewNPDU(false, false, false, true)
c := services.NewConfirmedReadProperty(bvlc, npdu)
c.APDU.Service = services.ServiceConfirmedReadProperty
c.APDU.MaxSize = 5
c.APDU.InvokeID = 1
c.APDU.Objects = services.ConfirmedReadPropertyObjects(objectType, instanceNumber, propertyId)
c.SetLength()
return c.MarshalBinary()
}
func NewWriteProperty(objectType uint16, instanceNumber uint32, propertyId uint8, value float32) ([]byte, error) {
bvlc := plumbing.NewBVLC(plumbing.BVLCFuncUnicast)
npdu := plumbing.NewNPDU(false, false, false, true)
c := services.NewConfirmedWriteProperty(bvlc, npdu)
c.APDU.Service = services.ServiceConfirmedWriteProperty
c.APDU.MaxSize = 5
c.APDU.InvokeID = 1
c.APDU.Objects = services.ConfirmedWritePropertyObjects(objectType, instanceNumber, propertyId, value)
c.SetLength()
return c.MarshalBinary()
}