From c3f177074b8a67faa4de8383e1b113352c116721 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Tue, 12 Dec 2023 16:00:53 +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_elevator.go | 24 ++++++++++++ entity/iscs_bas.go | 24 ++++++++++++ fi/iscs_bas.go | 65 +++++++++++++++++++++++++++++++ sys/iscs_sys/iscs_bas_elevator.go | 53 +++++++++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 component/iscs_bas_elevator.go create mode 100644 sys/iscs_sys/iscs_bas_elevator.go diff --git a/component/iscs_bas_elevator.go b/component/iscs_bas_elevator.go new file mode 100644 index 0000000..721f33c --- /dev/null +++ b/component/iscs_bas_elevator.go @@ -0,0 +1,24 @@ +package component + +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/consts" +) + +// Escalator 自动扶梯 +type Escalator struct { + Running int8 //0-停止;1-上行;-1-下行 + EmergencyStop bool //true-急停 + Exception consts.DeviceExceptionEnum //具体异常 +} + +// Elevator 垂直电梯 +type Elevator struct { + Running bool //true-运行;false-停止 + Exception consts.DeviceExceptionEnum //具体异常 +} + +var ( + EscalatorType = ecs.NewComponentType[Escalator]() + ElevatorType = ecs.NewComponentType[Elevator]() +) diff --git a/entity/iscs_bas.go b/entity/iscs_bas.go index ece6961..b7f553e 100644 --- a/entity/iscs_bas.go +++ b/entity/iscs_bas.go @@ -85,3 +85,27 @@ func NewPurificationDeviceEntity(w ecs.World, id string) *ecs.Entry { } return e } + +// NewElevatorDeviceEntity 创建垂直电梯实体 +func NewElevatorDeviceEntity(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.ElevatorType)) + component.UidType.SetValue(e, component.Uid{Id: id}) + wd.EntityMap[id] = e + } + return e +} + +// NewEscalatorDeviceEntity 创建自动扶梯实体 +func NewEscalatorDeviceEntity(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.EscalatorType)) + component.UidType.SetValue(e, component.Uid{Id: id}) + wd.EntityMap[id] = e + } + return e +} diff --git a/fi/iscs_bas.go b/fi/iscs_bas.go index 9349ae4..3d67b7e 100644 --- a/fi/iscs_bas.go +++ b/fi/iscs_bas.go @@ -192,3 +192,68 @@ func PurificationDeviceOperate(w ecs.World, deviceId string, optStart bool) erro }) return r.Err } + +///////////////////////////////////////////////////////////////////////// + +// EscalatorOptEnum 自动扶梯操作定义 +type EscalatorOptEnum = uint8 + +const ( + EscalatorOptUp EscalatorOptEnum = iota //上行 + EscalatorOptDown //下行 + EscalatorOptStop //停止 + EscalatorOptEs //急停 +) + +// EscalatorDeviceOperate 自动扶梯操作 +func EscalatorDeviceOperate(w ecs.World, deviceId string, opt EscalatorOptEnum) 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.EscalatorType)) { + return ecs.NewErrResult(fmt.Errorf("设备[%s]不是自动扶梯", deviceId)) + } + // + escalator := component.EscalatorType.Get(deviceEntry) + escalator.EmergencyStop = false + switch opt { + case EscalatorOptUp: + escalator.Running = 1 + case EscalatorOptDown: + escalator.Running = -1 + case EscalatorOptStop: + escalator.Running = 0 + case EscalatorOptEs: + escalator.EmergencyStop = true + } + // + return ecs.NewOkEmptyResult() + }) + return r.Err +} + +// ElevatorDeviceOperate 垂直电梯操作 +// +// optRun : true-运行;false-停止 +func ElevatorDeviceOperate(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.ElevatorType)) { + return ecs.NewErrResult(fmt.Errorf("设备[%s]不是垂直电梯", deviceId)) + } + elevator := component.ElevatorType.Get(deviceEntry) + elevator.Running = optRun + // + return ecs.NewOkEmptyResult() + }) + return r.Err +} diff --git a/sys/iscs_sys/iscs_bas_elevator.go b/sys/iscs_sys/iscs_bas_elevator.go new file mode 100644 index 0000000..8928153 --- /dev/null +++ b/sys/iscs_sys/iscs_bas_elevator.go @@ -0,0 +1,53 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/consts" +) + +// ElevatorSystem 电梯(自动扶梯、垂直电梯) +type ElevatorSystem struct { + queryElevator *ecs.Query //垂直电梯 + queryEscalator *ecs.Query //自动扶梯 +} + +func NewElevatorSystem() *ElevatorSystem { + return &ElevatorSystem{ + queryElevator: ecs.NewQuery(filter.Contains(component.ElevatorType)), + queryEscalator: ecs.NewQuery(filter.Contains(component.EscalatorType)), + } +} +func (s *ElevatorSystem) Update(w ecs.World) { + s.queryElevator.Each(w, func(entry *ecs.Entry) { + elevator := component.ElevatorType.Get(entry) + elevator.Exception = consts.DeviceExceptionNon + if entry.HasComponent(component.DeviceFaultTag) { + elevator.Exception = consts.DeviceFault + } + if entry.HasComponent(component.DeviceAbnormalTag) { + elevator.Exception = consts.DeviceAbnormal + } + if entry.HasComponent(component.DeviceCommunicationInterruptTag) { + elevator.Exception = consts.DeviceCommunicationInterrupt + } + }) + // + s.queryElevator.Each(w, func(entry *ecs.Entry) { + escalator := component.EscalatorType.Get(entry) + if escalator.EmergencyStop { //急停 + escalator.Running = 0 + } + escalator.Exception = consts.DeviceExceptionNon + if entry.HasComponent(component.DeviceFaultTag) { + escalator.Exception = consts.DeviceFault + } + if entry.HasComponent(component.DeviceAbnormalTag) { + escalator.Exception = consts.DeviceAbnormal + } + if entry.HasComponent(component.DeviceCommunicationInterruptTag) { + escalator.Exception = consts.DeviceCommunicationInterrupt + } + }) +}