rts-sim-module/sys/device_sys/fadc_axle_device.go
2023-11-01 17:46:23 +08:00

107 lines
3.9 KiB
Go

package device_sys
import (
"github.com/yohamta/donburi"
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"log/slog"
)
// 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.calculateHf(axleCounterEntry, axleSectionEntry)
s.calculateDrst(axleCounterEntry)
s.calculatePdrst(axleCounterEntry)
s.calculateSectionState(axleCounterEntry, axleSectionEntry)
s.calculateAxleCount(axleCounterEntry, axleSectionEntry)
if "北京_12_酒仙桥_12G" == axleSectionId {
section := component.AxleSectionType.Get(axleSectionEntry)
counter := component.AxleCounterType.Get(axleCounterEntry)
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
sectionFault := component.AxleSectionFaultType.Get(axleSectionEntry)
slog.Info(axleSectionId,
"Drst", counterRt.Drst,
"Pdrst", counterRt.Pdrst,
"DoingPdrst", counterRt.DoingPdrst,
"Rac", counterRt.Rac,
"Rjo", counterRt.Rjo,
"Rjt", counterRt.Rjt,
"SectionFault", sectionFault.SectionFault,
"Occ", section.Occ,
"Count", counter.Count,
"Wave", counter.ShowCountWave())
}
}
})
}
// 计算计轴区段内车轴数
// 目前通过查看有哪些车在该计轴区段内实现,定性
func (s *FaDcAxleDeviceSystem) calculateAxleCount(axleCounterEntry *donburi.Entry, axleSectionEntry *donburi.Entry) {
//检查该区段内有没有车
// ...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 = counterRt.Rac && sectionFault.SectionFault // 技术原因拒绝复位
}