2023-12-11 17:16:51 +08:00
|
|
|
|
package fi
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
|
|
|
|
)
|
|
|
|
|
|
2023-12-12 13:08:37 +08:00
|
|
|
|
// DeviceHandTagOperate 设备设置手型图标操作
|
|
|
|
|
func DeviceHandTagOperate(w ecs.World, deviceId string, hand 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 hand {
|
|
|
|
|
if !deviceEntry.HasComponent(component.HandTag) {
|
|
|
|
|
deviceEntry.AddComponent(component.HandTag)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if deviceEntry.HasComponent(component.HandTag) {
|
|
|
|
|
deviceEntry.RemoveComponent(component.HandTag)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-11 17:16:51 +08:00
|
|
|
|
// CommonFanOperate 一般风机控制,如排烟风机、正压送风机、射流风机、普通风机、硬线风机
|
|
|
|
|
//
|
|
|
|
|
// power : 风机电源,大于0接通正转相序电源,小于0接通反转相序电源,等于0关闭电源
|
|
|
|
|
func CommonFanOperate(w ecs.World, deviceId string, power int) 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.FanType) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是风机", deviceId))
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
fan := component.FanType.Get(deviceEntry)
|
|
|
|
|
fan.Power = power
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SoftBypassFanOperate 如软启风机、隧道风机
|
|
|
|
|
func SoftBypassFanOperate(w ecs.World, deviceId string, power int, softStart bool, bypass 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.FanType) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是风机", deviceId))
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
fan := component.FanType.Get(deviceEntry)
|
|
|
|
|
fan.Bypass = bypass
|
|
|
|
|
fan.SoftStart = softStart
|
|
|
|
|
fan.Power = power
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FcBypassFanOperate (变频、旁路)回排风机
|
|
|
|
|
func FcBypassFanOperate(w ecs.World, deviceId string, power int, fc bool, bypass 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.FanType) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是风机", deviceId))
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
fan := component.FanType.Get(deviceEntry)
|
|
|
|
|
fan.Bypass = bypass
|
|
|
|
|
fan.Fc = fc
|
|
|
|
|
fan.Power = power
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TwoSpeedFanOperate 双速风机,转速模式设置
|
|
|
|
|
//
|
|
|
|
|
// highSpeedMode-true高速模式,false-低速模式
|
|
|
|
|
func TwoSpeedFanOperate(w ecs.World, deviceId string, power int, highSpeedMode 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.FanType) && deviceEntry.HasComponent(component.TwoSpeedFanTag)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是双速风机", deviceId))
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
fan := component.FanType.Get(deviceEntry)
|
|
|
|
|
fan.Power = power
|
|
|
|
|
//
|
|
|
|
|
deviceEntry.RemoveComponent(component.HighSpeedModeFanTag)
|
|
|
|
|
deviceEntry.RemoveComponent(component.LowSpeedModeFanTag)
|
|
|
|
|
if highSpeedMode {
|
|
|
|
|
deviceEntry.AddComponent(component.HighSpeedModeFanTag)
|
|
|
|
|
} else {
|
|
|
|
|
deviceEntry.AddComponent(component.LowSpeedModeFanTag)
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FanExceptionOperate 风机异常设置(故障、异常、通信中断)
|
|
|
|
|
func FanExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOptEnum) error {
|
|
|
|
|
return DeviceExceptionOperate(w, deviceId, opt)
|
|
|
|
|
}
|
2023-12-12 13:08:37 +08:00
|
|
|
|
|
|
|
|
|
// ElectricControlValveOperate 电动调节阀操作
|
|
|
|
|
//
|
|
|
|
|
// optOpen : true-触发开阀;false-触发关阀
|
|
|
|
|
func ElectricControlValveOperate(w ecs.World, deviceId string, optOpen 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.ElectricControlValveType) && deviceEntry.HasComponent(component.TwoPositionTransformType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是电动调节阀", deviceId))
|
|
|
|
|
}
|
|
|
|
|
valve := component.ElectricControlValveType.Get(deviceEntry)
|
|
|
|
|
valve.FireOpen = optOpen
|
|
|
|
|
valve.FireClose = !optOpen
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|