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

This commit is contained in:
xzb 2023-12-13 15:21:16 +08:00
parent caed8fcf76
commit 9244ec0080
5 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/consts"
)
// CivilDefenseDoor 人防门
type CivilDefenseDoor struct {
Open bool //true-开false-关
Exception consts.DeviceExceptionEnum //具体异常-通信中断、故障、报警、异常
}
var (
CivilDefenseDoorType = ecs.NewComponentType[CivilDefenseDoor]()
)

View File

@ -0,0 +1 @@
package component

View File

@ -316,3 +316,15 @@ func NewSectionEvacuationGuidanceEntity(w ecs.World, id string) *ecs.Entry {
}
return e
}
// NewCivilDefenseDoorEntity 创建人防门实体
func NewCivilDefenseDoorEntity(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.CivilDefenseDoorType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}

View File

@ -347,3 +347,25 @@ func BypassValveSwitchOperate(w ecs.World, deviceId string, openRate uint8) erro
})
return r.Err
}
// CivilDefenseDoorOperate 封闭式水容器(如冷却塔、水处理器)
//
// optOpen : true-开门false-关门
func CivilDefenseDoorOperate(w ecs.World, deviceId string, optOpen 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.CivilDefenseDoorType)) {
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是人防门", deviceId))
}
door := component.CivilDefenseDoorType.Get(deviceEntry)
door.Open = optOpen
//
return ecs.NewOkEmptyResult()
})
return r.Err
}

View File

@ -0,0 +1,37 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
type IscsDoorSystem struct {
queryCivilDefenseDoor *ecs.Query
}
func NewIscsDoorSystem() *IscsDoorSystem {
return &IscsDoorSystem{
queryCivilDefenseDoor: ecs.NewQuery(filter.Contains(component.CivilDefenseDoorType)),
}
}
func (s *IscsDoorSystem) Update(w ecs.World) {
s.queryCivilDefenseDoor.Each(w, func(entry *ecs.Entry) {
door := component.CivilDefenseDoorType.Get(entry)
//
door.Exception = consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceFaultTag) {
door.Exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceAlarmTag) {
door.Exception = consts.DeviceAlarm
}
if entry.HasComponent(component.DeviceAbnormalTag) {
door.Exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
door.Exception = consts.DeviceCommunicationInterrupt
}
})
}