From 88c54e23b82bae3342d12c849a9205929979b8f3 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 27 Sep 2023 16:49:10 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=A8=E5=8A=9B=E5=AD=A6link?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ats/verify/simulation/simulation_manage.go | 2 +- .../wayside/memory/wayside_memory_map.go | 128 +++++++++++++----- .../wayside/memory/wayside_simulation.go | 12 ++ rtss_simulation | 2 +- 4 files changed, 110 insertions(+), 34 deletions(-) diff --git a/ats/verify/simulation/simulation_manage.go b/ats/verify/simulation/simulation_manage.go index 88f7753..f40f9f2 100644 --- a/ats/verify/simulation/simulation_manage.go +++ b/ats/verify/simulation/simulation_manage.go @@ -166,7 +166,7 @@ func convert(info *dynamics.TrainInfo, sta *state.TrainState, simulation *memory zap.S().Debugf("原始消息:[%d-%d-%d]", info.Number, info.Link, info.LinkOffset) id, port, offset, runDirection, pointTo, kilometer := memory.QueryDeviceByCalcLink(simulation.Repo, strconv.Itoa(int(info.Link)), int64(info.LinkOffset), info.Up) zap.S().Debugf("转换后的消息:[%d-车头:%s-偏移:%d-上行:%v-是否ab:%v]", info.Number, id, offset, runDirection, pointTo) - sta.HeadDeviceId = id + sta.HeadDeviceId = strconv.Itoa(int(simulation.GetComIdByIndex(id))) sta.DevicePort = port sta.HeadOffset = offset sta.PointTo = pointTo diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_map.go b/ats/verify/simulation/wayside/memory/wayside_memory_map.go index dc91b9e..e4677c8 100644 --- a/ats/verify/simulation/wayside/memory/wayside_memory_map.go +++ b/ats/verify/simulation/wayside/memory/wayside_memory_map.go @@ -181,43 +181,107 @@ func QueryDeviceByCalcLink(repo *repository.Repository, id string, offset int64, if offset > link.Length() { panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("偏移【%d】超出link范围【%d】", offset, link.Length())}) } + // 判断是否在道岔上 + onTurnout, isA := isOnLinkTurnout(link, offset) + if onTurnout { + return ecsLinkMapToTurnout(isA, offset, up, link) + } else { + return ecsLinkMapToSection(offset, up, link) + } +} + +// 是否在link的道岔上 +func isOnLinkTurnout(link *repository.Link, offset int64) (bool, bool) { aTp := link.ARelation() + var turnoutOffset int64 + if aTp != nil { + turnoutOffset = aTp.Turnout().FindLinkPositionByPort(aTp.Port()).Offset() + } + if offset <= turnoutOffset { + return true, true + } bTp := link.BRelation() - aOffset := aTp.Turnout().FindLinkPositionByPort(aTp.Port()).Offset() - bOffset := bTp.Turnout().FindLinkPositionByPort(bTp.Port()).Offset() - if offset <= aOffset { - deviceId = aTp.Turnout().Id() - deviceOffset = aOffset - (aOffset - offset) - if up { - pointTo = false - } else { - pointTo = true - } - switch aTp.Port() { - case proto2.Port_A: - port = "A" - case proto2.Port_B: - port = "B" - case proto2.Port_C: - port = "C" - } - } else if offset >= bOffset { - deviceId = bTp.Turnout().Id() + if bTp != nil { + turnoutOffset = bTp.Turnout().FindLinkPositionByPort(bTp.Port()).Offset() + return offset >= turnoutOffset, false + } + return false, false +} + +// 处理在道岔上link映射 +func ecsLinkMapToTurnout(isA bool, offset int64, up bool, link *repository.Link) ( + deviceId, port string, deviceOffset int64, runDirection, pointTo bool, km int64) { + tp := link.ARelation() + if !isA { + tp = link.BRelation() + } + deviceId = tp.Turnout().Id() + tpOffset := tp.Turnout().FindLinkPositionByPort(tp.Port()).Offset() + crossKm, portKm := tp.Turnout().GetTurnoutKm(proto2.Port_None).Value, tp.Turnout().GetTurnoutKm(tp.Port()).Value + if isA { + deviceOffset = tpOffset - (tpOffset - offset) + pointTo = !up + } else { deviceOffset = link.Length() - offset - if up { - pointTo = true - } else { - pointTo = false - } - switch bTp.Port() { - case proto2.Port_A: - port = "A" - case proto2.Port_B: - port = "B" - case proto2.Port_C: - port = "C" + pointTo = up + } + // 查询公里标大于端口公里标 + if crossKm > portKm { + km = crossKm - deviceOffset + runDirection = pointTo + } else { + km = crossKm + deviceOffset + runDirection = !pointTo + } + switch tp.Port() { + case proto2.Port_A: + port = "A" + case proto2.Port_B: + port = "B" + case proto2.Port_C: + port = "C" + } + return +} + +// 处理在道岔上link映射 +func ecsLinkMapToSection(offset int64, up bool, link *repository.Link) ( + deviceId, port string, deviceOffset int64, runDirection, pointTo bool, km int64) { + var section *repository.PhysicalSection + for _, s := range link.PhysicalSections() { + ao, bo := s.ALinkPosition().Offset(), s.BLinkPosition().Offset() + if (ao <= offset && offset <= bo) || (bo <= offset && offset <= ao) { + section = s + break } } + if section == nil { + panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到link设备偏移【%d】", offset)}) + } + // 元素ID + deviceId = section.Id() + // link偏移变大方向 + ao, bo := section.ALinkPosition().Offset(), section.BLinkPosition().Offset() + ak, bk := section.AKilometer().Value, section.BKilometer().Value + if up { + pointTo = ao < bo + runDirection = ((ak < bk) == (ao < bo)) + } else { + pointTo = bo > ao + runDirection = ((ak > bk) == (ao > bo)) + } + // a点偏移 大于 b点偏移 + if ao > bo { + deviceOffset = ao - offset + } else { + deviceOffset = offset - ao + } + // a点公里标 大于 b点公里标 + if ak > bk { + km = ak - deviceOffset + } else { + km = ak + deviceOffset + } return } diff --git a/ats/verify/simulation/wayside/memory/wayside_simulation.go b/ats/verify/simulation/wayside/memory/wayside_simulation.go index 4f523fb..805619e 100644 --- a/ats/verify/simulation/wayside/memory/wayside_simulation.go +++ b/ats/verify/simulation/wayside/memory/wayside_simulation.go @@ -158,6 +158,18 @@ func (s *VerifySimulation) GetComIdByUid(uid string) string { return es[uid].CommonId } +// 获取仿真世界信息 +func (s *VerifySimulation) GetComIdByIndex(uid string) int32 { + es := s.uidMap + if es == nil { + panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无映射信息"}) + } + if es[uid] == nil { + panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无【uid】映射信息"}) + } + return es[uid].Index +} + func buildProtoRepository(mapIds []int32) (*proto.Repository, error) { repo := &proto.Repository{} var exceptStationGiMapIds []int32 diff --git a/rtss_simulation b/rtss_simulation index 5833de3..be88137 160000 --- a/rtss_simulation +++ b/rtss_simulation @@ -1 +1 @@ -Subproject commit 5833de36fbb1e153672aa1ddf049f7006eefca60 +Subproject commit be88137f2ab670707c7bd80f708ad1379c62f141