ISCS环境与设备监控系统ecs定义
This commit is contained in:
parent
f5dd2e8179
commit
f624ae5f08
@ -5,6 +5,8 @@ import (
|
|||||||
"joylink.club/rtsssimulation/consts"
|
"joylink.club/rtsssimulation/consts"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//水泵相关
|
||||||
|
|
||||||
// WaterPump 水泵
|
// WaterPump 水泵
|
||||||
// 如:冷冻水泵、冷却水循环泵、超声波型水泵、浮球型水泵
|
// 如:冷冻水泵、冷却水循环泵、超声波型水泵、浮球型水泵
|
||||||
type WaterPump struct {
|
type WaterPump struct {
|
||||||
@ -20,9 +22,20 @@ type FloatBallSwitch struct {
|
|||||||
|
|
||||||
// WaterTank 水池、水箱
|
// WaterTank 水池、水箱
|
||||||
type WaterTank struct {
|
type WaterTank struct {
|
||||||
Value int32 //水位,单位mm
|
Value int32 //水位,单位mm
|
||||||
|
Level WaterLevel //当前水位级别
|
||||||
|
Exception consts.DeviceExceptionEnum //具体异常-通信中断
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaterLevel 水位定义
|
||||||
|
type WaterLevel = uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
WaterLevelNormal WaterLevel = iota //正常安全水位
|
||||||
|
WaterLevelHigh //水位过高
|
||||||
|
WaterLevelLow //水位过低
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
WaterPumpType = ecs.NewComponentType[WaterPump]()
|
WaterPumpType = ecs.NewComponentType[WaterPump]()
|
||||||
FloatBallSwitchType = ecs.NewComponentType[FloatBallSwitch]()
|
FloatBallSwitchType = ecs.NewComponentType[FloatBallSwitch]()
|
||||||
|
@ -140,3 +140,15 @@ func NewFloatBallWaterPumpEntity(w ecs.World, id string) *ecs.Entry {
|
|||||||
entry.AddComponent(component.FloatBallSwitchType)
|
entry.AddComponent(component.FloatBallSwitchType)
|
||||||
return entry
|
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
|
||||||
|
}
|
||||||
|
@ -279,3 +279,25 @@ func ChillerUnitOperate(w ecs.World, deviceId string, optRun bool) error {
|
|||||||
})
|
})
|
||||||
return r.Err
|
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
|
||||||
|
}
|
||||||
|
@ -22,7 +22,7 @@ func NewWaterPumpSystem() *WaterPumpSystem {
|
|||||||
func (s *WaterPumpSystem) Update(w ecs.World) {
|
func (s *WaterPumpSystem) Update(w ecs.World) {
|
||||||
s.query.Each(w, func(entry *ecs.Entry) {
|
s.query.Each(w, func(entry *ecs.Entry) {
|
||||||
pump := component.WaterPumpType.Get(entry)
|
pump := component.WaterPumpType.Get(entry)
|
||||||
//浮球型水泵
|
//浮球型水泵,水箱水位控制浮球开关从而控制水泵开关
|
||||||
if entry.HasComponent(component.FloatBallSwitchType) {
|
if entry.HasComponent(component.FloatBallSwitchType) {
|
||||||
fbs := component.FloatBallSwitchType.Get(entry)
|
fbs := component.FloatBallSwitchType.Get(entry)
|
||||||
pump.Running = fbs.On
|
pump.Running = fbs.On
|
||||||
|
61
sys/iscs_sys/iscs_bas_water_tank.go
Normal file
61
sys/iscs_sys/iscs_bas_water_tank.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user