-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathgoose_publisher.go
More file actions
148 lines (117 loc) · 3.76 KB
/
Copy pathgoose_publisher.go
File metadata and controls
148 lines (117 loc) · 3.76 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
package iec61850
/*
#include "goose_publisher.h"
#include "mms_value.h"
static bool is_publisher_not_null(GoosePublisher p) {
return p != NULL;
}
static void destroy_linked_list_val(LinkedList value) {
LinkedList_destroyDeep(value, (LinkedListValueDeleteFunction)MmsValue_delete);
}
*/
import "C"
import (
"errors"
"unsafe"
)
type (
LinkedListValue struct {
internalLinkedList *C.struct_sLinkedList
}
GoosePublisherConf struct {
InterfaceID string
AppID uint16
DstAddr [6]uint8
VlanID uint16
VlanPriority uint8
}
GoosePublisher struct {
internalPublisher *C.struct_sGoosePublisher
}
)
var (
ErrCreateGoosePublisher = errors.New("can not create goose publisher")
ErrSendGooseValue = errors.New("can not send goose value")
)
func NewGoosePublisher(conf GoosePublisherConf) (publisher *GoosePublisher, err error) {
parameters := C.struct_sCommParameters{}
parameters.appId = C.uint16_t(conf.AppID)
parameters.vlanId = C.uint16_t(conf.VlanID)
parameters.vlanPriority = C.uint8_t(conf.VlanPriority)
for i := 0; i < len(conf.DstAddr); i++ {
parameters.dstAddress[i] = C.uint8_t(conf.DstAddr[i])
}
ether := C.CString(conf.InterfaceID)
defer C.free(unsafe.Pointer(ether))
cGoosePublisher := C.GoosePublisher_create(¶meters, ether)
if !bool(C.is_publisher_not_null(cGoosePublisher)) {
err = ErrCreateGoosePublisher
return
}
publisher = &GoosePublisher{
internalPublisher: cGoosePublisher,
}
return
}
func (receiver *GoosePublisher) SetGoCbRef(goCbRef string) {
ref := C.CString(goCbRef)
defer C.free(unsafe.Pointer(ref))
C.GoosePublisher_setGoCbRef(receiver.internalPublisher, ref)
}
func (receiver *GoosePublisher) SetDataSetRef(dataSetRef string) {
ref := C.CString(dataSetRef)
defer C.free(unsafe.Pointer(ref))
C.GoosePublisher_setDataSetRef(receiver.internalPublisher, ref)
}
func (receiver *GoosePublisher) SetConfRev(confRef uint32) {
C.GoosePublisher_setConfRev(receiver.internalPublisher, C.uint32_t(confRef))
}
func (receiver *GoosePublisher) SetTimeAllowedToLive(timeAllowedToLive uint32) {
C.GoosePublisher_setTimeAllowedToLive(receiver.internalPublisher, C.uint32_t(timeAllowedToLive))
}
func (receiver *GoosePublisher) SetSimulation(simulation bool) {
C.GoosePublisher_setSimulation(receiver.internalPublisher, C.bool(simulation))
}
func (receiver *GoosePublisher) SetStNum(stNum uint32) {
C.GoosePublisher_setStNum(receiver.internalPublisher, C.uint32_t(stNum))
}
func (receiver *GoosePublisher) SetSqNum(sqNum uint32) {
C.GoosePublisher_setSqNum(receiver.internalPublisher, C.uint32_t(sqNum))
}
func (receiver *GoosePublisher) SetNeedsCommission(ndsCom bool) {
C.GoosePublisher_setNeedsCommission(receiver.internalPublisher, C.bool(ndsCom))
}
func (receiver *GoosePublisher) IncreaseStNum() {
C.GoosePublisher_increaseStNum(receiver.internalPublisher)
}
func (receiver *GoosePublisher) Reset() {
C.GoosePublisher_reset(receiver.internalPublisher)
}
func (receiver *GoosePublisher) Publish(dataSet *LinkedListValue) error {
if int(C.GoosePublisher_publish(receiver.internalPublisher, dataSet.internalLinkedList)) == -1 {
return ErrSendGooseValue
}
return nil
}
func (receiver *GoosePublisher) Close() {
C.GoosePublisher_destroy(receiver.internalPublisher)
}
func NewLinkedListValue() *LinkedListValue {
return &LinkedListValue{
internalLinkedList: C.LinkedList_create(),
}
}
func (receiver *LinkedListValue) Add(value *MmsValue) error {
rawVal, err := toMmsValue(value.Type, value.Value)
if err != nil {
return err
}
C.LinkedList_add(receiver.internalLinkedList, unsafe.Pointer(rawVal))
return nil
}
func (receiver *LinkedListValue) Size() int {
return int(C.LinkedList_size(receiver.internalLinkedList))
}
func (receiver *LinkedListValue) Destroy() {
C.destroy_linked_list_val(receiver.internalLinkedList)
}