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

45 lines
1.3 KiB
Go

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// BasFanSystem ISCS BAS 风机
type BasFanSystem struct {
query *ecs.Query
}
func NewBasFanSystem() *BasFanSystem {
return &BasFanSystem{
query: ecs.NewQuery(filter.Contains(component.FanType)),
}
}
func (s *BasFanSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
fan := component.FanType.Get(entry)
//
fanState := component.FanStateType.Get(entry)
fanState.Fc = fan.Fc
fanState.Bypass = fan.Bypass
fanState.Running = fan.Power != 0
fanState.Forward = fan.Power > 0
fanState.SoftStart = fan.SoftStart
fanState.HighSpeed = fanState.Running && entry.HasComponent(component.HighSpeedModeFanTag)
fanState.SlowSpeed = fanState.Running && entry.HasComponent(component.LowSpeedModeFanTag)
fanState.Hand = entry.HasComponent(component.HandTag)
//
if entry.HasComponent(component.DeviceFaultTag) {
fanState.Exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceAbnormalTag) {
fanState.Exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
fanState.Exception = consts.DeviceCommunicationInterrupt
}
})
}