From 1d93d5951816546003555bd74adb1d9619ee051e Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 13 Dec 2023 16:01:20 +0800 Subject: [PATCH] =?UTF-8?q?ISCS=E7=8E=AF=E5=A2=83=E4=B8=8E=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=9B=91=E6=8E=A7=E7=B3=BB=E7=BB=9Fecs=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/iscs_bas_plc.go | 15 +++++++++++++++ entity/iscs_bas.go | 12 ++++++++++++ sys/iscs_sys/iscs_bas_plc.go | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 sys/iscs_sys/iscs_bas_plc.go diff --git a/component/iscs_bas_plc.go b/component/iscs_bas_plc.go index cc264c9..9f6402d 100644 --- a/component/iscs_bas_plc.go +++ b/component/iscs_bas_plc.go @@ -1 +1,16 @@ 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]() +) diff --git a/entity/iscs_bas.go b/entity/iscs_bas.go index de39590..568b9d2 100644 --- a/entity/iscs_bas.go +++ b/entity/iscs_bas.go @@ -328,3 +328,15 @@ func NewCivilDefenseDoorEntity(w ecs.World, id string) *ecs.Entry { } 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 +} diff --git a/sys/iscs_sys/iscs_bas_plc.go b/sys/iscs_sys/iscs_bas_plc.go new file mode 100644 index 0000000..aba6be2 --- /dev/null +++ b/sys/iscs_sys/iscs_bas_plc.go @@ -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 + }) +}