-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathclient_sg.go
95 lines (80 loc) · 2.2 KB
/
client_sg.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
package iec61850
// #include <iec61850_client.h>
import "C"
import (
"fmt"
"github.com/spf13/cast"
"unsafe"
)
const (
ActDA = "%s/%s.SGCB.ActSG"
EditDA = "%s/%s.SGCB.EditSG"
CnfDA = "%s/%s.SGCB.CnfEdit"
)
type SettingGroup struct {
NumOfSG int
ActSG int
EditSG int
CnfEdit bool
}
// WriteSG 写入SettingGroup
func (c *Client) WriteSG(ld, ln, objectRef string, fc FC, actSG int, value interface{}) error {
// Set active setting group
if err := c.Write(fmt.Sprintf(ActDA, ld, ln), SP, actSG); err != nil {
return err
}
// Set edit setting group
if err := c.Write(fmt.Sprintf(EditDA, ld, ln), SP, actSG); err != nil {
return err
}
// Change a setting group value
if err := c.Write(objectRef, fc, value); err != nil {
return err
}
// Confirm new setting group values
if err := c.Write(fmt.Sprintf(CnfDA, ld, ln), SP, true); err != nil {
return err
}
return nil
}
// GetSG 获取SettingGroup
func (c *Client) GetSG(objectRef string) (*SettingGroup, error) {
var clientError C.IedClientError
cObjectRef := C.CString(objectRef)
defer C.free(unsafe.Pointer(cObjectRef))
// 获取类型
sgcbVarSpec := C.IedConnection_getVariableSpecification(c.conn, &clientError, cObjectRef, C.FunctionalConstraint(SP))
if err := GetIedClientError(clientError); err != nil {
return nil, err
}
defer C.MmsVariableSpecification_destroy(sgcbVarSpec)
// Read SGCB
sgcbVal := C.IedConnection_readObject(c.conn, &clientError, cObjectRef, C.FunctionalConstraint(SP))
if err := GetIedClientError(clientError); err != nil {
return nil, err
}
//defer C.MmsValue_delete(sgcbVal)
numOfSGValue, err := c.getSubElementValue(sgcbVal, sgcbVarSpec, "NumOfSG")
if err != nil {
return nil, err
}
actSGValue, err := c.getSubElementValue(sgcbVal, sgcbVarSpec, "ActSG")
if err != nil {
return nil, err
}
editSGValue, err := c.getSubElementValue(sgcbVal, sgcbVarSpec, "EditSG")
if err != nil {
return nil, err
}
cnfEditValue, err := c.getSubElementValue(sgcbVal, sgcbVarSpec, "CnfEdit")
if err != nil {
return nil, err
}
sg := &SettingGroup{
NumOfSG: cast.ToInt(numOfSGValue),
ActSG: cast.ToInt(actSGValue),
EditSG: cast.ToInt(editSGValue),
CnfEdit: cast.ToBool(cnfEditValue),
}
return sg, nil
}