From ee7492c5807fda8a19545078ccf1b4fbbecbb21c Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 22 Nov 2023 16:35:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BD=A6=E5=BA=94=E7=AD=94=E5=99=A8?= =?UTF-8?q?=E5=A4=A9=E7=BA=BF=E6=8E=A2=E6=B5=8B=E8=BD=A8=E6=97=81=E5=BA=94?= =?UTF-8?q?=E7=AD=94=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository/transponder.go | 15 +++--- sys/device_sys/balise_detection.go | 84 +++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 7 deletions(-) diff --git a/repository/transponder.go b/repository/transponder.go index ec6a3eb..e08f746 100644 --- a/repository/transponder.go +++ b/repository/transponder.go @@ -24,10 +24,13 @@ func (t *Transponder) bindLinkPosition(position *LinkPosition) { t.linkPosition = position } -//func (r *Transponder) bindSection(section *PhysicalSection) { -// r.section = section -//} +// func (r *Transponder) bindSection(section *PhysicalSection) { +// r.section = section +// } // -//func (r *Transponder) bindTurnoutPort(turnoutPort TurnoutPort) { -// r.turnoutPort = turnoutPort -//} +// func (r *Transponder) bindTurnoutPort(turnoutPort TurnoutPort) { +// r.turnoutPort = turnoutPort +// } +func (t *Transponder) LinkPosition() *LinkPosition { + return t.linkPosition +} diff --git a/sys/device_sys/balise_detection.go b/sys/device_sys/balise_detection.go index 6ed2245..16d19c6 100644 --- a/sys/device_sys/balise_detection.go +++ b/sys/device_sys/balise_detection.go @@ -1,3 +1,85 @@ package device_sys -//列车应答器天线探测轨旁应答器 +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" + "joylink.club/rtsssimulation/repository" +) + +// BaliseDetectSystem 列车应答器天线探测轨旁应答器 +type BaliseDetectSystem struct { + trainQuery *ecs.Query +} + +func NewBaliseDetectSystem() *BaliseDetectSystem { + return &BaliseDetectSystem{ + trainQuery: ecs.NewQuery(filter.Contains(component.UidType, component.TrainPositionInfoType)), + } +} +func (s *BaliseDetectSystem) Update(w ecs.World) { + wd := entity.GetWorldData(w) + balises := wd.Repo.ResponderList() + //所有列车 + //列车速度80KM/H时,222mm/10ms + s.trainQuery.Each(w, func(entry *ecs.Entry) { + tp := component.TrainPositionInfoType.Get(entry) + detectedBalise := s.detect(wd, tp, balises) + if detectedBalise != nil { //列车应答器天线扫描到应答器,获取应答器报文发送给BTM + + } + }) +} +func (s *BaliseDetectSystem) detect(wd *component.WorldData, tp *component.TrainPositionInfo, balises []*repository.Transponder) *repository.Transponder { + scanRange := s.calculateScanRange(wd, tp) + for _, balise := range balises { + if scanRange.contains(balise.LinkPosition()) { + return balise + } + } + return nil +} + +const scanWidth = int64(1000) //1000mm +// 计算车载应答器天线扫描范围,如果应答器在此范围内则天线可以接收到应答器报文 +func (s *BaliseDetectSystem) calculateScanRange(wd *component.WorldData, tp *component.TrainPositionInfo) *scanRange { + headLink := wd.Repo.FindLink(tp.HeadLink) + if tp.Up { //列车运行方向a->b + if tp.HeadLinkOffset >= scanWidth { + return newScanRange(headLink.Id(), tp.HeadLinkOffset-scanWidth, tp.HeadLinkOffset) + } else { + return newScanRange(headLink.Id(), 0, tp.HeadLinkOffset) + } + } else { //列车运行方向b->a + if headLink.Length()-tp.HeadLinkOffset >= scanWidth { + return newScanRange(headLink.Id(), tp.HeadLinkOffset, tp.HeadLinkOffset+scanWidth) + } else { + return newScanRange(headLink.Id(), tp.HeadLinkOffset, headLink.Length()) + } + } +} + +type scanRange struct { + linkId string + startOffset int64 + endOffset int64 +} + +func newScanRange(linkId string, start int64, end int64) *scanRange { + return &scanRange{linkId: linkId, startOffset: start, endOffset: end} +} +func (s *scanRange) format() { + if s.startOffset > s.endOffset { + s.startOffset, s.endOffset = s.endOffset, s.startOffset + } +} + +// true-应答器balisePosition在该scanRange内 +func (s *scanRange) contains(balisePosition *repository.LinkPosition) bool { + if s.linkId != balisePosition.Link().Id() { + return false + } + s.format() + return balisePosition.Offset() >= s.startOffset && balisePosition.Offset() <= s.endOffset +}