120 lines
4.0 KiB
Go
120 lines
4.0 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
)
|
|
|
|
type Signal3XH2System struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewSignal3XH2System() *Signal3XH2System {
|
|
return &Signal3XH2System{query: ecs.NewQuery(filter.Contains(component.Signal3XH2ElectronicType))}
|
|
}
|
|
|
|
// Update world 执行
|
|
func (s *Signal3XH2System) Update(w ecs.World) {
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
state := component.Signal3XH2ElectronicType.Get(entry)
|
|
lsq := component.Signal3XH2LsqType.Get(entry)
|
|
lsc := component.Signal3XH2LscType.Get(entry)
|
|
lights := component.SignalLightsType.Get(entry)
|
|
Z3XH2_L := lights.GetLightByTag(component.LdTag)
|
|
Z3XH2_H := lights.GetLightByTag(component.HdTag)
|
|
Z3XH2_U := lights.GetLightByTag(component.UdTag)
|
|
s.calculateLsq(state, lsq)
|
|
s.calculateU(state, Z3XH2_U)
|
|
s.calculateL(state, Z3XH2_L)
|
|
s.calculateH(state, Z3XH2_H)
|
|
s.calculateDJ(state, Z3XH2_L, Z3XH2_H)
|
|
s.calculate2DJ(state, Z3XH2_U)
|
|
s.calculateLsc(state, lsc)
|
|
})
|
|
}
|
|
|
|
// 联锁驱
|
|
func (s *Signal3XH2System) calculateLsq(state *component.Signal3XH2Electronic, lsq *component.Signal3XH2Lsq) {
|
|
ddj := component.RelayDriveType.Get(state.Z3XH2_DDJ)
|
|
lxj := component.RelayDriveType.Get(state.Z3XH2_LXJ)
|
|
yxj := component.RelayDriveType.Get(state.Z3XH2_YXJ)
|
|
//
|
|
ddjQ := lsq.Z3XH2_DDJ_Q
|
|
ddj.Td = ddjQ
|
|
ddj.Xq = ddjQ
|
|
//
|
|
lxjQ := lsq.Z3XH2_LXJ_Q
|
|
lxj.Td = lxjQ
|
|
lxj.Xq = lxjQ
|
|
//
|
|
yxjQ := lsq.Z3XH2_YXJ_Q
|
|
yxj.Td = yxjQ
|
|
yxj.Xq = yxjQ
|
|
}
|
|
|
|
// 联锁采
|
|
func (s *Signal3XH2System) calculateLsc(state *component.Signal3XH2Electronic, lsc *component.Signal3XH2Lsc) {
|
|
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
|
|
dj := component.BitStateType.Get(state.Z3XH2_DJ)
|
|
edj := component.BitStateType.Get(state.Z3XH2_2DJ)
|
|
yxj := component.BitStateType.Get(state.Z3XH2_YXJ)
|
|
//
|
|
lsc.Z3XH2_2DJ_Xq = edj.Val
|
|
lsc.Z3XH2_DJ_Xq = dj.Val
|
|
lsc.Z3XH2_DDJ_Lx = !ddj.Val
|
|
lsc.Z3XH2_LXJ_Xq = lxj.Val
|
|
lsc.Z3XH2_YXJ_Xq = yxj.Val
|
|
}
|
|
func (s *Signal3XH2System) calculateU(state *component.Signal3XH2Electronic, Z3XH2_U *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
|
|
dj := component.BitStateType.Get(state.Z3XH2_DJ)
|
|
yxj := component.BitStateType.Get(state.Z3XH2_YXJ)
|
|
driveU := component.LightDriveType.Get(Z3XH2_U)
|
|
isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val
|
|
driveU.Td = isU
|
|
}
|
|
|
|
func (s *Signal3XH2System) calculateL(state *component.Signal3XH2Electronic, Z3XH2_L *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
|
|
driveL := component.LightDriveType.Get(Z3XH2_L)
|
|
isL := !ddj.Val && lxj.Val
|
|
driveL.Td = isL
|
|
}
|
|
|
|
func (s *Signal3XH2System) calculateH(state *component.Signal3XH2Electronic, Z3XH2_H *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
|
|
driveH := component.LightDriveType.Get(Z3XH2_H)
|
|
isH := !ddj.Val && !lxj.Val
|
|
driveH.Td = isH
|
|
}
|
|
|
|
func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic, Z3XH2_L *ecs.Entry, Z3XH2_H *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
|
|
ld := component.BitStateType.Get(Z3XH2_L)
|
|
hd := component.BitStateType.Get(Z3XH2_H)
|
|
isDJ := ld.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val
|
|
//通知继电器进行动作
|
|
drive := component.RelayDriveType.Get(state.Z3XH2_DJ)
|
|
drive.Td = isDJ
|
|
drive.Xq = isDJ
|
|
}
|
|
|
|
func (s *Signal3XH2System) calculate2DJ(state *component.Signal3XH2Electronic, Z3XH2_U *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
|
|
dj := component.BitStateType.Get(state.Z3XH2_DJ)
|
|
yxj := component.BitStateType.Get(state.Z3XH2_YXJ)
|
|
ud := component.BitStateType.Get(Z3XH2_U)
|
|
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
|
|
//通知继电器进行动作
|
|
drive := component.RelayDriveType.Get(state.Z3XH2_2DJ)
|
|
drive.Td = is2DJ
|
|
drive.Xq = is2DJ
|
|
}
|