229 lines
8.9 KiB
Go
229 lines
8.9 KiB
Go
package memory
|
|
|
|
import (
|
|
"fmt"
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
|
"log/slog"
|
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component/component_proto"
|
|
"joylink.club/rtsssimulation/consts"
|
|
"joylink.club/rtsssimulation/fi"
|
|
"joylink.club/rtsssimulation/repository"
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
)
|
|
|
|
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]})
|
|
}
|
|
}
|