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

52 lines
1.7 KiB
Go
Raw Normal View History

2023-10-08 13:59:15 +08:00
package circuit_sys
import (
"joylink.club/ecs"
"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 {
return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType, component.Signal2XH1FilamentType))}
}
// Update world 执行
func (s *Signal2XH1System) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
state := component.Signal2XH1ElectronicType.Get(entry)
filament := component.Signal2XH1FilamentType.Get(entry)
s.calculateL(state, filament)
s.calculateH(state, filament)
2023-10-08 16:00:05 +08:00
s.calculateDJ(state, filament)
2023-10-08 13:59:15 +08:00
})
}
func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) {
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
isL := !ddj.Val && lxj.Val && filament.Lf
filament.L = isL
}
func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) {
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
isH := !ddj.Val && !lxj.Val && filament.Hf
filament.H = isH
}
2023-10-08 16:00:05 +08:00
func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) {
2023-10-08 13:59:15 +08:00
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
dj := component.BitStateType.Get(state.Z2XH1_DJ)
isDJ := !ddj.Val && lxj.Val && filament.Lf || !ddj.Val && !lxj.Val && filament.Hf
//通知继电器进行动作
if dj.Val != isDJ {
drive := component.RelayDriveType.Get(state.Z2XH1_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
}