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

This commit is contained in:
xzb 2023-12-12 18:07:38 +08:00
parent c3f177074b
commit f5dd2e8179
6 changed files with 176 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/consts"
)
// ChillerUnit 冷水机组
type ChillerUnit struct {
Running bool //true-正常运行false-停机
Exception consts.DeviceExceptionEnum //具体异常
}
var ChillerUnitType = ecs.NewComponentType[ChillerUnit]() //冷水机组

View File

@ -0,0 +1,30 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/consts"
)
// WaterPump 水泵
// 如:冷冻水泵、冷却水循环泵、超声波型水泵、浮球型水泵
type WaterPump struct {
Running bool //true-正常运行false-停止
Exception consts.DeviceExceptionEnum //具体异常
}
// FloatBallSwitch 浮球控制的开关,用于浮球型水泵
// 浮球由水箱水位控制
type FloatBallSwitch struct {
On bool //true-水位超过某个限度后开关开启false-开关关闭
}
// WaterTank 水池、水箱
type WaterTank struct {
Value int32 //水位单位mm
}
var (
WaterPumpType = ecs.NewComponentType[WaterPump]()
FloatBallSwitchType = ecs.NewComponentType[FloatBallSwitch]()
WaterTankType = ecs.NewComponentType[WaterTank]()
)

View File

@ -109,3 +109,34 @@ func NewEscalatorDeviceEntity(w ecs.World, id string) *ecs.Entry {
}
return e
}
// NewChillerUnitEntity 创建冷水机组实体
func NewChillerUnitEntity(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.ChillerUnitType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewWaterPumpEntity 创建水泵实体
func NewWaterPumpEntity(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.WaterPumpType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewFloatBallWaterPumpEntity 创建浮球型水泵
func NewFloatBallWaterPumpEntity(w ecs.World, id string) *ecs.Entry {
entry := NewWaterPumpEntity(w, id)
entry.AddComponent(component.FloatBallSwitchType)
return entry
}

View File

@ -257,3 +257,25 @@ func ElevatorDeviceOperate(w ecs.World, deviceId string, optRun bool) error {
})
return r.Err
}
// ChillerUnitOperate 冷水机组
//
// optRun : true-正常运行false-停止
func ChillerUnitOperate(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.ChillerUnitType)) {
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是冷水机组", deviceId))
}
elevator := component.ChillerUnitType.Get(deviceEntry)
elevator.Running = optRun
//
return ecs.NewOkEmptyResult()
})
return r.Err
}

View File

@ -0,0 +1,37 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// ChillerUnitSystem 冷水机组
type ChillerUnitSystem struct {
query *ecs.Query
}
func NewChillerUnitSystem() *ChillerUnitSystem {
return &ChillerUnitSystem{
query: ecs.NewQuery(filter.Contains(component.ChillerUnitType)),
}
}
func (s *ChillerUnitSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
device := component.ChillerUnitType.Get(entry)
//
device.Exception = consts.DeviceExceptionNon
//
if entry.HasComponent(component.DeviceFaultTag) {
device.Exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceAbnormalTag) {
device.Exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
device.Exception = consts.DeviceCommunicationInterrupt
}
})
}

View File

@ -0,0 +1,42 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// WaterPumpSystem 水泵
// 如:冷冻水泵、冷却水循环泵、超声波型水泵、浮球型水泵
// 注:浮球型水泵通过浮球来控制水泵的开启关闭
type WaterPumpSystem struct {
query *ecs.Query
}
func NewWaterPumpSystem() *WaterPumpSystem {
return &WaterPumpSystem{
query: ecs.NewQuery(filter.Contains(component.WaterPumpType)),
}
}
func (s *WaterPumpSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
pump := component.WaterPumpType.Get(entry)
//浮球型水泵
if entry.HasComponent(component.FloatBallSwitchType) {
fbs := component.FloatBallSwitchType.Get(entry)
pump.Running = fbs.On
}
//
pump.Exception = consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceFaultTag) {
pump.Exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceAbnormalTag) {
pump.Exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
pump.Exception = consts.DeviceCommunicationInterrupt
}
})
}