Repository navigation
Expand file tree
/
Copy pathclient_report.go
More file actions
206 lines (159 loc) · 5.93 KB
/
Copy pathclient_report.go
File metadata and controls
206 lines (159 loc) · 5.93 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
package iec61850
/*
#include <iec61850_client.h>
extern void reportCallbackFunctionBridge(void* parameter, ClientReport report);
*/
import "C"
import (
"unsafe"
)
var reportCallbacks = make(map[int32]*reportCallbackHandler)
type ReasonForInclusion int
const (
IEC61850_REASON_NOT_INCLUDED ReasonForInclusion = 0
IEC61850_REASON_DATA_CHANGE ReasonForInclusion = 1
IEC61850_REASON_QUALITY_CHANGE ReasonForInclusion = 2
IEC61850_REASON_DATA_UPDATE ReasonForInclusion = 4
IEC61850_REASON_INTEGRITY ReasonForInclusion = 8
IEC61850_REASON_GI ReasonForInclusion = 16
IEC61850_REASON_UNKNOWN ReasonForInclusion = 32
)
type reportCallbackHandler struct {
handler ReportCallbackFunction
}
type ClientReport struct {
Report C.ClientReport
}
type ReportCallbackFunction func(clientReport ClientReport)
//export reportCallbackFunctionBridge
func reportCallbackFunctionBridge(parameter unsafe.Pointer, report C.ClientReport) {
callbackId := int32(uintptr(parameter))
if call, ok := reportCallbacks[callbackId]; ok {
call.handler(ClientReport{
Report: report,
})
}
}
func (reason ReasonForInclusion) GetValueAsString() string {
return C.GoString(C.ReasonForInclusion_getValueAsString(C.ReasonForInclusion(reason)))
}
func (clientReport *ClientReport) GetElement(elementIndex int) (MmsValue, error) {
dataSetValues := C.ClientReport_getDataSetValues(clientReport.Report)
cMmsValue := C.MmsValue_getElement(dataSetValues, C.int(elementIndex))
mmsType := MmsType(C.MmsValue_getType(cMmsValue))
MmsVal, err := toGoValue(cMmsValue, mmsType)
if err != nil {
return MmsValue{}, err
}
return MmsValue{
Value: MmsVal,
Type: mmsType,
}, nil
}
func (clientReport *ClientReport) GetRcbReference() string {
return C.GoString(C.ClientReport_getRcbReference(clientReport.Report))
}
func (clientReport *ClientReport) GetRptId() string {
return C.GoString(C.ClientReport_getRptId(clientReport.Report))
}
func (clientReport *ClientReport) GetReasonForInclusion(elementIndex int) ReasonForInclusion {
reason := C.ClientReport_getReasonForInclusion(clientReport.Report, C.int(elementIndex))
return ReasonForInclusion(reason)
}
func (clientReport *ClientReport) HasTimestamp() bool {
return bool(C.ClientReport_hasTimestamp(clientReport.Report))
}
func (clientReport *ClientReport) GetTimestamp() int64 {
return int64(C.ClientReport_getTimestamp(clientReport.Report))
}
func (clientReport *ClientReport) HasSeqNum() bool {
return bool(C.ClientReport_hasSeqNum(clientReport.Report))
}
func (clientReport *ClientReport) GetSeqNum() int16 {
return int16(C.ClientReport_getSeqNum(clientReport.Report))
}
func (clientReport *ClientReport) HasDataSetName() bool {
return bool(C.ClientReport_hasDataSetName(clientReport.Report))
}
func (clientReport *ClientReport) HasReasonForInclusion() bool {
return bool(C.ClientReport_hasReasonForInclusion(clientReport.Report))
}
func (clientReport *ClientReport) HasConfRev() bool {
return bool(C.ClientReport_hasConfRev(clientReport.Report))
}
func (clientReport *ClientReport) GetConfRev() int32 {
return int32(C.ClientReport_getConfRev(clientReport.Report))
}
func (clientReport *ClientReport) HasBufOvfl() bool {
return bool(C.ClientReport_hasBufOvfl(clientReport.Report))
}
func (clientReport *ClientReport) GetBufOvfl() bool {
return bool(C.ClientReport_getBufOvfl(clientReport.Report))
}
func (clientReport *ClientReport) HasDataReference() bool {
return bool(C.ClientReport_hasDataReference(clientReport.Report))
}
func (clientReport *ClientReport) GetDataReference(elementIndex int) string {
return C.GoString(C.ClientReport_getDataReference(clientReport.Report, C.int(elementIndex)))
}
func (clientReport *ClientReport) GetDataSetName() string {
return C.GoString(C.ClientReport_getDataSetName(clientReport.Report))
}
func (clientReport *ClientReport) GetDataSetValues() (MmsValue, error) {
cMmsValue := C.ClientReport_getDataSetValues(clientReport.Report)
mmsType := MmsType(C.MmsValue_getType(cMmsValue))
mmsValue, err := toGoValue(cMmsValue, mmsType)
if err != nil {
return MmsValue{}, err
}
return MmsValue{
Value: mmsValue,
Type: mmsType,
}, nil
}
func (clientReport *ClientReport) HasSubSeqNum() bool {
return bool(C.ClientReport_hasSubSeqNum(clientReport.Report))
}
func (clientReport *ClientReport) GetSubSeqNum() int16 {
return int16(C.ClientReport_getSubSeqNum(clientReport.Report))
}
func (clientReport *ClientReport) GetMoreSeqmentsFollow() bool {
return bool(C.ClientReport_getMoreSeqmentsFollow(clientReport.Report))
}
func (c *Client) InstallReportHandler(objectReference string, function ReportCallbackFunction) error {
var clientError C.IedClientError
cObjectRef, freeCObjectRef := allocCString(objectReference)
defer freeCObjectRef()
rcb := C.IedConnection_getRCBValues(c.conn, &clientError, cObjectRef, nil)
if err := GetIedClientError(clientError); err != nil {
return err
}
defer C.ClientReportControlBlock_destroy(rcb)
callbackId := callbackIdGen.Add(1)
cPtr := intToPointerBug58625(callbackId)
reportCallbacks[callbackId] = &reportCallbackHandler{
handler: function,
}
C.IedConnection_installReportHandler(c.conn, cObjectRef, C.ClientReportControlBlock_getRptId(rcb), (*[0]byte)(C.reportCallbackFunctionBridge), cPtr)
return nil
}
func (c *Client) UninstallReportHandler(objectReference string) {
cObjectRef, freeCObjectRef := allocCString(objectReference)
defer freeCObjectRef()
C.IedConnection_uninstallReportHandler(c.conn, cObjectRef)
}
func (c *Client) TriggerGIReport(objectReference string) error {
var clientError C.IedClientError
cObjectRef, freeCObjectRef := allocCString(objectReference)
defer freeCObjectRef()
rcb := C.IedConnection_getRCBValues(c.conn, &clientError, cObjectRef, nil)
if err := GetIedClientError(clientError); err != nil {
return err
}
defer C.ClientReportControlBlock_destroy(rcb)
C.IedConnection_triggerGIReport(c.conn, &clientError, cObjectRef)
if err := GetIedClientError(clientError); err != nil {
return err
}
return nil
}