-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmodel.go
153 lines (128 loc) · 3.64 KB
/
model.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
package iec61850
// #include <iec61850_server.h>
import "C"
import (
"os"
"unsafe"
)
type IedModel struct {
_iedModel *C.IedModel
}
type ModelNode struct {
ObjectReference string
_modelNode unsafe.Pointer
}
func NewIedModel(name string) *IedModel {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &IedModel{
_iedModel: C.IedModel_create(cname),
}
}
func (m *IedModel) Destroy() {
C.IedModel_destroy(m._iedModel)
}
func (m *IedModel) GetModelNodeByObjectReference(objectRef string) *ModelNode {
cObjectRef := C.CString(objectRef)
defer C.free(unsafe.Pointer(cObjectRef))
do := C.IedModel_getModelNodeByObjectReference(m._iedModel, cObjectRef)
if do == nil {
return nil
}
return &ModelNode{_modelNode: unsafe.Pointer(do), ObjectReference: objectRef}
}
func CreateModelFromConfigFileEx(filepath string) (*IedModel, error) {
if _, err := os.Stat(filepath); err != nil {
if os.IsNotExist(err) {
return nil, err
}
}
cFilepath := C.CString(filepath)
// 释放内存
defer C.free(unsafe.Pointer(cFilepath))
model := &IedModel{
_iedModel: C.ConfigFileParser_createModelFromConfigFileEx(cFilepath),
}
return model, nil
}
type LogicalDevice struct {
device *C.LogicalDevice
}
func (m *IedModel) CreateLogicalDevice(name string) *LogicalDevice {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &LogicalDevice{
device: C.LogicalDevice_create(cname, m._iedModel),
}
}
type LogicalNode struct {
node *C.LogicalNode
}
func (d *LogicalDevice) CreateLogicalNode(name string) *LogicalNode {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &LogicalNode{
node: C.LogicalNode_create(cname, d.device),
}
}
type DataObject struct {
object *C.DataObject
}
// ENS: EnumerationString
// VSS: Visible String Setting
// SAV: Sampled Value
// APC: Analogue Process Control
func (n *LogicalNode) CreateDataObjectCDC_ENS(name string) *DataObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &DataObject{
object: C.CDC_ENS_create(cname, (*C.ModelNode)(n.node), 0),
}
}
func (n *LogicalNode) CreateDataObjectCDC_VSS(name string) *DataObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &DataObject{
object: C.CDC_VSS_create(cname, (*C.ModelNode)(n.node), 0),
}
}
func (n *LogicalNode) CreateDataObjectCDC_SAV(name string, isInteger bool) *DataObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &DataObject{
object: C.CDC_SAV_create(cname, (*C.ModelNode)(n.node), 0, C.bool(isInteger)),
}
}
func (n *LogicalNode) CreateDataObjectCDC_APC(name string, ctlModel int) *DataObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &DataObject{
object: C.CDC_APC_create(cname, (*C.ModelNode)(n.node), 0, C.uint(ctlModel), C.bool(false)),
}
}
type DataAttribute struct {
attribute *C.DataAttribute
}
func (do *DataObject) GetChild(name string) *DataAttribute {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &DataAttribute{
attribute: (*C.DataAttribute)(unsafe.Pointer(C.ModelNode_getChild((*C.ModelNode)(unsafe.Pointer(do.object)), cname))),
}
}
type DataSet struct {
dataSet *C.DataSet
}
// CreateDataSet creates a new DataSet under this LogicalNode.
func (ln *LogicalNode) CreateDataSet(name string) *DataSet {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
cDataSet := C.DataSet_create(cName, ln.node)
return &DataSet{dataSet: cDataSet}
}
// AddDataSetEntry adds a new DataSetEntry to this DataSet.
func (ds *DataSet) AddDataSetEntry(ref string) {
cRef := C.CString(ref)
defer C.free(unsafe.Pointer(cRef))
C.DataSetEntry_create(ds.dataSet, cRef, -1, nil)
}