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

This commit is contained in:
xzb 2023-12-12 16:00:53 +08:00
parent 64b74a0623
commit c3f177074b
4 changed files with 166 additions and 0 deletions

View File

@ -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]()
)

View File

@ -85,3 +85,27 @@ func NewPurificationDeviceEntity(w ecs.World, id string) *ecs.Entry {
} }
return e 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
}

View File

@ -192,3 +192,68 @@ func PurificationDeviceOperate(w ecs.World, deviceId string, optStart bool) erro
}) })
return r.Err 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
}

View File

@ -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
}
})
}