130 lines
4.0 KiB
Go
130 lines
4.0 KiB
Go
package fi
|
||
|
||
import (
|
||
"fmt"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/component"
|
||
"joylink.club/rtsssimulation/entity"
|
||
)
|
||
|
||
// TransBusbarBackupOperate 母线备自投投入操作
|
||
func TransBusbarBackupOperate(w ecs.World, deviceId string, input 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 input {
|
||
if !deviceEntry.HasComponent(component.BackupZiTouInputTag) {
|
||
deviceEntry.AddComponent(component.BackupZiTouInputTag)
|
||
}
|
||
} else {
|
||
if deviceEntry.HasComponent(component.BackupZiTouInputTag) {
|
||
deviceEntry.RemoveComponent(component.BackupZiTouInputTag)
|
||
}
|
||
}
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
|
||
// SwitchThreePositionOptEnum 三工位开关操作枚举定义
|
||
type SwitchThreePositionOptEnum = uint8
|
||
|
||
const (
|
||
StpOpened SwitchThreePositionOptEnum = iota //开关分闸,线路断开,未与任何位置接通
|
||
StpClosedPosition1 //开关合闸到位置1,与位置1线路导通
|
||
StpClosedPosition2 //开关合闸到位置2,与位置2线路导通
|
||
)
|
||
|
||
// ThreePositionSwitchOperate 三工位开关操作
|
||
func ThreePositionSwitchOperate(w ecs.World, deviceId string, opt SwitchThreePositionOptEnum) 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))
|
||
}
|
||
//
|
||
optConvert := func(opt SwitchThreePositionOptEnum) (component.SwitchThreePosition, error) {
|
||
switch opt {
|
||
case StpOpened:
|
||
return component.StpOpened, nil
|
||
case StpClosedPosition1:
|
||
return component.StpClosedPosition1, nil
|
||
case StpClosedPosition2:
|
||
return component.StpClosedPosition2, nil
|
||
default:
|
||
return component.StpOpened, fmt.Errorf("三工位开关操作[%d]不存在", opt)
|
||
}
|
||
}
|
||
//
|
||
if deviceEntry.HasComponent(component.ThreePositionSwitchType) {
|
||
position, e := optConvert(opt)
|
||
if e == nil {
|
||
component.ThreePositionSwitchType.Get(deviceEntry).Position = position
|
||
} else {
|
||
return ecs.NewErrResult(e)
|
||
}
|
||
} else {
|
||
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是三工位开关", deviceId))
|
||
}
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|
||
|
||
/////////////////////////////////////////////////////////////
|
||
|
||
// HandcartSwitchOptEnum 手车式开关操作枚举定义
|
||
type HandcartSwitchOptEnum = uint8
|
||
|
||
const (
|
||
HpOpened HandcartSwitchOptEnum = iota //工作位分闸
|
||
HpClosed //工作位合闸
|
||
HpTest //实验位
|
||
)
|
||
|
||
// HandcartSwitchOperate 手车式开关操作
|
||
func HandcartSwitchOperate(w ecs.World, deviceId string, opt HandcartSwitchOptEnum) 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))
|
||
}
|
||
//
|
||
optConvert := func(opt HandcartSwitchOptEnum) (component.HandcarPosition, error) {
|
||
switch opt {
|
||
case HpOpened:
|
||
return component.HpOpened, nil
|
||
case HpClosed:
|
||
return component.HpClosed, nil
|
||
case HpTest:
|
||
return component.HpTest, nil
|
||
default:
|
||
return component.StpOpened, fmt.Errorf("手车式开关操作[%d]不存在", opt)
|
||
}
|
||
}
|
||
//
|
||
if deviceEntry.HasComponent(component.HandcartSwitchType) {
|
||
position, e := optConvert(opt)
|
||
if e == nil {
|
||
component.HandcartSwitchType.Get(deviceEntry).Position = position
|
||
} else {
|
||
return ecs.NewErrResult(e)
|
||
}
|
||
} else {
|
||
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是手车式开关", deviceId))
|
||
}
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|