95 lines
3.2 KiB
Go
95 lines
3.2 KiB
Go
package device_sys
|
|
|
|
import (
|
|
"github.com/yohamta/donburi"
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
)
|
|
|
|
// AxleSectionSystem 计轴区段设备
|
|
type AxleSectionSystem struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewAxleSectionSystem() *AxleSectionSystem {
|
|
return &AxleSectionSystem{
|
|
query: ecs.NewQuery(filter.Contains(component.AxleSectionStateType, component.AxleSectionDeviceType, component.AxleSectionRuntimeType)),
|
|
}
|
|
}
|
|
func (s *AxleSectionSystem) Update(w ecs.World) {
|
|
s.query.Each(w, func(entry *donburi.Entry) {
|
|
s.calculateDrst(entry)
|
|
s.calculatePdrst(entry)
|
|
s.calculateSectionState(entry)
|
|
s.calculateHf(entry)
|
|
s.calculateAxleCount(entry)
|
|
/*
|
|
{
|
|
if component.UidType.Get(entry).Id == "北京_12_酒仙桥_6G" {
|
|
state := component.AxleSectionStateType.Get(entry)
|
|
device := component.AxleSectionDeviceType.Get(entry)
|
|
rt := component.AxleSectionRuntimeType.Get(entry)
|
|
fmt.Printf("===>>计轴区段(北京_12_酒仙桥_6G): Clr=%t, Occ=%t, Drst=%t, Pdrst=%t, Rac=%t, Rjo=%t, Rjt=%t, Count=%d Pdrsting=%t\n",
|
|
state.Clr, state.Occ, device.Drst, device.Pdrst, device.Rac, device.Rjo, device.Rjt, rt.Count(), rt.DoingPdrst)
|
|
}
|
|
}
|
|
*/
|
|
})
|
|
}
|
|
|
|
// 计算计轴区段内车轴数
|
|
// 目前通过查看有哪些车在该计轴区段内实现,定性
|
|
func (s *AxleSectionSystem) calculateAxleCount(entry *donburi.Entry) {
|
|
//收集该计轴区段上的车轴数
|
|
//device.Count = 该计轴区段上当前车轴数
|
|
|
|
}
|
|
|
|
// 计算计轴区段状态
|
|
func (s *AxleSectionSystem) calculateSectionState(entry *donburi.Entry) {
|
|
state := component.AxleSectionStateType.Get(entry)
|
|
rt := component.AxleSectionRuntimeType.Get(entry)
|
|
isIdle := rt.Count() <= 0 && !rt.DoingPdrst //区段空闲:区段内车轴数为零且没有预复位
|
|
state.Clr = isIdle
|
|
state.Occ = !isIdle
|
|
}
|
|
|
|
// 计轴直接复位
|
|
func (s *AxleSectionSystem) calculateDrst(entry *donburi.Entry) {
|
|
device := component.AxleSectionDeviceType.Get(entry)
|
|
rt := component.AxleSectionRuntimeType.Get(entry)
|
|
if device.Drst && !device.Rjo && !device.Rjt { //直接复位且没有拒绝原因
|
|
rt.SetCount(0)
|
|
rt.DoingPdrst = false
|
|
rt.CountTrainOutPulse = false
|
|
rt.CountTrainInPulse = false
|
|
}
|
|
}
|
|
|
|
// 计轴预复位
|
|
func (s *AxleSectionSystem) calculatePdrst(entry *donburi.Entry) {
|
|
device := component.AxleSectionDeviceType.Get(entry)
|
|
rt := component.AxleSectionRuntimeType.Get(entry)
|
|
if device.Pdrst && !device.Rjo && !device.Rjt && !rt.DoingPdrst { //预复位且没有拒绝原因
|
|
rt.SetCount(0)
|
|
rt.DoingPdrst = true
|
|
rt.CountTrainOutPulse = false
|
|
rt.CountTrainInPulse = false
|
|
}
|
|
//压道车通过该计轴区段,完成计轴预复位
|
|
if rt.CountTrainInPulse && rt.CountTrainOutPulse {
|
|
rt.DoingPdrst = false
|
|
}
|
|
}
|
|
|
|
// 复位回复运算
|
|
func (s *AxleSectionSystem) calculateHf(entry *donburi.Entry) {
|
|
device := component.AxleSectionDeviceType.Get(entry)
|
|
state := component.AxleSectionStateType.Get(entry)
|
|
rt := component.AxleSectionRuntimeType.Get(entry)
|
|
device.Rac = device.Drst || device.Pdrst
|
|
device.Rjo = device.Rac && state.Clr && !state.Occ && !rt.DoingPdrst //空闲拒绝复位(排除预复位过程中)
|
|
device.Rjt = false // 技术原因拒绝复位
|
|
}
|