rts-sim-module/sys/circuit_sys/signal_3xh2.go

145 lines
4.8 KiB
Go
Raw Normal View History

2023-10-08 16:48:10 +08:00
package circuit_sys
import (
"joylink.club/ecs"
2023-10-09 13:23:34 +08:00
"joylink.club/ecs/filter"
2023-10-08 16:48:10 +08:00
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
2023-10-08 16:48:10 +08:00
)
type Signal3XH2System struct {
query *ecs.Query
}
func NewSignal3XH2System() *Signal3XH2System {
2023-10-12 16:13:56 +08:00
return &Signal3XH2System{query: ecs.NewQuery(filter.Contains(
component.Signal3XH2ElectronicType,
component.Signal3XH2LsqType,
component.Signal3XH2LscType,
component.SignalLightsType))}
2023-10-08 16:48:10 +08:00
}
// Update world 执行
func (s *Signal3XH2System) Update(w ecs.World) {
wd := entity.GetWorldData(w)
2023-10-12 14:19:00 +08:00
s.query.Each(w, func(entry *ecs.Entry) {
circuit := component.Signal3XH2ElectronicType.Get(entry)
excite3xh2ByCiDrive(circuit, wd)
//lsq := component.Signal3XH2LsqType.Get(entry)
//lsc := component.Signal3XH2LscType.Get(entry)
2023-10-12 14:19:00 +08:00
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(circuit, lsq)
s.calculateU(circuit, Z3XH2_U)
s.calculateL(circuit, Z3XH2_L)
s.calculateH(circuit, Z3XH2_H)
s.calculateDJ(circuit, Z3XH2_L, Z3XH2_H)
s.calculate2DJ(circuit, Z3XH2_U)
//s.calculateLsc(circuit, lsc)
2023-10-08 16:48:10 +08:00
})
}
// 根据联锁驱动给继电器励磁
func excite3xh2ByCiDrive(circuit *component.Signal3XH2Electronic, wd *component.WorldData) {
bit, err := wd.QueryQdBit(component.UidType.Get(circuit.Z3XH2_DDJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.Z3XH2_DDJ).Td = bit
}
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH2_LXJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.Z3XH2_LXJ).Td = bit
}
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH2_YXJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.Z3XH2_YXJ).Td = bit
}
}
2023-10-12 14:19:00 +08:00
// 联锁驱
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) {
2023-10-08 16:48:10 +08:00
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)
2023-10-12 14:19:00 +08:00
driveU := component.LightDriveType.Get(Z3XH2_U)
2023-10-11 17:25:25 +08:00
isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val
driveU.Td = isU
2023-10-08 16:48:10 +08:00
}
2023-10-12 14:19:00 +08:00
func (s *Signal3XH2System) calculateL(state *component.Signal3XH2Electronic, Z3XH2_L *ecs.Entry) {
2023-10-08 16:48:10 +08:00
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
2023-10-12 14:19:00 +08:00
driveL := component.LightDriveType.Get(Z3XH2_L)
2023-10-11 17:25:25 +08:00
isL := !ddj.Val && lxj.Val
driveL.Td = isL
2023-10-08 16:48:10 +08:00
}
2023-10-12 14:19:00 +08:00
func (s *Signal3XH2System) calculateH(state *component.Signal3XH2Electronic, Z3XH2_H *ecs.Entry) {
2023-10-08 16:48:10 +08:00
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
2023-10-12 14:19:00 +08:00
driveH := component.LightDriveType.Get(Z3XH2_H)
2023-10-11 17:25:25 +08:00
isH := !ddj.Val && !lxj.Val
driveH.Td = isH
2023-10-08 16:48:10 +08:00
}
2023-10-12 14:19:00 +08:00
func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic, Z3XH2_L *ecs.Entry, Z3XH2_H *ecs.Entry) {
2023-10-08 16:48:10 +08:00
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
2023-10-12 14:19:00 +08:00
ld := component.BitStateType.Get(Z3XH2_L)
hd := component.BitStateType.Get(Z3XH2_H)
2023-10-11 17:25:25 +08:00
isDJ := ld.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val
2023-10-08 16:48:10 +08:00
//通知继电器进行动作
2023-10-11 17:25:25 +08:00
drive := component.RelayDriveType.Get(state.Z3XH2_DJ)
drive.Td = isDJ
drive.Xq = isDJ
2023-10-08 16:48:10 +08:00
}
2023-10-12 14:19:00 +08:00
func (s *Signal3XH2System) calculate2DJ(state *component.Signal3XH2Electronic, Z3XH2_U *ecs.Entry) {
2023-10-08 16:48:10 +08:00
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)
2023-10-12 14:19:00 +08:00
ud := component.BitStateType.Get(Z3XH2_U)
2023-10-11 17:25:25 +08:00
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
2023-10-08 16:48:10 +08:00
//通知继电器进行动作
2023-10-11 17:25:25 +08:00
drive := component.RelayDriveType.Get(state.Z3XH2_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
2023-10-08 16:48:10 +08:00
}