package device_sys import ( "log/slog" "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/entity" ) // FaDcAxleDeviceSystem FaDc计轴设备管理器系统 type FaDcAxleDeviceSystem struct { query *ecs.Query } func NewFaDcAxleDeviceSystem() *FaDcAxleDeviceSystem { return &FaDcAxleDeviceSystem{ query: ecs.NewQuery(filter.Contains(component.AxleManageDeviceType)), } } func (s *FaDcAxleDeviceSystem) Update(w ecs.World) { data := entity.GetWorldData(w) s.query.Each(w, func(entry *ecs.Entry) { faDcDevice := component.AxleManageDeviceType.Get(entry) for axleSectionId, axleRuntime := range faDcDevice.Adrs { axleSectionEntry := data.EntityMap[axleSectionId] sectionState := component.PhysicalSectionStateType.Get(axleSectionEntry) axleDevice := component.AxlePhysicalSectionType.Get(axleSectionEntry) // sectionFault := axleSectionEntry.HasComponent(component.AxleSectionFaultTag) s.calculateHf(sectionFault, axleSectionEntry, sectionState, axleDevice, axleRuntime) s.calculateDrst(axleSectionEntry, sectionState, axleDevice, axleRuntime) s.calculatePdrst(axleSectionEntry, sectionState, axleDevice, axleRuntime) s.calculateSectionState(sectionFault, sectionState, axleDevice, axleRuntime) if "北京_12_酒仙桥_15G" == axleSectionId && false { sectionFault := axleSectionEntry.HasComponent(component.AxleSectionFaultTag) slog.Info(axleSectionId, "Drst", axleRuntime.Drst, "Pdrst", axleRuntime.Pdrst, "DoingPdrst", axleRuntime.DoingPdrst, "Rac", axleRuntime.Rac, "Rjo", axleRuntime.Rjo, "Rjt", axleRuntime.Rjt, "SectionFault", sectionFault, "Occ", sectionState.Occ, "Count", axleDevice.Count, "Wave", axleDevice.ShowCountWave()) } } }) } // 计算计轴区段状态 func (s *FaDcAxleDeviceSystem) calculateSectionState(sectionFault bool, sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) { sectionState.Occ = axleDevice.Count > 0 || sectionFault } // 计轴直接复位 func (s *FaDcAxleDeviceSystem) calculateDrst(axleSectionEntry *ecs.Entry, sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) { isFault := axleSectionEntry.HasComponent(component.AxleSectionFaultTag) if axleRuntime.Drst && !axleRuntime.Rjo && !axleRuntime.Rjt && isFault { //直接复位且没有拒绝原因 axleDevice.UpdateCount(0) axleDevice.ResetCountPulse() axleRuntime.DoingPdrst = false //清除故障 if axleSectionEntry.HasComponent(component.AxleSectionFaultTag) { axleSectionEntry.RemoveComponent(component.AxleSectionFaultTag) } } } // 计轴预复位 func (s *FaDcAxleDeviceSystem) calculatePdrst(axleSectionEntry *ecs.Entry, sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) { isFault := axleSectionEntry.HasComponent(component.AxleSectionFaultTag) if axleRuntime.Pdrst && !axleRuntime.Rjo && !axleRuntime.Rjt && !axleRuntime.DoingPdrst && isFault { //预复位且没有拒绝原因 axleDevice.UpdateCount(0) axleDevice.ResetCountPulse() axleRuntime.DoingPdrst = true } //压道车通过该计轴区段,完成计轴预复位 if axleRuntime.DoingPdrst && isFault && axleDevice.IsCount010Pulse() { axleRuntime.DoingPdrst = false //清除故障 axleSectionEntry.RemoveComponent(component.AxleSectionFaultTag) } } // 复位回复运算 func (s *FaDcAxleDeviceSystem) calculateHf(sectionFault bool, axleSectionEntry *ecs.Entry, sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) { axleRuntime.Rac = axleRuntime.Drst || axleRuntime.Pdrst axleRuntime.Rjo = axleRuntime.Rac && !sectionState.Occ && !axleRuntime.DoingPdrst //空闲拒绝复位(排除预复位过程中) axleRuntime.Rjt = false // 技术原因拒绝复位 }