diff --git a/component/iscs_bas_pump.go b/component/iscs_bas_pump.go index 4856d5e..6f610ad 100644 --- a/component/iscs_bas_pump.go +++ b/component/iscs_bas_pump.go @@ -5,6 +5,8 @@ import ( "joylink.club/rtsssimulation/consts" ) +//水泵相关 + // WaterPump 水泵 // 如:冷冻水泵、冷却水循环泵、超声波型水泵、浮球型水泵 type WaterPump struct { @@ -20,9 +22,20 @@ type FloatBallSwitch struct { // WaterTank 水池、水箱 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 ( WaterPumpType = ecs.NewComponentType[WaterPump]() FloatBallSwitchType = ecs.NewComponentType[FloatBallSwitch]() diff --git a/entity/iscs_bas.go b/entity/iscs_bas.go index b0d70ac..6f5c831 100644 --- a/entity/iscs_bas.go +++ b/entity/iscs_bas.go @@ -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 +} diff --git a/fi/iscs_bas.go b/fi/iscs_bas.go index 4ac8c8f..2f1147e 100644 --- a/fi/iscs_bas.go +++ b/fi/iscs_bas.go @@ -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 +} diff --git a/sys/iscs_sys/iscs_bas_water_pump.go b/sys/iscs_sys/iscs_bas_water_pump.go index 8405c70..6d396ac 100644 --- a/sys/iscs_sys/iscs_bas_water_pump.go +++ b/sys/iscs_sys/iscs_bas_water_pump.go @@ -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 diff --git a/sys/iscs_sys/iscs_bas_water_tank.go b/sys/iscs_sys/iscs_bas_water_tank.go new file mode 100644 index 0000000..e9c9f8c --- /dev/null +++ b/sys/iscs_sys/iscs_bas_water_tank.go @@ -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 +}