rts-sim-module/fi/iscs_fas.go
2023-12-15 13:34:22 +08:00

99 lines
2.9 KiB
Go

package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
// SmokeDetectorIsolateOperate 烟感隔离设置
func SmokeDetectorIsolateOperate(w ecs.World, deviceId string, isolate 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.SmokeDetectorType)) {
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是烟感", deviceId))
}
detector := component.SmokeDetectorType.Get(deviceEntry)
if isolate {
detector.State = component.StaIsolate
} else {
detector.State = component.StaNormal
}
//
return ecs.NewOkEmptyResult()
})
return r.Err
}
// TemperatureDetectorIsolateOperate 温感隔离设置
func TemperatureDetectorIsolateOperate(w ecs.World, deviceId string, isolate 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.TemperatureDetectorType)) {
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是温感", deviceId))
}
detector := component.TemperatureDetectorType.Get(deviceEntry)
if isolate {
detector.State = component.StaIsolate
} else {
detector.State = component.StaNormal
}
//
return ecs.NewOkEmptyResult()
})
return r.Err
}
///////////////////////////////////////////////
// MfabOperate 火灾报警按钮操作定义
type MfabOperate = uint8
const (
MfabOperatePress MfabOperate = iota //按下按钮
MfabOperateReset //按钮复位
MfabOperateSetIsolate //按钮隔离设置
MfabOperateCancelIsolate //按钮隔离取消
)
// ManualFireAlarmButtonOperate 火灾报警按钮操作
func ManualFireAlarmButtonOperate(w ecs.World, deviceId string, opt MfabOperate) 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.ManualFireAlarmButtonType)) {
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是火灾报警按钮", deviceId))
}
button := component.ManualFireAlarmButtonType.Get(deviceEntry)
//
switch opt {
case MfabOperatePress:
button.Pressed = true
case MfabOperateReset:
button.Pressed = false
case MfabOperateSetIsolate:
button.State = component.MfabIsolate
case MfabOperateCancelIsolate:
button.State = component.MfabNon
}
//
return ecs.NewOkEmptyResult()
})
return r.Err
}