ISCS环境与设备监控系统ecs定义

This commit is contained in:
xzb 2023-12-13 17:27:26 +08:00
parent 661790e208
commit e27ccfd184
4 changed files with 92 additions and 0 deletions

View File

@ -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]()

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}
})
}