From 312300e8ba43a6e6e48b9be464f74c1b8963af38 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 27 Dec 2023 09:57:56 +0800 Subject: [PATCH] =?UTF-8?q?iscs=20=20bas=20=20=E5=A4=A7=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/main.go | 6 +++- fi/iscs_bas.go | 5 ---- fi/motor.go | 57 ++++++++++++++++++++++++++++++++++++ sys/iscs_sys/iscs_bas_fan.go | 9 ++---- 4 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 fi/motor.go diff --git a/examples/main.go b/examples/main.go index b6056d4..99447bb 100644 --- a/examples/main.go +++ b/examples/main.go @@ -3,6 +3,7 @@ package main import ( "joylink.club/ecs" "joylink.club/rtsssimulation/entity" + "joylink.club/rtsssimulation/fi" "joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/sys" "time" @@ -23,7 +24,10 @@ func main() { repo, _ := repository.BuildRepository(protoRepo) sim, _ := newIscsSimulation(repo) sim.StartUp() - sim.SetSpeed(1) + time.Sleep(2 * time.Second) + fi.MotorOperate(sim, "fan2", fi.FiMsOnForward, 60) + time.Sleep(8 * time.Second) + fi.MotorOperate(sim, "fan2", fi.FiMsOnReverse, 60) time.Sleep(8 * time.Second) sim.Close() time.Sleep(2 * time.Second) diff --git a/fi/iscs_bas.go b/fi/iscs_bas.go index 910f176..db9b880 100644 --- a/fi/iscs_bas.go +++ b/fi/iscs_bas.go @@ -8,11 +8,6 @@ import ( "joylink.club/rtsssimulation/entity" ) -// FanExceptionOperate 风机异常设置(故障、异常、通信中断) -func FanExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOptEnum) error { - return DeviceExceptionOperate(w, deviceId, opt) -} - // PurificationDeviceOperate 净化装置操作 // // optStart : true-启动净化器;false-关停净化器 diff --git a/fi/motor.go b/fi/motor.go new file mode 100644 index 0000000..6965174 --- /dev/null +++ b/fi/motor.go @@ -0,0 +1,57 @@ +package fi + +import ( + "fmt" + "joylink.club/ecs" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" +) + +// FiMotorSwitch 电机电源开关定义 +type FiMotorSwitch uint8 + +const ( + FiMsOff FiMotorSwitch = iota //关闭电源 + FiMsOnForward //正转电源 + FiMsOnReverse //反转电源 +) + +func MotorOperate(w ecs.World, deviceId string, fiMs FiMotorSwitch, fc uint16) error { + if fc < 0 || fc > 100 { + return fmt.Errorf("设置变频器频率[%d]不在[0,100]范围内", fc) + } + ms, e := func(fiMs FiMotorSwitch) (component.MotorSwitch, error) { + switch fiMs { + case FiMsOff: + return component.MsOff, nil + case FiMsOnForward: + return component.MsOnForward, nil + case FiMsOnReverse: + return component.MsOnReverse, nil + default: + return 0, fmt.Errorf("参数fiMs[%d]无法映射到component.MotorSwitch", fiMs) + } + }(fiMs) + if e != nil { + return e + } + 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.MotorType) { + return ecs.NewErrResult(fmt.Errorf("设备[%s]不是电机", deviceId)) + } + motor := component.MotorType.Get(deviceEntry) + motor.Ms = ms + if deviceEntry.HasComponent(component.MotorFcType) { //变频电机 + component.MotorFcType.Get(deviceEntry).F = fc + } + // + return ecs.NewOkEmptyResult() + }) + return r.Err +} diff --git a/sys/iscs_sys/iscs_bas_fan.go b/sys/iscs_sys/iscs_bas_fan.go index 69619a1..7b9f347 100644 --- a/sys/iscs_sys/iscs_bas_fan.go +++ b/sys/iscs_sys/iscs_bas_fan.go @@ -1,7 +1,6 @@ package iscs_sys import ( - "fmt" "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" @@ -20,13 +19,9 @@ func NewFanSystem() *FanSystem { } func (s *FanSystem) Update(w ecs.World) { s.query.Each(w, func(entry *ecs.Entry) { - fanId := component.UidType.Get(entry).Id + //fanId := component.UidType.Get(entry).Id fan := component.MotorType.Get(entry) - fmt.Printf("====>>>fanId = %s , forward = %t , speed = %f , ms = %d\n", fanId, fan.Forward, fan.Speed, fan.Ms) - fan.Ms = component.MsOnForward - if entry.HasComponent(component.MotorFcType) { - component.MotorFcType.Get(entry).F = 80 - } + //fmt.Printf("====>>>fanId = %s , forward = %t , speed = %f , ms = %d\n", fanId, fan.Forward, fan.Speed, fan.Ms) //一般风机(3000 r/min) if entry.HasComponent(component.CommonFanTag) { if fan.Speed > 3000 {