2023-10-13 14:41:55 +08:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-01-11 10:24:56 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
2023-10-26 17:16:07 +08:00
|
|
|
"log/slog"
|
|
|
|
|
2023-10-17 15:09:37 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
2024-01-11 10:24:56 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
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) {
|
2024-01-11 10:24:56 +08:00
|
|
|
signalUid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.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
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
func changeSignalJCKXHState(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) {
|
2023-10-13 14:41:55 +08:00
|
|
|
switch toAspect {
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_U:
|
2023-10-13 14:41:55 +08:00
|
|
|
fi.DriveSignalJCKXHLx(w, signalUid)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_B:
|
2023-10-13 14:41:55 +08:00
|
|
|
fi.DriveSignalJCKXHDx(w, signalUid)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_H:
|
2023-10-13 14:41:55 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
func changeSignalDCXHState(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) {
|
2023-10-13 14:41:55 +08:00
|
|
|
switch toAspect {
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_B:
|
2023-10-13 14:41:55 +08:00
|
|
|
fi.DriveSignalDCXHDx(w, signalUid)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_A:
|
2023-10-13 14:41:55 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
func changeSignal3XH4State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) {
|
2023-10-13 14:41:55 +08:00
|
|
|
switch toAspect {
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_OFF:
|
2023-10-13 14:41:55 +08:00
|
|
|
fi.DriveSignal3XH4Dd(w, signalUid, false)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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
|
|
|
}
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
func changeSignal3XH3State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) {
|
2023-10-13 14:41:55 +08:00
|
|
|
switch toAspect {
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_OFF:
|
2023-10-13 14:41:55 +08:00
|
|
|
fi.DriveSignal3XH3Dd(w, signalUid, false)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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
|
|
|
}
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
func changeSignal3XH2State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) {
|
2023-10-13 14:41:55 +08:00
|
|
|
switch toAspect {
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_OFF:
|
2023-10-13 14:41:55 +08:00
|
|
|
fi.DriveSignal3XH2Dd(w, signalUid, false)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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
|
|
|
}
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
func changeSignal3XH1State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) {
|
2023-10-13 14:41:55 +08:00
|
|
|
switch toAspect {
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_OFF:
|
2023-10-13 14:41:55 +08:00
|
|
|
fi.DriveSignal3XH1Dd(w, signalUid, false)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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
|
|
|
}
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
func changeSignal2XH1State(w ecs.World, signalUid string, toAspect state_proto.Signal_Aspect) {
|
2023-10-13 14:41:55 +08:00
|
|
|
switch toAspect {
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.Signal_OFF:
|
2023-10-13 14:41:55 +08:00
|
|
|
fi.DriveSignal2XH1Dd(w, signalUid, false)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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)
|
2024-01-11 10:24:56 +08:00
|
|
|
case state_proto.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
|
|
|
}
|
|
|
|
}
|