rts-sim-testing-service/ts/simulation/wayside/memory/wayside_memory_signal.go

229 lines
8.8 KiB
Go
Raw Normal View History

2023-10-13 14:41:55 +08:00
package memory
import (
"fmt"
2023-10-26 17:16:07 +08:00
"log/slog"
2023-10-17 15:09:37 +08:00
"joylink.club/bj-rtsts-server/dto"
2023-10-19 15:08:43 +08:00
"joylink.club/bj-rtsts-server/dto/request_proto"
2023-10-26 17:16:07 +08:00
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/protos/state"
2023-10-13 14:41:55 +08:00
"joylink.club/ecs"
2023-10-19 15:08:43 +08:00
"joylink.club/rtsssimulation/component/component_proto"
2023-10-13 14:41:55 +08:00
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/fi"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto"
)
2023-10-19 15:08:43 +08:00
func ChangeSignalState(simulation *VerifySimulation, req *dto.SignalOperationReqDto) {
signalUid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Signal{})
2023-10-13 14:41:55 +08:00
signalModel, err := simulation.Repo.FindModel(signalUid, proto.DeviceType_DeviceType_Signal)
if err != nil {
panic(fmt.Sprintf("信号机[%s]模型不存在", signalUid))
}
signalGroupCode := signalModel.(*repository.Signal).Code()
2023-10-17 17:39:05 +08:00
slog.Info("信号机操作", "uid", signalUid, "组合类型码", signalGroupCode)
2023-10-19 15:08:43 +08:00
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 {
2023-10-19 15:27:35 +08:00
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]})
2023-10-19 15:08:43 +08:00
}
}
2023-10-13 14:41:55 +08:00
}
2023-10-19 15:08:43 +08:00
2023-10-13 14:41:55 +08:00
}
func changeSignalJCKXHState(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
switch toAspect {
case state.Signal_U:
fi.DriveSignalJCKXHLx(w, signalUid)
case state.Signal_B:
fi.DriveSignalJCKXHDx(w, signalUid)
case state.Signal_H:
fi.DriveSignalJCKXHNon(w, signalUid)
2023-10-17 10:16:11 +08:00
default:
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
2023-10-13 14:41:55 +08:00
}
}
func changeSignalDCXHState(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
switch toAspect {
case state.Signal_B:
fi.DriveSignalDCXHDx(w, signalUid)
case state.Signal_A:
fi.DriveSignalDCXHNon(w, signalUid)
2023-10-17 10:16:11 +08:00
default:
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
2023-10-13 14:41:55 +08:00
}
}
func changeSignal3XH4State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
switch toAspect {
case state.Signal_OFF:
fi.DriveSignal3XH4Dd(w, signalUid, false)
case state.Signal_L:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH4Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH4Lx(w, signalUid, true)
case state.Signal_U:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH4Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH4Lx(w, signalUid, false)
case state.Signal_H:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH4Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH4Non(w, signalUid)
2023-10-17 10:16:11 +08:00
default:
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
2023-10-13 14:41:55 +08:00
}
}
func changeSignal3XH3State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
switch toAspect {
case state.Signal_OFF:
fi.DriveSignal3XH3Dd(w, signalUid, false)
case state.Signal_U:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH3Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH3Lx(w, signalUid)
case state.Signal_HU:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH3Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH3Yx(w, signalUid)
case state.Signal_H:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH3Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH3Non(w, signalUid)
2023-10-17 10:16:11 +08:00
default:
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
2023-10-13 14:41:55 +08:00
}
}
func changeSignal3XH2State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
switch toAspect {
case state.Signal_OFF:
fi.DriveSignal3XH2Dd(w, signalUid, false)
case state.Signal_L:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH2Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH2Lx(w, signalUid)
case state.Signal_HU:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH2Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH2Yx(w, signalUid)
case state.Signal_H:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH2Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH2Non(w, signalUid)
2023-10-17 10:16:11 +08:00
default:
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
2023-10-13 14:41:55 +08:00
}
}
func changeSignal3XH1State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
switch toAspect {
case state.Signal_OFF:
fi.DriveSignal3XH1Dd(w, signalUid, false)
case state.Signal_L:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH1Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH1Lx(w, signalUid, true)
case state.Signal_U:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH1Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH1Lx(w, signalUid, false)
case state.Signal_HU:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH1Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH1Yx(w, signalUid)
case state.Signal_H:
2023-10-17 09:44:31 +08:00
fi.DriveSignal3XH1Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal3XH1Non(w, signalUid)
2023-10-17 10:16:11 +08:00
default:
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
2023-10-13 14:41:55 +08:00
}
}
func changeSignal2XH1State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
switch toAspect {
case state.Signal_OFF:
fi.DriveSignal2XH1Dd(w, signalUid, false)
case state.Signal_L:
2023-10-17 09:23:40 +08:00
fi.DriveSignal2XH1Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal2XH1Lx(w, signalUid)
case state.Signal_H:
2023-10-17 09:23:40 +08:00
fi.DriveSignal2XH1Dd(w, signalUid, true)
2023-10-13 14:41:55 +08:00
fi.DriveSignal2XH1Non(w, signalUid)
2023-10-17 09:23:40 +08:00
default:
2023-10-17 10:16:11 +08:00
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
2023-10-13 14:41:55 +08:00
}
}