53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package device_sys
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/consts"
|
|
"joylink.club/rtsssimulation/entity"
|
|
)
|
|
|
|
type CiQcSys struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewCiQcSys() *CiQcSys {
|
|
return &CiQcSys{
|
|
query: ecs.NewQuery(filter.Contains(component.CiQcTableType, component.CiQcStateType)),
|
|
}
|
|
}
|
|
|
|
func (s *CiQcSys) Update(w ecs.World) {
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
// 采集设备状态
|
|
data := entity.GetWorldData(w)
|
|
table := component.CiQcTableType.Get(entry)
|
|
state := component.CiQcStateType.Get(entry)
|
|
for i, cj := range table.CjBits {
|
|
bit := true
|
|
if len(cj.RefRelays) > 0 {
|
|
for _, cdi := range cj.RefRelays {
|
|
re, ok := data.EntityMap[cdi.RelayId]
|
|
if !ok {
|
|
panic(fmt.Errorf("联锁码位采集系统运行异常,没有id=%s的继电器实体", cdi.RelayId))
|
|
}
|
|
if !re.HasComponent(component.BitStateType) {
|
|
panic(fmt.Errorf("联锁码位采集系统运行异常,id=%s的继电器实体没有BitState组件", cdi.RelayId))
|
|
}
|
|
s := component.BitStateType.Get(re)
|
|
if cdi.Q != s.Val {
|
|
bit = false
|
|
break
|
|
}
|
|
}
|
|
} else {
|
|
bit = false
|
|
}
|
|
consts.SetBitOfBytes(state.Cbs, i, bit)
|
|
}
|
|
})
|
|
}
|