增加屏蔽门故障操作及逻辑

This commit is contained in:
joylink_zhangsai 2023-11-06 10:52:57 +08:00
parent 4bcc1c0b16
commit dfe96a977c
4 changed files with 73 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package component
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component/component_proto"
)
@ -30,6 +31,20 @@ type PsdInterlockDriveCircuit struct {
KMJ8 bool
}
var AsdCannotOpenTag = ecs.NewTag()
var AsdCannotCloseTag = ecs.NewTag()
func GetAsdFaultTag(fault component_proto.Psd_Fault) (ecs.IComponentType, error) {
switch fault {
case component_proto.Psd_AsdCannotClose:
return AsdCannotCloseTag, nil
case component_proto.Psd_AsdCannotOpen:
return AsdCannotOpenTag, nil
default:
return nil, fmt.Errorf("未知的屏蔽门故障类型[%s]", fault)
}
}
var AsdTag = ecs.NewTag()
var AsdListType = ecs.NewComponentType[AsdList]()

View File

@ -4,6 +4,7 @@ import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/entity"
)
@ -91,6 +92,48 @@ func CancelInterlockGm(world ecs.World, id string) error {
return result.Err
}
func SetPsdFault(world ecs.World, id string, fault component_proto.Psd_Fault, asdCodes []int32) error {
result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(world)
psdEntry, ok := wd.EntityMap[id]
if !ok {
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id))
}
tag, err := component.GetAsdFaultTag(fault)
if err != nil {
return ecs.NewErrResult(err)
}
asdList := component.AsdListType.Get(psdEntry).List
for _, code := range asdCodes {
asdEntry := asdList[int(code-1)]
asdEntry.AddComponent(tag)
}
return ecs.NewOkEmptyResult()
})
return result.Err
}
func CancelPsdFault(world ecs.World, id string, fault component_proto.Psd_Fault, asdCodes []int32) error {
result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(world)
psdEntry, ok := wd.EntityMap[id]
if !ok {
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id))
}
tag, err := component.GetAsdFaultTag(fault)
if err != nil {
return ecs.NewErrResult(err)
}
asdList := component.AsdListType.Get(psdEntry).List
for _, code := range asdCodes {
asdEntry := asdList[int(code-1)]
asdEntry.RemoveComponent(tag)
}
return ecs.NewOkEmptyResult()
})
return result.Err
}
func setPsdKm(psdEntry *ecs.Entry, group int) {
if psdEntry.HasComponent(component.PsdInterlockDriveCircuitType) { //有联锁区段电路
driveCircuit := component.PsdInterlockDriveCircuitType.Get(psdEntry)

@ -1 +1 @@
Subproject commit 8b25469d6ef3e8aeb1a19326d879293a9958bfe8
Subproject commit e1a4fb8476c783332fc58c9d44a670de85cd7261

View File

@ -25,16 +25,26 @@ func (s *AsdSys) Update(world ecs.World) {
twoPosition := component.TwoPositionTransformType.Get(entry)
asdState := component.AsdStateType.Get(entry)
pos := twoPosition.Pos
if psdMotorState.TD {
if entry.HasComponent(component.AsdCannotOpenTag) {
pos = consts.TwoPosMin
speed = 0
} else if entry.HasComponent(component.AsdCannotCloseTag) {
pos = consts.TwoPosMax
speed = 0
} else if psdMotorState.TD {
if psdMotorState.KM {
twoPosition.Speed = speed
if pos == consts.TwoPosMax { //开门到位后断电
if pos == consts.TwoPosMax {
psdMotorState.TD = false
twoPosition.Speed = 0
} else {
twoPosition.Speed = speed
}
} else {
twoPosition.Speed = -speed
if pos == consts.TwoPosMin { //关门到位后断电
psdMotorState.TD = false
twoPosition.Speed = 0
} else {
twoPosition.Speed = -speed
}
}
}