-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathclient_control.go
More file actions
255 lines (216 loc) · 7.65 KB
/
client_control.go
File metadata and controls
255 lines (216 loc) · 7.65 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package iec61850
// #include <iec61850_client.h>
import "C"
import "unsafe"
type ControlObjectParam struct {
CtlVal bool
OrIdent string
OrCat int
Test bool
Check bool
OperateTime uint64
}
type ControlObjectParamAPC struct {
CtlVal float32
OrIdent string
OrCat int
Test bool
Check bool
OperateTime uint64
}
type ControlObjectParamINC struct {
CtlVal int
OrIdent string
OrCat int
Test bool
Check bool
OperateTime uint64
}
func NewControlObjectParam(ctlVal bool) *ControlObjectParam {
return &ControlObjectParam{
CtlVal: ctlVal,
OrIdent: "",
OrCat: 0,
Test: false,
Check: false,
OperateTime: 0,
}
}
func NewControlObjectParamAPC(ctlVal float32) *ControlObjectParamAPC {
return &ControlObjectParamAPC{
CtlVal: ctlVal,
OrIdent: "",
OrCat: 0,
Test: false,
Check: false,
OperateTime: 0,
}
}
func NewControlObjectParamINC(ctlVal int) *ControlObjectParamINC {
return &ControlObjectParamINC{
CtlVal: ctlVal,
OrIdent: "",
OrCat: 0,
Test: false,
Check: false,
OperateTime: 0,
}
}
// ControlForDirectWithNormalSecurity 控制模式 1[direct-with-normal-security]
func (c *Client) ControlForDirectWithNormalSecurity(objectRef string, ctlVal bool) error {
return c.ControlByControlModel(objectRef, CONTROL_MODEL_DIRECT_NORMAL, NewControlObjectParam(ctlVal))
}
func (c *Client) ControlByControlModelINC(objectRef string, controlModel ControlModel, param *ControlObjectParamINC) error {
cObjectRef := C.CString(objectRef)
defer C.free(unsafe.Pointer(cObjectRef))
control := C.ControlObjectClient_create(cObjectRef, c.conn)
if control == nil {
return CreateControlObjectClientFail
}
ctlVal := C.MmsValue_newIntegerFromInt32(C.int(param.CtlVal))
defer C.MmsValue_delete(ctlVal)
switch controlModel {
case CONTROL_MODEL_SBO_NORMAL:
if !bool(C.ControlObjectClient_select(control)) {
return ControlSelectFail
}
case CONTROL_MODEL_DIRECT_ENHANCED:
C.ControlObjectClient_setCommandTerminationHandler(control, nil, nil)
case CONTROL_MODEL_SBO_ENHANCED:
C.ControlObjectClient_setCommandTerminationHandler(control, nil, nil)
if !bool(C.ControlObjectClient_selectWithValue(control, ctlVal)) {
return ControlSelectFail
}
}
var cOrIdent *C.char
if param.OrIdent != "" {
cOrIdent = C.CString(param.OrIdent)
defer C.free(unsafe.Pointer(cOrIdent))
}
C.ControlObjectClient_setControlModel(control, C.ControlModel(controlModel))
C.ControlObjectClient_setOrigin(control, cOrIdent, C.int(param.OrCat))
C.ControlObjectClient_setInterlockCheck(control, C.bool(param.Check))
C.ControlObjectClient_setSynchroCheck(control, C.bool(param.Check))
C.ControlObjectClient_setTestMode(control, C.bool(param.Test))
if !bool(C.ControlObjectClient_operate(control, ctlVal, 0)) {
return ControlObjectFail
}
return nil
}
func (c *Client) ControlByControlModelAPC(objectRef string, controlModel ControlModel, param *ControlObjectParamAPC) error {
cObjectRef := C.CString(objectRef)
defer C.free(unsafe.Pointer(cObjectRef))
control := C.ControlObjectClient_create(cObjectRef, c.conn)
if control == nil {
return CreateControlObjectClientFail
}
ctlVal := C.MmsValue_newFloat(C.float(param.CtlVal))
defer C.MmsValue_delete(ctlVal)
switch controlModel {
case CONTROL_MODEL_SBO_NORMAL:
if !bool(C.ControlObjectClient_select(control)) {
return ControlSelectFail
}
case CONTROL_MODEL_DIRECT_ENHANCED:
C.ControlObjectClient_setCommandTerminationHandler(control, nil, nil)
case CONTROL_MODEL_SBO_ENHANCED:
C.ControlObjectClient_setCommandTerminationHandler(control, nil, nil)
if !bool(C.ControlObjectClient_selectWithValue(control, ctlVal)) {
return ControlSelectFail
}
}
var cOrIdent *C.char
if param.OrIdent != "" {
cOrIdent = C.CString(param.OrIdent)
defer C.free(unsafe.Pointer(cOrIdent))
}
C.ControlObjectClient_setControlModel(control, C.ControlModel(controlModel))
C.ControlObjectClient_setOrigin(control, cOrIdent, C.int(param.OrCat))
C.ControlObjectClient_setInterlockCheck(control, C.bool(param.Check))
C.ControlObjectClient_setSynchroCheck(control, C.bool(param.Check))
C.ControlObjectClient_setTestMode(control, C.bool(param.Test))
if !bool(C.ControlObjectClient_operate(control, ctlVal, 0)) {
return ControlObjectFail
}
return nil
}
func (c *Client) ControlByControlModel(objectRef string, controlModel ControlModel, param *ControlObjectParam) error {
cObjectRef := C.CString(objectRef)
defer C.free(unsafe.Pointer(cObjectRef))
control := C.ControlObjectClient_create(cObjectRef, c.conn)
if control == nil {
return CreateControlObjectClientFail
}
defer C.ControlObjectClient_destroy(control)
ctlVal := C.MmsValue_newBoolean(C.bool(param.CtlVal))
defer C.MmsValue_delete(ctlVal)
// Select before operate
switch controlModel {
case CONTROL_MODEL_SBO_NORMAL:
if !bool(C.ControlObjectClient_select(control)) {
return ControlSelectFail
}
case CONTROL_MODEL_DIRECT_ENHANCED:
C.ControlObjectClient_setCommandTerminationHandler(control, nil, nil)
case CONTROL_MODEL_SBO_ENHANCED:
C.ControlObjectClient_setCommandTerminationHandler(control, nil, nil)
if !bool(C.ControlObjectClient_selectWithValue(control, ctlVal)) {
return ControlSelectFail
}
}
var cOrIdent *C.char
if param.OrIdent != "" {
cOrIdent = C.CString(param.OrIdent)
defer C.free(unsafe.Pointer(cOrIdent))
}
C.ControlObjectClient_setControlModel(control, C.ControlModel(controlModel))
C.ControlObjectClient_setOrigin(control, cOrIdent, C.int(param.OrCat))
C.ControlObjectClient_setInterlockCheck(control, C.bool(param.Check))
C.ControlObjectClient_setSynchroCheck(control, C.bool(param.Check))
C.ControlObjectClient_setTestMode(control, C.bool(param.Test))
if !bool(C.ControlObjectClient_operate(control, ctlVal, C.uint64_t(param.OperateTime))) {
return ControlObjectFail
}
return nil
}
// ControlForSboWithNormalSecurity 控制模式 2[sbo-with-normal-security]
func (c *Client) ControlForSboWithNormalSecurity(objectRef string, value bool) error {
return c.ControlByControlModel(objectRef, CONTROL_MODEL_SBO_NORMAL, NewControlObjectParam(value))
}
// ControlForDirectWithEnhancedSecurity 控制模式 3[direct-with-enhanced-security]
func (c *Client) ControlForDirectWithEnhancedSecurity(objectRef string, value bool) error {
return c.ControlByControlModel(objectRef, CONTROL_MODEL_DIRECT_ENHANCED, NewControlObjectParam(value))
}
// ControlForSboWithEnhancedSecurity 控制模式 4[sbo-with-enhanced-security]
func (c *Client) ControlForSboWithEnhancedSecurity(objectRef string, value bool) error {
return c.ControlByControlModel(objectRef, CONTROL_MODEL_SBO_ENHANCED, NewControlObjectParam(value))
}
func (c *Client) control(objectRef string, value, _select, direct, enhanced bool) error {
cObjectRef := C.CString(objectRef)
defer C.free(unsafe.Pointer(cObjectRef))
control := C.ControlObjectClient_create(cObjectRef, c.conn)
if control == nil {
return CreateControlObjectClientFail
}
// Select before operate
defer C.ControlObjectClient_destroy(control)
if _select && !enhanced && !bool(C.ControlObjectClient_select(control)) {
return ControlSelectFail
}
// Direct control with enhanced security
if enhanced {
C.ControlObjectClient_setCommandTerminationHandler(control, nil, nil)
}
ctlVal := C.MmsValue_newBoolean(C.bool(value))
defer C.MmsValue_delete(ctlVal)
// Select before operate with enhanced security
if _select && enhanced && !bool(C.ControlObjectClient_selectWithValue(control, ctlVal)) {
return ControlSelectFail
}
// Direct control
if direct {
C.ControlObjectClient_setOrigin(control, nil, 3)
}
C.ControlObjectClient_operate(control, ctlVal, 0)
return nil
}