rts-sim-module/sys/iscs_sys/iscs_exception.go
2023-12-19 11:11:27 +08:00

49 lines
1.3 KiB
Go

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// IscsExceptionSystem 设备故障异常等例外处理
type IscsExceptionSystem struct {
query *ecs.Query
}
func NewIscsExceptionSystem() *IscsExceptionSystem {
return &IscsExceptionSystem{
query: ecs.NewQuery(filter.Contains(component.DeviceExceptionType)),
}
}
func (s *IscsExceptionSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
device := component.DeviceExceptionType.Get(entry)
//
exception := consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceFaultTag) {
exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceAlarmTag) {
exception = consts.DeviceAlarm
}
if entry.HasComponent(component.DeviceStartTimeoutTag) {
exception = consts.DeviceStartTimeout
}
if entry.HasComponent(component.DeviceModuleFaultTag) {
exception = consts.DeviceModuleFault
}
if entry.HasComponent(component.DeviceAbnormalTag) {
exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
exception = consts.DeviceCommunicationInterrupt
}
//
if device.Exception != exception {
device.Exception = exception
}
})
}