117 lines
4.1 KiB
Go
117 lines
4.1 KiB
Go
package fi
|
|
|
|
import (
|
|
"fmt"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
)
|
|
|
|
// PlacingCardOptEnum 设备置牌操作枚举定义
|
|
type PlacingCardOptEnum = uint8
|
|
|
|
// 设备置牌操作枚举定义
|
|
const (
|
|
PlacingNonCard PlacingCardOptEnum = iota
|
|
PlacingOverhaulCard
|
|
PlacingLandingCard
|
|
PlacingHandCard
|
|
PlacingOtherCard
|
|
)
|
|
|
|
// DevicePlacingCardOperate 设备置牌操作
|
|
func DevicePlacingCardOperate(w ecs.World, deviceId string, placingCard PlacingCardOptEnum) 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))
|
|
}
|
|
clearAllPlacingTags := func(deviceEntry *ecs.Entry) {
|
|
deviceEntry.RemoveComponent(component.DevicePlacingLandingCardTag)
|
|
deviceEntry.RemoveComponent(component.DevicePlacingOverhaulCardTag)
|
|
deviceEntry.RemoveComponent(component.DevicePlacingOtherCardTag)
|
|
deviceEntry.RemoveComponent(component.DevicePlacingHandTag)
|
|
}
|
|
switch placingCard {
|
|
case PlacingLandingCard:
|
|
clearAllPlacingTags(deviceEntry)
|
|
deviceEntry.AddComponent(component.DevicePlacingLandingCardTag)
|
|
case PlacingOverhaulCard:
|
|
clearAllPlacingTags(deviceEntry)
|
|
deviceEntry.AddComponent(component.DevicePlacingOverhaulCardTag)
|
|
case PlacingOtherCard:
|
|
clearAllPlacingTags(deviceEntry)
|
|
deviceEntry.AddComponent(component.DevicePlacingOtherCardTag)
|
|
case PlacingHandCard:
|
|
clearAllPlacingTags(deviceEntry)
|
|
deviceEntry.AddComponent(component.DevicePlacingHandTag)
|
|
default:
|
|
clearAllPlacingTags(deviceEntry)
|
|
}
|
|
//
|
|
return ecs.NewOkEmptyResult()
|
|
})
|
|
return r.Err
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// DeviceExceptionOptEnum 设备例外操作枚举定义
|
|
type DeviceExceptionOptEnum = uint8
|
|
|
|
const (
|
|
DeviceExceptionNon DeviceExceptionOptEnum = iota //无例外
|
|
DeviceExceptionCommunicationInterrupt //通信中断
|
|
DeviceExceptionAbnormal //异常
|
|
DeviceExceptionFault //故障 有预告信号产生
|
|
DeviceExceptionAlarm //报警 有事故信号产生
|
|
DeviceExceptionStartTimeout //启动超时
|
|
DeviceExceptionModuleFault //模块故障
|
|
)
|
|
|
|
// DeviceExceptionOperate 设备例外操作
|
|
func DeviceExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOptEnum) 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))
|
|
}
|
|
clearAllExceptions := func(deviceEntry *ecs.Entry) {
|
|
deviceEntry.RemoveComponent(component.DeviceCommunicationInterruptTag)
|
|
deviceEntry.RemoveComponent(component.DeviceAbnormalTag)
|
|
deviceEntry.RemoveComponent(component.DeviceFaultTag)
|
|
deviceEntry.RemoveComponent(component.DeviceAlarmTag)
|
|
deviceEntry.RemoveComponent(component.DeviceStartTimeoutTag)
|
|
deviceEntry.RemoveComponent(component.DeviceModuleFaultTag)
|
|
}
|
|
//
|
|
switch opt {
|
|
case DeviceExceptionCommunicationInterrupt:
|
|
clearAllExceptions(deviceEntry)
|
|
deviceEntry.AddComponent(component.DeviceCommunicationInterruptTag)
|
|
case DeviceExceptionAlarm:
|
|
clearAllExceptions(deviceEntry)
|
|
deviceEntry.AddComponent(component.DeviceAlarmTag)
|
|
case DeviceExceptionAbnormal:
|
|
clearAllExceptions(deviceEntry)
|
|
deviceEntry.AddComponent(component.DeviceAbnormalTag)
|
|
case DeviceExceptionFault:
|
|
clearAllExceptions(deviceEntry)
|
|
deviceEntry.AddComponent(component.DeviceFaultTag)
|
|
case DeviceExceptionStartTimeout:
|
|
clearAllExceptions(deviceEntry)
|
|
deviceEntry.AddComponent(component.DeviceStartTimeoutTag)
|
|
case DeviceExceptionModuleFault:
|
|
clearAllExceptions(deviceEntry)
|
|
deviceEntry.AddComponent(component.DeviceModuleFaultTag)
|
|
default:
|
|
clearAllExceptions(deviceEntry)
|
|
}
|
|
//
|
|
return ecs.NewOkEmptyResult()
|
|
})
|
|
return r.Err
|
|
}
|