From 2a3ba5a2a7c337dcf8cb0b6227f9f30fe74915e0 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Thu, 23 Nov 2023 13:55:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=AD=94=E5=99=A8=E5=AE=9E=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository/repository.go | 4 +++- sys/bind.go | 2 ++ sys/device_sys/balise.go | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 sys/device_sys/balise.go diff --git a/repository/repository.go b/repository/repository.go index fec6674..f758aa7 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -236,7 +236,9 @@ func (repo *Repository) FindModel(deviceId string, deviceType proto.DeviceType) func (repo *Repository) FindLink(id string) *Link { return repo.linkMap[id] } - +func (repo *Repository) FindTransponder(id string) *Transponder { + return repo.responderMap[id] +} func (repo *Repository) FindTurnout(id string) *Turnout { return repo.turnoutMap[id] } diff --git a/sys/bind.go b/sys/bind.go index d0b2505..e88a83e 100644 --- a/sys/bind.go +++ b/sys/bind.go @@ -37,5 +37,7 @@ func BindSystem(w ecs.World) { //物理区段 device_sys.NewFaDcAxleDeviceSystem(), device_sys.NewSectionDetectSystem(), + //应答器 + device_sys.NewBaliseSystem(), ) } diff --git a/sys/device_sys/balise.go b/sys/device_sys/balise.go new file mode 100644 index 0000000..eee787d --- /dev/null +++ b/sys/device_sys/balise.go @@ -0,0 +1,41 @@ +package device_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" +) + +type BaliseSystem struct { + baliseQuery *ecs.Query +} + +func NewBaliseSystem() *BaliseSystem { + return &BaliseSystem{baliseQuery: ecs.NewQuery(filter.Contains(component.UidType, component.BaliseStateType))} +} +func (s *BaliseSystem) Update(w ecs.World) { + s.baliseQuery.Each(w, func(entry *ecs.Entry) { + baliseState := component.BaliseStateType.Get(entry) + baliseState.ValidTelegram = s.findValidTelegram(w, entry) + }) +} + +// 获取应答器有效报文 +func (s *BaliseSystem) findValidTelegram(w ecs.World, entry *ecs.Entry) []byte { + wd := entity.GetWorldData(w) + id := component.UidType.Get(entry).Id + if entry.HasComponent(component.BaliseFB) { + baliseModel := wd.Repo.FindTransponder(id) + return baliseModel.FixedTelegram() + } else if entry.HasComponent(component.BaliseDB) { + + } else if entry.HasComponent(component.BaliseIB) { + + } else if entry.HasComponent(component.BaliseVB) { + + } else if entry.HasComponent(component.BaliseWB) { + + } + return nil +}