rts-sim-module/sys/device_sys/fadc_axle_device.go
2023-10-31 17:39:10 +08:00

96 lines
3.5 KiB
Go

package device_sys
import (
"github.com/yohamta/donburi"
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// FaDcAxleDeviceSystem FaDc计轴设备管理器系统
type FaDcAxleDeviceSystem struct {
query *ecs.Query
}
func NewFaDcAxleDeviceSystem() *FaDcAxleDeviceSystem {
return &FaDcAxleDeviceSystem{
query: ecs.NewQuery(filter.Contains(component.FaDcAxleDeviceType)),
}
}
func (s *FaDcAxleDeviceSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *donburi.Entry) {
faDcDevice := component.FaDcAxleDeviceType.Get(entry)
for _, axleSectionEntry := range faDcDevice.Sections {
axleSectionId := component.UidType.Get(axleSectionEntry).Id
axleCounterEntry := faDcDevice.CounterMap[axleSectionId]
//
s.calculateDrst(axleCounterEntry)
s.calculatePdrst(axleCounterEntry)
s.calculateSectionState(axleCounterEntry, axleSectionEntry)
s.calculateHf(axleCounterEntry, axleSectionEntry)
s.calculateAxleCount(axleCounterEntry, axleSectionEntry)
}
})
}
// 计算计轴区段内车轴数
// 目前通过查看有哪些车在该计轴区段内实现,定性
func (s *FaDcAxleDeviceSystem) calculateAxleCount(axleCounterEntry *donburi.Entry, axleSectionEntry *donburi.Entry) {
sectionFault := component.AxleSectionFaultType.Get(axleSectionEntry)
counter := component.AxleCounterType.Get(axleCounterEntry)
if sectionFault.SectionFault { //设置计轴故障
counter.UpdateCount(1)
} else {
//取消计轴故障
counter.UpdateCount(0)
//检查该区段内有没有车
// ...todo
}
}
// 计算计轴区段状态
func (s *FaDcAxleDeviceSystem) calculateSectionState(axleCounterEntry *donburi.Entry, axleSectionEntry *donburi.Entry) {
section := component.AxleSectionType.Get(axleSectionEntry)
counter := component.AxleCounterType.Get(axleCounterEntry)
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
isIdle := counter.Count <= 0 && !counterRt.DoingPdrst //区段空闲:区段内车轴数为零且没有预复位
section.Occ = !isIdle
}
// 计轴直接复位
func (s *FaDcAxleDeviceSystem) calculateDrst(axleCounterEntry *donburi.Entry) {
counter := component.AxleCounterType.Get(axleCounterEntry)
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
if counterRt.Drst && !counterRt.Rjo && !counterRt.Rjt { //直接复位且没有拒绝原因
counter.UpdateCount(0)
counter.ResetCountPulse()
counterRt.DoingPdrst = false
}
}
// 计轴预复位
func (s *FaDcAxleDeviceSystem) calculatePdrst(axleCounterEntry *donburi.Entry) {
counter := component.AxleCounterType.Get(axleCounterEntry)
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
if counterRt.Pdrst && !counterRt.Rjo && !counterRt.Rjt && !counterRt.DoingPdrst { //预复位且没有拒绝原因
counter.UpdateCount(0)
counter.ResetCountPulse()
counterRt.DoingPdrst = true
}
//压道车通过该计轴区段,完成计轴预复位
if counter.IsCount010Pulse() {
counterRt.DoingPdrst = false
}
}
// 复位回复运算
func (s *FaDcAxleDeviceSystem) calculateHf(axleCounterEntry *donburi.Entry, axleSectionEntry *donburi.Entry) {
section := component.AxleSectionType.Get(axleSectionEntry)
sectionFault := component.AxleSectionFaultType.Get(axleSectionEntry)
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
counterRt.Rac = counterRt.Drst || counterRt.Pdrst
counterRt.Rjo = counterRt.Rac && !section.Occ && !counterRt.DoingPdrst //空闲拒绝复位(排除预复位过程中)
counterRt.Rjt = sectionFault.SectionFault // 技术原因拒绝复位
}