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 +}