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

This commit is contained in:
xzb 2023-12-13 10:21:02 +08:00
parent f5dd2e8179
commit f624ae5f08
5 changed files with 110 additions and 2 deletions

View File

@ -5,6 +5,8 @@ import (
"joylink.club/rtsssimulation/consts"
)
//水泵相关
// WaterPump 水泵
// 如:冷冻水泵、冷却水循环泵、超声波型水泵、浮球型水泵
type WaterPump struct {
@ -21,8 +23,19 @@ type FloatBallSwitch struct {
// WaterTank 水池、水箱
type WaterTank struct {
Value int32 //水位单位mm
Level WaterLevel //当前水位级别
Exception consts.DeviceExceptionEnum //具体异常-通信中断
}
// WaterLevel 水位定义
type WaterLevel = uint8
const (
WaterLevelNormal WaterLevel = iota //正常安全水位
WaterLevelHigh //水位过高
WaterLevelLow //水位过低
)
var (
WaterPumpType = ecs.NewComponentType[WaterPump]()
FloatBallSwitchType = ecs.NewComponentType[FloatBallSwitch]()

View File

@ -140,3 +140,15 @@ func NewFloatBallWaterPumpEntity(w ecs.World, id string) *ecs.Entry {
entry.AddComponent(component.FloatBallSwitchType)
return entry
}
// NewWaterTankEntity 创建水池或水箱实体
func NewWaterTankEntity(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.WaterTankType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}

View File

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

View File

@ -22,7 +22,7 @@ func NewWaterPumpSystem() *WaterPumpSystem {
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

View File

@ -0,0 +1,61 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// WaterTankSystem 水池水箱
type WaterTankSystem struct {
query *ecs.Query
}
func NewWaterTankSystem() *WaterTankSystem {
return &WaterTankSystem{
query: ecs.NewQuery(filter.Contains(component.WaterTankType, component.UidType)),
}
}
func (s *WaterTankSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
waterTankId := component.UidType.Get(entry).Id
waterTank := component.WaterTankType.Get(entry)
waterTank.Level = s.calculateWaterLevel(w, waterTankId, waterTank.Value)
//
waterTank.Exception = consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
waterTank.Exception = consts.DeviceCommunicationInterrupt
}
//
waterPumps := s.findWaterPumps(w, waterTankId)
for _, waterPump := range waterPumps {
//浮球型水泵,通过水箱水位等级来控制浮球开关从而控制水泵开关
if waterPump.HasComponent(component.FloatBallSwitchType) {
floatBall := component.FloatBallSwitchType.Get(waterPump)
switch waterTank.Level {
case component.WaterLevelNormal:
fallthrough
case component.WaterLevelLow:
floatBall.On = false
case component.WaterLevelHigh:
floatBall.On = true
}
}
//
}
})
}
// 根据水箱来获取水箱内的水泵实体
func (s *WaterTankSystem) findWaterPumps(w ecs.World, waterTankId string) (waterPumps []*ecs.Entry) {
//todo
panic("WaterTankSystem.findWaterPumps 方法未实现")
return waterPumps
}
// 根据水箱水深计算水箱水位等级
func (s *WaterTankSystem) calculateWaterLevel(w ecs.World, waterTankId string, waterTankVale int32) component.WaterLevel {
//todo
return component.WaterLevelNormal
}