signal jckxh
This commit is contained in:
parent
2e1e393987
commit
b09216f783
34
component/signal_jckxh.go
Normal file
34
component/signal_jckxh.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package component
|
||||||
|
|
||||||
|
import "joylink.club/ecs"
|
||||||
|
|
||||||
|
// SignalJCKXHElectronic 电路状态:信号机JCKXH(红-白-黄) 进/出库列车兼调车信号机(三显示不封灯、有单黄显示、无引导)
|
||||||
|
type SignalJCKXHElectronic struct {
|
||||||
|
//灯丝继电器,true-吸合
|
||||||
|
JCKXH_DJ *ecs.Entry
|
||||||
|
//调车信号继电器,true-吸合
|
||||||
|
JCKXH_DXJ *ecs.Entry
|
||||||
|
//列车信号继电器,true-吸合
|
||||||
|
JCKXH_LXJ *ecs.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignalJCKXHFilament 信号机JCKXH 灯丝状态
|
||||||
|
type SignalJCKXHFilament struct {
|
||||||
|
// 物理黄灯,true-灯丝正常
|
||||||
|
Uf bool
|
||||||
|
// 物理白灯,true-灯丝正常
|
||||||
|
Bf bool
|
||||||
|
// 物理红灯,true-灯丝正常
|
||||||
|
Hf bool
|
||||||
|
// 物理黄灯,true-亮
|
||||||
|
U bool
|
||||||
|
// 物理白灯,true-亮
|
||||||
|
B bool
|
||||||
|
// 物理红灯,true-亮
|
||||||
|
H bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
SignalJCKXHElectronicType = ecs.NewComponentType[SignalJCKXHElectronic]()
|
||||||
|
SignalJCKXHFilamentType = ecs.NewComponentType[SignalJCKXHFilament]()
|
||||||
|
)
|
@ -45,6 +45,9 @@ func LoadSignals(w ecs.World) error {
|
|||||||
return le
|
return le
|
||||||
}
|
}
|
||||||
case consts.SIGNAL_JCKXH:
|
case consts.SIGNAL_JCKXH:
|
||||||
|
if le := loadSignalJckxh(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
|
||||||
|
return le
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("id=[%s]的信号机,无效组合类型[%s]", signal.Id(), group.Code())
|
return fmt.Errorf("id=[%s]的信号机,无效组合类型[%s]", signal.Id(), group.Code())
|
||||||
}
|
}
|
||||||
|
37
entity/signal_jckxh.go
Normal file
37
entity/signal_jckxh.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"joylink.club/rtsssimulation/consts"
|
||||||
|
"joylink.club/rtsssimulation/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
func loadSignalJckxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
|
||||||
|
|
||||||
|
if len(elecs) == 3 { //jckxh组合类型包含3个继电器
|
||||||
|
signalEntry.AddComponent(component.SignalJCKXHElectronicType)
|
||||||
|
signalEntry.AddComponent(component.SignalJCKXHFilamentType)
|
||||||
|
//
|
||||||
|
elecState := &component.SignalJCKXHElectronic{}
|
||||||
|
for _, elec := range elecs {
|
||||||
|
switch elec.Code() {
|
||||||
|
case consts.SIGNAL_DJ:
|
||||||
|
elecState.JCKXH_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||||||
|
case consts.SIGNAL_DXJ:
|
||||||
|
elecState.JCKXH_DXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||||||
|
case consts.SIGNAL_LXJ:
|
||||||
|
elecState.JCKXH_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("id=[%s]的信号机jckxh,无效电子元器件名称[%s]", signal.Id(), elec.Code())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
component.SignalJCKXHElectronicType.Set(signalEntry, elecState)
|
||||||
|
component.SignalJCKXHFilamentType.Set(signalEntry, &component.SignalJCKXHFilament{Uf: true, Bf: true, Hf: true, U: false, B: false, H: false})
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("id=[%s]的信号机jckxh,电子元器件数量须为3", signal.Id())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -22,5 +22,6 @@ func BindSystem(w ecs.World) {
|
|||||||
circuit_sys.NewSignal3XH2System(),
|
circuit_sys.NewSignal3XH2System(),
|
||||||
circuit_sys.NewSignal3XH3System(),
|
circuit_sys.NewSignal3XH3System(),
|
||||||
circuit_sys.NewSignal3XH4System(),
|
circuit_sys.NewSignal3XH4System(),
|
||||||
circuit_sys.NewSignalDCXHSystem())
|
circuit_sys.NewSignalDCXHSystem(),
|
||||||
|
circuit_sys.NewSignalJCKXHSystem())
|
||||||
}
|
}
|
||||||
|
60
sys/circuit_sys/signal_jckxh.go
Normal file
60
sys/circuit_sys/signal_jckxh.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package circuit_sys
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/yohamta/donburi/filter"
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SignalJCKXHSystem struct {
|
||||||
|
query *ecs.Query
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSignalJCKXHSystem() *SignalJCKXHSystem {
|
||||||
|
return &SignalJCKXHSystem{query: ecs.NewQuery(filter.Contains(component.SignalJCKXHElectronicType, component.SignalJCKXHFilamentType))}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update world 执行
|
||||||
|
func (s *SignalJCKXHSystem) Update(w ecs.World) {
|
||||||
|
s.query.Each(w, func(e *ecs.Entry) {
|
||||||
|
state := component.SignalJCKXHElectronicType.Get(e)
|
||||||
|
filament := component.SignalJCKXHFilamentType.Get(e)
|
||||||
|
//
|
||||||
|
s.calculateU(state, filament)
|
||||||
|
s.calculateB(state, filament)
|
||||||
|
s.calculateH(state, filament)
|
||||||
|
s.calculateDJ(state, filament)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SignalJCKXHSystem) calculateU(state *component.SignalJCKXHElectronic, filament *component.SignalJCKXHFilament) {
|
||||||
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
||||||
|
isU := filament.Uf && lxj.Val
|
||||||
|
filament.U = isU
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SignalJCKXHSystem) calculateB(state *component.SignalJCKXHElectronic, filament *component.SignalJCKXHFilament) {
|
||||||
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
||||||
|
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
|
||||||
|
isB := filament.Bf && !lxj.Val && dxj.Val
|
||||||
|
filament.B = isB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SignalJCKXHSystem) calculateH(state *component.SignalJCKXHElectronic, filament *component.SignalJCKXHFilament) {
|
||||||
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
||||||
|
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
|
||||||
|
isH := filament.Bf && !lxj.Val && dxj.Val
|
||||||
|
filament.H = isH
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SignalJCKXHSystem) calculateDJ(state *component.SignalJCKXHElectronic, filament *component.SignalJCKXHFilament) {
|
||||||
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
||||||
|
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
|
||||||
|
dj := component.BitStateType.Get(state.JCKXH_DJ)
|
||||||
|
isDJ := filament.Uf && lxj.Val || filament.Bf && !lxj.Val && dxj.Val || filament.Bf && !lxj.Val && dxj.Val
|
||||||
|
if isDJ != dj.Val {
|
||||||
|
drive := component.RelayDriveType.Get(state.JCKXH_DJ)
|
||||||
|
drive.Td = isDJ
|
||||||
|
drive.Xq = isDJ
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user