-
Notifications
You must be signed in to change notification settings - Fork 15
/
info.go
163 lines (131 loc) · 4.97 KB
/
info.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
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
// Package info provides the OSI presentation layer.
package info
import "errors"
// CommonAddr is a station address. Zero is not used.
// The width is controlled by Params.AddrSize.
// See companion standard 101, subclause 7.2.4.
type CommonAddr uint16
// ErrAddrZero signals an uninitialized CommonAddr.
var errAddrZero = errors.New("part5: common address 0 is not used")
// GlobalAddr is the broadcast address. Use is restricted
// to C_IC_NA_1, C_CI_NA_1, C_CS_NA_1 and C_RP_NA_1.
// When in 8-bit mode 255 is mapped to this value on the fly.
const GlobalAddr CommonAddr = 65535
// ObjAddr is the information object address.
// The width is controlled by Params.ObjAddrSize.
// See companion standard 101, subclause 7.2.5.
type ObjAddr uint
// Zero means that the address is irrelevant.
const IrrelevantAddr ObjAddr = 0
// SinglePoint is a measured value of a switch.
// See companion standard 101, subclause 7.2.6.1.
type SinglePoint uint
const (
Off SinglePoint = iota
On
)
// DoublePoint is a measured value of a determination aware switch.
// See companion standard 101, subclause 7.2.6.2.
// See http://blog.iec61850.com/2009/04/why-do-we-need-single-point-and-double.html
type DoublePoint uint
const (
IndeterminateOrIntermediate DoublePoint = iota
DeterminedOff
DeterminedOn
Indeterminate
)
// Quality descriptor flags attribute measured values.
// See companion standard 101, subclause 7.2.6.3.
const (
// Overflow marks whether the value is beyond a predefined range.
Overflow = 1 << iota
_ // reserve
_ // reserve
// TimeInvalid flags that the elapsed time was incorrectly acquired.
// This attribute is only valid for events of protection equipment.
// See companion standard 101, subclause 7.2.6.4.
TimeInvalid
// Blocked flags that the value is blocked for transmission; the
// value remains in the state that was acquired before it was blocked.
Blocked
// Substituted flags that the value was provided by the input of
// an operator (dispatcher) instead of an automatic source.
Substituted
// NotTopical flags that the most recent update was unsuccessful.
NotTopical
// Invalid flags that the value was incorrectly acquired.
Invalid
// OK means no flags, no problems.
OK = 0
)
// StepPos is a measured value with transient state indication.
// See companion standard 101, subclause 7.2.6.5.
type StepPos uint
// NewStepPos returns a new step position.
// Values out of [-64, 63] oveflow silently.
func NewStepPos(value int, transient bool) StepPos {
p := StepPos(value & 0x7f)
if transient {
p |= 0x80
}
return p
}
// Pos returns the value in [-64, 63] plus whether the equipment is transient state.
func (p StepPos) Pos() (value int, transient bool) {
u := uint(p)
if u&0x40 == 0 {
// trim rest
value = int(u & 0x3f)
} else {
// sign extend
value = int(u) | (-1 &^ 0x3f)
}
transient = u&0x80 != 0
return
}
// Normal is a 16-bit normalized value.
// See companion standard 101, subclause 7.2.6.6.
type Normal int16
// Float64 returns the value in [-1, 1 − 2⁻¹⁵].
func (n Normal) Float64() float64 { return float64(n) / 32768 }
// Qualifier Of Parameter Of Measured Values
// See companion standard 101, subclause 7.2.6.24.
const (
_ = iota // 0: not used
Threashold // 1: threshold value
Smoothing // 2: smoothing factor (filter time constant)
LowLimit // 3: low limit for transmission of measured values
HighLimit // 4: high limit for transmission of measured values
// 5‥31: reserved for standard definitions of this companion standard (compatible range)
// 32‥63: reserved for special use (private range)
ChangeFlag = 64 // marks local parameter change
InOperationFlag = 128 // marks parameter operation
)
// Cmd is a command.
// See companion standard 101, subclause 7.2.6.26.
type Cmd uint
// Qual returns the qualifier of command.
//
// 0: no additional definition
// 1: short pulse duration (circuit-breaker), duration determined by a system parameter in the outstation
// 2: long pulse duration, duration determined by a system parameter in the outstation
// 3: persistent output
// 4‥8: reserved for standard definitions of this companion standard
// 9‥15: reserved for the selection of other predefined functions
// 16‥31: reserved for special use (private range)
func (c Cmd) Qual() uint { return uint((c >> 2) & 31) }
// Exec returns whether the command executes (or selects).
// See section 5, subclause 6.8.
func (c Cmd) Exec() bool { return c&128 == 0 }
// SetpointCmd is the qualifier of a set-point command.
// See companion standard 101, subclause 7.2.6.39.
type SetpointCmd uint
// Qual returns the qualifier of set-point command.
//
// 0: default
// 0‥63: reserved for standard definitions of this companion standard (compatible range)
// 64‥127: reserved for special use (private range)
func (c SetpointCmd) Qual() uint { return uint(c & 127) }
// Exec returns whether the command executes (or selects).
// See section 5, subclause 6.8.
func (c SetpointCmd) Exec() bool { return c&128 == 0 }