2023-08-01 17:08:45 +08:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
2023-09-28 18:24:36 +08:00
|
|
|
"fmt"
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
2023-10-13 17:43:48 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
2024-01-17 17:49:11 +08:00
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
2023-08-01 17:08:45 +08:00
|
|
|
)
|
|
|
|
|
2023-10-13 17:43:48 +08:00
|
|
|
// 处理道岔操作
|
2024-01-17 17:49:11 +08:00
|
|
|
func HandlePointsOperation(simulation *VerifySimulation, req *request_proto.PointsOperationReq) error {
|
2024-01-11 10:24:56 +08:00
|
|
|
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.Turnout{})
|
2024-01-17 17:49:11 +08:00
|
|
|
// 道岔强制位置
|
2024-01-18 13:10:28 +08:00
|
|
|
switch req.Operation {
|
|
|
|
case request_proto.Points_SetParams:
|
|
|
|
return setTurnoutForce(simulation.World, uid, request_proto.Points_FP_DW)
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("未知的道岔操作:%s", req.Operation)
|
|
|
|
}
|
2023-10-13 17:43:48 +08:00
|
|
|
}
|
2024-01-17 17:49:11 +08:00
|
|
|
|
|
|
|
func setTurnoutForce(w ecs.World, uid string, force request_proto.Points_Force) error {
|
|
|
|
return handleEntityState(w, uid, func(e *ecs.Entry) error {
|
|
|
|
if e.HasComponent(component.Zdj9TwoElectronicType) { // ZDJ9双机牵引道岔
|
|
|
|
zdj92 := component.Zdj9TwoElectronicType.Get(e)
|
|
|
|
switch force {
|
|
|
|
case request_proto.Points_FP_DW:
|
|
|
|
setRelayForce(zdj92.TDC_ZFBJ, false)
|
|
|
|
setRelayForce(zdj92.TDC_ZDBJ, true)
|
|
|
|
case request_proto.Points_FP_FW:
|
|
|
|
setRelayForce(zdj92.TDC_ZDBJ, false)
|
|
|
|
setRelayForce(zdj92.TDC_ZFBJ, true)
|
|
|
|
case request_proto.Points_FP_SB:
|
|
|
|
setRelayForce(zdj92.TDC_ZDBJ, false)
|
|
|
|
setRelayForce(zdj92.TDC_ZFBJ, false)
|
|
|
|
case request_proto.Points_FP_NONE:
|
|
|
|
cancelRelayForce(zdj92.TDC_ZDBJ)
|
|
|
|
cancelRelayForce(zdj92.TDC_ZFBJ)
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("未知的道岔强制位置参数:%s", force)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("未知的道岔牵引类型,无法设置强制位置")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleEntityState(w ecs.World, uid string, handler func(e *ecs.Entry) error) error {
|
|
|
|
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
|
|
|
wd := entity.GetWorldData(w)
|
|
|
|
entry, ok := wd.EntityMap[uid]
|
|
|
|
if ok {
|
|
|
|
err := handler(entry)
|
|
|
|
if err != nil {
|
|
|
|
return ecs.NewErrResult(err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的实体", uid))
|
|
|
|
}
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
})
|
|
|
|
return result.Err
|
|
|
|
}
|