rts-sim-module/system/debug_system.go

124 lines
4.1 KiB
Go
Raw Normal View History

2023-08-15 17:29:11 +08:00
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) {
2023-08-25 10:50:39 +08:00
//debugMovableDevice(w)
2023-08-25 13:26:23 +08:00
//debugPsd(w)
debugSwitch(w)
2023-08-22 14:37:30 +08:00
//debugSignal(w)
2023-08-24 10:27:50 +08:00
//debugTowPosButton(w)
2023-08-22 17:21:21 +08:00
}
2023-08-25 10:50:39 +08:00
// 可按速度移动组件
func debugMovableDevice(w ecs.World) {
query := ecs.NewQuery(filter.Contains(components.PercentageDeviceStateComponent, components.MovableDeviceStateComponent))
query.Each(w, func(e *ecs.Entry) {
id := components.DeviceIdentityComponent.Get(e).Id
if "psd1Cell1" == id {
percent := components.PercentageDeviceStateComponent.Get(e)
movable := components.MovableDeviceStateComponent.Get(e)
fmt.Printf("==>>屏蔽门cell [%s],curRateValue = %d ,targetRateValue = %d , speed = %d position = %d\n", id, percent.Rate, percent.Target, movable.Speed, movable.Position)
}
})
}
2023-08-22 17:21:21 +08:00
// 两档位按钮旋钮
func debugTowPosButton(w ecs.World) {
2023-08-23 16:01:01 +08:00
towPosButtonsQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TowPositionButtonStateComponent))
2023-08-22 17:21:21 +08:00
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)
}
}
})
2023-08-17 14:25:18 +08:00
}
// 屏蔽门状态
func debugPsd(w ecs.World) {
2023-08-29 15:00:56 +08:00
psdQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.PsdTagHandlerComponent))
2023-08-17 14:25:18 +08:00
psdQuery.Each(w, func(e *ecs.Entry) {
2023-08-18 10:06:17 +08:00
psdId := components.DeviceIdentityComponent.Get(e).Id
psdState := components.PsdStateComponent.Get(e)
2023-08-29 15:00:56 +08:00
psdTag := components.PsdTagHandlerComponent.Get(e).Tag
2023-08-17 14:25:18 +08:00
fmt.Printf("屏蔽门[%s] ,全关=%t ,全开=%t ,互锁解除=%t > ", psdId, psdState.AllClosed, psdState.AllOpened, psdState.InterlockReleased)
//
2023-08-25 10:50:39 +08:00
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
2023-08-17 14:25:18 +08:00
psdCellQuery.Each(w, func(e *ecs.Entry) {
2023-08-18 10:06:17 +08:00
psdCellId := components.DeviceIdentityComponent.Get(e).Id
2023-08-25 10:50:39 +08:00
psdCellPercent := components.PercentageDeviceStateComponent.Get(e)
psdCellMovable := components.MovableDeviceStateComponent.Get(e)
2023-08-17 14:25:18 +08:00
//
2023-08-25 10:50:39 +08:00
fmt.Printf("|| cell[%s] ,closeRate=%d ", psdCellId, GetRate(psdCellPercent.Rate))
if psdCellMovable.Speed > 0 {
if psdCellMovable.ToH {
fmt.Printf("== 关门操作中,移动速率=%d", psdCellMovable.Speed)
2023-08-17 14:25:18 +08:00
} else {
2023-08-25 10:50:39 +08:00
fmt.Printf("== 开门操作中,移动速率=%d", psdCellMovable.Speed)
2023-08-17 14:25:18 +08:00
}
}
2023-08-25 10:50:39 +08:00
2023-08-17 14:25:18 +08:00
})
//
fmt.Println()
})
2023-08-16 15:14:03 +08:00
}
// 显示信号机状态
func debugSignal(w ecs.World) {
2023-08-18 10:06:17 +08:00
siganlQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent))
2023-08-16 15:14:03 +08:00
siganlQuery.Each(w, func(e *ecs.Entry) {
2023-08-18 10:06:17 +08:00
id := components.DeviceIdentityComponent.Get(e).Id
state := components.SignalStateComponent.Get(e)
2023-08-16 15:14:03 +08:00
fmt.Printf("==>>信号机[%s],显示=%d\n", id, state.Display)
})
2023-08-15 17:29:11 +08:00
}
// 显示道岔状态
func debugSwitch(w ecs.World) {
2023-08-25 10:50:39 +08:00
switchesQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent))
2023-08-18 14:40:13 +08:00
switchesQuery.Each(w, func(e *ecs.Entry) {
2023-08-25 10:50:39 +08:00
percent := components.PercentageDeviceStateComponent.Get(e)
movable := components.MovableDeviceStateComponent.Get(e)
2023-08-18 14:40:13 +08:00
id := components.DeviceIdentityComponent.Get(e).Id
2023-08-25 10:50:39 +08:00
curRate := GetRate(percent.Rate)
2023-08-18 14:40:13 +08:00
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)
2023-08-25 10:50:39 +08:00
if movable.Speed > 0 {
fmt.Printf(" ==> 正在转动,移动速率[%d]", movable.Speed)
2023-08-18 14:40:13 +08:00
}
fmt.Println()
})
2023-08-15 17:29:11 +08:00
}