2023-09-26 18:06:15 +08:00
|
|
|
package device_sys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
2023-10-09 11:17:25 +08:00
|
|
|
"joylink.club/ecs/filter"
|
2023-09-26 18:06:15 +08:00
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 断相保护器
|
2023-09-27 18:39:18 +08:00
|
|
|
type DBQSys struct {
|
2023-09-26 18:06:15 +08:00
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
2023-09-27 18:39:18 +08:00
|
|
|
func NewDBQSys() *DBQSys {
|
|
|
|
return &DBQSys{
|
2023-09-28 14:34:00 +08:00
|
|
|
query: ecs.NewQuery(filter.Contains(component.DBQTag, component.DBQStateType)),
|
2023-09-26 18:06:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-27 18:39:18 +08:00
|
|
|
func (q *DBQSys) Update(w ecs.World) {
|
2023-09-26 18:06:15 +08:00
|
|
|
q.query.Each(w, func(entry *ecs.Entry) {
|
|
|
|
// 电路是否通电
|
2023-09-28 14:34:00 +08:00
|
|
|
dbq := component.DBQStateType.Get(entry)
|
2023-10-16 15:40:03 +08:00
|
|
|
// 定时器处理
|
|
|
|
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 {
|
2023-09-26 18:06:15 +08:00
|
|
|
dbq.Dzkg = true
|
2023-10-16 15:40:03 +08:00
|
|
|
} else if dbq.Dzkg && !(dbq.Td && counter.Val < consts.DBQTimeout) {
|
2023-09-26 18:06:15 +08:00
|
|
|
dbq.Dzkg = false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|