rts-sim-module/sys/iscs_sys/iscs_pscada_circuit_breaker.go

95 lines
2.9 KiB
Go
Raw Permalink Normal View History

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/repository"
)
type CircuitBreakerSystem struct {
query *ecs.Query
}
func NewCircuitBreakerSystem() *CircuitBreakerSystem {
return &CircuitBreakerSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.CircuitBreakerType)),
}
}
func (s *CircuitBreakerSystem) Update(w ecs.World) {
s.circuitBreakerTransPower(w)
}
// 断路器传递电能
func (s *CircuitBreakerSystem) circuitBreakerTransPower(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
breakerId := component.UidType.Get(entry).Id
closed := component.CircuitBreakerType.Get(entry).Closed
breakerModel := (wd.Repo.FindById(breakerId)).(*repository.CircuitBreaker)
//断路器A端连接的管线
breakerPortA := breakerModel.PortA
//断路器B端连接的管线
breakerPortB := breakerModel.PortB
//传递电能
towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB)
})
}
// 两位置开关传递电能(断路器、手车、隔离开关)
func towPipePortsTransPower(
wd *component.WorldData,
closed bool,
breakerPortA *repository.PipePort,
breakerPortB *repository.PipePort) {
//断路器A端连接的管线
breakerPortAPipeEntry := wd.EntityMap[breakerPortA.Device().Id()]
2024-01-05 15:21:29 +08:00
breakerPortAPipe := perfectPipeElectricity(breakerPortAPipeEntry)
//断路器B端连接的管线
breakerPortBPipeEntry := wd.EntityMap[breakerPortB.Device().Id()]
2024-01-05 15:21:29 +08:00
breakerPortBPipe := perfectPipeElectricity(breakerPortBPipeEntry)
2024-01-05 11:30:39 +08:00
//A->B
for portAPipePsId, portAPipePs := range breakerPortAPipe.Sources { //A
portBPipePs, ok := breakerPortBPipe.Sources[portAPipePsId] //B
if ok {
if portAPipePs.Fresh > portBPipePs.Fresh {
*breakerPortBPipe.Sources[portAPipePsId] = *portAPipePs
breakerPortBPipe.Sources[portAPipePsId].Fresh -= 1
if !closed {
2024-01-05 11:30:39 +08:00
breakerPortBPipe.Sources[portAPipePsId].SetOut0()
}
}
} else {
2024-01-05 11:30:39 +08:00
breakerPortBPipe.Sources[portAPipePsId] = component.NewElectricitySource()
*breakerPortBPipe.Sources[portAPipePsId] = *portAPipePs
breakerPortBPipe.Sources[portAPipePsId].Fresh -= 1
if !closed {
2024-01-05 11:30:39 +08:00
breakerPortBPipe.Sources[portAPipePsId].SetOut0()
}
}
}
//B->A
for portBPipePsId, portBPipePs := range breakerPortBPipe.Sources { //B
portAPipePs, ok := breakerPortAPipe.Sources[portBPipePsId] //A
if ok {
if portBPipePs.Fresh > portAPipePs.Fresh {
*breakerPortAPipe.Sources[portBPipePsId] = *portBPipePs
breakerPortAPipe.Sources[portBPipePsId].Fresh -= 1
if !closed {
2024-01-05 11:30:39 +08:00
breakerPortAPipe.Sources[portBPipePsId].SetOut0()
}
}
} else {
2024-01-05 11:30:39 +08:00
breakerPortAPipe.Sources[portBPipePsId] = component.NewElectricitySource()
*breakerPortAPipe.Sources[portBPipePsId] = *portBPipePs
breakerPortAPipe.Sources[portBPipePsId].Fresh -= 1
if !closed {
2024-01-05 11:30:39 +08:00
breakerPortAPipe.Sources[portBPipePsId].SetOut0()
}
}
}
}