2023-10-31 15:55:16 +08:00
|
|
|
package device_sys
|
|
|
|
|
|
|
|
import (
|
2023-11-16 16:12:37 +08:00
|
|
|
"log/slog"
|
|
|
|
|
2023-10-31 15:55:16 +08:00
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/ecs/filter"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
2023-11-06 14:35:32 +08:00
|
|
|
"joylink.club/rtsssimulation/entity"
|
2023-10-31 15:55:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// FaDcAxleDeviceSystem FaDc计轴设备管理器系统
|
|
|
|
type FaDcAxleDeviceSystem struct {
|
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFaDcAxleDeviceSystem() *FaDcAxleDeviceSystem {
|
|
|
|
return &FaDcAxleDeviceSystem{
|
2023-11-06 14:35:32 +08:00
|
|
|
query: ecs.NewQuery(filter.Contains(component.AxleManageDeviceType)),
|
2023-10-31 15:55:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func (s *FaDcAxleDeviceSystem) Update(w ecs.World) {
|
2023-11-06 14:35:32 +08:00
|
|
|
data := entity.GetWorldData(w)
|
2023-11-16 16:12:37 +08:00
|
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
2023-11-06 14:35:32 +08:00
|
|
|
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)
|
2023-10-31 15:55:16 +08:00
|
|
|
//
|
2023-11-15 13:20:44 +08:00
|
|
|
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)
|
2023-11-01 17:46:23 +08:00
|
|
|
|
2023-11-15 13:20:44 +08:00
|
|
|
if "北京_12_酒仙桥_15G" == axleSectionId && false {
|
2023-11-06 14:35:32 +08:00
|
|
|
sectionFault := axleSectionEntry.HasComponent(component.AxleSectionFaultTag)
|
2023-11-01 17:46:23 +08:00
|
|
|
slog.Info(axleSectionId,
|
2023-11-06 14:35:32 +08:00
|
|
|
"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())
|
2023-11-01 17:46:23 +08:00
|
|
|
}
|
2023-10-31 15:55:16 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 计算计轴区段状态
|
2023-11-15 13:20:44 +08:00
|
|
|
func (s *FaDcAxleDeviceSystem) calculateSectionState(sectionFault bool, sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
|
|
|
sectionState.Occ = axleDevice.Count > 0 || sectionFault
|
2023-10-31 15:55:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 计轴直接复位
|
2023-11-15 13:20:44 +08:00
|
|
|
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 { //直接复位且没有拒绝原因
|
2023-11-06 14:35:32 +08:00
|
|
|
axleDevice.UpdateCount(0)
|
|
|
|
axleDevice.ResetCountPulse()
|
|
|
|
axleRuntime.DoingPdrst = false
|
2023-11-15 13:20:44 +08:00
|
|
|
//清除故障
|
|
|
|
if axleSectionEntry.HasComponent(component.AxleSectionFaultTag) {
|
|
|
|
axleSectionEntry.RemoveComponent(component.AxleSectionFaultTag)
|
|
|
|
}
|
2023-10-31 15:55:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 计轴预复位
|
2023-11-15 13:20:44 +08:00
|
|
|
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 { //预复位且没有拒绝原因
|
2023-11-06 14:35:32 +08:00
|
|
|
axleDevice.UpdateCount(0)
|
|
|
|
axleDevice.ResetCountPulse()
|
|
|
|
axleRuntime.DoingPdrst = true
|
2023-10-31 15:55:16 +08:00
|
|
|
}
|
|
|
|
//压道车通过该计轴区段,完成计轴预复位
|
2023-11-15 13:20:44 +08:00
|
|
|
if axleRuntime.DoingPdrst && isFault && axleDevice.IsCount010Pulse() {
|
2023-11-06 14:35:32 +08:00
|
|
|
axleRuntime.DoingPdrst = false
|
2023-11-15 13:20:44 +08:00
|
|
|
//清除故障
|
|
|
|
axleSectionEntry.RemoveComponent(component.AxleSectionFaultTag)
|
2023-10-31 15:55:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 复位回复运算
|
2023-11-15 13:20:44 +08:00
|
|
|
func (s *FaDcAxleDeviceSystem) calculateHf(sectionFault bool, axleSectionEntry *ecs.Entry, sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
2023-11-06 14:35:32 +08:00
|
|
|
axleRuntime.Rac = axleRuntime.Drst || axleRuntime.Pdrst
|
|
|
|
axleRuntime.Rjo = axleRuntime.Rac && !sectionState.Occ && !axleRuntime.DoingPdrst //空闲拒绝复位(排除预复位过程中)
|
2023-11-15 13:20:44 +08:00
|
|
|
axleRuntime.Rjt = false // 技术原因拒绝复位
|
2023-10-31 15:55:16 +08:00
|
|
|
}
|