2023-12-11 17:16:51 +08:00
|
|
|
|
package fi
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
2023-12-13 17:01:19 +08:00
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
2023-12-11 17:16:51 +08:00
|
|
|
|
"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))
|
|
|
|
|
}
|
2023-12-12 14:41:39 +08:00
|
|
|
|
tps := component.TwoPositionTransformType.Get(deviceEntry) //最小表示全关,最大表示全开
|
|
|
|
|
if optOpen {
|
|
|
|
|
tps.Speed = component.CalculateTwoPositionAvgSpeed(component.ElectricControlValveOperationTime, w.Tick())
|
|
|
|
|
} else {
|
|
|
|
|
tps.Speed = -component.CalculateTwoPositionAvgSpeed(component.ElectricControlValveOperationTime, w.Tick())
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PurificationDeviceOperate 净化装置操作
|
|
|
|
|
//
|
|
|
|
|
// optStart : true-启动净化器;false-关停净化器
|
|
|
|
|
func PurificationDeviceOperate(w ecs.World, deviceId string, optStart 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.PurificationDeviceType) && deviceEntry.HasComponent(component.CounterType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是净化装置", deviceId))
|
|
|
|
|
}
|
|
|
|
|
device := component.PurificationDeviceType.Get(deviceEntry)
|
|
|
|
|
counter := component.CounterType.Get(deviceEntry)
|
|
|
|
|
if optStart {
|
|
|
|
|
if device.Running {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("净化装置[%s]已经启动在运行", deviceId))
|
|
|
|
|
}
|
|
|
|
|
device.Starting = true
|
|
|
|
|
counter.Val = 0
|
|
|
|
|
counter.Step = w.Tick()
|
|
|
|
|
} else { //关停
|
|
|
|
|
device.Running = false
|
|
|
|
|
}
|
2023-12-12 13:08:37 +08:00
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
2023-12-12 16:00:53 +08:00
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// EscalatorOptEnum 自动扶梯操作定义
|
|
|
|
|
type EscalatorOptEnum = uint8
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
EscalatorOptUp EscalatorOptEnum = iota //上行
|
|
|
|
|
EscalatorOptDown //下行
|
|
|
|
|
EscalatorOptStop //停止
|
|
|
|
|
EscalatorOptEs //急停
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// EscalatorDeviceOperate 自动扶梯操作
|
|
|
|
|
func EscalatorDeviceOperate(w ecs.World, deviceId string, opt EscalatorOptEnum) 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.EscalatorType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是自动扶梯", deviceId))
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
escalator := component.EscalatorType.Get(deviceEntry)
|
|
|
|
|
escalator.EmergencyStop = false
|
|
|
|
|
switch opt {
|
|
|
|
|
case EscalatorOptUp:
|
|
|
|
|
escalator.Running = 1
|
|
|
|
|
case EscalatorOptDown:
|
|
|
|
|
escalator.Running = -1
|
|
|
|
|
case EscalatorOptStop:
|
|
|
|
|
escalator.Running = 0
|
|
|
|
|
case EscalatorOptEs:
|
|
|
|
|
escalator.EmergencyStop = true
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ElevatorDeviceOperate 垂直电梯操作
|
|
|
|
|
//
|
|
|
|
|
// optRun : true-运行;false-停止
|
|
|
|
|
func ElevatorDeviceOperate(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.ElevatorType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是垂直电梯", deviceId))
|
|
|
|
|
}
|
|
|
|
|
elevator := component.ElevatorType.Get(deviceEntry)
|
|
|
|
|
elevator.Running = optRun
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
2023-12-12 18:07:38 +08:00
|
|
|
|
|
|
|
|
|
// ChillerUnitOperate 冷水机组
|
|
|
|
|
//
|
|
|
|
|
// optRun : true-正常运行;false-停止
|
|
|
|
|
func ChillerUnitOperate(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.ChillerUnitType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是冷水机组", deviceId))
|
|
|
|
|
}
|
|
|
|
|
elevator := component.ChillerUnitType.Get(deviceEntry)
|
|
|
|
|
elevator.Running = optRun
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
2023-12-13 10:21:02 +08:00
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
}
|
2023-12-13 14:54:23 +08:00
|
|
|
|
|
|
|
|
|
// WaterClosedContainerOperate 封闭式水容器(如冷却塔、水处理器)
|
|
|
|
|
//
|
|
|
|
|
// optRun : true-正常运行;false-停止
|
|
|
|
|
func WaterClosedContainerOperate(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.WaterClosedContainerType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是封闭式水容器(如冷却塔、水处理器)", deviceId))
|
|
|
|
|
}
|
|
|
|
|
container := component.WaterPumpType.Get(deviceEntry)
|
|
|
|
|
container.Running = optRun
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BypassValveSwitchOperate 旁通阀开关操作
|
|
|
|
|
//
|
|
|
|
|
// openRate 旁通阀开关打开百分比[0,100]
|
|
|
|
|
func BypassValveSwitchOperate(w ecs.World, deviceId string, openRate uint8) error {
|
|
|
|
|
if openRate < 0 || openRate > 100 {
|
|
|
|
|
return fmt.Errorf("旁通阀开关打开百分比值须在[0,100]范围内")
|
|
|
|
|
}
|
|
|
|
|
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.ControlValveType) && deviceEntry.HasComponent(component.BypassValveSwitchTag)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是旁通阀开关", deviceId))
|
|
|
|
|
}
|
|
|
|
|
component.ControlValveType.Get(deviceEntry).OpenRate = openRate
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
2023-12-13 15:21:16 +08:00
|
|
|
|
|
|
|
|
|
// CivilDefenseDoorOperate 封闭式水容器(如冷却塔、水处理器)
|
|
|
|
|
//
|
|
|
|
|
// optOpen : true-开门;false-关门
|
|
|
|
|
func CivilDefenseDoorOperate(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.CivilDefenseDoorType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是人防门", deviceId))
|
|
|
|
|
}
|
|
|
|
|
door := component.CivilDefenseDoorType.Get(deviceEntry)
|
|
|
|
|
door.Open = optOpen
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
2023-12-13 17:01:19 +08:00
|
|
|
|
|
|
|
|
|
// 应急照明操作
|
|
|
|
|
func emergencyLightingOperate(w ecs.World, deviceId string, opt component.EmergencyLightingMode) 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.EmergencyLightingType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是应急照明", deviceId))
|
|
|
|
|
}
|
2023-12-19 11:11:27 +08:00
|
|
|
|
de := component.DeviceExceptionType.Get(deviceEntry)
|
|
|
|
|
if de.Exception != consts.DeviceExceptionNon {
|
2023-12-13 17:01:19 +08:00
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("应急照明[%s]有故障,不能设置工作模式", deviceId))
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-12-19 11:11:27 +08:00
|
|
|
|
device := component.EmergencyLightingType.Get(deviceEntry)
|
|
|
|
|
device.Mode = opt
|
2023-12-13 17:01:19 +08:00
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EmergencyLightingAutoOperate 应急照明自动/正常运行
|
|
|
|
|
func EmergencyLightingAutoOperate(w ecs.World, deviceId string) error {
|
|
|
|
|
return emergencyLightingOperate(w, deviceId, component.ElmAuto)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EmergencyLightingEmergencyOperate 应急照明开启应急模式
|
|
|
|
|
func EmergencyLightingEmergencyOperate(w ecs.World, deviceId string) error {
|
|
|
|
|
return emergencyLightingOperate(w, deviceId, component.ElmEmergency)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EmergencyLightingFirefightingOperate 应急照明开启消防强制启动模式
|
|
|
|
|
func EmergencyLightingFirefightingOperate(w ecs.World, deviceId string) error {
|
|
|
|
|
return emergencyLightingOperate(w, deviceId, component.ElmFirefighting)
|
|
|
|
|
}
|
2023-12-13 17:27:26 +08:00
|
|
|
|
|
|
|
|
|
// AirCurtainOperate 空气幕操作
|
|
|
|
|
func AirCurtainOperate(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.AirCurtainType)) {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是空气幕", deviceId))
|
|
|
|
|
}
|
2023-12-19 11:11:27 +08:00
|
|
|
|
device := component.AirCurtainType.Get(deviceEntry)
|
|
|
|
|
de := component.DeviceExceptionType.Get(deviceEntry)
|
|
|
|
|
if optRun && de.Exception != consts.DeviceExceptionNon {
|
2023-12-13 17:27:26 +08:00
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("空气幕[%s]有故障,不能开启", deviceId))
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-12-19 11:11:27 +08:00
|
|
|
|
device.Running = optRun
|
2023-12-13 17:27:26 +08:00
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|