-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathclient_ld.go
155 lines (115 loc) · 3.95 KB
/
client_ld.go
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package iec61850
// #include <iec61850_client.h>
import "C"
import (
"fmt"
"unsafe"
)
func (c *Client) GetLogicalDeviceList() DataModel {
var clientError C.IedClientError
deviceList := C.IedConnection_getLogicalDeviceList(c.conn, &clientError)
var dataModel DataModel
device := deviceList.next
for device != nil {
var ld LD
ld.Data = C2GoStr((*C.char)(device.data))
logicalNodes := C.IedConnection_getLogicalDeviceDirectory(c.conn, &clientError, (*C.char)(device.data))
logicalNode := logicalNodes.next
for logicalNode != nil {
var ln LN
ln.Data = C2GoStr((*C.char)(logicalNode.data))
lnRef := fmt.Sprintf("%s/%s", ld.Data, C2GoStr((*C.char)(logicalNode.data)))
cRef := Go2CStr(lnRef)
defer C.free(unsafe.Pointer(cRef))
dataObjects := C.IedConnection_getLogicalNodeDirectory(c.conn, &clientError, cRef, C.ACSI_CLASS_DATA_OBJECT)
dataObject := dataObjects.next
for dataObject != nil {
var do DO
do.Data = C2GoStr((*C.char)(dataObject.data))
dataObject = dataObject.next
doRef := fmt.Sprintf("%s/%s.%s", C2GoStr((*C.char)(device.data)), C2GoStr((*C.char)(logicalNode.data)), do.Data)
var das []DA
c.GetDAs(doRef, das)
do.DAs = das
ln.DOs = append(ln.DOs, do)
}
C.LinkedList_destroy(dataObjects)
clnRef := Go2CStr(lnRef)
defer C.free(unsafe.Pointer(clnRef))
dataSets := C.IedConnection_getLogicalNodeDirectory(c.conn, &clientError, clnRef, C.ACSI_CLASS_DATA_SET)
dataSet := dataSets.next
for dataSet != nil {
var ds DS
ds.Data = C2GoStr((*C.char)(dataSet.data))
var isDeletable C.bool
dataSetRef := fmt.Sprintf("%s.%s", lnRef, ds.Data)
cdataSetRef := Go2CStr(dataSetRef)
defer C.free(unsafe.Pointer(cdataSetRef))
dataSetMembers := C.IedConnection_getDataSetDirectory(c.conn, &clientError, cdataSetRef, &isDeletable)
if isDeletable {
fmt.Println(fmt.Sprintf(" Data set: %s (deletable)", ds.Data))
} else {
fmt.Println(fmt.Sprintf(" Data set: %s (not deletable)", ds.Data))
}
dataSetMemberRef := dataSetMembers.next
for dataSetMemberRef != nil {
var dsRef DSRef
dsRef.Data = C2GoStr((*C.char)(dataSetMemberRef.data))
ds.DSRefs = append(ds.DSRefs, dsRef)
dataSetMemberRef = dataSetMemberRef.next
}
C.LinkedList_destroy(dataSetMembers)
dataSet = dataSet.next
ln.DSs = append(ln.DSs, ds)
}
C.LinkedList_destroy(dataSets)
clnRef1 := Go2CStr(lnRef)
defer C.free(unsafe.Pointer(clnRef1))
reports := C.IedConnection_getLogicalNodeDirectory(c.conn, &clientError, clnRef1, C.ACSI_CLASS_URCB)
report := reports.next
for report != nil {
var r URReport
r.Data = C2GoStr((*C.char)(report.data))
ln.URReports = append(ln.URReports, r)
report = report.next
}
C.LinkedList_destroy(reports)
clnRef2 := Go2CStr(lnRef)
defer C.free(unsafe.Pointer(clnRef2))
reports = C.IedConnection_getLogicalNodeDirectory(c.conn, &clientError, clnRef2, C.ACSI_CLASS_BRCB)
report = reports.next
for report != nil {
var r BRReport
r.Data = C2GoStr((*C.char)(report.data))
ln.BRReports = append(ln.BRReports, r)
report = report.next
}
C.LinkedList_destroy(reports)
ld.LNs = append(ld.LNs, ln)
logicalNode = logicalNode.next
}
C.LinkedList_destroy(logicalNodes)
dataModel.LDs = append(dataModel.LDs, ld)
device = device.next
}
C.LinkedList_destroy(deviceList)
return dataModel
}
func (c *Client) GetDAs(doRef string, das []DA) {
var clientError C.IedClientError
cdoRef := Go2CStr(doRef)
defer C.free(unsafe.Pointer(cdoRef))
dataAttributes := C.IedConnection_getDataDirectory(c.conn, &clientError, cdoRef)
defer C.LinkedList_destroy(dataAttributes)
if dataAttributes != nil {
dataAttribute := dataAttributes.next
for dataAttribute != nil {
var da DA
da.Data = C2GoStr((*C.char)(dataAttribute.data))
das = append(das, da)
dataAttribute = dataAttribute.next
daRef := fmt.Sprintf("%s.%s", doRef, da.Data)
c.GetDAs(daRef, das)
}
}
}