-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathcommon.go
More file actions
122 lines (99 loc) · 2.96 KB
/
Copy pathcommon.go
File metadata and controls
122 lines (99 loc) · 2.96 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
package iec61850
import (
"fmt"
"time"
)
/*
#include "iec61850_common.h"
*/
import "C"
type (
Timestamp struct {
cTimestamp C.Timestamp
}
Quality uint16
Validity uint16
)
const (
QUALITY_VALIDITY_GOOD Quality = 0
QUALITY_VALIDITY_INVALID Quality = 2
QUALITY_VALIDITY_RESERVED Quality = 1
QUALITY_VALIDITY_QUESTIONABLE Quality = 3
QUALITY_DETAIL_OVERFLOW Quality = 4
QUALITY_DETAIL_OUT_OF_RANGE Quality = 8
QUALITY_DETAIL_BAD_REFERENCE Quality = 16
QUALITY_DETAIL_OSCILLATORY Quality = 32
QUALITY_DETAIL_FAILURE Quality = 64
QUALITY_DETAIL_OLD_DATA Quality = 128
QUALITY_DETAIL_INCONSISTENT Quality = 256
QUALITY_DETAIL_INACCURATE Quality = 512
QUALITY_SOURCE_SUBSTITUTED Quality = 1024
QUALITY_TEST Quality = 2048
QUALITY_OPERATOR_BLOCKED Quality = 4096
QUALITY_DERIVED Quality = 8192
)
const (
VALIDITY_GOOD Validity = iota
VALIDITY_INVALID
VALIDITY_RESERVED
VALIDITY_QUESTIONABLE
)
func (receiver Quality) GetValidity() Validity {
return Validity(receiver & 0x3)
}
func NewTimestamp(time ...time.Time) *Timestamp {
v := C.Timestamp_create()
ret := &Timestamp{
cTimestamp: *v,
}
C.Timestamp_destroy(v)
switch len(time) {
case 0:
// skip
case 1:
ret.SetTime(time[0])
default:
panic(fmt.Errorf("expect got 0 or 1 time param, but got: %d", len(time)))
}
return ret
}
func (receiver *Timestamp) GetTimeInSeconds() uint32 {
return uint32(C.Timestamp_getTimeInSeconds(&receiver.cTimestamp))
}
func (receiver *Timestamp) GetTimeInMs() uint64 {
return uint64(C.Timestamp_getTimeInMs(&receiver.cTimestamp))
}
func (receiver *Timestamp) GetTimeInNs() uint64 {
return uint64(C.Timestamp_getTimeInNs(&receiver.cTimestamp))
}
func (receiver *Timestamp) GetTime() time.Time {
return time.Unix(0, int64(receiver.GetTimeInNs()))
}
func (receiver *Timestamp) IsLeapSecondKnown() bool {
return bool(C.Timestamp_isLeapSecondKnown(&receiver.cTimestamp))
}
func (receiver *Timestamp) SetLeapSecondKnown(value bool) *Timestamp {
C.Timestamp_setLeapSecondKnown(&receiver.cTimestamp, C.bool(value))
return receiver
}
func (receiver *Timestamp) HasClockFailure() bool {
return bool(C.Timestamp_hasClockFailure(&receiver.cTimestamp))
}
func (receiver *Timestamp) SetClockFailure(value bool) *Timestamp {
C.Timestamp_setClockFailure(&receiver.cTimestamp, C.bool(value))
return receiver
}
func (receiver *Timestamp) IsClockNotSynchronized() bool {
return bool(C.Timestamp_isClockNotSynchronized(&receiver.cTimestamp))
}
func (receiver *Timestamp) SetClockNotSynchronized(value bool) *Timestamp {
C.Timestamp_setClockNotSynchronized(&receiver.cTimestamp, C.bool(value))
return receiver
}
func (receiver *Timestamp) GetSubSecondPrecision() int {
return int(C.Timestamp_getSubsecondPrecision(&receiver.cTimestamp))
}
func (receiver *Timestamp) SetTime(time time.Time) *Timestamp {
C.Timestamp_setTimeInNanoseconds(&receiver.cTimestamp, C.nsSinceEpoch(time.UnixNano()))
return receiver
}