83 lines
2.7 KiB
Go
83 lines
2.7 KiB
Go
package memory
|
|
|
|
import (
|
|
"fmt"
|
|
"joylink.club/bj-rtsts-server/sys_error"
|
|
"unsafe"
|
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
appcomponent "joylink.club/bj-rtsts-server/ts/simulation/app_component"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/fi"
|
|
)
|
|
|
|
// 处理区段操作
|
|
func HandleSectionOperation(simulation *VerifySimulation, req *request_proto.SectionOperationReq) error {
|
|
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.Section{})
|
|
// 区段操作
|
|
switch req.Operation {
|
|
case request_proto.Section_SetFaultOcc:
|
|
return fi.AxleSectionFaultOccDrive(simulation.World, uid, true)
|
|
case request_proto.Section_SetParams:
|
|
err := setSectionParam(simulation.World, uid, req.Param)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if req.Param.MockDrst {
|
|
state, err := fi.AxleSectionDrstDrive(simulation.World, uid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if state.Rjo {
|
|
return sys_error.New("运营原因拒绝复位")
|
|
}
|
|
}
|
|
if req.Param.MockPdrst {
|
|
state, err := fi.AxleSectionPdrstDrive(simulation.World, uid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if state.Rjo {
|
|
return sys_error.New("运营原因拒绝预复位")
|
|
}
|
|
}
|
|
return err
|
|
default:
|
|
return fmt.Errorf("未知的区段操作:%s", req.Operation)
|
|
}
|
|
}
|
|
|
|
func setSectionParam(world ecs.World, uid string, sectionParam *request_proto.SectionParam) error {
|
|
return handleEntityState(world, uid, func(e *ecs.Entry) error {
|
|
e.AddComponent(appcomponent.SectionParamType, unsafe.Pointer(sectionParam))
|
|
return nil
|
|
})
|
|
}
|
|
|
|
// func ChangeAxleSectionState(simulation *VerifySimulation, req *dto.AxleSectionOperationReqDto) error {
|
|
// sectionUid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.Section{})
|
|
// slog.Debug("操作计轴区段", "axleSectionUid", sectionUid)
|
|
// if req.TrainIn {
|
|
// return fi.AxleSectionTrainDrive(simulation.World, sectionUid, true)
|
|
// }
|
|
// if req.TrainOut {
|
|
// return fi.AxleSectionTrainDrive(simulation.World, sectionUid, false)
|
|
// }
|
|
// switch req.Operation {
|
|
// case request_proto.Section_CancelDrst:
|
|
// return fi.AxleSectionDrstDrive(simulation.World, sectionUid, false)
|
|
// case request_proto.Section_SetDrst:
|
|
// return fi.AxleSectionDrstDrive(simulation.World, sectionUid, true)
|
|
// case request_proto.Section_CancelPdrst:
|
|
// return fi.AxleSectionPdrstDrive(simulation.World, sectionUid, false)
|
|
// case request_proto.Section_SetPdrst:
|
|
// return fi.AxleSectionPdrstDrive(simulation.World, sectionUid, true)
|
|
// case request_proto.Section_CancelFaultOcc:
|
|
// return fi.AxleSectionFaultOccDrive(simulation.World, sectionUid, false)
|
|
// case request_proto.Section_SetFaultOcc:
|
|
// return fi.AxleSectionFaultOccDrive(simulation.World, sectionUid, true)
|
|
// }
|
|
// return nil
|
|
// }
|