diff --git a/component/iscs_bas_air_curtain.go b/component/iscs_bas_air_curtain.go new file mode 100644 index 0000000..f6195b5 --- /dev/null +++ b/component/iscs_bas_air_curtain.go @@ -0,0 +1,14 @@ +package component + +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/consts" +) + +// AirCurtain 空气幕 +type AirCurtain struct { + Running bool //true-运行;false-停止 + Exception consts.DeviceExceptionEnum //具体异常-故障、报警、异常、通信中断 +} + +var AirCurtainType = ecs.NewComponentType[AirCurtain]() diff --git a/entity/iscs_bas.go b/entity/iscs_bas.go index b73d8a9..1e78c81 100644 --- a/entity/iscs_bas.go +++ b/entity/iscs_bas.go @@ -364,3 +364,15 @@ func NewEmergencyLightingEntity(w ecs.World, id string) *ecs.Entry { } return e } + +// NewAirCurtainEntity 创建空气幕实体 +func NewAirCurtainEntity(w ecs.World, id string) *ecs.Entry { + wd := GetWorldData(w) + e, ok := wd.EntityMap[id] + if !ok { + e := w.Entry(w.Create(component.UidType, component.AirCurtainType)) + component.UidType.SetValue(e, component.Uid{Id: id}) + wd.EntityMap[id] = e + } + return e +} diff --git a/fi/iscs_bas.go b/fi/iscs_bas.go index 9bd4cf9..a03603e 100644 --- a/fi/iscs_bas.go +++ b/fi/iscs_bas.go @@ -409,3 +409,27 @@ func EmergencyLightingEmergencyOperate(w ecs.World, deviceId string) error { func EmergencyLightingFirefightingOperate(w ecs.World, deviceId string) error { return emergencyLightingOperate(w, deviceId, component.ElmFirefighting) } + +// AirCurtainOperate 空气幕操作 +func AirCurtainOperate(w ecs.World, deviceId string, optRun bool) error { + r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] { + wd := entity.GetWorldData(w) + deviceEntry, ok := wd.EntityMap[deviceId] + if !ok { + return ecs.NewErrResult(fmt.Errorf("设备[%s]实体不存在", deviceId)) + } + // + if !(deviceEntry.HasComponent(component.AirCurtainType)) { + return ecs.NewErrResult(fmt.Errorf("设备[%s]不是空气幕", deviceId)) + } + ac := component.AirCurtainType.Get(deviceEntry) + if optRun && ac.Exception != consts.DeviceExceptionNon { + return ecs.NewErrResult(fmt.Errorf("空气幕[%s]有故障,不能开启", deviceId)) + } + // + ac.Running = optRun + // + return ecs.NewOkEmptyResult() + }) + return r.Err +} diff --git a/sys/iscs_sys/iscs_bas_air_curtain.go b/sys/iscs_sys/iscs_bas_air_curtain.go new file mode 100644 index 0000000..d9f5ba7 --- /dev/null +++ b/sys/iscs_sys/iscs_bas_air_curtain.go @@ -0,0 +1,42 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/consts" +) + +// AirCurtainSystem 空气幕 +type AirCurtainSystem struct { + query *ecs.Query +} + +func NewAirCurtainSystem() *AirCurtainSystem { + return &AirCurtainSystem{ + query: ecs.NewQuery(filter.Contains(component.AirCurtainType)), + } +} +func (s *AirCurtainSystem) Update(w ecs.World) { + s.query.Each(w, func(entry *ecs.Entry) { + ac := component.AirCurtainType.Get(entry) + // + ac.Exception = consts.DeviceExceptionNon + if entry.HasComponent(component.DeviceFaultTag) { + ac.Exception = consts.DeviceFault + } + if entry.HasComponent(component.DeviceAlarmTag) { + ac.Exception = consts.DeviceAlarm + } + if entry.HasComponent(component.DeviceAbnormalTag) { + ac.Exception = consts.DeviceAbnormal + } + if entry.HasComponent(component.DeviceCommunicationInterruptTag) { + ac.Exception = consts.DeviceCommunicationInterrupt + } + //异常停止运行 + if ac.Exception != consts.DeviceExceptionNon { + ac.Running = false + } + }) +}