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

This commit is contained in:
xzb 2023-12-13 16:10:18 +08:00
parent 1d93d59518
commit 8fe8fa76cb
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/consts"
)
// NetworkSwitch 交换机
type NetworkSwitch struct {
Normal bool //true-正常
Exception consts.DeviceExceptionEnum //具体异常-通信中断、异常
}
var (
NetworkSwitchType = ecs.NewComponentType[NetworkSwitch]()
)

View File

@ -340,3 +340,15 @@ func NewPlcControllerEntity(w ecs.World, id string) *ecs.Entry {
} }
return e return e
} }
// NewNetworkSwitchEntity 创建网络交换机实体
func NewNetworkSwitchEntity(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.NetworkSwitchType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}

View File

@ -0,0 +1,34 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
type NetworkSystem struct {
queryNetworkSwitch *ecs.Query
}
func NewNetworkSystem() *NetworkSystem {
return &NetworkSystem{
queryNetworkSwitch: ecs.NewQuery(filter.Contains(component.NetworkSwitchType)),
}
}
func (s *NetworkSystem) Update(w ecs.World) {
s.queryNetworkSwitch.Each(w, func(entry *ecs.Entry) {
ns := component.NetworkSwitchType.Get(entry)
//
ns.Exception = consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceAbnormalTag) {
ns.Exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
ns.Exception = consts.DeviceCommunicationInterrupt
}
//正常
ns.Normal = ns.Exception == consts.DeviceExceptionNon
})
}