100 lines
3.9 KiB
Go
100 lines
3.9 KiB
Go
package device_sys
|
|
|
|
import (
|
|
"github.com/yohamta/donburi"
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"log/slog"
|
|
)
|
|
|
|
// 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 *donburi.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)
|
|
//
|
|
s.calculateHf(axleSectionEntry, sectionState, axleDevice, axleRuntime)
|
|
s.calculateDrst(sectionState, axleDevice, axleRuntime)
|
|
s.calculatePdrst(sectionState, axleDevice, axleRuntime)
|
|
s.calculateSectionState(sectionState, axleDevice, axleRuntime)
|
|
s.calculateAxleCount(sectionState, axleDevice, axleRuntime)
|
|
|
|
if "北京_12_酒仙桥_12G" == axleSectionId && true {
|
|
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) calculateAxleCount(sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
|
//检查该区段内有没有车
|
|
// ...todo
|
|
}
|
|
|
|
// 计算计轴区段状态
|
|
func (s *FaDcAxleDeviceSystem) calculateSectionState(sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
|
|
|
isIdle := axleDevice.Count <= 0 && !axleRuntime.DoingPdrst //区段空闲:区段内车轴数为零且没有预复位
|
|
sectionState.Occ = !isIdle
|
|
}
|
|
|
|
// 计轴直接复位
|
|
func (s *FaDcAxleDeviceSystem) calculateDrst(sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
|
|
|
if axleRuntime.Drst && !axleRuntime.Rjo && !axleRuntime.Rjt { //直接复位且没有拒绝原因
|
|
axleDevice.UpdateCount(0)
|
|
axleDevice.ResetCountPulse()
|
|
axleRuntime.DoingPdrst = false
|
|
}
|
|
}
|
|
|
|
// 计轴预复位
|
|
func (s *FaDcAxleDeviceSystem) calculatePdrst(sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
|
|
|
if axleRuntime.Pdrst && !axleRuntime.Rjo && !axleRuntime.Rjt && !axleRuntime.DoingPdrst { //预复位且没有拒绝原因
|
|
axleDevice.UpdateCount(0)
|
|
axleDevice.ResetCountPulse()
|
|
axleRuntime.DoingPdrst = true
|
|
}
|
|
//压道车通过该计轴区段,完成计轴预复位
|
|
if axleDevice.IsCount010Pulse() {
|
|
axleRuntime.DoingPdrst = false
|
|
}
|
|
}
|
|
|
|
// 复位回复运算
|
|
func (s *FaDcAxleDeviceSystem) calculateHf(axleSectionEntry *ecs.Entry, sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
|
sectionFault := axleSectionEntry.HasComponent(component.AxleSectionFaultTag)
|
|
axleRuntime.Rac = axleRuntime.Drst || axleRuntime.Pdrst
|
|
axleRuntime.Rjo = axleRuntime.Rac && !sectionState.Occ && !axleRuntime.DoingPdrst //空闲拒绝复位(排除预复位过程中)
|
|
axleRuntime.Rjt = axleRuntime.Rac && sectionFault // 技术原因拒绝复位
|
|
}
|