【继电器操作接口】

This commit is contained in:
weizhihong 2023-10-07 17:48:39 +08:00
parent dd3a17fdd4
commit 5283348f5e
3 changed files with 51 additions and 0 deletions

View File

@ -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)

View File

@ -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 {
// 获取本地图下的继电器信息

View File

@ -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"`
}