From 59520435d22234dfd58f0780b288932f4639d77b Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Thu, 16 May 2024 21:19:53 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=E5=8C=BA=E6=AE=B5=E3=80=81?= =?UTF-8?q?Link=E3=80=81=E8=BF=90=E8=90=A5=E6=96=B9=E5=90=91/=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E4=B9=8B=E9=97=B4=E4=BA=92=E7=9B=B8=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rts-sim-module | 2 +- rts-sim-testing-message | 2 +- .../memory/wayside_memory_dir_transfer.go | 101 ++++++++++++++++++ .../wayside/memory/wayside_memory_map.go | 6 +- .../wayside/memory/wayside_memory_train.go | 2 +- 5 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 ts/simulation/wayside/memory/wayside_memory_dir_transfer.go diff --git a/rts-sim-module b/rts-sim-module index 90003ec..a613ac1 160000 --- a/rts-sim-module +++ b/rts-sim-module @@ -1 +1 @@ -Subproject commit 90003ec9429c7db26c43dd381277800d0dfd35fa +Subproject commit a613ac109bd53528c867975d5fc6493c00d99fc2 diff --git a/rts-sim-testing-message b/rts-sim-testing-message index e4c55ea..6d3ff56 160000 --- a/rts-sim-testing-message +++ b/rts-sim-testing-message @@ -1 +1 @@ -Subproject commit e4c55ea4b6f9f5f875d59fc5bba51fc21bc8ef97 +Subproject commit 6d3ff5644ebaad3ed1e7e6c03fcfb0f9a3427af0 diff --git a/ts/simulation/wayside/memory/wayside_memory_dir_transfer.go b/ts/simulation/wayside/memory/wayside_memory_dir_transfer.go new file mode 100644 index 0000000..49a68a1 --- /dev/null +++ b/ts/simulation/wayside/memory/wayside_memory_dir_transfer.go @@ -0,0 +1,101 @@ +package memory + +import ( + "errors" + "fmt" + "joylink.club/rtsssimulation/repository" + "joylink.club/rtsssimulation/util/number" +) + +// LinkRadialToSectionRadialAndOperationDir Link射线转区段射线+运营方向 +func LinkRadialToSectionRadialAndOperationDir(repo *repository.Repository, linkPosition *repository.LinkPosition, toBig bool) (sr *SectionRadial, up bool, err error) { + link := linkPosition.Link() + offset := linkPosition.Offset() + if offset > link.Length() { + return nil, false, errors.New(fmt.Sprintf("%d超出%s范围", offset, linkPosition.String())) + } + for _, section := range link.GetAllPhysicalSection() { + for _, linkRange := range section.LinkRanges() { + if linkRange.Link() != link { + continue + } + if linkRange.Start() < offset && offset < linkRange.End() { + sectionOffset := number.Abs(offset - section.ALinkPosition().Offset()) + toB := toBig && section.BLinkPosition().Offset() > section.ALinkPosition().Offset() + sr = &SectionRadial{ + Section: section, + Offset: sectionOffset, + ToB: toB, + } + break + } + } + } + if sr == nil { + return nil, false, errors.New(fmt.Sprintf("%s未找到对应的区段", linkPosition.String())) + } + aKm := convertRepoBaseKm(repo, sr.Section.AKilometer()) + bKm := convertRepoBaseKm(repo, sr.Section.BKilometer()) + up = sr.ToB && bKm.Value > aKm.Value + err = nil + return +} + +// SectionRadialToLinkRadial 区段射线转Link射线 +func SectionRadialToLinkRadial(sectionRadial *SectionRadial) (linkPosition *repository.LinkPosition, toBig bool) { + toBig = SectionDirToLinkDir(sectionRadial.Section, sectionRadial.ToB) + var offset int64 + if sectionRadial.ToB == toBig { //section与link偏移变化趋势相同 + offset = sectionRadial.Section.ALinkPosition().Offset() + sectionRadial.Offset + } else { + offset = sectionRadial.Section.BLinkPosition().Offset() - sectionRadial.Offset + } + linkPosition = repository.NewLinkPosition(sectionRadial.Section.ALinkPosition().Link(), offset) + return +} + +// OperationRadialToLinkRadial 运营射线转Link射线 +func OperationRadialToLinkRadial(repo *repository.Repository, section *repository.PhysicalSection, offset int64, up bool) (linkPosition *repository.LinkPosition, toBig bool) { + toB := OperationDirToSectionDir(repo, section, up) + return SectionRadialToLinkRadial(&SectionRadial{ + Section: section, + Offset: offset, + ToB: toB, + }) +} + +// SectionDirToLinkDir 区段方向转Link方向 +func SectionDirToLinkDir(section *repository.PhysicalSection, toB bool) (toBig bool) { + aOffset := section.ALinkPosition().Offset() + bOffset := section.BLinkPosition().Offset() + toBig = toB && bOffset > aOffset + return +} + +// SectionDirToOperationDir 区段方向转运营方向 +func SectionDirToOperationDir(repo *repository.Repository, section *repository.PhysicalSection, toB bool) (up bool) { + aKm := convertRepoBaseKm(repo, section.AKilometer()) + bKm := convertRepoBaseKm(repo, section.BKilometer()) + return toB && bKm.Value > aKm.Value +} + +// OperationDirToSectionDir 运营方向转区段方向 +func OperationDirToSectionDir(repo *repository.Repository, section *repository.PhysicalSection, up bool) (toB bool) { + aKm := convertRepoBaseKm(repo, section.AKilometer()) + bKm := convertRepoBaseKm(repo, section.BKilometer()) + return up && bKm.Value > aKm.Value +} + +// OperationDirToLinkDir 运营方向转Link方向 +func OperationDirToLinkDir(repo *repository.Repository, section *repository.PhysicalSection, up bool) (toBig bool) { + toB := OperationDirToSectionDir(repo, section, up) + return SectionDirToLinkDir(section, toB) +} + +// SectionRadial 区段射线。包含一个区段位置+方向 +// 加这个结构体只是因为上面函数返回值过多 +type SectionRadial struct { + Section *repository.PhysicalSection + Offset int64 + ToB bool +} diff --git a/ts/simulation/wayside/memory/wayside_memory_map.go b/ts/simulation/wayside/memory/wayside_memory_map.go index 079c483..84032ef 100644 --- a/ts/simulation/wayside/memory/wayside_memory_map.go +++ b/ts/simulation/wayside/memory/wayside_memory_map.go @@ -243,7 +243,7 @@ func findCalcLinkIdAndOffset(sim *VerifySimulation, link *repository.Link, offse } // 没有找到连接信息,说明已经到尽头找不到位置 if nextLink == nil { - err = sys_error.New(fmt.Sprintf("未找到对应的link信息, linkId=%s, offset=%d", link.Id(), offset)) + err = sys_error.New(fmt.Sprintf("未找到对应的link信息, linkId=%s, Offset=%d", link.Id(), offset)) return } // 下个link偏移 @@ -297,7 +297,7 @@ func getTurnoutNextPort(sim *VerifySimulation, turnoutId string, port string) (n return } -// 计算link offset 在道岔上的位置 +// 计算link Offset 在道岔上的位置 // 入参:仿真Repository、link、是否从A端开始、link偏移量、link运行方向 // 输出:设备Id、设备所在端口、设备偏移量、公里标信息(地图主坐标系) func calcTurnoutOffset(repo *repository.Repository, link *repository.Link, isA bool, offset int64, up bool) ( @@ -328,7 +328,7 @@ func calcTurnoutOffset(repo *repository.Repository, link *repository.Link, isA b return } -// 计算link offset 在区段上的位置 +// 计算link Offset 在区段上的位置 // 入参:仿真Repository、link、link偏移量、link运行方向 // 输出:设备Id、设备所在端口、设备偏移量、公里标信息(地图主坐标系) func calcSectionOffset(repo *repository.Repository, link *repository.Link, offset int64, up bool) ( diff --git a/ts/simulation/wayside/memory/wayside_memory_train.go b/ts/simulation/wayside/memory/wayside_memory_train.go index a72e1f8..2d5a55e 100644 --- a/ts/simulation/wayside/memory/wayside_memory_train.go +++ b/ts/simulation/wayside/memory/wayside_memory_train.go @@ -301,7 +301,7 @@ func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *mess panic(sys_error.New("动力学传输数据:列车车头位置计算出错", e1)) } runDirection, pointTo := QueryDirectionAndABByDevice(vs.Repo, id, port, info.Up) - //slog.Debug("处理动力学转换后的消息", "number", info.Number, "Link", info.Link, "车头位置", id, "偏移", offset, "是否上行", runDirection, "是否ab", pointTo) + //slog.Debug("处理动力学转换后的消息", "number", info.Number, "Link", info.Link, "车头位置", id, "偏移", Offset, "是否上行", runDirection, "是否ab", pointTo) // 车尾相对车头link的偏移量 calctailOffset := calcTrailTailOffset(outLinkOffset, int64(info.Len), info.Up) tailLinkId, tailDeviceId, tailDevicePort, tailLinkOffset, tailOffset, _, e2 := CalcInitializeLink(vs, outLinkId, calctailOffset, !info.Up)