signal jdxh

This commit is contained in:
xzb 2023-10-09 11:09:29 +08:00
parent b09216f783
commit 1a843be8aa
5 changed files with 152 additions and 1 deletions

36
component/signal_jdxh.go Normal file
View File

@ -0,0 +1,36 @@
package component
import "joylink.club/ecs"
// SignalJDXHElectronic 电路状态信号机JDXH(红-绿-黄) 进段信号机(三显示不封灯、无单黄显示、带引导)
type SignalJDXHElectronic struct {
// 2DJ灯丝继电器true-吸合
JDXH_2DJ *ecs.Entry
//灯丝继电器true-吸合
JDXH_DJ *ecs.Entry
//列车信号继电器true-吸合
JDXH_LXJ *ecs.Entry
//引导信号继电器true-吸合
JDXH_YXJ *ecs.Entry
}
// SignalJDXHFilament 信号机JDXH 灯丝状态
type SignalJDXHFilament struct {
// 物理黄灯true-灯丝正常
Uf bool
// 物理绿灯true-灯丝正常
Lf bool
// 物理红灯true-灯丝正常
Hf bool
// 物理黄灯true-亮
U bool
// 物理绿灯true-亮
L bool
// 物理红灯true-亮
H bool
}
var (
SignalJDXHElectronicType = ecs.NewComponentType[SignalJDXHElectronic]()
SignalJDXHFilamentType = ecs.NewComponentType[SignalJDXHFilament]()
)

View File

@ -40,6 +40,9 @@ func LoadSignals(w ecs.World) error {
return le
}
case consts.SIGNAL_JDXH:
if le := loadSignalJdxh(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
return le
}
case consts.SIGNAL_DCXH:
if le := loadSignalDcxh(w, signal, signalEntry, elecs, data.EntityMap); le != nil {
return le

39
entity/signal_jdxh.go Normal file
View File

@ -0,0 +1,39 @@
package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/repository"
)
func loadSignalJdxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Entry, elecs []repository.IGroupedElectronicComponent, entityMap map[string]*ecs.Entry) error {
if len(elecs) == 4 { //jdxh组合类型包含3个继电器
signalEntry.AddComponent(component.SignalJDXHElectronicType)
signalEntry.AddComponent(component.SignalJDXHFilamentType)
//
elecState := &component.SignalJDXHElectronic{}
for _, elec := range elecs {
switch elec.Code() {
case consts.SIGNAL_DJ:
elecState.JDXH_DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_2DJ:
elecState.JDXH_2DJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_LXJ:
elecState.JDXH_LXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
case consts.SIGNAL_YXJ:
elecState.JDXH_YXJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
default:
return fmt.Errorf("id=[%s]的信号机jdxh无效电子元器件名称[%s]", signal.Id(), elec.Code())
}
}
//
component.SignalJDXHElectronicType.Set(signalEntry, elecState)
component.SignalJDXHFilamentType.Set(signalEntry, &component.SignalJDXHFilament{Uf: true, Lf: true, Hf: true, U: false, L: false, H: false})
} else {
return fmt.Errorf("id=[%s]的信号机jdxh电子元器件数量须为4", signal.Id())
}
return nil
}

View File

@ -23,5 +23,6 @@ func BindSystem(w ecs.World) {
circuit_sys.NewSignal3XH3System(),
circuit_sys.NewSignal3XH4System(),
circuit_sys.NewSignalDCXHSystem(),
circuit_sys.NewSignalJCKXHSystem())
circuit_sys.NewSignalJCKXHSystem(),
circuit_sys.NewSignalJDXHSystem())
}

View File

@ -0,0 +1,72 @@
package circuit_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
type SignalJDXHSystem struct {
query *ecs.Query
}
func NewSignalJDXHSystem() *SignalJDXHSystem {
return &SignalJDXHSystem{query: ecs.NewQuery(filter.Contains(component.SignalJDXHElectronicType, component.SignalJDXHFilamentType))}
}
// Update world 执行
func (s *SignalJDXHSystem) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.SignalJDXHElectronicType.Get(e)
filament := component.SignalJDXHFilamentType.Get(e)
//
s.calculateL(state, filament)
s.calculateU(state, filament)
s.calculateH(state, filament)
s.calculateDJ(state, filament)
s.calculate2DJ(state, filament)
})
}
func (s *SignalJDXHSystem) calculateU(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
dj := component.BitStateType.Get(state.JDXH_DJ)
yxj := component.BitStateType.Get(state.JDXH_YXJ)
isU := filament.Uf && !lxj.Val && dj.Val && yxj.Val
filament.U = isU
}
func (s *SignalJDXHSystem) calculateL(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
isL := filament.Lf && lxj.Val
filament.L = isL
}
func (s *SignalJDXHSystem) calculateH(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
isH := filament.Hf && !lxj.Val
filament.H = isH
}
func (s *SignalJDXHSystem) calculateDJ(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
dj := component.BitStateType.Get(state.JDXH_DJ)
isDJ := filament.Lf && lxj.Val || filament.Hf && !lxj.Val
if isDJ != dj.Val {
drive := component.RelayDriveType.Get(state.JDXH_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
}
func (s *SignalJDXHSystem) calculate2DJ(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) {
lxj := component.BitStateType.Get(state.JDXH_LXJ)
dj := component.BitStateType.Get(state.JDXH_DJ)
edj := component.BitStateType.Get(state.JDXH_2DJ)
yxj := component.BitStateType.Get(state.JDXH_YXJ)
is2DJ := filament.Uf && !lxj.Val && dj.Val && yxj.Val
if is2DJ != edj.Val {
drive := component.RelayDriveType.Get(state.JDXH_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
}
}