diff --git a/api/simulation.go b/api/simulation.go index fad0103..f2d74c9 100644 --- a/api/simulation.go +++ b/api/simulation.go @@ -30,6 +30,7 @@ func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle authed.POST("/train/remove", removeTrain) authed.POST("/switch/operation", switchOperation) authed.GET("/getDataChannelName", getDataChannelName) + authed.POST("/relay/operation", relayOperation) // 初始化地图信息 initPublishMapInfo() @@ -265,6 +266,33 @@ func getDataChannelName(c *gin.Context) { c.JSON(http.StatusOK, config.SimulationId_prefix+apiproto.MemoryChangeServerSuffix) } +// 获取ATS测试-操作继电器 +// +// @Summary 获取ATS测试-操作继电器 +// +// @Security JwtAuth +// +// @Description ATS测试-操作继电器 +// @Tags ATS测试仿真Api +// @Accept json +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param RelayOperationReqDto body dto.RelayOperationReqDto true "ATS测试仿真-操作继电器" +// +// @Success 200 {object} string +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/simulation/relay/operation [post] +func relayOperation(c *gin.Context) { + req := &dto.RelayOperationReqDto{} + if err := c.ShouldBind(&req); err != nil { + panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + } + simulation := checkDeviceDataAndReturn(req.SimulationId) + zap.S().Info("传入状态参数", req) + memory.ChangeRelayState(simulation, req.MapId, req.Id, req.td) + c.JSON(http.StatusOK, "ok") +} + // 获取仿真设备数据并返回 func checkDeviceDataAndReturn(simId string) *memory.VerifySimulation { deviceMemory := simulation.FindSimulation(simId) diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_relay.go b/ats/verify/simulation/wayside/memory/wayside_memory_relay.go index 0cd73dd..e20f3a1 100644 --- a/ats/verify/simulation/wayside/memory/wayside_memory_relay.go +++ b/ats/verify/simulation/wayside/memory/wayside_memory_relay.go @@ -1,12 +1,28 @@ package memory import ( + "fmt" + "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/state" + "joylink.club/bj-rtsts-server/dto" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/entity" ) +// 继电器操作方法 +func ChangeRelayState(sim *VerifySimulation, mapId int32, id string, td bool) { + uid := QueryUidByMidAndComId(mapId, id, &graphicData.Relay{}) + entry, ok := entity.GetEntityByUid(sim.World, uid) + if !ok { + panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在【comId:%s】实体", mapId, uid)}) + } + if entry.HasComponent(component.RelayDriveType) { + relayDrive := component.RelayDriveType.Get(entry) + relayDrive.Td = td + } +} + // 获取仿真地图的继电器状态,前端推送 func GetMapAllRelayState(sim *VerifySimulation, mapId int32) []*state.ReplyState { // 获取本地图下的继电器信息 diff --git a/dto/simulation.go b/dto/simulation.go index 690a0eb..796589a 100644 --- a/dto/simulation.go +++ b/dto/simulation.go @@ -90,3 +90,10 @@ type SimulationInfoRspDto struct { ProjectId int32 `form:"projectId" json:"projectId"` } type SimulationInfoRspDtoArr []SimulationInfoRspDto + +type RelayOperationReqDto struct { + SimulationId string `form:"simulationId" json:"simulationId" binding:"required"` + MapId int32 `json:"mapId" from:"mapId" binding:"required"` + Id string `form:"id" json:"id" binding:"required"` + Td bool `form:"td" json:"td"` +}