forked from thinkgos/go-iecp5
/
information.go
executable file
·528 lines (456 loc) · 16.6 KB
/
information.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
// Copyright 2020 thinkgos (thinkgo@aliyun.com). All rights reserved.
// Use of this source code is governed by a version 3 of the GNU General
// Public License, license that can be found in the LICENSE file.
package asdu
// about information object 应用服务数据单元 - 信息对象
// InfoObjAddr is the information object address.
// See companion standard 101, subclass 7.2.5.
// The width is controlled by Params.InfoObjAddrSize.
// <0>: 无关的信息对象地址
// - width 1: <1..255>
// - width 2: <1..65535>
// - width 3: <1..16777215>
type InfoObjAddr uint
// InfoObjAddrIrrelevant Zero means that the information object address is irrelevant.
const InfoObjAddrIrrelevant InfoObjAddr = 0
// SinglePoint is a measured value of a switch.
// See companion standard 101, subclass 7.2.6.1.
type SinglePoint byte
// SinglePoint defined
const (
SPIOff SinglePoint = iota // 关
SPIOn // 开
)
// Value single point to byte
func (sf SinglePoint) Value() byte {
return byte(sf & 0x01)
}
// DoublePoint is a measured value of a determination aware switch.
// See companion standard 101, subclass 7.2.6.2.
type DoublePoint byte
// DoublePoint defined
const (
DPIIndeterminateOrIntermediate DoublePoint = iota // 不确定或中间状态
DPIDeterminedOff // 确定状态开
DPIDeterminedOn // 确定状态关
DPIIndeterminate // 不确定或中间状态
)
// Value double point to byte
func (sf DoublePoint) Value() byte {
return byte(sf & 0x03)
}
// QualityDescriptor Quality descriptor flags attribute measured values.
// See companion standard 101, subclass 7.2.6.3.
type QualityDescriptor byte
// QualityDescriptor defined.
const (
// QDSOverflow marks whether the value is beyond a predefined range.
QDSOverflow QualityDescriptor = 1 << iota
_ // reserve
_ // reserve
_ // reserve
// QDSBlocked flags that the value is blocked for transmission; the
// value remains in the state that was acquired before it was blocked.
QDSBlocked
// QDSSubstituted flags that the value was provided by the input of
// an operator (dispatcher) instead of an automatic source.
QDSSubstituted
// QDSNotTopical flags that the most recent update was unsuccessful.
QDSNotTopical
// QDSInvalid flags that the value was incorrectly acquired.
QDSInvalid
// QDSGood means no flags, no problems.
QDSGood QualityDescriptor = 0
)
//QualityDescriptorProtection Quality descriptor Protection Equipment flags attribute.
// See companion standard 101, subclass 7.2.6.4.
type QualityDescriptorProtection byte
// QualityDescriptorProtection defined.
const (
_ QualityDescriptorProtection = 1 << iota // reserve
_ // reserve
_ // reserve
// QDPElapsedTimeInvalid flags that the elapsed time was incorrectly acquired.
QDPElapsedTimeInvalid
// QDPBlocked flags that the value is blocked for transmission; the
// value remains in the state that was acquired before it was blocked.
QDPBlocked
// QDPSubstituted flags that the value was provided by the input of
// an operator (dispatcher) instead of an automatic source.
QDPSubstituted
// QDPNotTopical flags that the most recent update was unsuccessful.
QDPNotTopical
// QDPInvalid flags that the value was incorrectly acquired.
QDPInvalid
// QDPGood means no flags, no problems.
QDPGood QualityDescriptorProtection = 0
)
// StepPosition is a measured value with transient state indication.
// 带瞬变状态指示的测量值,用于变压器步位置或其它步位置的值
// See companion standard 101, subclass 7.2.6.5.
// Val range <-64..63>
// bit[0-5]: <-64..63>
// NOTE: bit6 为符号位
// bit7: 0: 设备未在瞬变状态 1: 设备处于瞬变状态
type StepPosition struct {
Val int
HasTransient bool
}
// Value returns step position value.
func (sf StepPosition) Value() byte {
p := sf.Val & 0x7f
if sf.HasTransient {
p |= 0x80
}
return byte(p)
}
// ParseStepPosition parse byte to StepPosition.
func ParseStepPosition(b byte) StepPosition {
step := StepPosition{HasTransient: (b & 0x80) != 0}
if b&0x40 == 0 {
step.Val = int(b & 0x3f)
} else {
step.Val = int(b) | (-1 &^ 0x3f)
}
return step
}
// Normalize is a 16-bit normalized value in[-1, 1 − 2⁻¹⁵]..
// 规一化值 f归一= 32768 * f真实 / 满码值
// See companion standard 101, subclass 7.2.6.6.
type Normalize int16
// Float64 returns the value in [-1, 1 − 2⁻¹⁵].
func (sf Normalize) Float64() float64 {
return float64(sf) / 32768
}
// BinaryCounterReading is binary counter reading
// See companion standard 101, subclass 7.2.6.9.
// CounterReading: 计数器读数 [bit0...bit31]
// SeqNumber: 顺序记法 [bit32...bit40]
// SQ: 顺序号 [bit32...bit36]
// CY: 进位 [bit37]
// CA: 计数量被调整
// IV: 无效
type BinaryCounterReading struct {
CounterReading int32
SeqNumber byte
HasCarry bool
IsAdjusted bool
IsInvalid bool
}
// SingleEvent is single event
// See companion standard 101, subclass 7.2.6.10.
type SingleEvent byte
// SingleEvent dSequenceNotationefined
const (
SEIndeterminateOrIntermediate SingleEvent = iota // 不确定或中间状态
SEDeterminedOff // 确定状态开
SEDeterminedOn // 确定状态关
SEIndeterminate // 不确定或中间状态
)
// StartEvent Start event protection
type StartEvent byte
// StartEvent defined
// See companion standard 101, subclass 7.2.6.11.
const (
SEPGeneralStart StartEvent = 1 << iota // 总启动
SEPStartL1 // A相保护启动
SEPStartL2 // B相保护启动
SEPStartL3 // C相保护启动
SEPStartEarthCurrent // 接地电流保护启动
SEPStartReverseDirection // 反向保护启动
// other reserved
)
// OutputCircuitInfo output command information
// See companion standard 101, subclass 7.2.6.12.
type OutputCircuitInfo byte
// OutputCircuitInfo defined
const (
OCIGeneralCommand OutputCircuitInfo = 1 << iota // 总命令输出至输出电路
OCICommandL1 // A 相保护命令输出至输出电路
OCICommandL2 // B 相保护命令输出至输出电路
OCICommandL3 // C 相保护命令输出至输出电路
// other reserved
)
// FBPTestWord test special value
// See companion standard 101, subclass 7.2.6.14.
const FBPTestWord uint16 = 0x55aa
// SingleCommand Single command
// See companion standard 101, subclass 7.2.6.15.
type SingleCommand byte
// SingleCommand defined
const (
SCOOn SingleCommand = iota
SCOOff
)
// DoubleCommand double command
// See companion standard 101, subclass 7.2.6.16.
type DoubleCommand byte
// DoubleCommand defined
const (
DCONotAllow0 DoubleCommand = iota
DCOOn
DCOOff
DCONotAllow3
)
// StepCommand step command
// See companion standard 101, subclass 7.2.6.17.
type StepCommand byte
// StepCommand defined
const (
SCONotAllow0 StepCommand = iota
SCOStepDown
SCOStepUP
SCONotAllow3
)
// COICause Initialization reason
// See companion standard 101, subclass 7.2.6.21.
type COICause byte
// COICause defined
// 0: 当地电源合上
// 1: 当地手动复位
// 2: 远方复位
// <3..31>: 本配讨标准备的标准定义保留
// <32...127>: 为特定使用保留
const (
COILocalPowerOn COICause = iota
COILocalHandReset
COIRemoteReset
)
// CauseOfInitial cause of initial
// Cause: see COICause
// IsLocalChange: false - 未改变当地参数的初始化
// true - 改变当地参数后的初始化
type CauseOfInitial struct {
Cause COICause
IsLocalChange bool
}
// ParseCauseOfInitial parse byte to cause of initial
func ParseCauseOfInitial(b byte) CauseOfInitial {
return CauseOfInitial{
Cause: COICause(b & 0x7f),
IsLocalChange: b&0x80 == 0x80,
}
}
// Value CauseOfInitial to byte
func (sf CauseOfInitial) Value() byte {
if sf.IsLocalChange {
return byte(sf.Cause | 0x80)
}
return byte(sf.Cause)
}
// QualifierOfInterrogation Qualifier Of Interrogation
// See companion standard 101, subclass 7.2.6.22.
type QualifierOfInterrogation byte
// QualifierOfInterrogation defined
const (
// <1..19>: 为标准定义保留
QOIStation QualifierOfInterrogation = 20 + iota // interrogated by station interrogation
QOIGroup1 // interrogated by group 1 interrogation
QOIGroup2 // interrogated by group 2 interrogation
QOIGroup3 // interrogated by group 3 interrogation
QOIGroup4 // interrogated by group 4 interrogation
QOIGroup5 // interrogated by group 5 interrogation
QOIGroup6 // interrogated by group 6 interrogation
QOIGroup7 // interrogated by group 7 interrogation
QOIGroup8 // interrogated by group 8 interrogation
QOIGroup9 // interrogated by group 9 interrogation
QOIGroup10 // interrogated by group 10 interrogation
QOIGroup11 // interrogated by group 11 interrogation
QOIGroup12 // interrogated by group 12 interrogation
QOIGroup13 // interrogated by group 13 interrogation
QOIGroup14 // interrogated by group 14 interrogation
QOIGroup15 // interrogated by group 15 interrogation
QOIGroup16 // interrogated by group 16 interrogation
// <37..63>:为标准定义保留
// <64..255>: 为特定使用保留
// 0:未使用
QOIUnused QualifierOfInterrogation = 0
)
// QCCRequest 请求 [bit0...bit5]
// See companion standard 101, subclass 7.2.6.23.
type QCCRequest byte
// QCCFreeze 冻结 [bit6,bit7]
// See companion standard 101, subclass 7.2.6.23.
type QCCFreeze byte
// QCCRequest and QCCFreeze defined
const (
QCCUnused QCCRequest = iota
QCCGroup1
QCCGroup2
QCCGroup3
QCCGroup4
QCCTotal
// <6..31>: 为标准定义
// <32..63>: 为特定使用保留
QCCFrzRead QCCFreeze = 0x00 // 读(无冻结或复位)
QCCFrzFreezeNoReset QCCFreeze = 0x40 // 计数量冻结不带复位(被冻结的值为累计量)
QCCFrzFreezeReset QCCFreeze = 0x80 // 计数量冻结带复位(被冻结的值为增量信息)
QCCFrzReset QCCFreeze = 0xc0 // 计数量复位
)
// QualifierCountCall 计数量召唤命令限定词
// See companion standard 101, subclass 7.2.6.23.
type QualifierCountCall struct {
Request QCCRequest
Freeze QCCFreeze
}
// ParseQualifierCountCall parse byte to QualifierCountCall
func ParseQualifierCountCall(b byte) QualifierCountCall {
return QualifierCountCall{
Request: QCCRequest(b & 0x3f),
Freeze: QCCFreeze(b & 0xc0),
}
}
// Value QualifierCountCall to byte
func (sf QualifierCountCall) Value() byte {
return byte(sf.Request&0x3f) | byte(sf.Freeze&0xc0)
}
// QPMCategory 测量参数类别
type QPMCategory byte
// QPMCategory defined
const (
QPMUnused QPMCategory = iota // 0: not used
QPMThreshold // 1: threshold value
QPMSmoothing // 2: smoothing factor (filter time constant)
QPMLowLimit // 3: low limit for transmission of measured values
QPMHighLimit // 4: high limit for transmission of measured values
// 5‥31: reserved for standard definitions of sf companion standard (compatible range)
// 32‥63: reserved for special use (private range)
QPMChangeFlag QPMCategory = 0x40 // bit6 marks local parameter change 当地参数改变
QPMInOperationFlag QPMCategory = 0x80 // bit7 marks parameter operation 参数在运行
)
// QualifierOfParameterMV Qualifier Of Parameter Of Measured Values 测量值参数限定词
// See companion standard 101, subclass 7.2.6.24.
// QPMCategory : [bit0...bit5] 参数类型
// IsChange : [bit6]当地参数改变,false - 未改变,true - 改变
// IsInOperation : [bit7] 参数在运行,false - 运行, true - 不在运行
type QualifierOfParameterMV struct {
Category QPMCategory
IsChange bool
IsInOperation bool
}
// ParseQualifierOfParamMV parse byte to QualifierOfParameterMV
func ParseQualifierOfParamMV(b byte) QualifierOfParameterMV {
return QualifierOfParameterMV{
Category: QPMCategory(b & 0x3f),
IsChange: b&0x40 == 0x40,
IsInOperation: b&0x80 == 0x80,
}
}
// Value QualifierOfParameterMV to byte
func (sf QualifierOfParameterMV) Value() byte {
v := byte(sf.Category) & 0x3f
if sf.IsChange {
v |= 0x40
}
if sf.IsInOperation {
v |= 0x80
}
return v
}
// QualifierOfParameterAct Qualifier Of Parameter Activation 参数激活限定词
// See companion standard 101, subclass 7.2.6.25.
type QualifierOfParameterAct byte
// QualifierOfParameterAct defined
const (
QPAUnused QualifierOfParameterAct = iota
// 激活/停止激活这之前装载的参数(信息对象地址=0)
QPADeActPrevLoadedParameter
// 激活/停止激活所寻址信息对象的参数
QPADeActObjectParameter
// 激活/停止激活所寻址的持续循环或周期传输的信息对象
QPADeActObjectTransmission
// 4‥127: reserved for standard definitions of sf companion standard (compatible range)
// 128‥255: reserved for special use (private range)
)
// QOCQual the qualifier of qual.
// See companion standard 101, subclass 7.2.6.26.
type QOCQual byte
// QOCQual defined
const (
// 0: no additional definition
// 无另外的定义
QOCNoAdditionalDefinition QOCQual = iota
// 1: short pulse duration (circuit-breaker), duration determined by a system parameter in the outstation
// 短脉冲持续时间(断路器),持续时间由被控站内的系统参数所确定
QOCShortPulseDuration
// 2: long pulse duration, duration determined by a system parameter in the outstation
// 长脉冲持续时间,持续时间由被控站内的系统参数所确定
QOCLongPulseDuration
// 3: persistent output
// 持续输出
QOCPersistentOutput
// 4‥8: reserved for standard definitions of sf companion standard
// 9‥15: reserved for the selection of other predefined functions
// 16‥31: reserved for special use (private range)
)
// QualifierOfCommand is a qualifier of command. 命令限定词
// See companion standard 101, subclass 7.2.6.26.
// See section 5, subclass 6.8.
// InSelect: true - selects, false - executes.
type QualifierOfCommand struct {
Qual QOCQual
InSelect bool
}
// ParseQualifierOfCommand parse byte to QualifierOfCommand
func ParseQualifierOfCommand(b byte) QualifierOfCommand {
return QualifierOfCommand{
Qual: QOCQual((b >> 2) & 0x1f),
InSelect: b&0x80 == 0x80,
}
}
// Value QualifierOfCommand to byte
func (sf QualifierOfCommand) Value() byte {
v := (byte(sf.Qual) & 0x1f) << 2
if sf.InSelect {
v |= 0x80
}
return v
}
// QualifierOfResetProcessCmd 复位进程命令限定词
// See companion standard 101, subclass 7.2.6.27.
type QualifierOfResetProcessCmd byte
// QualifierOfResetProcessCmd defined
const (
// 未采用
QRPUnused QualifierOfResetProcessCmd = iota
// 进程的总复位
QPRGeneralRest
// 复位事件缓冲区等待处理的带时标的信息
QPRResetPendingInfoWithTimeTag
// <3..127>: 为标准保留
//<128..255>: 为特定使用保留
)
/*
TODO: file 文件相关未定义
*/
// QOSQual is the qualifier of a set-point command qual.
// See companion standard 101, subclass 7.2.6.39.
// 0: default
// 0‥63: reserved for standard definitions of sf companion standard (compatible range)
// 64‥127: reserved for special use (private range)
type QOSQual uint
// QualifierOfSetpointCmd is a qualifier of command. 设定命令限定词
// See section 5, subclass 6.8.
// InSelect: true - selects, false - executes.
type QualifierOfSetpointCmd struct {
Qual QOSQual
InSelect bool
}
// ParseQualifierOfSetpointCmd parse byte to QualifierOfSetpointCmd
func ParseQualifierOfSetpointCmd(b byte) QualifierOfSetpointCmd {
return QualifierOfSetpointCmd{
Qual: QOSQual(b & 0x7f),
InSelect: b&0x80 == 0x80,
}
}
// Value QualifierOfSetpointCmd to byte
func (sf QualifierOfSetpointCmd) Value() byte {
v := byte(sf.Qual) & 0x7f
if sf.InSelect {
v |= 0x80
}
return v
}
// StatusAndStatusChangeDetection 状态和状态变位检出
// See companion standard 101, subclass 7.2.6.40.
type StatusAndStatusChangeDetection uint32