diff --git a/component/signal.go b/component/signal.go index 0bc7d2e..a40f84d 100644 --- a/component/signal.go +++ b/component/signal.go @@ -123,16 +123,36 @@ type Signal3XH2Electronic struct { Z3XH2_LXJ *ecs.Entry //引导信号继电器,true-吸合 Z3XH2_YXJ *ecs.Entry - // 物理黄灯,true-亮 - Z3XH2_U *ecs.Entry - // 物理绿灯,true-亮 - Z3XH2_L *ecs.Entry - // 物理红灯,true-亮 - Z3XH2_H *ecs.Entry +} + +// Signal3XH2Lsq 联锁驱 +type Signal3XH2Lsq struct { + //true-联锁施加励磁电流驱动继电器DDJ + Z3XH2_DDJ_Q bool + ////true-联锁施加励磁电流驱动继电器LXJ + Z3XH2_LXJ_Q bool + ////true-联锁施加励磁电流驱动继电器LXJ + Z3XH2_YXJ_Q bool +} + +// Signal3XH2Lsc 联锁采 +type Signal3XH2Lsc struct { + //true-继电器DJ吸起 + Z3XH2_DJ_Xq bool + //true-继电器2DJ吸起 + Z3XH2_2DJ_Xq bool + //true-继电器DDJ落下 + Z3XH2_DDJ_Lx bool + //true-继电器LXJ吸起 + Z3XH2_LXJ_Xq bool + //true-继电器YXJ吸起 + Z3XH2_YXJ_Xq bool } var ( Signal3XH2ElectronicType = ecs.NewComponentType[Signal3XH2Electronic]() + Signal3XH2LsqType = ecs.NewComponentType[Signal3XH2Lsq]() + Signal3XH2LscType = ecs.NewComponentType[Signal3XH2Lsc]() ) ////////////////////////////////////////////////////////////////////////////// diff --git a/entity/signal_3xh2.go b/entity/signal_3xh2.go index 68d563d..10f19a4 100644 --- a/entity/signal_3xh2.go +++ b/entity/signal_3xh2.go @@ -12,8 +12,11 @@ func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent if len(elecs) == 5 { //3xh2组合类型包含5个继电器 signalEntry.AddComponent(component.Signal3XH2ElectronicType) + signalEntry.AddComponent(component.Signal3XH2LsqType) + signalEntry.AddComponent(component.Signal3XH2LscType) + signalEntry.AddComponent(component.SignalLightsType) // - elecState := &component.Signal3XH2Electronic{Z3XH2_L: NewLightLEntity(w), Z3XH2_H: NewLightHEntity(w), Z3XH2_U: NewLightUEntity(w)} + elecState := &component.Signal3XH2Electronic{} for _, elec := range elecs { switch elec.Code() { case consts.SIGNAL_DDJ: @@ -32,6 +35,9 @@ func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent } // component.Signal3XH2ElectronicType.Set(signalEntry, elecState) + component.Signal3XH2LsqType.Set(signalEntry, &component.Signal3XH2Lsq{}) + component.Signal3XH2LscType.Set(signalEntry, &component.Signal3XH2Lsc{}) + component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag)) } else { return fmt.Errorf("id=[%s]的信号机3xh2,电子元器件数量须为5", signal.Id()) } diff --git a/fi/signal_3xh2.go b/fi/signal_3xh2.go index c975a98..02bdb50 100644 --- a/fi/signal_3xh2.go +++ b/fi/signal_3xh2.go @@ -15,11 +15,8 @@ func DriveSignal3XH2Dd(w ecs.World, signalId string, dd bool) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal3XH2ElectronicType.Get(signalEntry) - driveDd := component.RelayDriveType.Get(state.Z3XH2_DDJ) - //点灯继电器落下时才点灯 - driveDd.Td = !dd - driveDd.Xq = !dd + lsq := component.Signal3XH2LsqType.Get(signalEntry) + lsq.Z3XH2_DDJ_Q = !dd } }) } @@ -30,13 +27,9 @@ func DriveSignal3XH2Lx(w ecs.World, signalId string) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal3XH2ElectronicType.Get(signalEntry) - driveLx := component.RelayDriveType.Get(state.Z3XH2_LXJ) - driveLx.Td = true - driveLx.Xq = true - driveYx := component.RelayDriveType.Get(state.Z3XH2_YXJ) - driveYx.Td = false - driveYx.Xq = false + lsq := component.Signal3XH2LsqType.Get(signalEntry) + lsq.Z3XH2_LXJ_Q = true + lsq.Z3XH2_YXJ_Q = false } }) } @@ -47,13 +40,9 @@ func DriveSignal3XH2Yx(w ecs.World, signalId string) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal3XH2ElectronicType.Get(signalEntry) - driveLx := component.RelayDriveType.Get(state.Z3XH2_LXJ) - driveLx.Td = false - driveLx.Xq = false - driveYx := component.RelayDriveType.Get(state.Z3XH2_YXJ) - driveYx.Td = true - driveYx.Xq = true + lsq := component.Signal3XH2LsqType.Get(signalEntry) + lsq.Z3XH2_LXJ_Q = false + lsq.Z3XH2_YXJ_Q = true } }) } @@ -64,13 +53,9 @@ func DriveSignal3XH2Non(w ecs.World, signalId string) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal3XH2ElectronicType.Get(signalEntry) - driveLx := component.RelayDriveType.Get(state.Z3XH2_LXJ) - driveLx.Td = false - driveLx.Xq = false - driveYx := component.RelayDriveType.Get(state.Z3XH2_YXJ) - driveYx.Td = false - driveYx.Xq = false + lsq := component.Signal3XH2LsqType.Get(signalEntry) + lsq.Z3XH2_LXJ_Q = false + lsq.Z3XH2_YXJ_Q = false } }) } diff --git a/jl-ecs-go b/jl-ecs-go index 74c0211..af60502 160000 --- a/jl-ecs-go +++ b/jl-ecs-go @@ -1 +1 @@ -Subproject commit 74c02116147b7b4e86b56c790c9075e039e6fe82 +Subproject commit af605020f1bccf1f1b2ab5a4ae4966d1c6c9776c diff --git a/sys/circuit_sys/signal_3xh2.go b/sys/circuit_sys/signal_3xh2.go index 323d736..39577a6 100644 --- a/sys/circuit_sys/signal_3xh2.go +++ b/sys/circuit_sys/signal_3xh2.go @@ -16,47 +16,88 @@ func NewSignal3XH2System() *Signal3XH2System { // Update world 执行 func (s *Signal3XH2System) Update(w ecs.World) { - s.query.Each(w, func(e *ecs.Entry) { - state := component.Signal3XH2ElectronicType.Get(e) - s.calculateU(state) - s.calculateL(state) - s.calculateH(state) - s.calculateDJ(state) - s.calculate2DJ(state) + s.query.Each(w, func(entry *ecs.Entry) { + state := component.Signal3XH2ElectronicType.Get(entry) + lsq := component.Signal3XH2LsqType.Get(entry) + lsc := component.Signal3XH2LscType.Get(entry) + lights := component.SignalLightsType.Get(entry) + Z3XH2_L := lights.GetLightByTag(component.LdTag) + Z3XH2_H := lights.GetLightByTag(component.HdTag) + Z3XH2_U := lights.GetLightByTag(component.UdTag) + s.calculateLsq(state, lsq) + s.calculateU(state, Z3XH2_U) + s.calculateL(state, Z3XH2_L) + s.calculateH(state, Z3XH2_H) + s.calculateDJ(state, Z3XH2_L, Z3XH2_H) + s.calculate2DJ(state, Z3XH2_U) + s.calculateLsc(state, lsc) }) } -func (s *Signal3XH2System) calculateU(state *component.Signal3XH2Electronic) { +// 联锁驱 +func (s *Signal3XH2System) calculateLsq(state *component.Signal3XH2Electronic, lsq *component.Signal3XH2Lsq) { + ddj := component.RelayDriveType.Get(state.Z3XH2_DDJ) + lxj := component.RelayDriveType.Get(state.Z3XH2_LXJ) + yxj := component.RelayDriveType.Get(state.Z3XH2_YXJ) + // + ddjQ := lsq.Z3XH2_DDJ_Q + ddj.Td = ddjQ + ddj.Xq = ddjQ + // + lxjQ := lsq.Z3XH2_LXJ_Q + lxj.Td = lxjQ + lxj.Xq = lxjQ + // + yxjQ := lsq.Z3XH2_YXJ_Q + yxj.Td = yxjQ + yxj.Xq = yxjQ +} + +// 联锁采 +func (s *Signal3XH2System) calculateLsc(state *component.Signal3XH2Electronic, lsc *component.Signal3XH2Lsc) { + ddj := component.BitStateType.Get(state.Z3XH2_DDJ) + lxj := component.BitStateType.Get(state.Z3XH2_LXJ) + dj := component.BitStateType.Get(state.Z3XH2_DJ) + edj := component.BitStateType.Get(state.Z3XH2_2DJ) + yxj := component.BitStateType.Get(state.Z3XH2_YXJ) + // + lsc.Z3XH2_2DJ_Xq = edj.Val + lsc.Z3XH2_DJ_Xq = dj.Val + lsc.Z3XH2_DDJ_Lx = !ddj.Val + lsc.Z3XH2_LXJ_Xq = lxj.Val + lsc.Z3XH2_YXJ_Xq = yxj.Val +} +func (s *Signal3XH2System) calculateU(state *component.Signal3XH2Electronic, Z3XH2_U *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH2_DDJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ) dj := component.BitStateType.Get(state.Z3XH2_DJ) yxj := component.BitStateType.Get(state.Z3XH2_YXJ) - driveU := component.LightDriveType.Get(state.Z3XH2_U) + driveU := component.LightDriveType.Get(Z3XH2_U) isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val driveU.Td = isU } -func (s *Signal3XH2System) calculateL(state *component.Signal3XH2Electronic) { +func (s *Signal3XH2System) calculateL(state *component.Signal3XH2Electronic, Z3XH2_L *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH2_DDJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ) - driveL := component.LightDriveType.Get(state.Z3XH2_L) + driveL := component.LightDriveType.Get(Z3XH2_L) isL := !ddj.Val && lxj.Val driveL.Td = isL } -func (s *Signal3XH2System) calculateH(state *component.Signal3XH2Electronic) { +func (s *Signal3XH2System) calculateH(state *component.Signal3XH2Electronic, Z3XH2_H *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH2_DDJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ) - driveH := component.LightDriveType.Get(state.Z3XH2_H) + driveH := component.LightDriveType.Get(Z3XH2_H) isH := !ddj.Val && !lxj.Val driveH.Td = isH } -func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic) { +func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic, Z3XH2_L *ecs.Entry, Z3XH2_H *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH2_DDJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ) - ld := component.BitStateType.Get(state.Z3XH2_L) - hd := component.BitStateType.Get(state.Z3XH2_H) + ld := component.BitStateType.Get(Z3XH2_L) + hd := component.BitStateType.Get(Z3XH2_H) isDJ := ld.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val //通知继电器进行动作 drive := component.RelayDriveType.Get(state.Z3XH2_DJ) @@ -64,12 +105,12 @@ func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic) { drive.Xq = isDJ } -func (s *Signal3XH2System) calculate2DJ(state *component.Signal3XH2Electronic) { +func (s *Signal3XH2System) calculate2DJ(state *component.Signal3XH2Electronic, Z3XH2_U *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH2_DDJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ) dj := component.BitStateType.Get(state.Z3XH2_DJ) yxj := component.BitStateType.Get(state.Z3XH2_YXJ) - ud := component.BitStateType.Get(state.Z3XH2_U) + ud := component.BitStateType.Get(Z3XH2_U) is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val //通知继电器进行动作 drive := component.RelayDriveType.Get(state.Z3XH2_2DJ)