2023-10-08 13:59:15 +08:00
|
|
|
package circuit_sys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
2023-10-09 11:17:25 +08:00
|
|
|
"joylink.club/ecs/filter"
|
2023-10-08 13:59:15 +08:00
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Signal2XH1System struct {
|
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSignal2XH1System() *Signal2XH1System {
|
2023-10-11 14:12:51 +08:00
|
|
|
return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType))}
|
2023-10-08 13:59:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update world 执行
|
|
|
|
func (s *Signal2XH1System) Update(w ecs.World) {
|
|
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
|
|
state := component.Signal2XH1ElectronicType.Get(entry)
|
2023-10-11 14:12:51 +08:00
|
|
|
s.calculateL(state)
|
|
|
|
s.calculateH(state)
|
|
|
|
s.calculateDJ(state)
|
2023-10-08 13:59:15 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-11 14:12:51 +08:00
|
|
|
func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic) {
|
|
|
|
driveL := component.LightDriveType.Get(state.Z2XH1_L)
|
2023-10-08 13:59:15 +08:00
|
|
|
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
2023-10-11 14:12:51 +08:00
|
|
|
isL := !ddj.Val && lxj.Val
|
2023-10-11 17:11:13 +08:00
|
|
|
driveL.Td = isL
|
2023-10-08 13:59:15 +08:00
|
|
|
}
|
2023-10-11 14:12:51 +08:00
|
|
|
func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic) {
|
|
|
|
driveH := component.LightDriveType.Get(state.Z2XH1_H)
|
2023-10-08 13:59:15 +08:00
|
|
|
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
2023-10-11 14:12:51 +08:00
|
|
|
isH := !ddj.Val && !lxj.Val
|
2023-10-11 17:11:13 +08:00
|
|
|
driveH.Td = isH
|
2023-10-08 13:59:15 +08:00
|
|
|
}
|
2023-10-11 14:12:51 +08:00
|
|
|
func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic) {
|
2023-10-08 13:59:15 +08:00
|
|
|
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
2023-10-11 16:57:48 +08:00
|
|
|
ld := component.BitStateType.Get(state.Z2XH1_L)
|
|
|
|
hd := component.BitStateType.Get(state.Z2XH1_H)
|
|
|
|
isDJ := !ddj.Val && lxj.Val && ld.Val || !ddj.Val && !lxj.Val && hd.Val
|
2023-10-08 13:59:15 +08:00
|
|
|
//通知继电器进行动作
|
2023-10-11 17:11:13 +08:00
|
|
|
drive := component.RelayDriveType.Get(state.Z2XH1_DJ)
|
|
|
|
drive.Td = isDJ
|
|
|
|
drive.Xq = isDJ
|
2023-10-08 13:59:15 +08:00
|
|
|
}
|