iscs bas 大系统

This commit is contained in:
xzb 2023-12-27 09:57:56 +08:00
parent 6f52757c5d
commit 312300e8ba
4 changed files with 64 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"joylink.club/ecs" "joylink.club/ecs"
"joylink.club/rtsssimulation/entity" "joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/fi"
"joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/repository/model/proto"
"joylink.club/rtsssimulation/sys" "joylink.club/rtsssimulation/sys"
"time" "time"
@ -23,7 +24,10 @@ func main() {
repo, _ := repository.BuildRepository(protoRepo) repo, _ := repository.BuildRepository(protoRepo)
sim, _ := newIscsSimulation(repo) sim, _ := newIscsSimulation(repo)
sim.StartUp() 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) time.Sleep(8 * time.Second)
sim.Close() sim.Close()
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)

View File

@ -8,11 +8,6 @@ import (
"joylink.club/rtsssimulation/entity" "joylink.club/rtsssimulation/entity"
) )
// FanExceptionOperate 风机异常设置(故障、异常、通信中断)
func FanExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOptEnum) error {
return DeviceExceptionOperate(w, deviceId, opt)
}
// PurificationDeviceOperate 净化装置操作 // PurificationDeviceOperate 净化装置操作
// //
// optStart : true-启动净化器false-关停净化器 // optStart : true-启动净化器false-关停净化器

57
fi/motor.go Normal file
View File

@ -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
}

View File

@ -1,7 +1,6 @@
package iscs_sys package iscs_sys
import ( import (
"fmt"
"joylink.club/ecs" "joylink.club/ecs"
"joylink.club/ecs/filter" "joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component"
@ -20,13 +19,9 @@ func NewFanSystem() *FanSystem {
} }
func (s *FanSystem) Update(w ecs.World) { func (s *FanSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) { 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) fan := component.MotorType.Get(entry)
fmt.Printf("====>>>fanId = %s , forward = %t , speed = %f , ms = %d\n", fanId, fan.Forward, fan.Speed, fan.Ms) //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
}
//一般风机(3000 r/min) //一般风机(3000 r/min)
if entry.HasComponent(component.CommonFanTag) { if entry.HasComponent(component.CommonFanTag) {
if fan.Speed > 3000 { if fan.Speed > 3000 {