diff --git a/component/signal.go b/component/signal.go index d784b18..7dde9c5 100644 --- a/component/signal.go +++ b/component/signal.go @@ -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]() +) diff --git a/component/signal_3xh4.go b/component/signal_3xh4.go deleted file mode 100644 index a6bde64..0000000 --- a/component/signal_3xh4.go +++ /dev/null @@ -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]() -) diff --git a/entity/signal_3xh4.go b/entity/signal_3xh4.go index 7d5a049..8f3cb74 100644 --- a/entity/signal_3xh4.go +++ b/entity/signal_3xh4.go @@ -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()) } diff --git a/fi/signal_3xh4.go b/fi/signal_3xh4.go index 41eb59c..e6de4e6 100644 --- a/fi/signal_3xh4.go +++ b/fi/signal_3xh4.go @@ -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 } }) } diff --git a/sys/circuit_sys/signal_3xh2.go b/sys/circuit_sys/signal_3xh2.go index 39577a6..b926b03 100644 --- a/sys/circuit_sys/signal_3xh2.go +++ b/sys/circuit_sys/signal_3xh2.go @@ -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 执行 diff --git a/sys/circuit_sys/signal_3xh3.go b/sys/circuit_sys/signal_3xh3.go index 7485fcf..3f01aa7 100644 --- a/sys/circuit_sys/signal_3xh3.go +++ b/sys/circuit_sys/signal_3xh3.go @@ -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 执行 diff --git a/sys/circuit_sys/signal_3xh4.go b/sys/circuit_sys/signal_3xh4.go index ecdf774..11dc948 100644 --- a/sys/circuit_sys/signal_3xh4.go +++ b/sys/circuit_sys/signal_3xh4.go @@ -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 }