2023-12-21 16:14:02 +08:00
|
|
|
|
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{
|
2023-12-21 18:10:51 +08:00
|
|
|
|
query: ecs.NewQuery(filter.Contains(component.UidType, component.RectifierType, component.DeviceExceptionType)),
|
2023-12-21 16:14:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (s *RectifierSystem) Update(w ecs.World) {
|
2023-12-22 09:46:11 +08:00
|
|
|
|
wd := entity.GetWorldData(w)
|
2023-12-21 18:10:51 +08:00
|
|
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
2023-12-22 09:46:11 +08:00
|
|
|
|
s.rectifierTransPower(wd, entry)
|
|
|
|
|
s.rectifier(wd, entry)
|
2023-12-21 18:10:51 +08:00
|
|
|
|
})
|
2023-12-22 09:46:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 整流器其他一般信息计算收集
|
|
|
|
|
func (s *RectifierSystem) rectifier(wd *component.WorldData, entry *ecs.Entry) {
|
|
|
|
|
rectifier := component.RectifierType.Get(entry)
|
|
|
|
|
exception := component.DeviceExceptionType.Get(entry)
|
2023-12-21 18:10:51 +08:00
|
|
|
|
//
|
2023-12-22 15:29:57 +08:00
|
|
|
|
rectifier.Normal = exception.Exception.Non()
|
2023-12-21 16:14:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 整流器电能传递
|
|
|
|
|
// 当线路接通时零线和负极电压规定值为1,当线路断开时零线和负极电压规定值为0
|
2023-12-22 09:46:11 +08:00
|
|
|
|
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 11:30:39 +08:00
|
|
|
|
portLPipe := component.PipeElectricityType.Get(portLPipeEntry)
|
2023-12-22 09:46:11 +08:00
|
|
|
|
//
|
|
|
|
|
portZPipeEntry := wd.EntityMap[portZ.Device().Id()]
|
2024-01-05 11:30:39 +08:00
|
|
|
|
portZPipe := component.PipeElectricityType.Get(portZPipeEntry)
|
2023-12-22 09:46:11 +08:00
|
|
|
|
portFPipeEntry := wd.EntityMap[portF.Device().Id()]
|
2024-01-05 11:30:39 +08:00
|
|
|
|
portFPipe := component.PipeElectricityType.Get(portFPipeEntry)
|
2023-12-22 09:46:11 +08:00
|
|
|
|
//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) //交流电压转直流电压
|
2023-12-22 09:46:11 +08:00
|
|
|
|
//L->Z
|
|
|
|
|
zps, zpsOk := portZPipe.Sources[lpsId]
|
|
|
|
|
if zpsOk {
|
2024-01-05 11:30:39 +08:00
|
|
|
|
zps.U = dcVoltage
|
2023-12-22 09:46:11 +08:00
|
|
|
|
zps.Fresh = lps.Fresh - 1
|
|
|
|
|
zps.Ac = false
|
2024-01-05 11:30:39 +08:00
|
|
|
|
zps.Sx = false
|
2023-12-22 09:46:11 +08:00
|
|
|
|
} else {
|
2024-01-05 11:30:39 +08:00
|
|
|
|
portZPipe.Sources[lpsId] = &component.ElectricitySource{Ac: false, Sx: false, U: dcVoltage, Fresh: lps.Fresh - 1}
|
2023-12-22 09:46:11 +08:00
|
|
|
|
}
|
|
|
|
|
//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
|
2023-12-22 09:46:11 +08:00
|
|
|
|
fps.Fresh = lps.Fresh - 1
|
|
|
|
|
fps.Ac = false
|
2024-01-05 11:30:39 +08:00
|
|
|
|
fps.Sx = false
|
2023-12-22 09:46:11 +08:00
|
|
|
|
} else {
|
2024-01-05 11:30:39 +08:00
|
|
|
|
portFPipe.Sources[lpsId] = &component.ElectricitySource{Ac: false, Sx: false, U: dcFVoltage, Fresh: lps.Fresh - 1}
|
2023-12-21 16:14:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-22 09:46:11 +08:00
|
|
|
|
}
|
2023-12-21 16:14:02 +08:00
|
|
|
|
|
|
|
|
|
}
|