188 lines
6.2 KiB
Go
188 lines
6.2 KiB
Go
package iscs_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/consts"
|
|
)
|
|
|
|
// IscsPscadaSystem 电力监控系统
|
|
type IscsPscadaSystem struct {
|
|
queryCircuitBreaker *ecs.Query
|
|
queryHandcartSwitch *ecs.Query
|
|
queryRectifier *ecs.Query
|
|
queryThreePositionSwitch *ecs.Query
|
|
queryTransBusbarBackupZiTou *ecs.Query
|
|
queryVoltageTransformer *ecs.Query
|
|
queryWireCabinet *ecs.Query
|
|
}
|
|
|
|
func NewIscsPscadaSystem() *IscsPscadaSystem {
|
|
return &IscsPscadaSystem{
|
|
queryCircuitBreaker: ecs.NewQuery(filter.Contains(component.IscsCircuitBreakerStateType, component.TwoPositionSwitchType)),
|
|
queryHandcartSwitch: ecs.NewQuery(filter.Contains(component.IscsHandcartSwitchStateType, component.HandcartSwitchType)),
|
|
queryRectifier: ecs.NewQuery(filter.Contains(component.IscsRectifierStateType, component.ElecDeviceType)),
|
|
queryThreePositionSwitch: ecs.NewQuery(filter.Contains(component.IscsIscsThreePositionSwitchStateType, component.ThreePositionSwitchType)),
|
|
queryTransBusbarBackupZiTou: ecs.NewQuery(filter.Contains(component.IscsTransBackupZiTouStateType)),
|
|
queryVoltageTransformer: ecs.NewQuery(filter.Contains(component.IscsVoltageTransformerStateType, component.ElecDeviceType)),
|
|
queryWireCabinet: ecs.NewQuery(filter.Contains(component.IscsWireCabinetStateType, component.ElecDeviceType)),
|
|
}
|
|
}
|
|
func (s *IscsPscadaSystem) Update(w ecs.World) {
|
|
s.circuitBreaker(w)
|
|
s.handcartSwitch(w)
|
|
s.rectifier(w)
|
|
s.threePositionSwitch(w)
|
|
s.transBusbarBackupZiTou(w)
|
|
s.voltageTransformer(w)
|
|
s.wireCabinet(w)
|
|
}
|
|
func (s *IscsPscadaSystem) wireCabinet(w ecs.World) {
|
|
s.queryWireCabinet.Each(w, func(entry *ecs.Entry) {
|
|
wcState := component.IscsWireCabinetStateType.Get(entry)
|
|
wc := component.ElecDeviceType.Get(entry)
|
|
//
|
|
normal := true
|
|
if entry.HasComponent(component.DeviceFaultTag) {
|
|
wcState.State = consts.WcsFault
|
|
normal = false
|
|
}
|
|
if entry.HasComponent(component.DeviceAlarmTag) {
|
|
wcState.State = consts.WcsAlarm
|
|
normal = false
|
|
}
|
|
if entry.HasComponent(component.DeviceAbnormalTag) || entry.HasComponent(component.DeviceCommunicationInterruptTag) {
|
|
wcState.State = consts.WcsAbnormal
|
|
normal = false
|
|
}
|
|
wc.Normal = normal
|
|
if normal {
|
|
wcState.State = consts.WcsNormal
|
|
}
|
|
})
|
|
}
|
|
func (s *IscsPscadaSystem) voltageTransformer(w ecs.World) {
|
|
s.queryVoltageTransformer.Each(w, func(entry *ecs.Entry) {
|
|
vtState := component.IscsVoltageTransformerStateType.Get(entry)
|
|
vt := component.ElecDeviceType.Get(entry)
|
|
//
|
|
normal := true
|
|
if entry.HasComponent(component.DeviceFaultTag) {
|
|
vtState.State = consts.VtfFault
|
|
normal = false
|
|
}
|
|
if entry.HasComponent(component.DeviceAlarmTag) {
|
|
vtState.State = consts.VtfAlarm
|
|
normal = false
|
|
}
|
|
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
|
|
vtState.State = consts.VtfCommunicationInterrupt
|
|
normal = false
|
|
}
|
|
vt.Normal = normal
|
|
if normal {
|
|
vtState.State = consts.VtfNormal
|
|
}
|
|
})
|
|
}
|
|
|
|
// 电路母线备自投处理
|
|
func (s *IscsPscadaSystem) transBusbarBackupZiTou(w ecs.World) {
|
|
s.queryTransBusbarBackupZiTou.Each(w, func(entry *ecs.Entry) {
|
|
ziTouState := component.IscsTransBackupZiTouStateType.Get(entry)
|
|
//
|
|
if entry.HasComponent(component.BackupZiTouInputTag) {
|
|
ziTouState.State = consts.TbztInput
|
|
} else {
|
|
ziTouState.State = consts.TbztExit
|
|
}
|
|
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
|
|
ziTouState.State = consts.TbztCommunicationInterrupt
|
|
}
|
|
|
|
})
|
|
}
|
|
func (s *IscsPscadaSystem) threePositionSwitch(w ecs.World) {
|
|
s.queryThreePositionSwitch.Each(w, func(entry *ecs.Entry) {
|
|
tpSwitchState := component.IscsIscsThreePositionSwitchStateType.Get(entry)
|
|
tpSwitch := component.ThreePositionSwitchType.Get(entry)
|
|
//
|
|
switch tpSwitch.Position {
|
|
case component.StpOpened:
|
|
tpSwitchState.State = consts.TpsOpened
|
|
case component.StpClosedPosition1:
|
|
tpSwitchState.State = consts.TpsDisconnectSwitchClosed
|
|
case component.StpClosedPosition2:
|
|
tpSwitchState.State = consts.TpsLandingSwitchClosed
|
|
}
|
|
if entry.HasComponent(component.DeviceAbnormalTag) {
|
|
tpSwitchState.State = consts.TpsAbnormal
|
|
}
|
|
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
|
|
tpSwitchState.State = consts.TpsCommunicationInterrupt
|
|
}
|
|
})
|
|
}
|
|
func (s *IscsPscadaSystem) rectifier(w ecs.World) {
|
|
s.queryRectifier.Each(w, func(entry *ecs.Entry) {
|
|
rectifierState := component.IscsRectifierStateType.Get(entry)
|
|
elecDevice := component.ElecDeviceType.Get(entry)
|
|
//
|
|
normal := true
|
|
if entry.HasComponent(component.DeviceFaultTag) {
|
|
rectifierState.State = consts.RsFault
|
|
normal = false
|
|
}
|
|
if entry.HasComponent(component.DeviceAlarmTag) {
|
|
rectifierState.State = consts.RsAlarm
|
|
normal = false
|
|
}
|
|
//
|
|
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
|
|
rectifierState.State = consts.RsCommunicationInterrupt
|
|
normal = false
|
|
}
|
|
//
|
|
elecDevice.Normal = normal
|
|
//
|
|
if normal {
|
|
rectifierState.State = consts.RsNormal
|
|
}
|
|
})
|
|
}
|
|
func (s *IscsPscadaSystem) handcartSwitch(w ecs.World) {
|
|
s.queryHandcartSwitch.Each(w, func(entry *ecs.Entry) {
|
|
hdSwitchState := component.IscsHandcartSwitchStateType.Get(entry)
|
|
hdSwitch := component.HandcartSwitchType.Get(entry)
|
|
//
|
|
switch hdSwitch.Position {
|
|
case component.HpOpened:
|
|
hdSwitchState.State = consts.HcsWorkPosOpened
|
|
case component.HpClosed:
|
|
hdSwitchState.State = consts.HcsWorkPosClosed
|
|
case component.HpTest:
|
|
hdSwitchState.State = consts.HcsTestPos
|
|
}
|
|
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
|
|
hdSwitchState.State = consts.HcsCommunicationInterrupt
|
|
}
|
|
})
|
|
}
|
|
func (s *IscsPscadaSystem) circuitBreaker(w ecs.World) {
|
|
s.queryCircuitBreaker.Each(w, func(entry *ecs.Entry) {
|
|
tpSwitchState := component.IscsCircuitBreakerStateType.Get(entry)
|
|
tpSwitch := component.TwoPositionSwitchType.Get(entry)
|
|
//
|
|
if tpSwitch.Closed {
|
|
tpSwitchState.State = consts.CbsClosed
|
|
} else {
|
|
tpSwitchState.State = consts.CbsOpened
|
|
}
|
|
//
|
|
if entry.HasComponent(component.DeviceCommunicationInterruptTag) || entry.HasComponent(component.DeviceAbnormalTag) {
|
|
tpSwitchState.State = consts.CbsAbnormal
|
|
}
|
|
})
|
|
}
|