rts-sim-module/system/debug_system.go
2023-08-22 17:21:21 +08:00

107 lines
3.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package system
import (
"fmt"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
)
// 调试时显示一些信息
type DebugSystem struct {
}
func NewDebugSystem() *DebugSystem {
return &DebugSystem{}
}
// world 执行
func (me *DebugSystem) Update(w ecs.World) {
//debugPsd(w)
//debugSwitch(w)
//debugSignal(w)
debugTowPosButton(w)
}
// 两档位按钮旋钮
func debugTowPosButton(w ecs.World) {
towPosButtonsQuery.Each(w, func(e *ecs.Entry) {
id := components.DeviceIdentityComponent.Get(e).Id
state := components.TowPositionButtonStateComponent.Get(e)
switch {
case state.Pos1 && !state.Pos2:
{
fmt.Printf("两档位按钮[%s],处于 一 档稳态\n", id)
}
case !state.Pos1 && state.Pos2:
{
fmt.Printf("两档位按钮[%s],处于 二 档稳态\n", id)
}
case !state.Pos1 && !state.Pos2:
{
fmt.Printf("两档位按钮[%s],处于未知或变换过程中 ......\n", id)
}
default:
{
fmt.Printf("两档位按钮[%s],异常同时处于 一二 档 \n", id)
}
}
})
}
// 屏蔽门状态
func debugPsd(w ecs.World) {
psdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent))
psdQuery.Each(w, func(e *ecs.Entry) {
psdId := components.DeviceIdentityComponent.Get(e).Id
psdState := components.PsdStateComponent.Get(e)
psdTag := components.EntityTagHandlerComponent.Get(e).Tag
fmt.Printf("屏蔽门[%s] ,全关=%t ,全开=%t ,互锁解除=%t > ", psdId, psdState.AllClosed, psdState.AllOpened, psdState.InterlockReleased)
//
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag, components.PercentageDeviceComponent))
psdCellQuery.Each(w, func(e *ecs.Entry) {
psdCellId := components.DeviceIdentityComponent.Get(e).Id
psdCellState := components.PercentageDeviceComponent.Get(e)
//
fmt.Printf("|| cell[%s] ,closeRate=%d ", psdCellId, psdCellState.Rate)
if e.HasComponent(components.PercentageDeviceOperatingComponent) {
psdCellOpt := components.PercentageDeviceOperatingComponent.Get(e)
if psdCellOpt.ToH {
fmt.Printf("== 关门操作中,剩余移动距离=%d", psdCellOpt.RemainingDistance)
} else {
fmt.Printf("== 开门操作中,剩余移动距离=%d", psdCellOpt.RemainingDistance)
}
}
})
//
fmt.Println()
})
}
// 显示信号机状态
func debugSignal(w ecs.World) {
siganlQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent))
siganlQuery.Each(w, func(e *ecs.Entry) {
id := components.DeviceIdentityComponent.Get(e).Id
state := components.SignalStateComponent.Get(e)
fmt.Printf("==>>信号机[%s],显示=%d\n", id, state.Display)
})
}
// 显示道岔状态
func debugSwitch(w ecs.World) {
switchesQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent))
switchesQuery.Each(w, func(e *ecs.Entry) {
id := components.DeviceIdentityComponent.Get(e).Id
curRate := components.PercentageDeviceComponent.Get(e).Rate
j := components.SwitchRelayStateComponent.Get(e)
fmt.Printf("道岔 [%s],当前位置百分比 [%d] ,Dcj = %t, Fcj = %t, Dbj = %t ,Fbj = %t ,", id, curRate, j.DcJ, j.FcJ, j.DbJ, j.FbJ)
if e.HasComponent(components.PercentageDeviceOperatingComponent) {
opt := components.PercentageDeviceOperatingComponent.Get(e)
fmt.Printf(" ==> 正在转动,剩余距离[%d]ms", opt.RemainingDistance)
}
fmt.Println()
})
}