rts-sim-module/sys/device_sys/dbq.go
walker 97b2880c7b 修改断相保护器系统逻辑bug
修改道岔挤岔故障bug
修改计数器系统逻辑bug
2023-10-16 15:40:03 +08:00

46 lines
1.2 KiB
Go

package device_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// 断相保护器
type DBQSys struct {
query *ecs.Query
}
func NewDBQSys() *DBQSys {
return &DBQSys{
query: ecs.NewQuery(filter.Contains(component.DBQTag, component.DBQStateType)),
}
}
func (q *DBQSys) Update(w ecs.World) {
q.query.Each(w, func(entry *ecs.Entry) {
// 电路是否通电
dbq := component.DBQStateType.Get(entry)
// 定时器处理
counter := component.CounterType.Get(entry)
if dbq.Td && counter.Val < consts.DBQTimeout && counter.Step == 0 { // 通电但开关未开,启动
// 定时器启动
counter.Step = w.Tick()
} else if dbq.Td && counter.Val >= consts.DBQTimeout && counter.Step != 0 { // 已经启动,判定延时切断
// 判断定时器是否超时,如果超时,断开电子开关
counter.Step = 0
} else if !dbq.Td && counter.Val > 0 { // 断电,数字计时器
counter.Val = 0
counter.Step = 0
}
// 电子开关状态变化
if !dbq.Dzkg && dbq.Td && counter.Val < consts.DBQTimeout {
dbq.Dzkg = true
} else if dbq.Dzkg && !(dbq.Td && counter.Val < consts.DBQTimeout) {
dbq.Dzkg = false
}
})
}