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

This commit is contained in:
xzb 2023-12-13 16:01:20 +08:00
parent 9244ec0080
commit 1d93d59518
3 changed files with 63 additions and 0 deletions

View File

@ -1 +1,16 @@
package component package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/consts"
)
// PlcController PLC控制器
type PlcController struct {
Normal bool //true-正常
Exception consts.DeviceExceptionEnum //具体异常-通信中断、故障、异常
}
var (
PlcControllerType = ecs.NewComponentType[PlcController]()
)

View File

@ -328,3 +328,15 @@ func NewCivilDefenseDoorEntity(w ecs.World, id string) *ecs.Entry {
} }
return e return e
} }
// NewPlcControllerEntity 创建PLC控制器实体
func NewPlcControllerEntity(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.PlcControllerType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}

View File

@ -0,0 +1,36 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
type PlcControllerSystem struct {
query *ecs.Query
}
func NewPlcControllerSystem() *PlcControllerSystem {
return &PlcControllerSystem{
query: ecs.NewQuery(filter.Contains(component.PlcControllerType)),
}
}
func (s *PlcControllerSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
plc := component.PlcControllerType.Get(entry)
//
plc.Exception = consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceFaultTag) {
plc.Exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceAbnormalTag) {
plc.Exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
plc.Exception = consts.DeviceCommunicationInterrupt
}
//正常
plc.Normal = plc.Exception == consts.DeviceExceptionNon
})
}