package memory import ( "fmt" "joylink.club/bj-rtsts-server/dto/data_proto" "joylink.club/bj-rtsts-server/dto/request_proto" "joylink.club/ecs" "joylink.club/rtsssimulation/component" ) func HandleSignalOperation(simulation *VerifySimulation, req *request_proto.SignalOperationReq) error { uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.Signal{}) var err error // 道岔强制位置 err = handleSignalForce(simulation.World, uid, req.Param.Force) return err } func handleSignalForce(world ecs.World, uid string, signal_Force request_proto.Signal_Force) error { return handleEntityState(world, uid, func(e *ecs.Entry) error { switch signal_Force { case request_proto.Signal_SF_NONE: return setSignalForceNone(world, e) case request_proto.Signal_SF_M: return setSignalForceM(world, e) case request_proto.Signal_SF_H: return setSignalForceH(world, e) case request_proto.Signal_SF_L: return setSignalForceL(world, e) case request_proto.Signal_SF_U: return setSignalForceU(world, e) case request_proto.Signal_SF_HU: return setSignalForceHU(world, e) case request_proto.Signal_SF_A: return setSignalForceA(world, e) case request_proto.Signal_SF_B: return setSignalForceB(world, e) default: return fmt.Errorf("未知的信号机强制操作:%s", signal_Force) } }) } func setSignalForceNone(w ecs.World, e *ecs.Entry) error { if e.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机 signal2XH1 := component.Signal2XH1ElectronicType.Get(e) cancelRelayForce(signal2XH1.Z2XH1_LXJ) cancelRelayForce(signal2XH1.Z2XH1_DDJ) cancelRelayForce(signal2XH1.Z2XH1_DJ) } else if e.HasComponent(component.Signal3XH1ElectronicType) { // 3XH1信号机 signal3XH1 := component.Signal3XH1ElectronicType.Get(e) cancelRelayForce(signal3XH1.Z3XH1_DDJ) cancelRelayForce(signal3XH1.Z3XH1_DJ) cancelRelayForce(signal3XH1.Z3XH1_2DJ) cancelRelayForce(signal3XH1.Z3XH1_ZXJ) cancelRelayForce(signal3XH1.Z3XH1_LXJ) cancelRelayForce(signal3XH1.Z3XH1_YXJ) } else if e.HasComponent(component.Signal3XH2ElectronicType) { // 3XH2信号机 signal3XH2 := component.Signal3XH2ElectronicType.Get(e) cancelRelayForce(signal3XH2.Z3XH2_DDJ) cancelRelayForce(signal3XH2.Z3XH2_DJ) cancelRelayForce(signal3XH2.Z3XH2_2DJ) cancelRelayForce(signal3XH2.Z3XH2_LXJ) cancelRelayForce(signal3XH2.Z3XH2_YXJ) } else if e.HasComponent(component.Signal3XH3ElectronicType) { // 3XH3信号机 signal3XH3 := component.Signal3XH3ElectronicType.Get(e) cancelRelayForce(signal3XH3.Z3XH3_DDJ) cancelRelayForce(signal3XH3.Z3XH3_DJ) cancelRelayForce(signal3XH3.Z3XH3_2DJ) cancelRelayForce(signal3XH3.Z3XH3_LXJ) cancelRelayForce(signal3XH3.Z3XH3_YXJ) } else if e.HasComponent(component.Signal3XH4ElectronicType) { // 3XH4信号机 signal3XH4 := component.Signal3XH4ElectronicType.Get(e) cancelRelayForce(signal3XH4.Z3XH4_DDJ) cancelRelayForce(signal3XH4.Z3XH4_DJ) cancelRelayForce(signal3XH4.Z3XH4_LXJ) cancelRelayForce(signal3XH4.Z3XH4_ZXJ) } return nil } // 设置信号机强制灭灯 func setSignalForceM(w ecs.World, e *ecs.Entry) error { if e.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机 signal2XH1 := component.Signal2XH1ElectronicType.Get(e) setRelayForce(signal2XH1.Z2XH1_LXJ, false) setRelayForce(signal2XH1.Z2XH1_DDJ, true) setRelayForce(signal2XH1.Z2XH1_DJ, false) } else if e.HasComponent(component.Signal3XH1ElectronicType) { // 3XH1信号机 signal3XH1 := component.Signal3XH1ElectronicType.Get(e) setRelayForce(signal3XH1.Z3XH1_DDJ, true) setRelayForce(signal3XH1.Z3XH1_DJ, false) setRelayForce(signal3XH1.Z3XH1_2DJ, false) setRelayForce(signal3XH1.Z3XH1_ZXJ, false) setRelayForce(signal3XH1.Z3XH1_LXJ, false) setRelayForce(signal3XH1.Z3XH1_YXJ, false) } else if e.HasComponent(component.Signal3XH2ElectronicType) { // 3XH2信号机 signal3XH2 := component.Signal3XH2ElectronicType.Get(e) setRelayForce(signal3XH2.Z3XH2_DDJ, true) setRelayForce(signal3XH2.Z3XH2_DJ, false) setRelayForce(signal3XH2.Z3XH2_2DJ, false) setRelayForce(signal3XH2.Z3XH2_LXJ, false) setRelayForce(signal3XH2.Z3XH2_YXJ, false) } else if e.HasComponent(component.Signal3XH3ElectronicType) { // 3XH3信号机 signal3XH3 := component.Signal3XH3ElectronicType.Get(e) setRelayForce(signal3XH3.Z3XH3_DDJ, true) setRelayForce(signal3XH3.Z3XH3_DJ, false) setRelayForce(signal3XH3.Z3XH3_2DJ, false) setRelayForce(signal3XH3.Z3XH3_LXJ, false) setRelayForce(signal3XH3.Z3XH3_YXJ, false) } else if e.HasComponent(component.Signal3XH4ElectronicType) { // 3XH4信号机 signal3XH4 := component.Signal3XH4ElectronicType.Get(e) setRelayForce(signal3XH4.Z3XH4_DDJ, true) setRelayForce(signal3XH4.Z3XH4_DJ, false) setRelayForce(signal3XH4.Z3XH4_LXJ, false) setRelayForce(signal3XH4.Z3XH4_ZXJ, false) } else { return fmt.Errorf("未知的信号机型号") } return nil } // 设置信号机强制红灯 func setSignalForceH(w ecs.World, e *ecs.Entry) error { if e.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机 signal2XH1 := component.Signal2XH1ElectronicType.Get(e) setRelayForce(signal2XH1.Z2XH1_LXJ, false) setRelayForce(signal2XH1.Z2XH1_DDJ, false) setRelayForce(signal2XH1.Z2XH1_DJ, true) } else if e.HasComponent(component.Signal3XH1ElectronicType) { // 3XH1信号机 signal3XH1 := component.Signal3XH1ElectronicType.Get(e) setRelayForce(signal3XH1.Z3XH1_DDJ, false) setRelayForce(signal3XH1.Z3XH1_DJ, true) setRelayForce(signal3XH1.Z3XH1_2DJ, false) setRelayForce(signal3XH1.Z3XH1_ZXJ, false) setRelayForce(signal3XH1.Z3XH1_LXJ, false) setRelayForce(signal3XH1.Z3XH1_YXJ, false) } else if e.HasComponent(component.Signal3XH2ElectronicType) { // 3XH2信号机 signal3XH2 := component.Signal3XH2ElectronicType.Get(e) setRelayForce(signal3XH2.Z3XH2_DDJ, false) setRelayForce(signal3XH2.Z3XH2_DJ, true) setRelayForce(signal3XH2.Z3XH2_2DJ, false) setRelayForce(signal3XH2.Z3XH2_LXJ, false) setRelayForce(signal3XH2.Z3XH2_YXJ, false) } else if e.HasComponent(component.Signal3XH3ElectronicType) { // 3XH3信号机 signal3XH3 := component.Signal3XH3ElectronicType.Get(e) setRelayForce(signal3XH3.Z3XH3_DDJ, false) setRelayForce(signal3XH3.Z3XH3_DJ, true) setRelayForce(signal3XH3.Z3XH3_2DJ, false) setRelayForce(signal3XH3.Z3XH3_LXJ, false) setRelayForce(signal3XH3.Z3XH3_YXJ, false) } else if e.HasComponent(component.Signal3XH4ElectronicType) { // 3XH4信号机 signal3XH4 := component.Signal3XH4ElectronicType.Get(e) setRelayForce(signal3XH4.Z3XH4_DDJ, false) setRelayForce(signal3XH4.Z3XH4_DJ, true) setRelayForce(signal3XH4.Z3XH4_LXJ, false) setRelayForce(signal3XH4.Z3XH4_ZXJ, false) } else { return fmt.Errorf("未知的信号机型号") } return nil } // 设置信号机强制绿灯 func setSignalForceL(w ecs.World, e *ecs.Entry) error { if e.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机 signal2XH1 := component.Signal2XH1ElectronicType.Get(e) setRelayForce(signal2XH1.Z2XH1_DDJ, false) setRelayForce(signal2XH1.Z2XH1_LXJ, true) setRelayForce(signal2XH1.Z2XH1_DJ, true) } else if e.HasComponent(component.Signal3XH1ElectronicType) { // 3XH1信号机 signal3XH1 := component.Signal3XH1ElectronicType.Get(e) setRelayForce(signal3XH1.Z3XH1_DDJ, false) setRelayForce(signal3XH1.Z3XH1_LXJ, true) setRelayForce(signal3XH1.Z3XH1_ZXJ, true) setRelayForce(signal3XH1.Z3XH1_DJ, true) setRelayForce(signal3XH1.Z3XH1_2DJ, false) setRelayForce(signal3XH1.Z3XH1_YXJ, false) } else if e.HasComponent(component.Signal3XH2ElectronicType) { // 3XH2信号机 signal3XH2 := component.Signal3XH2ElectronicType.Get(e) setRelayForce(signal3XH2.Z3XH2_DDJ, false) setRelayForce(signal3XH2.Z3XH2_LXJ, true) setRelayForce(signal3XH2.Z3XH2_DJ, true) setRelayForce(signal3XH2.Z3XH2_2DJ, false) setRelayForce(signal3XH2.Z3XH2_YXJ, false) } else if e.HasComponent(component.Signal3XH3ElectronicType) { // 3XH3信号机 return fmt.Errorf("信号机不支持点绿灯") } else if e.HasComponent(component.Signal3XH4ElectronicType) { // 3XH4信号机 signal3XH4 := component.Signal3XH4ElectronicType.Get(e) setRelayForce(signal3XH4.Z3XH4_DDJ, false) setRelayForce(signal3XH4.Z3XH4_LXJ, true) setRelayForce(signal3XH4.Z3XH4_ZXJ, true) setRelayForce(signal3XH4.Z3XH4_DJ, true) } else { return fmt.Errorf("未知的信号机型号") } return nil } // 设置信号机强制黄灯 func setSignalForceU(w ecs.World, e *ecs.Entry) error { if e.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机 return fmt.Errorf("信号机不支持点黄灯") } else if e.HasComponent(component.Signal3XH1ElectronicType) { // 3XH1信号机 signal3XH1 := component.Signal3XH1ElectronicType.Get(e) setRelayForce(signal3XH1.Z3XH1_DDJ, false) setRelayForce(signal3XH1.Z3XH1_LXJ, true) setRelayForce(signal3XH1.Z3XH1_ZXJ, false) setRelayForce(signal3XH1.Z3XH1_DJ, true) setRelayForce(signal3XH1.Z3XH1_2DJ, false) setRelayForce(signal3XH1.Z3XH1_YXJ, false) } else if e.HasComponent(component.Signal3XH2ElectronicType) { // 3XH2信号机 return fmt.Errorf("信号机不支持点黄灯") } else if e.HasComponent(component.Signal3XH3ElectronicType) { // 3XH3信号机 signal3XH3 := component.Signal3XH3ElectronicType.Get(e) setRelayForce(signal3XH3.Z3XH3_DDJ, false) setRelayForce(signal3XH3.Z3XH3_LXJ, true) setRelayForce(signal3XH3.Z3XH3_YXJ, false) setRelayForce(signal3XH3.Z3XH3_DJ, true) setRelayForce(signal3XH3.Z3XH3_2DJ, false) } else if e.HasComponent(component.Signal3XH4ElectronicType) { // 3XH4信号机 signal3XH4 := component.Signal3XH4ElectronicType.Get(e) setRelayForce(signal3XH4.Z3XH4_DDJ, false) setRelayForce(signal3XH4.Z3XH4_LXJ, true) setRelayForce(signal3XH4.Z3XH4_ZXJ, false) setRelayForce(signal3XH4.Z3XH4_DJ, true) } else { return fmt.Errorf("未知的信号机型号") } return nil } // 设置信号机强制黄红灯(引导信号) func setSignalForceHU(w ecs.World, e *ecs.Entry) error { if e.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机 return fmt.Errorf("信号机不支持点黄红灯") } return nil } func setSignalForceA(w ecs.World, e *ecs.Entry) error { if e.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机 return fmt.Errorf("信号机不支持点蓝灯") } return nil } func setSignalForceB(w ecs.World, e *ecs.Entry) error { if e.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机 return fmt.Errorf("信号机不支持点白灯") } return nil } // func ChangeSignalState(simulation *VerifySimulation, req *dto.SignalOperationReqDto) { // signalUid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.Signal{}) // signalModel, err := simulation.Repo.FindModel(signalUid, proto.DeviceType_DeviceType_Signal) // if err != nil { // panic(fmt.Sprintf("信号机[%s]模型不存在", signalUid)) // } // signalGroupCode := signalModel.(*repository.Signal).Code() // slog.Info("信号机操作", "uid", signalUid, "组合类型码", signalGroupCode) // switch req.Operation { // case request_proto.Signal_Display: //信号机显示信号设置 // { // switch signalGroupCode { // case consts.SIGNAL_2XH1: // changeSignal2XH1State(simulation.World, signalUid, req.Aspect) // case consts.SIGNAL_3XH1: // changeSignal3XH1State(simulation.World, signalUid, req.Aspect) // case consts.SIGNAL_3XH2: // changeSignal3XH2State(simulation.World, signalUid, req.Aspect) // case consts.SIGNAL_3XH3: // changeSignal3XH3State(simulation.World, signalUid, req.Aspect) // case consts.SIGNAL_3XH4: // changeSignal3XH4State(simulation.World, signalUid, req.Aspect) // case consts.SIGNAL_DCXH: // changeSignalDCXHState(simulation.World, signalUid, req.Aspect) // case consts.SIGNAL_JCKXH: // changeSignalJCKXHState(simulation.World, signalUid, req.Aspect) // default: // panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: fmt.Sprintf("操作[%s]的信号机,无法识别组合类型[%s]", signalUid, signalGroupCode)}) // } // } // case request_proto.Signal_LightHFaultDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_H, component_proto.Signal_DS, true) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightHCancelDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_H, component_proto.Signal_DS, false) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightLFaultDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_L, component_proto.Signal_DS, true) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightLCancelDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_L, component_proto.Signal_DS, false) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightUFaultDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_U, component_proto.Signal_DS, true) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightUCancelDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_U, component_proto.Signal_DS, false) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightAFaultDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_A, component_proto.Signal_DS, true) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightACancelDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_A, component_proto.Signal_DS, false) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightBFaultDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_B, component_proto.Signal_DS, true) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // case request_proto.Signal_LightBCancelDs: // { // e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_B, component_proto.Signal_DS, false) // if e != nil { // panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]}) // } // } // } // } // func changeSignalJCKXHState(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) { // switch toAspect { // case state_proto.Signal_U: // fi.DriveSignalJCKXHLx(w, signalUid) // case state_proto.Signal_B: // fi.DriveSignalJCKXHDx(w, signalUid) // case state_proto.Signal_H: // fi.DriveSignalJCKXHNon(w, signalUid) // default: // panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]}) // } // } // func changeSignalDCXHState(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) { // switch toAspect { // case state_proto.Signal_B: // fi.DriveSignalDCXHDx(w, signalUid) // case state_proto.Signal_A: // fi.DriveSignalDCXHNon(w, signalUid) // default: // panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]}) // } // } // func changeSignal3XH4State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) { // switch toAspect { // case state_proto.Signal_OFF: // fi.DriveSignal3XH4Dd(w, signalUid, false) // case state_proto.Signal_L: // fi.DriveSignal3XH4Dd(w, signalUid, true) // fi.DriveSignal3XH4Lx(w, signalUid, true) // case state_proto.Signal_U: // fi.DriveSignal3XH4Dd(w, signalUid, true) // fi.DriveSignal3XH4Lx(w, signalUid, false) // case state_proto.Signal_H: // fi.DriveSignal3XH4Dd(w, signalUid, true) // fi.DriveSignal3XH4Non(w, signalUid) // default: // panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]}) // } // } // func changeSignal3XH3State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) { // switch toAspect { // case state_proto.Signal_OFF: // fi.DriveSignal3XH3Dd(w, signalUid, false) // case state_proto.Signal_U: // fi.DriveSignal3XH3Dd(w, signalUid, true) // fi.DriveSignal3XH3Lx(w, signalUid) // case state_proto.Signal_HU: // fi.DriveSignal3XH3Dd(w, signalUid, true) // fi.DriveSignal3XH3Yx(w, signalUid) // case state_proto.Signal_H: // fi.DriveSignal3XH3Dd(w, signalUid, true) // fi.DriveSignal3XH3Non(w, signalUid) // default: // panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]}) // } // } // func changeSignal3XH2State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) { // switch toAspect { // case state_proto.Signal_OFF: // fi.DriveSignal3XH2Dd(w, signalUid, false) // case state_proto.Signal_L: // fi.DriveSignal3XH2Dd(w, signalUid, true) // fi.DriveSignal3XH2Lx(w, signalUid) // case state_proto.Signal_HU: // fi.DriveSignal3XH2Dd(w, signalUid, true) // fi.DriveSignal3XH2Yx(w, signalUid) // case state_proto.Signal_H: // fi.DriveSignal3XH2Dd(w, signalUid, true) // fi.DriveSignal3XH2Non(w, signalUid) // default: // panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]}) // } // } // func changeSignal3XH1State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) { // switch toAspect { // case state_proto.Signal_OFF: // fi.DriveSignal3XH1Dd(w, signalUid, false) // case state_proto.Signal_L: // fi.DriveSignal3XH1Dd(w, signalUid, true) // fi.DriveSignal3XH1Lx(w, signalUid, true) // case state_proto.Signal_U: // fi.DriveSignal3XH1Dd(w, signalUid, true) // fi.DriveSignal3XH1Lx(w, signalUid, false) // case state_proto.Signal_HU: // fi.DriveSignal3XH1Dd(w, signalUid, true) // fi.DriveSignal3XH1Yx(w, signalUid) // case state_proto.Signal_H: // fi.DriveSignal3XH1Dd(w, signalUid, true) // fi.DriveSignal3XH1Non(w, signalUid) // default: // panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]}) // } // } // func changeSignal2XH1State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) { // switch toAspect { // case state_proto.Signal_OFF: // fi.DriveSignal2XH1Dd(w, signalUid, false) // case state_proto.Signal_L: // fi.DriveSignal2XH1Dd(w, signalUid, true) // fi.DriveSignal2XH1Lx(w, signalUid) // case state_proto.Signal_H: // fi.DriveSignal2XH1Dd(w, signalUid, true) // fi.DriveSignal2XH1Non(w, signalUid) // default: // panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]}) // } // }