2023-12-11 17:16:51 +08:00
|
|
|
|
package fi
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2023-12-29 17:48:57 +08:00
|
|
|
|
|
2023-12-11 17:16:51 +08:00
|
|
|
|
"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-27 11:28:34 +08:00
|
|
|
|
// ValveOperate 阀门操作
|
|
|
|
|
//
|
|
|
|
|
// deviceId 阀门id;
|
|
|
|
|
// openRate 阀门打开百分比值,0-全关,100-全开;
|
|
|
|
|
func ValveOperate(w ecs.World, deviceId string, openRate uint8) error {
|
|
|
|
|
if openRate < 0 || openRate > 100 {
|
|
|
|
|
return fmt.Errorf("阀门打开百分比值[%d]不在范围[0,100]内", openRate)
|
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-12-29 17:48:57 +08:00
|
|
|
|
if !(deviceEntry.HasComponent(component.ValveType) && deviceEntry.HasComponent(component.ValveControllerType) && deviceEntry.HasComponent(component.FixedPositionTransformType)) {
|
2023-12-27 11:28:34 +08:00
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是阀门", deviceId))
|
|
|
|
|
}
|
|
|
|
|
component.ValveControllerType.Get(deviceEntry).TargetOpenRate = openRate
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-12 14:41:39 +08:00
|
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
}
|