diff --git a/api/simulation.go b/api/simulation.go index 214cfda..3d7c978 100644 --- a/api/simulation.go +++ b/api/simulation.go @@ -183,7 +183,7 @@ func addTrain(c *gin.Context) { RunDirection: req.RunDirection, TrainLength: req.TrainLength, } - memory.AddTrainState(simulation, rsp) + memory.AddTrainState(simulation, rsp, req.MapId) c.JSON(http.StatusOK, &rsp) } diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_train.go b/ats/verify/simulation/wayside/memory/wayside_memory_train.go index b51d251..befe8d2 100644 --- a/ats/verify/simulation/wayside/memory/wayside_memory_train.go +++ b/ats/verify/simulation/wayside/memory/wayside_memory_train.go @@ -24,7 +24,7 @@ var UdpUpdateTime = struct { }{} // 增加列车状态 -func AddTrainState(vs *VerifySimulation, status *state.TrainState) { +func AddTrainState(vs *VerifySimulation, status *state.TrainState, mapId int32) { allTrainMap := &vs.Memory.Status.TrainStateMap _, ok := allTrainMap.Load(status.Id) if ok { @@ -34,17 +34,6 @@ func AddTrainState(vs *VerifySimulation, status *state.TrainState) { status.Show = true //向动力学发送初始化请求 trainIndex, _ := strconv.ParseUint(status.Id, 10, 16) - var mapId int32 - for _, m := range vs.MapIds { - vm := QueryMapVerifyStructure(m) - if vm.PhysicalSectionModelMap[status.HeadDeviceId] != nil || vm.SwitchDeviceModelMap[status.HeadDeviceId] != nil { - mapId = m - break - } - } - if mapId == 0 { - panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在设备【index:%s】", status.HeadDeviceId)}) - } // 映射link、偏移量、运行方向 linkId, loffset, up, pointTo, kilometer := QueryMapCalcLinkByDeviceInfo(mapId, status.HeadDeviceId, status.DevicePort, status.HeadOffset, status.RunDirection) status.Up = up diff --git a/ats/verify/simulation/wayside/memory/wayside_simulation.go b/ats/verify/simulation/wayside/memory/wayside_simulation.go index d68f2a6..efac6d9 100644 --- a/ats/verify/simulation/wayside/memory/wayside_simulation.go +++ b/ats/verify/simulation/wayside/memory/wayside_simulation.go @@ -106,6 +106,7 @@ func buildProtoRepository(storages []*graphicData.RtssGraphicStorage, mapIds []i func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphicStorage, mapId int32) { axleCountingMap := make(map[string]*graphicData.AxleCounting) + uidsMap := getMapElementIdMap(mapId) for _, data := range storage.AxleCountings { axleCountingMap[data.Common.Id] = data cpType := proto.CheckPointType_AxleCounter @@ -113,12 +114,12 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi cpType = proto.CheckPointType_Boundary } cp := &proto.CheckPoint{ - Id: GetDeviceUidByCommonId(mapId, data.Common.Id, data), + Id: data.Common.Id, Km: convertKm(data.KilometerSystem), Type: cpType, DevicePorts: convertDevicePorts(data.AxleCountingRef), } - repo.CheckPoints = append(repo.CheckPoints, cp) + repo.CheckPoints = append(repo.CheckPoints, converCheckPointUid(cp, uidsMap)) } for _, data := range storage.Section { var turnoutIds []string @@ -126,12 +127,12 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi turnoutIds = findTurnoutIds(axleCountingMap, data.AxleCountings) } physicalSection := &proto.PhysicalSection{ - Id: GetDeviceUidByCommonId(mapId, data.Common.Id, data), + Id: data.Common.Id, ADevicePort: convertDevicePort(data.PaRef), BDevicePort: convertDevicePort(data.PbRef), TurnoutIds: turnoutIds, } - repo.PhysicalSections = append(repo.PhysicalSections, physicalSection) + repo.PhysicalSections = append(repo.PhysicalSections, converSectionUid(physicalSection, uidsMap)) } for _, data := range storage.Turnouts { var km *proto.Kilometer @@ -143,13 +144,13 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi } repo.KilometerConverts = append(repo.KilometerConverts, buildKmConverts(data.KilometerSystem)...) turnout := &proto.Turnout{ - Id: GetDeviceUidByCommonId(mapId, data.Common.Id, data), + Id: data.Common.Id, Km: km, ADevicePort: convertDevicePort(data.PaRef), BDevicePort: convertDevicePort(data.PbRef), CDevicePort: convertDevicePort(data.PcRef), } - repo.Turnouts = append(repo.Turnouts, turnout) + repo.Turnouts = append(repo.Turnouts, converTurnoutUid(turnout, uidsMap)) } for _, data := range storage.Signals { var sectionId string @@ -161,12 +162,12 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi turnoutPort = convertDevicePort(data.RefDev) } signal := &proto.Signal{ - Id: GetDeviceUidByCommonId(mapId, data.Common.Id, data), + Id: data.Common.Id, Km: convertKm(data.KilometerSystem), SectionId: sectionId, TurnoutPort: turnoutPort, } - repo.Signals = append(repo.Signals, signal) + repo.Signals = append(repo.Signals, converSignalUid(signal, uidsMap)) } for _, data := range storage.Transponders { var sectionId string @@ -178,12 +179,12 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi turnoutPort = convertDevicePort(data.TransponderRef) } responder := &proto.Transponder{ - Id: GetDeviceUidByCommonId(mapId, data.Common.Id, data), + Id: data.Common.Id, Km: convertKm(data.KilometerSystem), SectionId: sectionId, TurnoutPort: turnoutPort, } - repo.Transponders = append(repo.Transponders, responder) + repo.Transponders = append(repo.Transponders, converTransponderUid(responder, uidsMap)) } slopeKsMap := make(map[string]*graphicData.SlopeKiloMarker) for _, data := range storage.SlopeKiloMarker { @@ -201,11 +202,11 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi kms = append(kms, convertKm(slopeKsMap[id].KilometerSystem[0])) } slope := &proto.Slope{ - Id: GetDeviceUidByCommonId(mapId, data.Common.Id, data), + Id: data.Common.Id, Kms: kms, Degree: data.SlopeNumber, } - repo.Slopes = append(repo.Slopes, slope) + repo.Slopes = append(repo.Slopes, converSlopeUid(slope, uidsMap)) } for _, data := range storage.Curvatures { var kms []*proto.Kilometer @@ -213,14 +214,107 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi kms = append(kms, convertKm(curveKsMap[id].KilometerSystem[0])) } slope := &proto.SectionalCurvature{ - Id: GetDeviceUidByCommonId(mapId, data.Common.Id, data), + Id: data.Common.Id, Kms: kms, Radius: data.CurvatureNumber, } - repo.SectionalCurvatures = append(repo.SectionalCurvatures, slope) + repo.SectionalCurvatures = append(repo.SectionalCurvatures, converCurvatureUid(slope, uidsMap)) } } +func converCheckPointUid(data *proto.CheckPoint, uidsMap *GraphicMapElementIdStructure) *proto.CheckPoint { + data.Id = uidsMap.AxlePointIds[data.Id].Uid + for _, c := range data.DevicePorts { + c.DeviceId = converRefUid(c.DeviceId, c.DeviceType, uidsMap) + } + return data +} + +func converSectionUid(data *proto.PhysicalSection, uidsMap *GraphicMapElementIdStructure) *proto.PhysicalSection { + data.Id = uidsMap.PhysicalSectionIds[data.Id].Uid + if data.ADevicePort != nil { + data.ADevicePort.DeviceId = converRefUid(data.ADevicePort.DeviceId, data.ADevicePort.DeviceType, uidsMap) + } + if data.BDevicePort != nil { + data.BDevicePort.DeviceId = converRefUid(data.BDevicePort.DeviceId, data.BDevicePort.DeviceType, uidsMap) + } + tids := make([]string, len(data.TurnoutIds)) + for i, tid := range data.TurnoutIds { + tids[i] = converRefUid(tid, proto.DeviceType_DeviceType_Turnout, uidsMap) + } + data.TurnoutIds = tids + return data +} + +func converTurnoutUid(data *proto.Turnout, uidsMap *GraphicMapElementIdStructure) *proto.Turnout { + data.Id = uidsMap.TurnoutIds[data.Id].Uid + if data.ADevicePort != nil { + data.ADevicePort.DeviceId = converRefUid(data.ADevicePort.DeviceId, data.ADevicePort.DeviceType, uidsMap) + } + if data.BDevicePort != nil { + data.BDevicePort.DeviceId = converRefUid(data.BDevicePort.DeviceId, data.BDevicePort.DeviceType, uidsMap) + } + if data.CDevicePort != nil { + data.CDevicePort.DeviceId = converRefUid(data.CDevicePort.DeviceId, data.CDevicePort.DeviceType, uidsMap) + } + return data +} + +func converSignalUid(data *proto.Signal, uidsMap *GraphicMapElementIdStructure) *proto.Signal { + data.Id = uidsMap.SignalIds[data.Id].Uid + if data.SectionId != "" { + data.SectionId = converRefUid(data.SectionId, proto.DeviceType_DeviceType_PhysicalSection, uidsMap) + } + if data.TurnoutPort != nil { + data.TurnoutPort.DeviceId = converRefUid(data.TurnoutPort.DeviceId, data.TurnoutPort.DeviceType, uidsMap) + } + return data +} + +func converTransponderUid(data *proto.Transponder, uidsMap *GraphicMapElementIdStructure) *proto.Transponder { + data.Id = uidsMap.TransponderIds[data.Id].Uid + if data.SectionId != "" { + data.SectionId = converRefUid(data.SectionId, proto.DeviceType_DeviceType_PhysicalSection, uidsMap) + } + if data.TurnoutPort != nil { + data.TurnoutPort.DeviceId = converRefUid(data.TurnoutPort.DeviceId, data.TurnoutPort.DeviceType, uidsMap) + } + return data +} + +func converSlopeUid(data *proto.Slope, uidsMap *GraphicMapElementIdStructure) *proto.Slope { + data.Id = uidsMap.SlopeIds[data.Id].Uid + return data +} + +func converCurvatureUid(data *proto.SectionalCurvature, uidsMap *GraphicMapElementIdStructure) *proto.SectionalCurvature { + data.Id = uidsMap.CurvatureIds[data.Id].Uid + return data +} + +func converRefUid(id string, d proto.DeviceType, uidsMap *GraphicMapElementIdStructure) string { + var elementId *ElementIdStructure + switch d { + case proto.DeviceType_DeviceType_CheckPoint: + elementId = uidsMap.AxlePointIds[id] + case proto.DeviceType_DeviceType_PhysicalSection: + elementId = uidsMap.PhysicalSectionIds[id] + case proto.DeviceType_DeviceType_SectionalCurvature: + elementId = uidsMap.CurvatureIds[id] + case proto.DeviceType_DeviceType_Signal: + elementId = uidsMap.SignalIds[id] + case proto.DeviceType_DeviceType_Slope: + elementId = uidsMap.SlopeIds[id] + case proto.DeviceType_DeviceType_Transponder: + elementId = uidsMap.TransponderIds[id] + case proto.DeviceType_DeviceType_Turnout: + elementId = uidsMap.TurnoutIds[id] + default: + panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "异常的设备类型-" + d.String()}) + } + return elementId.Uid +} + func convertKm(ks *graphicData.KilometerSystem) *proto.Kilometer { var dir proto.Direction switch ks.Direction {