package memory import ( "fmt" "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: var err error setSectionParam(simulation.World, uid, req.Param) if req.Param.MockDrst { err = fi.AxleSectionDrstDrive(simulation.World, uid, true) } else { err = fi.AxleSectionDrstDrive(simulation.World, uid, false) } if err != nil { return err } if req.Param.MockPdrst { err = fi.AxleSectionPdrstDrive(simulation.World, uid, true) } else { err = fi.AxleSectionPdrstDrive(simulation.World, uid, false) } 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 // }