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

86 lines
2.5 KiB
Go
Raw 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 RectifierSystem struct {
query *ecs.Query
}
func NewRectifierSystem() *RectifierSystem {
return &RectifierSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.RectifierType, component.DeviceExceptionType)),
}
}
func (s *RectifierSystem) Update(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
s.rectifierTransPower(wd, entry)
s.rectifier(wd, entry)
})
}
// 整流器其他一般信息计算收集
func (s *RectifierSystem) rectifier(wd *component.WorldData, entry *ecs.Entry) {
rectifier := component.RectifierType.Get(entry)
exception := component.DeviceExceptionType.Get(entry)
//
2023-12-22 15:29:57 +08:00
rectifier.Normal = exception.Exception.Non()
}
// 整流器电能传递
// 当线路接通时零线和负极电压规定值为1当线路断开时零线和负极电压规定值为0
func (s *RectifierSystem) rectifierTransPower(wd *component.WorldData, entry *ecs.Entry) {
rectifierId := component.UidType.Get(entry).Id
rectifierModel := wd.Repo.FindById(rectifierId).(*repository.Rectifier)
//
portL := rectifierModel.PortA //交火
//portN := rectifierModel.PortB //交零
portZ := rectifierModel.PortC //直正
portF := rectifierModel.PortD //直负
//
portLPipeEntry := wd.EntityMap[portL.Device().Id()]
2024-01-05 15:21:29 +08:00
portLPipe := perfectPipeElectricity(portLPipeEntry)
//
portZPipeEntry := wd.EntityMap[portZ.Device().Id()]
2024-01-05 15:21:29 +08:00
portZPipe := perfectPipeElectricity(portZPipeEntry)
portFPipeEntry := wd.EntityMap[portF.Device().Id()]
2024-01-05 15:21:29 +08:00
portFPipe := perfectPipeElectricity(portFPipeEntry)
//L->Z、F
for lpsId, lps := range portLPipe.Sources {
if lps.Ac {
2024-01-05 11:30:39 +08:00
dcVoltage := uint32(float64(lps.U) * 0.9) //交流电压转直流电压
//L->Z
zps, zpsOk := portZPipe.Sources[lpsId]
if zpsOk {
2024-01-05 11:30:39 +08:00
zps.U = dcVoltage
zps.Fresh = lps.Fresh - 1
zps.Ac = false
2024-01-05 11:30:39 +08:00
zps.Sx = false
} else {
2024-01-05 11:30:39 +08:00
portZPipe.Sources[lpsId] = &component.ElectricitySource{Ac: false, Sx: false, U: dcVoltage, Fresh: lps.Fresh - 1}
}
//L->F
fps, fpsOk := portFPipe.Sources[lpsId]
dcFVoltage := uint32(0)
if dcVoltage > 0 {
dcFVoltage = 1
}
if fpsOk {
2024-01-05 11:30:39 +08:00
fps.U = dcFVoltage
fps.Fresh = lps.Fresh - 1
fps.Ac = false
2024-01-05 11:30:39 +08:00
fps.Sx = false
} else {
2024-01-05 11:30:39 +08:00
portFPipe.Sources[lpsId] = &component.ElectricitySource{Ac: false, Sx: false, U: dcFVoltage, Fresh: lps.Fresh - 1}
}
}
}
}