signal 3xh4 驱采

This commit is contained in:
xzb 2023-10-12 16:13:56 +08:00
parent 1180549f1d
commit e5238067a9
7 changed files with 148 additions and 96 deletions

View File

@ -201,3 +201,45 @@ var (
Signal3XH3LsqType = ecs.NewComponentType[Signal3XH3Lsq]()
Signal3XH3LscType = ecs.NewComponentType[Signal3XH3Lsc]()
)
///////////////////////////////////////////////////////////////////////////////
// Signal3XH4Electronic 电路状态信号机3XH-4(红-绿-黄) 出站兼道岔防护信号机(三显示不封灯、有单黄显示、无引导)
type Signal3XH4Electronic struct {
// 点灯继电器true-吸合,常态落下表示逻辑点灯
Z3XH4_DDJ *ecs.Entry
//灯丝继电器true-吸合
Z3XH4_DJ *ecs.Entry
//列车信号继电器true-吸合
Z3XH4_LXJ *ecs.Entry
//开通正线信号继电器true-吸合
Z3XH4_ZXJ *ecs.Entry
}
// Signal3XH4Lsq 联锁驱
type Signal3XH4Lsq struct {
//true-联锁施加励磁电流驱动继电器DDJ
Z3XH4_DDJ_Q bool
////true-联锁施加励磁电流驱动继电器LXJ
Z3XH4_LXJ_Q bool
////true-联锁施加励磁电流驱动继电器ZXJ
Z3XH4_ZXJ_Q bool
}
// Signal3XH4Lsc 联锁采
type Signal3XH4Lsc struct {
//true-继电器DJ吸起
Z3XH4_DJ_Xq bool
//true-继电器DDJ落下
Z3XH4_DDJ_Lx bool
//true-继电器LXJ吸起
Z3XH4_LXJ_Xq bool
//true-继电器ZXJ吸起
Z3XH4_ZXJ_Xq bool
}
var (
Signal3XH4ElectronicType = ecs.NewComponentType[Signal3XH4Electronic]()
Signal3XH4LsqType = ecs.NewComponentType[Signal3XH4Lsq]()
Signal3XH4LscType = ecs.NewComponentType[Signal3XH4Lsc]()
)

View File

@ -1,36 +0,0 @@
package component
import "joylink.club/ecs"
// Signal3XH4Electronic 电路状态信号机3XH-4(红-绿-黄) 出站兼道岔防护信号机(三显示不封灯、有单黄显示、无引导)
type Signal3XH4Electronic struct {
// 点灯继电器true-吸合,常态落下表示逻辑点灯
Z3XH4_DDJ *ecs.Entry
//灯丝继电器true-吸合
Z3XH4_DJ *ecs.Entry
//列车信号继电器true-吸合
Z3XH4_LXJ *ecs.Entry
//开通正线信号继电器true-吸合
Z3XH4_ZXJ *ecs.Entry
}
// Signal3XH4Filament 信号机3XH-4 灯丝状态
type Signal3XH4Filament struct {
// 物理黄灯true-灯丝正常
Uf bool
// 物理绿灯true-灯丝正常
Lf bool
// 物理红灯true-灯丝正常
Hf bool
// 物理黄灯true-亮
U bool
// 物理绿灯true-亮
L bool
// 物理红灯true-亮
H bool
}
var (
Signal3XH4ElectronicType = ecs.NewComponentType[Signal3XH4Electronic]()
Signal3XH4FilamentType = ecs.NewComponentType[Signal3XH4Filament]()
)

View File

@ -12,7 +12,9 @@ func loadSignal3xh4(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 4 { //3xh4组合类型包含4个继电器
signalEntry.AddComponent(component.Signal3XH4ElectronicType)
signalEntry.AddComponent(component.Signal3XH4FilamentType)
signalEntry.AddComponent(component.Signal3XH4LsqType)
signalEntry.AddComponent(component.Signal3XH4LscType)
signalEntry.AddComponent(component.SignalLightsType)
//
elecState := &component.Signal3XH4Electronic{}
for _, elec := range elecs {
@ -31,7 +33,9 @@ func loadSignal3xh4(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
}
//
component.Signal3XH4ElectronicType.Set(signalEntry, elecState)
component.Signal3XH4FilamentType.Set(signalEntry, &component.Signal3XH4Filament{Uf: true, Lf: true, Hf: true, U: false, L: false, H: false})
component.Signal3XH4LsqType.Set(signalEntry, &component.Signal3XH4Lsq{})
component.Signal3XH4LscType.Set(signalEntry, &component.Signal3XH4Lsc{})
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
} else {
return fmt.Errorf("id=[%s]的信号机3xh4电子元器件数量须为4", signal.Id())
}

View File

@ -15,11 +15,8 @@ func DriveSignal3XH4Dd(w ecs.World, signalId string, dd bool) {
wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId]
if ok {
state := component.Signal3XH4ElectronicType.Get(signalEntry)
driveDd := component.RelayDriveType.Get(state.Z3XH4_DDJ)
//点灯继电器落下时才点灯
driveDd.Td = !dd
driveDd.Xq = !dd
lsq := component.Signal3XH4LsqType.Get(signalEntry)
lsq.Z3XH4_DDJ_Q = !dd
}
})
}
@ -31,13 +28,9 @@ func DriveSignal3XH4Lx(w ecs.World, signalId string, zx bool) {
wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId]
if ok {
state := component.Signal3XH4ElectronicType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH4_LXJ)
driveLx.Td = true
driveLx.Xq = true
driveZx := component.RelayDriveType.Get(state.Z3XH4_ZXJ)
driveZx.Td = zx
driveZx.Xq = zx
lsq := component.Signal3XH4LsqType.Get(signalEntry)
lsq.Z3XH4_LXJ_Q = true
lsq.Z3XH4_ZXJ_Q = zx
}
})
}
@ -48,13 +41,9 @@ func DriveSignal3XH4Non(w ecs.World, signalId string) {
wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId]
if ok {
state := component.Signal3XH4ElectronicType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH4_LXJ)
driveLx.Td = false
driveLx.Xq = false
driveZx := component.RelayDriveType.Get(state.Z3XH4_ZXJ)
driveZx.Td = false
driveZx.Xq = false
lsq := component.Signal3XH4LsqType.Get(signalEntry)
lsq.Z3XH4_LXJ_Q = false
lsq.Z3XH4_ZXJ_Q = false
}
})
}

View File

@ -11,7 +11,11 @@ type Signal3XH2System struct {
}
func NewSignal3XH2System() *Signal3XH2System {
return &Signal3XH2System{query: ecs.NewQuery(filter.Contains(component.Signal3XH2ElectronicType))}
return &Signal3XH2System{query: ecs.NewQuery(filter.Contains(
component.Signal3XH2ElectronicType,
component.Signal3XH2LsqType,
component.Signal3XH2LscType,
component.SignalLightsType))}
}
// Update world 执行

View File

@ -11,7 +11,11 @@ type Signal3XH3System struct {
}
func NewSignal3XH3System() *Signal3XH3System {
return &Signal3XH3System{query: ecs.NewQuery(filter.Contains(component.Signal3XH3ElectronicType))}
return &Signal3XH3System{query: ecs.NewQuery(filter.Contains(
component.Signal3XH3ElectronicType,
component.Signal3XH3LsqType,
component.Signal3XH3LscType,
component.SignalLightsType))}
}
// Update world 执行

View File

@ -11,56 +11,101 @@ type Signal3XH4System struct {
}
func NewSignal3XH4System() *Signal3XH4System {
return &Signal3XH4System{query: ecs.NewQuery(filter.Contains(component.Signal3XH4ElectronicType, component.Signal3XH4FilamentType))}
return &Signal3XH4System{query: ecs.NewQuery(filter.Contains(
component.Signal3XH4ElectronicType,
component.Signal3XH4LsqType,
component.Signal3XH4LscType,
component.SignalLightsType))}
}
// Update world 执行
func (s *Signal3XH4System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.Signal3XH4ElectronicType.Get(e)
filament := component.Signal3XH4FilamentType.Get(e)
s.query.Each(w, func(entry *ecs.Entry) {
state := component.Signal3XH4ElectronicType.Get(entry)
lsq := component.Signal3XH4LsqType.Get(entry)
lsc := component.Signal3XH4LscType.Get(entry)
lights := component.SignalLightsType.Get(entry)
Z3XH4_H := lights.GetLightByTag(component.HdTag)
Z3XH4_L := lights.GetLightByTag(component.LdTag)
Z3XH4_U := lights.GetLightByTag(component.UdTag)
//
s.calculateU(state, filament)
s.calculateL(state, filament)
s.calculateH(w, state, filament)
s.calculateDJ(w, e, state, filament)
s.calculateLsq(state, lsq)
s.calculateU(state, Z3XH4_U)
s.calculateL(state, Z3XH4_L)
s.calculateH(state, Z3XH4_H)
s.calculateDJ(state, Z3XH4_H, Z3XH4_L, Z3XH4_U)
s.calculateLsc(state, lsc)
})
}
func (s *Signal3XH4System) calculateU(state *component.Signal3XH4Electronic, filament *component.Signal3XH4Filament) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isU := filament.Uf && !ddj.Val && lxj.Val && !zxj.Val
filament.U = isU
// 联锁驱
func (s *Signal3XH4System) calculateLsq(state *component.Signal3XH4Electronic, lsq *component.Signal3XH4Lsq) {
ddj := component.RelayDriveType.Get(state.Z3XH4_DDJ)
lxj := component.RelayDriveType.Get(state.Z3XH4_LXJ)
zxj := component.RelayDriveType.Get(state.Z3XH4_ZXJ)
//
ddjQ := lsq.Z3XH4_DDJ_Q
ddj.Td = ddjQ
ddj.Xq = ddjQ
//
lxjQ := lsq.Z3XH4_LXJ_Q
lxj.Td = lxjQ
lxj.Xq = lxjQ
//
zxjQ := lsq.Z3XH4_ZXJ_Q
zxj.Td = zxjQ
zxj.Xq = zxjQ
}
func (s *Signal3XH4System) calculateL(state *component.Signal3XH4Electronic, filament *component.Signal3XH4Filament) {
// 联锁采
func (s *Signal3XH4System) calculateLsc(state *component.Signal3XH4Electronic, lsc *component.Signal3XH4Lsc) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isL := filament.Lf && !ddj.Val && lxj.Val && zxj.Val
filament.L = isL
}
func (s *Signal3XH4System) calculateH(w ecs.World, state *component.Signal3XH4Electronic, filament *component.Signal3XH4Filament) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
isH := filament.Hf && !ddj.Val && !lxj.Val
filament.H = isH
}
func (s *Signal3XH4System) calculateDJ(w ecs.World, e *ecs.Entry, state *component.Signal3XH4Electronic, filament *component.Signal3XH4Filament) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
dj := component.BitStateType.Get(state.Z3XH4_DJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
//
lsc.Z3XH4_DJ_Xq = dj.Val
lsc.Z3XH4_DDJ_Lx = !ddj.Val
lsc.Z3XH4_LXJ_Xq = lxj.Val
lsc.Z3XH4_ZXJ_Xq = zxj.Val
}
func (s *Signal3XH4System) calculateU(state *component.Signal3XH4Electronic, Z3XH4_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isDJ := filament.Uf && !ddj.Val && lxj.Val && !zxj.Val ||
filament.Lf && !ddj.Val && lxj.Val && zxj.Val ||
filament.Hf && !ddj.Val && !lxj.Val
if isDJ != dj.Val {
drive := component.RelayDriveType.Get(state.Z3XH4_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
isU := !ddj.Val && lxj.Val && !zxj.Val
driveU := component.LightDriveType.Get(Z3XH4_U)
driveU.Td = isU
}
func (s *Signal3XH4System) calculateL(state *component.Signal3XH4Electronic, Z3XH4_L *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isL := !ddj.Val && lxj.Val && zxj.Val
driveL := component.LightDriveType.Get(Z3XH4_L)
driveL.Td = isL
}
func (s *Signal3XH4System) calculateH(state *component.Signal3XH4Electronic, Z3XH4_H *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
isH := !ddj.Val && !lxj.Val
driveH := component.LightDriveType.Get(Z3XH4_H)
driveH.Td = isH
}
func (s *Signal3XH4System) calculateDJ(state *component.Signal3XH4Electronic, Z3XH4_H *ecs.Entry, Z3XH4_L *ecs.Entry, Z3XH4_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
hd := component.BitStateType.Get(Z3XH4_H)
ld := component.BitStateType.Get(Z3XH4_L)
ud := component.BitStateType.Get(Z3XH4_U)
isDJ := ud.Val && !ddj.Val && lxj.Val && !zxj.Val ||
ld.Val && !ddj.Val && lxj.Val && zxj.Val ||
hd.Val && !ddj.Val && !lxj.Val
drive := component.RelayDriveType.Get(state.Z3XH4_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}