diff --git a/deprecated/entities/button_entity.go b/deprecated/entities/button_entity.go deleted file mode 100644 index 9dfc5be..0000000 --- a/deprecated/entities/button_entity.go +++ /dev/null @@ -1,23 +0,0 @@ -package entities - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/system" -) - -// CreateSelfResetButtonEntity 创建自复位按钮实体 -func CreateSelfResetButtonEntity(w ecs.World, buttonId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.ButtonStateComponent, system.ButtonSelfRestTag) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: buttonId}) - system.ButtonStateComponent.Set(e, system.NewButtonState()) - system.ButtonSelfRestTag.Set(e, &system.ButtonSelfRestState{KeepAxTime: 0}) - return e -} - -// CreateNonResetButtonEntity 创建非自复位按钮实体 -func CreateNonResetButtonEntity(w ecs.World, buttonId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.ButtonStateComponent, system.ButtonNonRestTag) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: buttonId}) - system.ButtonStateComponent.Set(e, system.NewButtonState()) - return e -} diff --git a/deprecated/entities/common_entity.go b/deprecated/entities/common_entity.go deleted file mode 100644 index 48fe32e..0000000 --- a/deprecated/entities/common_entity.go +++ /dev/null @@ -1,22 +0,0 @@ -package entities - -import ( - "time" - - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/system" -) - -// CreateModelStorageEntity 创建模型仓库实体 -func CreateModelStorageEntity(w ecs.World, modelManager system.IModelManager) *ecs.Entry { - e := w.Create(system.ModelStorageComponent) - system.ModelStorageComponent.Set(e, &system.ModelStorageRef{ModelManager: modelManager}) - return e -} - -// CreateSystemTimerEntity 创建系统时钟实体 -func CreateSystemTimerEntity(w ecs.World, systemTime time.Time) *ecs.Entry { - e := w.Create(system.SystemTimerComponent) - system.SystemTimerComponent.Set(e, system.NewSystemTimer(&systemTime)) - return e -} diff --git a/deprecated/entities/dcb_entity.go b/deprecated/entities/dcb_entity.go deleted file mode 100644 index 69430d5..0000000 --- a/deprecated/entities/dcb_entity.go +++ /dev/null @@ -1,14 +0,0 @@ -package entities - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/system" -) - -// CreateDcbCircuitEntity 创建门控箱电路实体 -func CreateDcbCircuitEntity(w ecs.World, dcbCircuitId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.DcbCircuitStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: dcbCircuitId}) - system.DcbCircuitStateComponent.Set(e, system.NewDcbCircuitState()) - return e -} diff --git a/deprecated/entities/emps_entity.go b/deprecated/entities/emps_entity.go deleted file mode 100644 index fa9b618..0000000 --- a/deprecated/entities/emps_entity.go +++ /dev/null @@ -1,13 +0,0 @@ -package entities - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/system" -) - -func CreateEmpsCircuitEntity(w ecs.World, empsCircuitId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.EmpsCircuitStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: empsCircuitId}) - system.EmpsCircuitStateComponent.Set(e, system.NewEmpsCircuitState()) - return e -} diff --git a/deprecated/entities/psd_entity.go b/deprecated/entities/psd_entity.go deleted file mode 100644 index b3763a3..0000000 --- a/deprecated/entities/psd_entity.go +++ /dev/null @@ -1,102 +0,0 @@ -package entities - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/system" -) - -// CreatePsdCircuitEntity 创建车站屏蔽门电路实体 -func CreatePsdCircuitEntity(w ecs.World, psdCircuitId string, psd system.IPsdModel) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.PsdCircuitStateComponent, system.PsdTagsComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: psdCircuitId}) - system.PsdCircuitStateComponent.Set(e, system.NewPsdCircuitState()) - system.PsdTagsComponent.Set(e, system.NewPsdTags()) - // - type psdCell struct { - id string - STag bool //上行侧屏蔽门子门标签 - S4KmUpTag bool //上行侧4编组运行方向上行时屏蔽门子门标签 - S4KmDownTag bool //上行侧4编组运行方向下行时屏蔽门子门标签 - S8KmUpTag bool //上行侧8编组运行方向上行时屏蔽门子门标签 - S8KmDownTag bool //上行侧8编组运行方向下行时屏蔽门子门标签 - XTag bool - X4KmUpTag bool - X4KmDownTag bool - X8KmUpTag bool - X8KmDownTag bool - } - psdCellsMap := make(map[string]*psdCell) - // - for _, pc := range psd.FindSPsdCells() { - cell := &psdCell{id: pc.Id(), STag: true} - psdCellsMap[cell.id] = cell - } - for _, pc := range psd.FindXPsdCells() { - cell := &psdCell{id: pc.Id(), XTag: true} - psdCellsMap[cell.id] = cell - } - for _, pc := range psd.FindS4KmUpPsdCells() { - psdCellsMap[pc.Id()].S4KmUpTag = true - } - for _, pc := range psd.FindS4KmDownPsdCells() { - psdCellsMap[pc.Id()].S4KmDownTag = true - } - for _, pc := range psd.FindS8KmUpPsdCells() { - psdCellsMap[pc.Id()].S8KmUpTag = true - } - for _, pc := range psd.FindS8KmDownPsdCells() { - psdCellsMap[pc.Id()].S8KmDownTag = true - } - for _, pc := range psd.FindX4KmUpPsdCells() { - psdCellsMap[pc.Id()].X4KmUpTag = true - } - for _, pc := range psd.FindX4KmDownPsdCells() { - psdCellsMap[pc.Id()].X4KmDownTag = true - } - for _, pc := range psd.FindX8KmUpPsdCells() { - psdCellsMap[pc.Id()].X8KmUpTag = true - } - for _, pc := range psd.FindX8KmDownPsdCells() { - psdCellsMap[pc.Id()].X8KmDownTag = true - } - // - tags := system.PsdTagsComponent.Get(e) - for cellId, cell := range psdCellsMap { - cellEntry := w.Create(system.EntityIdentityComponent, system.PsdCellStateComponent, system.PercentageDeviceStateComponent) - system.EntityIdentityComponent.Set(cellEntry, &system.EntityIdentity{Id: cellId}) - system.PsdCellStateComponent.Set(cellEntry, system.NewPsdCellState()) - system.PercentageDeviceStateComponent.Set(cellEntry, system.NewPercentageDeviceStateL()) //默认关门状态 - if cell.STag { - cellEntry.AddComponent(tags.STag) - } - if cell.S4KmUpTag { - cellEntry.AddComponent(tags.S4KmUpTag) - } - if cell.S4KmDownTag { - cellEntry.AddComponent(tags.S4KmDownTag) - } - if cell.S8KmUpTag { - cellEntry.AddComponent(tags.S8KmUpTag) - } - if cell.S8KmDownTag { - cellEntry.AddComponent(tags.S8KmDownTag) - } - if cell.XTag { - cellEntry.AddComponent(tags.XTag) - } - if cell.X4KmUpTag { - cellEntry.AddComponent(tags.X4KmUpTag) - } - if cell.X4KmDownTag { - cellEntry.AddComponent(tags.X4KmDownTag) - } - if cell.X8KmUpTag { - cellEntry.AddComponent(tags.X8KmUpTag) - } - if cell.X8KmDownTag { - cellEntry.AddComponent(tags.X8KmDownTag) - } - } - // - return e -} diff --git a/deprecated/entities/relay_entity.go b/deprecated/entities/relay_entity.go deleted file mode 100644 index 8e3db29..0000000 --- a/deprecated/entities/relay_entity.go +++ /dev/null @@ -1,37 +0,0 @@ -package entities - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/simulation" - "joylink.club/rtsssimulation/deprecated/system" - "joylink.club/rtsssimulation/repository" -) - -type RelayState struct { - Id string - Xh bool -} - -// CreateRelayEntity 创建继电器实体 -func CreateRelayEntity(w ecs.World, relayId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.RelayStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: relayId}) - system.RelayStateComponent.Set(e, system.NewRelayState()) - return e -} - -func CreateRelayEntries(world ecs.World, relays []*repository.Relay) { - for _, relay := range relays { - CreateRelayEntity(world, relay.Id()) - } -} - -func GetRelayState(worldId ecs.WorldId, relayId string) *RelayState { - sim := simulation.FindSimulation(worldId) - entry := sim.GetEntry(relayId) - if entry == nil { - return nil - } - state := system.RelayStateComponent.Get(entry) - return &RelayState{Id: relayId, Xh: state.Xh} -} diff --git a/deprecated/entities/signal_entity.go b/deprecated/entities/signal_entity.go deleted file mode 100644 index 444bfa7..0000000 --- a/deprecated/entities/signal_entity.go +++ /dev/null @@ -1,73 +0,0 @@ -package entities - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/system" -) - -func CreateSignal3XH1Entity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.Signal3XH1StateComponent, system.Signal3XH1FilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.Signal3XH1StateComponent.Set(e, system.NewSignal3XH1State()) - system.Signal3XH1FilamentStateComponent.Set(e, system.NewSignal3XH1FilamentState()) - return e -} - -func CreateSignal2XH1CdcEntity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.Signal2XH1StateComponent, system.Signal2XH1FilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.Signal2XH1StateComponent.Set(e, system.NewSignal2XH1CdcState()) - system.Signal2XH1FilamentStateComponent.Set(e, system.NewSignal2XH1FilamentState()) - return e -} -func CreateSignal2XH1CzqzEntity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.Signal2XH1StateComponent, system.Signal2XH1FilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.Signal2XH1StateComponent.Set(e, system.NewSignal2XH1CzqzState()) - system.Signal2XH1FilamentStateComponent.Set(e, system.NewSignal2XH1FilamentState()) - return e -} - -func CreateSignal3XH2Entity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.Signal3XH2StateComponent, system.Signal3XH2FilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.Signal3XH2StateComponent.Set(e, system.NewSignal3XH2State()) - system.Signal3XH2FilamentStateComponent.Set(e, system.NewSignal3XH2FilamentState()) - return e -} - -func CreateSignal3XH3Entity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.Signal3XH3StateComponent, system.Signal3XH3FilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.Signal3XH3StateComponent.Set(e, system.NewSignal3XH3State()) - system.Signal3XH3FilamentStateComponent.Set(e, system.NewSignal3XH3FilamentState()) - return e -} -func CreateSignal3XH4Entity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.Signal3XH4StateComponent, system.Signal3XH4FilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.Signal3XH4StateComponent.Set(e, system.NewSignal3XH4State()) - system.Signal3XH4FilamentStateComponent.Set(e, system.NewSignal3XH4FilamentState()) - return e -} -func CreateSignalJDXHEntity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.SignalJDXHStateComponent, system.SignalJDXHFilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.SignalJDXHStateComponent.Set(e, system.NewSignalJDXHState()) - system.SignalJDXHFilamentStateComponent.Set(e, system.NewSignalJDXHFilamentState()) - return e -} -func CreateSignalDCXHEntity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.SignalDCXHStateComponent, system.SignalDCXHFilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.SignalDCXHStateComponent.Set(e, system.NewSignalDCXHState()) - system.SignalDCXHFilamentStateComponent.Set(e, system.NewSignalDCXHFilamentState()) - return e -} -func CreateSignalJCKXHEntity(w ecs.World, signalId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.SignalJCKXHStateComponent, system.SignalJCKXHFilamentStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId}) - system.SignalJCKXHStateComponent.Set(e, system.NewSignalJCKXHState()) - system.SignalJCKXHFilamentStateComponent.Set(e, system.NewSignalJCKXHFilamentState()) - return e -} diff --git a/deprecated/entities/spks_entity.go b/deprecated/entities/spks_entity.go deleted file mode 100644 index fcd64d9..0000000 --- a/deprecated/entities/spks_entity.go +++ /dev/null @@ -1,14 +0,0 @@ -package entities - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/system" -) - -// CreateSpksCircuitEntity 创建人员防护按钮电路实体 -func CreateSpksCircuitEntity(w ecs.World, spksCircuitId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, system.SpksCircuitStateComponent) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: spksCircuitId}) - system.SpksCircuitStateComponent.Set(e, system.NewSpksCircuitState()) - return e -} diff --git a/deprecated/entities/switch_entity.go b/deprecated/entities/switch_entity.go deleted file mode 100644 index 1163849..0000000 --- a/deprecated/entities/switch_entity.go +++ /dev/null @@ -1,87 +0,0 @@ -package entities - -import ( - "time" - - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/simulation" - "joylink.club/rtsssimulation/deprecated/system" - "joylink.club/rtsssimulation/repository" -) - -type Position int - -type TurnoutState struct { - Id string - Normal bool - Reverse bool - Turning bool -} - -const ( - SK Position = iota //四开(不会起名字) - D //定位 - F //反位 -) - -// CreateSwitch2jzdj9Entity 双机zdj9 -// 默认定位 -func CreateSwitch2jzdj9Entity(w ecs.World, switchId string) *ecs.Entry { - e := w.Create(system.EntityIdentityComponent, - system.Switch2jZdj9StateComponent, - system.PercentageDeviceState1Component, - system.PercentageDeviceState2Component) - system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: switchId}) - //电路 - system.Switch2jZdj9StateComponent.Set(e, system.NewSwitch2jZdj9State()) - //J1 - j1 := system.NewPercentageDeviceStateM() //定位 - system.PercentageDeviceState1Component.Set(e, j1) - //J2 - j2 := system.NewPercentageDeviceStateM() //定位 - system.PercentageDeviceState2Component.Set(e, j2) - return e -} - -func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout) []*ecs.Entry { - var entries []*ecs.Entry - for _, turnout := range turnouts { - if len(turnout.RelayGroups()) == 0 { - continue - } - entries = append(entries, CreateSwitch2jzdj9Entity(world, turnout.Id())) - } - return entries -} - -func TurnToNormal(worldId ecs.WorldId, turnoutId string) { - sim := simulation.FindSimulation(worldId) - system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true) - system.Switch2jZdj9DriveDc(sim.World(), turnoutId, true) - go func() { - <-time.After(5 * time.Second) - system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false) - system.Switch2jZdj9DriveDc(sim.World(), turnoutId, false) - }() -} - -func TurnToReverse(worldId ecs.WorldId, turnoutId string) { - sim := simulation.FindSimulation(worldId) - system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true) - system.Switch2jZdj9DriveFc(sim.World(), turnoutId, true) - go func() { - <-time.After(5 * time.Second) - system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false) - system.Switch2jZdj9DriveFc(sim.World(), turnoutId, false) - }() -} - -func GetTurnoutState(worldId ecs.WorldId, turnoutId string) *TurnoutState { - sim := simulation.FindSimulation(worldId) - entry := sim.GetEntry(turnoutId) - if entry == nil { - return nil - } - state := system.Switch2jZdj9StateComponent.Get(entry) - return &TurnoutState{Id: turnoutId, Normal: state.IsNormal(), Reverse: state.IsReverse(), Turning: state.IsTurning()} -} diff --git a/deprecated/simulation/simulation.go b/deprecated/simulation/simulation.go deleted file mode 100644 index 77a1d48..0000000 --- a/deprecated/simulation/simulation.go +++ /dev/null @@ -1,55 +0,0 @@ -package simulation - -import ( - "sync" - - "joylink.club/ecs" - "joylink.club/rtsssimulation/repository" -) - -var ( - simulationManager = make(map[ecs.WorldId]*Simulation) -) - -type Simulation struct { - world ecs.World - repo *repository.Repository - entityMap sync.Map -} - -func (s *Simulation) World() ecs.World { - return s.world -} - -func (s *Simulation) Repo() *repository.Repository { - return s.repo -} - -func (s *Simulation) AddEntry(id string, entity *ecs.Entry) { - s.entityMap.Store(id, entity) -} - -func (s *Simulation) GetEntry(id string) *ecs.Entry { - e, ok := s.entityMap.Load(id) - if ok { - return e.(*ecs.Entry) - } - return nil -} - -func CreateSimulation(repo *repository.Repository, world ecs.World) *Simulation { - sim := &Simulation{ - world: world, - repo: repo, - } - simulationManager[world.Id()] = sim - return sim -} - -func DestroySimulation(id ecs.WorldId) { - delete(simulationManager, id) -} - -func FindSimulation(id ecs.WorldId) *Simulation { - return simulationManager[id] -} diff --git a/deprecated/simulation/world/config.go b/deprecated/simulation/world/config.go deleted file mode 100644 index 496b8d4..0000000 --- a/deprecated/simulation/world/config.go +++ /dev/null @@ -1,21 +0,0 @@ -package world - -import ( - "time" - - "joylink.club/rtsssimulation/deprecated/system" - - "joylink.club/ecs" -) - -// WorldConfig 仿真world配置 -type WorldConfig struct { - //模型管理器,接收模型仓库管理器实例的指针 - ModelManager system.IModelManager - //world 系统 - Systems []ecs.ISystem - //world tick - Tick int - //world 起始时间 - InitTime time.Time -} diff --git a/deprecated/simulation/world/init.go b/deprecated/simulation/world/init.go deleted file mode 100644 index 8619149..0000000 --- a/deprecated/simulation/world/init.go +++ /dev/null @@ -1,204 +0,0 @@ -package world - -import ( - "time" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - "joylink.club/rtsssimulation/deprecated/entities" - "joylink.club/rtsssimulation/deprecated/simulation" - "joylink.club/rtsssimulation/deprecated/system" - "joylink.club/rtsssimulation/repository" -) - -func CreateSimulation(repo *repository.Repository) ecs.WorldId { - wc := &WorldConfig{ - Systems: []ecs.ISystem{system.NewSwitch2jZdj9System(), system.NewRelaySystem()}, - Tick: 200, - InitTime: time.Now(), - } - w := InitializeWorld(wc) - sim := simulation.CreateSimulation(repo, w) - //添加实体 - entities.CreateSystemTimerEntity(w, wc.InitTime) - initDeviceEntries(w, sim, repo) - //初始化组件 - InitComponent(w, repo) - //添加监听器 - system.Switch2jzdj9AddListeners(w) - system.RelayAddListeners(w) - //启动 - w.StartUp() - return w.Id() -} - -func initDeviceEntries(w ecs.World, sim *simulation.Simulation, repo *repository.Repository) { - // 初始化道岔 - for _, turnout := range repo.TurnoutList() { - if len(turnout.RelayGroups()) == 0 { - continue - } - sim.AddEntry(turnout.Id(), entities.CreateSwitch2jzdj9Entity(w, turnout.Id())) - } - // 初始化继电器 - for _, relay := range repo.RelayList() { - sim.AddEntry(relay.Id(), entities.CreateRelayEntity(w, relay.Id())) - } -} - -// InitializeWorld 初始化仿真world -func InitializeWorld(config *WorldConfig) ecs.World { - world := ecs.NewWorld(config.Tick) - // 添加系统 - world.AddSystem(system.NewTimerSystem()) - world.AddSystem(system.NewPercentageMovableSystem()) - for _, sys := range config.Systems { - world.AddSystem(sys) - } - // 添加内置实体 - entities.CreateSystemTimerEntity(world, config.InitTime) - entities.CreateModelStorageEntity(world, config.ModelManager) - // - return world -} - -func InitComponent(world ecs.World, repo *repository.Repository) { - query := ecs.NewQuery(filter.Contains(system.Switch2jZdj9StateComponent)) - query.Each(world, func(turnoutEntry *ecs.Entry) { - turnout := repo.FindTurnout(system.EntityIdentityComponent.Get(turnoutEntry).Id) - turnoutState := system.Switch2jZdj9StateComponent.Get(turnoutEntry) - { - relay := turnout.FindRelay("TDC", "DCJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.DCJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDC", "FCJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.FCJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDC", "YCJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.YCJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDC", "ZDBJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.ZDBJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDC", "ZFBJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.ZFBJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ1", "1DQJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J1_1DQJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ1", "BHJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J1_BHJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ1", "2DQJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J1_2DQJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ1", "1DQJF") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J1_1DQJF - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ1", "DBJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J1_DBJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ1", "FBJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J1_FBJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ1", "QDJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J1_QDJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ1", "ZBHJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J1_ZBHJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ2", "1DQJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J2_1DQJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ2", "BHJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J2_BHJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ2", "2DQJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J2_2DQJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ2", "1DQJF") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J2_1DQJF - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ2", "DBJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J2_DBJ - relayState.ResetNeedXh() - } - { - relay := turnout.FindRelay("TDFJ2", "FBJ") - relayEntry := system.FindEntityById(world, relay.Id()) - relayState := system.RelayStateComponent.Get(relayEntry) - relayState.Xh = turnoutState.J2_FBJ - relayState.ResetNeedXh() - } - }) -} diff --git a/deprecated/system/button_system.go b/deprecated/system/button_system.go deleted file mode 100644 index e39e0b9..0000000 --- a/deprecated/system/button_system.go +++ /dev/null @@ -1,59 +0,0 @@ -package system - -import ( - "joylink.club/ecs" - "joylink.club/ecs/filter" -) - -// ButtonState 广义按钮开关状态,开关有三个接点,分别为公共接点、常开点和常闭点 -type ButtonState struct { - //true-公共接点接通常开点,false-公共接点接通常闭点 - Ckd bool -} - -// ButtonSelfRestState 广义自复位按钮,复位状态 -type ButtonSelfRestState struct { - //自复位按钮保持按下剩余时间,ms - KeepAxTime int64 -} - -var ( - ButtonStateComponent = ecs.NewComponentType[ButtonState]() - ButtonSelfRestTag = ecs.NewComponentType[ButtonSelfRestState]() //自复位按钮标签 - ButtonNonRestTag = ecs.NewTag() //非自复位按钮标签 -) - -type ButtonSystem struct { - selfRestQuery *ecs.Query -} - -func NewButtonSystem() *ButtonSystem { - return &ButtonSystem{selfRestQuery: ecs.NewQuery(filter.Contains(ButtonStateComponent, ButtonSelfRestTag))} -} -func NewButtonState() *ButtonState { - return &ButtonState{Ckd: false} -} - -// Update world 执行 -func (me *ButtonSystem) Update(w ecs.World) { - me.selfRestQuery.Each(w, func(e *ecs.Entry) { - state := ButtonStateComponent.Get(e) - me.calculateSelfRest(w, e, state) - }) -} - -// 自复位按钮运算 -func (me *ButtonSystem) calculateSelfRest(w ecs.World, e *ecs.Entry, state *ButtonState) { - if state.Ckd { - reset := ButtonSelfRestTag.Get(e) - if reset.KeepAxTime > 0 { - reset.KeepAxTime -= int64(w.Tick()) - if reset.KeepAxTime < 0 { - reset.KeepAxTime = 0 - } - } - if reset.KeepAxTime <= 0 { - state.Ckd = false - } - } -} diff --git a/deprecated/system/dcb_system.go b/deprecated/system/dcb_system.go deleted file mode 100644 index 206367b..0000000 --- a/deprecated/system/dcb_system.go +++ /dev/null @@ -1,246 +0,0 @@ -package system - -import ( - "joylink.club/ecs" - "joylink.club/ecs/filter" -) - -// DcbCircuitState 门控箱电路 A---按钮 J---继电器 -type DcbCircuitState struct { - //下行站台门关闭继电器,true-继电器吸起 - XPCBJ bool - //ture-按钮开关接通常开点 - MKX5_PCB5A bool - //ture-按钮开关接通常开点 - MKX5_PCB5_MKXPL5A bool - //ture-按钮开关接通常开点 - MKX3_PCB3A bool - //ture-按钮开关接通常开点 - MKX3_PCB3_MKXPL3A bool - //ture-按钮开关接通常开点 - MKX1_PCB1A bool - //ture-按钮开关接通常开点 - MKX1_PCB1_MKXPL1A bool - - //下行站台门打开继电器,true-继电器吸起 - XPOBJ bool - //ture-按钮开关接通常开点 - MKX5_POB5A bool - //ture-按钮开关接通常开点 - MKX5_POB5_MKXPL5A bool - //ture-按钮开关接通常开点 - MKX3_POB3A bool - //ture-按钮开关接通常开点 - MKX3_POB3_MKXPL3A bool - //ture-按钮开关接通常开点 - MKX1_POB1A bool - //ture-按钮开关接通常开点 - MKX1_POB1_MKXPL1A bool - - //下行站台确认继电器,true-继电器吸起 - XPABJ bool - //ture-按钮开关接通常开点 - MKX5_PAB5A bool - //ture-按钮开关接通常开点 - MKX5_PAB5_MKXPL5A bool - //ture-按钮开关接通常开点 - MKX3_PAB3A bool - //ture-按钮开关接通常开点 - MKX3_PAB3_MKXPL3A bool - //ture-按钮开关接通常开点 - MKX1_PAB1A bool - //ture-按钮开关接通常开点 - MKX1_PAB1_MKXPL1A bool - - //上行站台门关闭继电器,true-继电器吸起 - SPCBJ bool - //ture-按钮开关接通常开点 - MKX6_PCB6A bool - //ture-按钮开关接通常开点 - MKX6_PCB6_MKXPL6A bool - //ture-按钮开关接通常开点 - MKX4_PCB4A bool - //ture-按钮开关接通常开点 - MKX4_PCB4_MKXPL4A bool - //ture-按钮开关接通常开点 - MKX2_PCB2A bool - //ture-按钮开关接通常开点 - MKX2_PCB2_MKXPL2A bool - - //上行站台门开门继电器,true-继电器吸起 - SPOBJ bool - //ture-按钮开关接通常开点 - MKX6_POB6A bool - //ture-按钮开关接通常开点 - MKX6_POB6_MKXPL6A bool - //ture-按钮开关接通常开点 - MKX4_POB4A bool - //ture-按钮开关接通常开点 - MKX4_POB4_MKXPL4A bool - //ture-按钮开关接通常开点 - MKX2_POB2A bool - //ture-按钮开关接通常开点 - MKX2_POB2_MKXPL2A bool - - //上行站台门开门继电器,true-继电器吸起 - SPABJ bool - //ture-按钮开关接通常开点 - MKX6_PAB6A bool - //ture-按钮开关接通常开点 - MKX6_PAB6_MKXPL6A bool - //ture-按钮开关接通常开点 - MKX4_PAB4A bool - //ture-按钮开关接通常开点 - MKX4_PAB4_MKXPL4A bool - //ture-按钮开关接通常开点 - MKX2_PAB2A bool - //ture-按钮开关接通常开点 - MKX2_PAB2_MKXPL2A bool -} - -var DcbCircuitStateComponent = ecs.NewComponentType[DcbCircuitState]() - -type DcbCircuitSystem struct { - query *ecs.Query -} - -func NewDcbCircuitState() *DcbCircuitState { - return &DcbCircuitState{ - //下行站台门关闭继电器,true-继电器吸起 - XPCBJ: false, - //ture-按钮开关接通常开点 - MKX5_PCB5A: false, - //ture-按钮开关接通常开点 - MKX5_PCB5_MKXPL5A: true, - //ture-按钮开关接通常开点 - MKX3_PCB3A: false, - //ture-按钮开关接通常开点 - MKX3_PCB3_MKXPL3A: true, - //ture-按钮开关接通常开点 - MKX1_PCB1A: false, - //ture-按钮开关接通常开点 - MKX1_PCB1_MKXPL1A: true, - - //下行站台门打开继电器,true-继电器吸起 - XPOBJ: false, - //ture-按钮开关接通常开点 - MKX5_POB5A: false, - //ture-按钮开关接通常开点 - MKX5_POB5_MKXPL5A: true, - //ture-按钮开关接通常开点 - MKX3_POB3A: false, - //ture-按钮开关接通常开点 - MKX3_POB3_MKXPL3A: true, - //ture-按钮开关接通常开点 - MKX1_POB1A: false, - //ture-按钮开关接通常开点 - MKX1_POB1_MKXPL1A: true, - - //下行站台确认继电器,true-继电器吸起 - XPABJ: false, - //ture-按钮开关接通常开点 - MKX5_PAB5A: false, - //ture-按钮开关接通常开点 - MKX5_PAB5_MKXPL5A: true, - //ture-按钮开关接通常开点 - MKX3_PAB3A: false, - //ture-按钮开关接通常开点 - MKX3_PAB3_MKXPL3A: true, - //ture-按钮开关接通常开点 - MKX1_PAB1A: false, - //ture-按钮开关接通常开点 - MKX1_PAB1_MKXPL1A: true, - - //上行站台门关闭继电器,true-继电器吸起 - SPCBJ: false, - //ture-按钮开关接通常开点 - MKX6_PCB6A: false, - //ture-按钮开关接通常开点 - MKX6_PCB6_MKXPL6A: true, - //ture-按钮开关接通常开点 - MKX4_PCB4A: false, - //ture-按钮开关接通常开点 - MKX4_PCB4_MKXPL4A: true, - //ture-按钮开关接通常开点 - MKX2_PCB2A: false, - //ture-按钮开关接通常开点 - MKX2_PCB2_MKXPL2A: true, - - //上行站台门开门继电器,true-继电器吸起 - SPOBJ: false, - //ture-按钮开关接通常开点 - MKX6_POB6A: false, - //ture-按钮开关接通常开点 - MKX6_POB6_MKXPL6A: true, - //ture-按钮开关接通常开点 - MKX4_POB4A: false, - //ture-按钮开关接通常开点 - MKX4_POB4_MKXPL4A: true, - //ture-按钮开关接通常开点 - MKX2_POB2A: false, - //ture-按钮开关接通常开点 - MKX2_POB2_MKXPL2A: true, - - //上行站台门开门继电器,true-继电器吸起 - SPABJ: false, - //ture-按钮开关接通常开点 - MKX6_PAB6A: false, - //ture-按钮开关接通常开点 - MKX6_PAB6_MKXPL6A: true, - //ture-按钮开关接通常开点 - MKX4_PAB4A: false, - //ture-按钮开关接通常开点 - MKX4_PAB4_MKXPL4A: true, - //ture-按钮开关接通常开点 - MKX2_PAB2A: false, - //ture-按钮开关接通常开点 - MKX2_PAB2_MKXPL2A: true, - } -} -func NewDcbCircuitSystem() *DcbCircuitSystem { - return &DcbCircuitSystem{query: ecs.NewQuery(filter.Contains(DcbCircuitStateComponent))} -} - -// Update world 执行 -func (me *DcbCircuitSystem) Update(w ecs.World) { - me.query.Each(w, func(e *ecs.Entry) { - state := DcbCircuitStateComponent.Get(e) - // - me.calculateXPCBJ(state) - me.calculateXPOBJ(state) - me.calculateXPABJ(state) - me.calculateSPCBJ(state) - me.calculateSPOBJ(state) - me.calculateSPABJ(state) - }) -} -func (me *DcbCircuitSystem) calculateXPCBJ(state *DcbCircuitState) { - state.XPCBJ = state.MKX5_PCB5A && state.MKX5_PCB5_MKXPL5A || - state.MKX3_PCB3A && state.MKX3_PCB3_MKXPL3A || - state.MKX1_PCB1A && state.MKX1_PCB1_MKXPL1A -} -func (me *DcbCircuitSystem) calculateXPOBJ(state *DcbCircuitState) { - state.XPOBJ = state.MKX5_POB5A && state.MKX5_POB5_MKXPL5A || - state.MKX3_POB3A && state.MKX3_POB3_MKXPL3A || - state.MKX1_POB1A && state.MKX1_POB1_MKXPL1A -} -func (me *DcbCircuitSystem) calculateXPABJ(state *DcbCircuitState) { - state.XPABJ = state.MKX5_PAB5A && state.MKX5_PAB5_MKXPL5A || - state.MKX3_PAB3A && state.MKX3_PAB3_MKXPL3A || - state.MKX1_PAB1A && state.MKX1_PAB1_MKXPL1A -} -func (me *DcbCircuitSystem) calculateSPCBJ(state *DcbCircuitState) { - state.SPCBJ = state.MKX6_PCB6A && state.MKX6_PCB6_MKXPL6A || - state.MKX4_PCB4A && state.MKX4_PCB4_MKXPL4A || - state.MKX2_PCB2A && state.MKX2_PCB2_MKXPL2A -} -func (me *DcbCircuitSystem) calculateSPOBJ(state *DcbCircuitState) { - state.SPOBJ = state.MKX6_POB6A && state.MKX6_POB6_MKXPL6A || - state.MKX4_POB4A && state.MKX4_POB4_MKXPL4A || - state.MKX2_POB2A && state.MKX2_POB2_MKXPL2A -} -func (me *DcbCircuitSystem) calculateSPABJ(state *DcbCircuitState) { - state.SPABJ = state.MKX6_PAB6A && state.MKX6_PAB6_MKXPL6A || - state.MKX4_PAB4A && state.MKX4_PAB4_MKXPL4A || - state.MKX2_PAB2A && state.MKX2_PAB2_MKXPL2A -} diff --git a/deprecated/system/dubug_system.go b/deprecated/system/dubug_system.go deleted file mode 100644 index 5f0c6c2..0000000 --- a/deprecated/system/dubug_system.go +++ /dev/null @@ -1,29 +0,0 @@ -package system - -import ( - "fmt" - "joylink.club/ecs" - "log" -) - -type DebugSystem struct { -} - -func NewDebugSystem() *DebugSystem { - return &DebugSystem{} -} - -// Update world 执行 -func (debug *DebugSystem) Update(w ecs.World) { - zdj9Query.Each(w, func(entry *ecs.Entry) { - swId := EntityIdentityComponent.Get(entry).Id - swState := Switch2jZdj9StateComponent.Get(entry) - j1 := PercentageDeviceState1Component.Get(entry) - j2 := PercentageDeviceState2Component.Get(entry) - //log.Println(fmt.Sprintf("==>>2JZDJ9=%s QDJ=%t j1-2DQJ=%t j2-2DQJ=%t", swId, swState.J1_QDJ, swState.J1_2DQJ, swState.J2_2DQJ)) - //log.Println(fmt.Sprintf("==>>2JZDJ9=%s j1-1DQJ=%t j2-1DQJ=%t", swId, swState.J1_1DQJ, swState.J2_1DQJ)) - log.Println(fmt.Sprintf("==>>2JZDJ9=%s YCJ=%t DCJ=%t FCJ=%t j1-2DQJ=%t j2-2DQJ=%t ZDBJ=%t ZFBJ=%t j1=%d j2=%d", - swId, swState.YCJ, swState.DCJ, swState.FCJ, swState.J1_2DQJ, swState.J2_2DQJ, swState.ZDBJ, swState.ZFBJ, j1.P, j2.P)) - - }) -} diff --git a/deprecated/system/emp_system.go b/deprecated/system/emp_system.go deleted file mode 100644 index 71dfa86..0000000 --- a/deprecated/system/emp_system.go +++ /dev/null @@ -1,120 +0,0 @@ -package system - -import ( - "joylink.club/ecs" - "joylink.club/ecs/filter" -) - -//站台紧急停车按钮 - -type EmpsCircuitState struct { - //ture-按钮开关接通常开点 - XEMPFA bool - //ture-按钮开关接通常开点 - SEMPFA bool - //ture-灯亮 - XEMPD bool - //ture-灯亮 - SEMPD bool - //ture-按钮开关接通常开点 - SDA bool - //true-蜂鸣器响 - FMQ bool - //ture-按钮开关接通常开点 - QBA bool - //ture-继电器吸起,接通常开点 - XEMPJ bool - //ture-继电器吸起,接通常开点 - SEMPJ bool - //EMP-X ture-按钮开关接通常开点 - XEMPA bool - //EMP-S ture-按钮开关接通常开点 - SEMPA bool - //EMP1 ture-按钮开关接通常开点 - EMP1A bool - //EMP2 ture-按钮开关接通常开点 - EMP2A bool - //EMP3 ture-按钮开关接通常开点 - EMP3A bool - //EMP4 ture-按钮开关接通常开点 - EMP4A bool - //EMP5 ture-按钮开关接通常开点 - EMP5A bool - //EMP6 ture-按钮开关接通常开点 - EMP6A bool -} -type EmpsCircuitSystem struct { - query *ecs.Query -} - -func NewEmpsCircuitSystem() *EmpsCircuitSystem { - return &EmpsCircuitSystem{query: ecs.NewQuery(filter.Contains(EmpsCircuitStateComponent))} -} -func NewEmpsCircuitState() *EmpsCircuitState { - return &EmpsCircuitState{ - //ture-按钮开关接通常开点 - XEMPFA: false, - //ture-按钮开关接通常开点 - SEMPFA: false, - //ture-灯亮 - XEMPD: false, - //ture-灯亮 - SEMPD: false, - //ture-按钮开关接通常开点 - SDA: false, - //true-蜂鸣器响 - FMQ: false, - //ture-按钮开关接通常开点 - QBA: false, - //ture-继电器吸起,接通常开点 - XEMPJ: true, - //ture-继电器吸起,接通常开点 - SEMPJ: true, - //EMP-X ture-按钮开关接通常开点 - XEMPA: true, - //EMP-S ture-按钮开关接通常开点 - SEMPA: true, - //EMP1 ture-按钮开关接通常开点 - EMP1A: true, - //EMP2 ture-按钮开关接通常开点 - EMP2A: true, - //EMP3 ture-按钮开关接通常开点 - EMP3A: true, - //EMP4 ture-按钮开关接通常开点 - EMP4A: true, - //EMP5 ture-按钮开关接通常开点 - EMP5A: true, - //EMP6 ture-按钮开关接通常开点 - EMP6A: true, - } -} - -var ( - EmpsCircuitStateComponent = ecs.NewComponentType[EmpsCircuitState]() -) - -// Update world 执行 -func (me *EmpsCircuitSystem) Update(w ecs.World) { - me.query.Each(w, func(e *ecs.Entry) { - state := EmpsCircuitStateComponent.Get(e) - me.calculateXEMPJ(state) - me.calculateSEMPJ(state) - me.calculateEMPD(state) - me.calculateFMQ(state) - }) -} -func (me *EmpsCircuitSystem) calculateXEMPJ(state *EmpsCircuitState) { - state.XEMPJ = state.XEMPFA || state.XEMPJ && state.XEMPA && state.EMP5A && state.EMP3A && state.EMP1A -} -func (me *EmpsCircuitSystem) calculateSEMPJ(state *EmpsCircuitState) { - state.SEMPJ = state.SEMPFA || state.SEMPJ && state.SEMPA && state.EMP6A && state.EMP4A && state.EMP2A -} -func (me *EmpsCircuitSystem) calculateEMPD(state *EmpsCircuitState) { - state.XEMPD = state.SDA || !state.XEMPJ - state.SEMPD = state.SDA || !state.SEMPJ -} - -// 蜂鸣器运算 -func (me *EmpsCircuitSystem) calculateFMQ(state *EmpsCircuitState) { - state.FMQ = state.QBA && state.XEMPJ && state.SEMPJ || !state.QBA && (!state.XEMPJ || !state.SEMPJ) -} diff --git a/deprecated/system/event/button_event.go b/deprecated/system/event/button_event.go deleted file mode 100644 index 2ccf600..0000000 --- a/deprecated/system/event/button_event.go +++ /dev/null @@ -1,3 +0,0 @@ -package sysEvent - -//广义按钮相关事件 diff --git a/deprecated/system/event/relay_event.go b/deprecated/system/event/relay_event.go deleted file mode 100644 index 518fc0f..0000000 --- a/deprecated/system/event/relay_event.go +++ /dev/null @@ -1,27 +0,0 @@ -package sysEvent - -import "joylink.club/ecs" - -// RelayActionEvent 继电器动作事件 -// 由继电器实体系统产生,表示继电器吸合落下动作 -type RelayActionEvent struct { - //继电器id - Id string - //true -吸合 - Xh bool -} - -// RelayNeedChangeEvent 继电器状态须改变事件 -// 由电路系统运算发现某个继电器需要改变,则由电路系统产生该事件来通知对应继电器产生对应动作 -type RelayNeedChangeEvent struct { - //继电器id - Id string - //true -吸合 - Xh bool -} - -// RelayActionEventBus 继电器动作事件总线 -var RelayActionEventBus = ecs.NewEventType[RelayActionEvent]() - -// RelayNeedChangeEventBus 继电器状态须改变事件总线 -var RelayNeedChangeEventBus = ecs.NewEventType[RelayNeedChangeEvent]() diff --git a/deprecated/system/event/signal_3xh1_event.go b/deprecated/system/event/signal_3xh1_event.go deleted file mode 100644 index b67bc9b..0000000 --- a/deprecated/system/event/signal_3xh1_event.go +++ /dev/null @@ -1,18 +0,0 @@ -package sysEvent - -import "joylink.club/ecs" - -// Signal3XH1AspectChangedEvent 信号机3XH1显示状态变化事件 -type Signal3XH1AspectChangedEvent struct { - //信号机id - Id string - // 物理黄灯,true-亮 - U bool - // 物理绿灯,true-亮 - L bool - // 物理红灯,true-亮 - H bool -} - -// Signal3XH1AspectChangedEventBus 信号机3XH1显示状态变化事件总线 -var Signal3XH1AspectChangedEventBus = ecs.NewEventType[Signal3XH1AspectChangedEvent]() diff --git a/deprecated/system/model_umi.go b/deprecated/system/model_umi.go deleted file mode 100644 index 4631cb1..0000000 --- a/deprecated/system/model_umi.go +++ /dev/null @@ -1,30 +0,0 @@ -package system - -import ( - "joylink.club/rtsssimulation/repository" - "joylink.club/rtsssimulation/repository/model/proto" -) - -// system 视角的模型定义 - -type DeviceType = proto.DeviceType - -// IDeviceModel 仿真底层设备模型定义 -// 用户所有设备模型定义须实现该接口 -type IDeviceModel = repository.Identity - -// IRelayCRole 获取继电器在具体电路中的角色(组合类型、功能名称) -// 如信号机3XH-1电路中点灯继电器:组合类型-"3XH-1" 功能名称-"DDJ" -// 对应设备电路中有继电器的设备模型须实现该接口 -type IRelayCRole = repository.IRelayCRole - -// IModelManager 模型管理接口 -type IModelManager = repository.IModelManager - -///////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////// - -// IPsdModel 仿真底层屏蔽门模型 -// 用户所有屏蔽门模型定义须实现该接口 -type IPsdModel = repository.IPsdModel diff --git a/deprecated/system/percentage_system.go b/deprecated/system/percentage_system.go deleted file mode 100644 index c5e880c..0000000 --- a/deprecated/system/percentage_system.go +++ /dev/null @@ -1,98 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" -) - -// PercentageDeviceState 百分比设备 -// 起始位置p=0,终点位置p=100000,总路程100000 -type PercentageDeviceState struct { - //速度,矢量 - V int64 - //位置,[PD_L,PD_M] - P int64 -} - -func NewPercentageDeviceStateL() *PercentageDeviceState { - return &PercentageDeviceState{V: 0, P: PD_L} -} -func NewPercentageDeviceStateM() *PercentageDeviceState { - return &PercentageDeviceState{V: 0, P: PD_M} -} -func (me *PercentageDeviceState) isToL() bool { - return me.P <= PD_L -} -func (me *PercentageDeviceState) isToM() bool { - return me.P >= PD_M -} - -// GetRate 获取百分比即(P/(PD_M-PD_L))*100 -func (me *PercentageDeviceState) GetRate() int8 { - if me.P < PD_L { - me.P = PD_L - } - if me.P > PD_M { - me.P = PD_M - } - return int8((float64(me.P) / float64(PD_M)) * float64(100)) -} - -// SetRate 设置百分比即P=(PD_M-PD_L)*(rate/100) -func (me *PercentageDeviceState) SetRate(rate int8) { - if rate < 0 || rate > 100 { - panic(fmt.Sprintf("rate须在[0,100]中,rate=%d", rate)) - } - me.P = int64(float64(PD_M-PD_L) * (float64(rate) / float64(100))) -} - -// 百分比设备位置范围 -const ( - PD_L int64 = 0 - PD_M int64 = 100000 -) - -// PercentageDeviceStateComponent 一维移动的物体组件 -var PercentageDeviceStateComponent = ecs.NewComponentType[PercentageDeviceState]() -var PercentageDeviceState1Component = ecs.NewComponentType[PercentageDeviceState]() -var PercentageDeviceState2Component = ecs.NewComponentType[PercentageDeviceState]() - -type PercentageMovableSystem struct { - query *ecs.Query -} - -func NewPercentageMovableSystem() *PercentageMovableSystem { - return &PercentageMovableSystem{ - query: ecs.NewQuery(filter.Or(filter.Contains(PercentageDeviceStateComponent), filter.Contains(PercentageDeviceState1Component), filter.Contains(PercentageDeviceState2Component))), - } -} - -// Update world 执行 -func (me *PercentageMovableSystem) Update(w ecs.World) { - me.query.Each(w, func(e *ecs.Entry) { - if e.HasComponent(PercentageDeviceStateComponent) { - state := PercentageDeviceStateComponent.Get(e) - me.move(w, state) - } - if e.HasComponent(PercentageDeviceState1Component) { - state := PercentageDeviceState1Component.Get(e) - me.move(w, state) - } - if e.HasComponent(PercentageDeviceState2Component) { - state := PercentageDeviceState2Component.Get(e) - me.move(w, state) - } - - }) -} -func (me *PercentageMovableSystem) move(w ecs.World, state *PercentageDeviceState) { - state.P += state.V * int64(w.Tick()) - if state.P < PD_L { - state.P = PD_L - } - if state.P > PD_M { - state.P = PD_M - } -} diff --git a/deprecated/system/psd_system.go b/deprecated/system/psd_system.go deleted file mode 100644 index 984eebf..0000000 --- a/deprecated/system/psd_system.go +++ /dev/null @@ -1,416 +0,0 @@ -package system - -import ( - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// PsdDriveXGMJ 联锁驱动XGMJ -func PsdDriveXGMJ(w ecs.World, psdCircuitId string, lsDrive bool) bool { - psdEntry := FindEntityById(w, psdCircuitId) - if psdEntry == nil { - return false - } - psdState := PsdCircuitStateComponent.Get(psdEntry) - psdState.XGMLs = lsDrive - return true -} - -// PsdDriveSGMJ 联锁驱动SGMJ -func PsdDriveSGMJ(w ecs.World, psdCircuitId string, lsDrive bool) bool { - psdEntry := FindEntityById(w, psdCircuitId) - if psdEntry == nil { - return false - } - psdState := PsdCircuitStateComponent.Get(psdEntry) - psdState.SGMLs = lsDrive - return true -} - -// PsdDrive4XKMJ 联锁驱动4XKMJ -func PsdDrive4XKMJ(w ecs.World, psdCircuitId string, lsDrive bool) bool { - psdEntry := FindEntityById(w, psdCircuitId) - if psdEntry == nil { - return false - } - psdState := PsdCircuitStateComponent.Get(psdEntry) - psdState.G4XKMLs = lsDrive - return true -} - -// PsdDrive4SKMJ 联锁驱动4SKMJ -func PsdDrive4SKMJ(w ecs.World, psdCircuitId string, lsDrive bool) bool { - psdEntry := FindEntityById(w, psdCircuitId) - if psdEntry == nil { - return false - } - psdState := PsdCircuitStateComponent.Get(psdEntry) - psdState.G4SKMLs = lsDrive - return true -} - -// PsdDrive8XKMJ 联锁驱动8XKMJ -func PsdDrive8XKMJ(w ecs.World, psdCircuitId string, lsDrive bool) bool { - psdEntry := FindEntityById(w, psdCircuitId) - if psdEntry == nil { - return false - } - psdState := PsdCircuitStateComponent.Get(psdEntry) - psdState.G8XKMLs = lsDrive - return true -} - -// PsdDrive8SKMJ 联锁驱动8SKMJ -func PsdDrive8SKMJ(w ecs.World, psdCircuitId string, lsDrive bool) bool { - psdEntry := FindEntityById(w, psdCircuitId) - if psdEntry == nil { - return false - } - psdState := PsdCircuitStateComponent.Get(psdEntry) - psdState.G8SKMLs = lsDrive - return true -} - -////////////////////////////////////////////////////////////// - -// PsdCircuitState 站台门控制电路状态,Psd为车站所有屏蔽门子门的集合 -// 旁路继电器的工作原理是,当电路中的电流超过预定的阈值时,旁路继电器会自动断开电路,从而防止电路发生短路或过载等故障。 -type PsdCircuitState struct { - //关门继电器,true-吸合 - XGMJ bool - //true-联锁驱动 - XGMLs bool - //4编组开门继电器,true-吸合 - G4XKMJ bool - //true-联锁驱动 - G4XKMLs bool - //8编组开门继电器,true-吸合 - G8XKMJ bool - //true-联锁驱动 - G8XKMLs bool - //门关闭继电器,true-吸合 - XMGJ bool - //门旁路继电器,true-吸合 - XMPLJ bool - //车站下行侧屏蔽门开门码 - XOpenCode OpenCode - //关门继电器,true-吸合 - SGMJ bool - //true-联锁驱动 - SGMLs bool - //4编组开门继电器,true-吸合 - G4SKMJ bool - //true-联锁驱动 - G4SKMLs bool - //8编组开门继电器,true-吸合 - G8SKMJ bool - //true-联锁驱动 - G8SKMLs bool - //门关闭继电器,true-吸合 - SMGJ bool - //门旁路继电器,true-吸合 - SMPLJ bool - //车站上行侧屏蔽门开门码 - SOpenCode OpenCode -} - -// PsdCellState 车站屏蔽门子门 -type PsdCellState struct { - //屏蔽门打开的百分比,则0-完全关闭,100-完全打开 - Rate int8 - //关门操作被激活 - actClosing bool - //开门操作被激活 - actOpening bool -} - -// PsdTags 屏蔽门标签 -type PsdTags struct { - STag EntityTag //上行侧屏蔽门子门标签 - S4KmUpTag EntityTag //上行侧4编组运行方向上行时屏蔽门子门标签 - S4KmDownTag EntityTag //上行侧4编组运行方向下行时屏蔽门子门标签 - S8KmUpTag EntityTag //上行侧8编组运行方向上行时屏蔽门子门标签 - S8KmDownTag EntityTag //上行侧8编组运行方向下行时屏蔽门子门标签 - XTag EntityTag - X4KmUpTag EntityTag - X4KmDownTag EntityTag - X8KmUpTag EntityTag - X8KmDownTag EntityTag - queryMap map[EntityTag]*ecs.Query -} - -// 屏蔽门子门查询 -func (me *PsdTags) psdCellsQuery(tag EntityTag) *ecs.Query { - if query, ok := me.queryMap[tag]; !ok { - query = ecs.NewQuery(filter.Contains(tag)) - me.queryMap[tag] = query - } - return me.queryMap[tag] -} - -// PsdsCircuitSystem 站台门电路系统 -type PsdsCircuitSystem struct { -} - -func NewPsdsCircuitSystem() *PsdsCircuitSystem { - return &PsdsCircuitSystem{} -} -func NewPsdTags() *PsdTags { - return &PsdTags{S4KmUpTag: NewTag(), S8KmDownTag: NewTag(), S4KmDownTag: NewTag(), S8KmUpTag: NewTag(), STag: NewTag(), - XTag: NewTag(), X4KmDownTag: NewTag(), X4KmUpTag: NewTag(), X8KmDownTag: NewTag(), X8KmUpTag: NewTag(), - queryMap: make(map[EntityTag]*ecs.Query, 10)} -} -func NewPsdCellState() *PsdCellState { - return &PsdCellState{} -} -func NewPsdCircuitState() *PsdCircuitState { - return &PsdCircuitState{XMGJ: true, SMGJ: true, XMPLJ: false, XGMJ: false, XOpenCode: OpenCodeNon, G8SKMJ: false, - G4SKMJ: false, G4XKMJ: false, G8XKMJ: false, SGMJ: false, SMPLJ: false, SOpenCode: OpenCodeNon} -} - -var ( - PsdCircuitStateComponent = ecs.NewComponentType[PsdCircuitState]() - PsdCellStateComponent = ecs.NewComponentType[PsdCellState]() - PsdTagsComponent = ecs.NewComponentType[PsdTags]() - psdCircuitQuery = ecs.NewQuery(filter.Contains(PsdCircuitStateComponent)) - psdCellQuery = ecs.NewQuery(filter.Contains(PsdCellStateComponent)) -) - -// OpenCode 开门码 -type OpenCode int8 - -// 开门码枚举 -const ( - OpenCodeNon OpenCode = iota //无效开门码 - OpenCodeUp //运行方向为上行的开门码 - OpenCodeDown //运行方向为下行的开门码 -) -const ( - PsdCellRateClosed int8 = 0 - PsdCellRateOpened int8 = 100 -) - -// PSD组合类型和继电器功能名称 -const ( - PSD_GT = "PSD" - PSD_XGMJ = "XGMJ" - PSD_4XKMJ = "4XKMJ" - PSD_8XKMJ = "8XKMJ" - PSD_XMGJ = "XMGJ" - PSD_XMPLJ = "XMPLJ" - PSD_SGMJ = "SGMJ" - PSD_4SKMJ = "4SKMJ" - PSD_8SKMJ = "8SKMJ" - PSD_SMGJ = "SMGJ" - PSD_SMPLJ = "SMPLJ" -) - -// Update world 执行 -func (me *PsdsCircuitSystem) Update(w ecs.World) { - - // - psdCircuitQuery.Each(w, func(psdCircuitEntry *ecs.Entry) { - me.calculateMG(w, psdCircuitEntry) - me.calculateGM(w, psdCircuitEntry) - me.calculate4KM(w, psdCircuitEntry) - me.calculate8KM(w, psdCircuitEntry) - me.calculateCellAct(w, psdCircuitEntry) - me.calculateCellMove(w, psdCircuitEntry) - }) -} - -// 屏蔽门子门移动运算,暂定门从全关到全开耗时2000ms,则v=50/ms -func (me *PsdsCircuitSystem) calculateCellMove(w ecs.World, psdCircuitEntry *ecs.Entry) { - psdTags := PsdTagsComponent.Get(psdCircuitEntry) - psdTags.psdCellsQuery(psdTags.XTag).Each(w, func(cellEntry *ecs.Entry) { - cellState := PsdCellStateComponent.Get(cellEntry) - cellMove := PercentageDeviceStateComponent.Get(cellEntry) - if cellState.actClosing { - cellMove.V = -50 - } - if cellState.actOpening { - cellMove.V = 50 - } - cellState.Rate = cellMove.GetRate() - }) - psdTags.psdCellsQuery(psdTags.STag).Each(w, func(cellEntry *ecs.Entry) { - cellState := PsdCellStateComponent.Get(cellEntry) - cellMove := PercentageDeviceStateComponent.Get(cellEntry) - if cellState.actClosing { - cellMove.V = -50 - } - if cellState.actOpening { - cellMove.V = 50 - } - cellState.Rate = cellMove.GetRate() - }) -} - -// 屏蔽门子门移动运算,暂定门从全关到全开耗时2000ms,则v=50/ms -func (me *PsdsCircuitSystem) calculateCellAct(w ecs.World, psdCircuitEntry *ecs.Entry) { - state := PsdCircuitStateComponent.Get(psdCircuitEntry) - psdTags := PsdTagsComponent.Get(psdCircuitEntry) - //关门 - if state.XGMJ { - psdTags.psdCellsQuery(psdTags.XTag).Each(w, func(cellEntry *ecs.Entry) { - cellState := PsdCellStateComponent.Get(cellEntry) - cellState.actClosing = true - cellState.actOpening = false - }) - } - if state.SGMJ { - psdTags.psdCellsQuery(psdTags.STag).Each(w, func(cellEntry *ecs.Entry) { - cellState := PsdCellStateComponent.Get(cellEntry) - cellState.actClosing = true - cellState.actOpening = false - }) - } - //开门 - if state.G4XKMJ { - var cellTag EntityTag = nil - if state.XOpenCode == OpenCodeUp { - cellTag = psdTags.X4KmUpTag - } else if state.XOpenCode == OpenCodeDown { - cellTag = psdTags.X4KmDownTag - } - if cellTag != nil { - psdTags.psdCellsQuery(cellTag).Each(w, func(cellEntry *ecs.Entry) { - cellState := PsdCellStateComponent.Get(cellEntry) - cellState.actClosing = false - cellState.actOpening = true - }) - } - } - if state.G4SKMJ { - var cellTag EntityTag = nil - if state.SOpenCode == OpenCodeUp { - cellTag = psdTags.S4KmUpTag - } else if state.SOpenCode == OpenCodeDown { - cellTag = psdTags.S4KmDownTag - } - if cellTag != nil { - psdTags.psdCellsQuery(cellTag).Each(w, func(cellEntry *ecs.Entry) { - cellState := PsdCellStateComponent.Get(cellEntry) - cellState.actClosing = false - cellState.actOpening = true - }) - } - } - if state.G8XKMJ { - var cellTag EntityTag = nil - if state.XOpenCode == OpenCodeUp { - cellTag = psdTags.X8KmUpTag - } else if state.XOpenCode == OpenCodeDown { - cellTag = psdTags.X8KmDownTag - } - if cellTag != nil { - psdTags.psdCellsQuery(cellTag).Each(w, func(cellEntry *ecs.Entry) { - cellState := PsdCellStateComponent.Get(cellEntry) - cellState.actClosing = false - cellState.actOpening = true - }) - } - } - if state.G8SKMJ { - var cellTag EntityTag = nil - if state.SOpenCode == OpenCodeUp { - cellTag = psdTags.S8KmUpTag - } else if state.SOpenCode == OpenCodeDown { - cellTag = psdTags.S8KmDownTag - } - if cellTag != nil { - psdTags.psdCellsQuery(cellTag).Each(w, func(cellEntry *ecs.Entry) { - cellState := PsdCellStateComponent.Get(cellEntry) - cellState.actClosing = false - cellState.actOpening = true - }) - } - } -} - -func (me *PsdsCircuitSystem) calculateMG(w ecs.World, psdCircuitEntry *ecs.Entry) { - state := PsdCircuitStateComponent.Get(psdCircuitEntry) - psdTags := PsdTagsComponent.Get(psdCircuitEntry) - // - isXMG := true - psdTags.psdCellsQuery(psdTags.XTag).Each(w, func(cellEntry *ecs.Entry) { - if isXMG { - cellState := PsdCellStateComponent.Get(cellEntry) - if cellState.Rate > PsdCellRateClosed { - isXMG = false - } - } - }) - if isXMG != state.XMGJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_XMGJ, isXMG); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } - // - isSMG := true - psdTags.psdCellsQuery(psdTags.STag).Each(w, func(cellEntry *ecs.Entry) { - if isSMG { - cellState := PsdCellStateComponent.Get(cellEntry) - if cellState.Rate > PsdCellRateClosed { - isSMG = false - } - } - }) - if isSMG != state.SMGJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_SMGJ, isSMG); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} - -func (me *PsdsCircuitSystem) calculateGM(w ecs.World, psdCircuitEntry *ecs.Entry) { - state := PsdCircuitStateComponent.Get(psdCircuitEntry) - //关门继电器:联锁励磁||自闭保持 - isXGM := state.XGMLs || state.XGMJ && !state.G4XKMJ && !state.G8XKMJ - isSGM := state.SGMLs || state.SGMJ && !state.G4SKMJ && !state.G8SKMJ - if isXGM != state.XGMJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_XGMJ, isXGM); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } - if isSGM != state.SGMJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_SGMJ, isSGM); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} - -func (me *PsdsCircuitSystem) calculate4KM(w ecs.World, psdCircuitEntry *ecs.Entry) { - //4编组开门继电器:联锁励磁||自闭保持 - state := PsdCircuitStateComponent.Get(psdCircuitEntry) - is4XKM := state.G4XKMLs || state.G4XKMJ && !state.G8XKMJ && !state.XGMJ - is4SKM := state.G4SKMLs || state.G4SKMJ && !state.G8SKMJ && !state.SGMJ - if is4XKM != state.G4XKMJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_4XKMJ, is4XKM); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } - if is4SKM != state.G4SKMJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_4SKMJ, is4SKM); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} - -func (me *PsdsCircuitSystem) calculate8KM(w ecs.World, psdCircuitEntry *ecs.Entry) { - //8编组开门继电器:联锁励磁||自闭保持 - state := PsdCircuitStateComponent.Get(psdCircuitEntry) - is8XKM := state.G8XKMLs || state.G8XKMJ && !state.G4XKMJ && !state.XGMJ - is8SKM := state.G8SKMLs || state.G8SKMJ && !state.G4SKMJ && !state.SGMJ - if is8XKM != state.G8XKMJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_8XKMJ, is8XKM); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } - if is8SKM != state.G8SKMJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_8SKMJ, is8SKM); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/relay_system.go b/deprecated/system/relay_system.go deleted file mode 100644 index 67274cf..0000000 --- a/deprecated/system/relay_system.go +++ /dev/null @@ -1,78 +0,0 @@ -package system - -import ( - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// RelayState 继电器有两个线圈1-2,3-4 -// 电流方向1->2,3->4或4->3,2->1时产生同向磁场 -type RelayState struct { - //继电器是否吸合 - //true-吸合 - Xh bool - //true-进行吸合动作,false-进行落下动作 - needXh bool -} - -func NewRelayState() *RelayState { - return &RelayState{Xh: false, needXh: false} -} - -// ResetNeedXh 使needXh同Xh -func (me *RelayState) ResetNeedXh() { - me.needXh = me.Xh -} - -// RelayStateComponent 继电器状态组件 -var RelayStateComponent = ecs.NewComponentType[RelayState]() - -// RelaySystem 继电器系统 -type RelaySystem struct { - relayQuery *ecs.Query -} - -// 继电器常量定义 -const ( - //JWXC-1700无极缓放继电器,缓放时间ms - JWXC_1700_RELEASE_TIME int64 = 300 - //JWJXC-H125/80无极加强缓放继电器,缓放时间ms - JWJXC_H125_80_RELEASE_TIME int64 = 300 - //整流式缓放继电器,缓放时间ms - JZXC_H18_RELEASE_TIME int64 = 300 - //JPXC-1000偏极继电器,缓放时间ms - JPXC_1000_RELEASE_TIME int64 = 500 -) - -func NewRelaySystem() *RelaySystem { - return &RelaySystem{ - relayQuery: ecs.NewQuery(filter.Contains(EntityIdentityComponent, RelayStateComponent)), - } -} - -func RelayAddListeners(w ecs.World) { - sysEvent.RelayNeedChangeEventBus.Subscribe(w, RelayNeedChangeEventProcessor) -} - -// RelayNeedChangeEventProcessor 继电器须要改变事件处理 -var RelayNeedChangeEventProcessor = func(w ecs.World, event sysEvent.RelayNeedChangeEvent) { - //log.Println("==>>收到继电器须改变事件:id = ", event.ButtonCode, " xh = ", event.Xh) - relayEntry := FindEntityById(w, event.Id) - relayState := RelayStateComponent.Get(relayEntry) - relayState.needXh = event.Xh -} - -// Update world 执行 -func (me *RelaySystem) Update(w ecs.World) { - me.relayQuery.Each(w, func(e *ecs.Entry) { - relayState := RelayStateComponent.Get(e) - //实际与目标不符,须动作 - if relayState.needXh != relayState.Xh { - relayState.Xh = relayState.needXh - //发送动作事件 - relayId := EntityIdentityComponent.Get(e).Id - sysEvent.RelayActionEventBus.Publish(w, &sysEvent.RelayActionEvent{Id: relayId, Xh: relayState.Xh}) - } - }) -} diff --git a/deprecated/system/signal_2xh1_system.go b/deprecated/system/signal_2xh1_system.go deleted file mode 100644 index b172c80..0000000 --- a/deprecated/system/signal_2xh1_system.go +++ /dev/null @@ -1,116 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// Signal2XH1State 电路状态:**信号机2XH-1(红-绿) 出段(场)信号机 或 **出站区间阻挡信号机 -type Signal2XH1State struct { - // 物理绿灯,true-亮 - L bool - // 物理红灯,true-亮 - H bool - // 点灯继电器,true-吸合,常态落下表示逻辑点灯 - DDJ bool - //灯丝继电器,true-吸合 - DJ bool - //列车信号继电器,true-吸合 - LXJ bool -} - -// Signal2XH1FilamentState 信号机2XH-1 灯丝状态 -type Signal2XH1FilamentState struct { - // 物理绿灯,true-灯丝正常 - Lf bool - // 物理红灯,true-灯丝正常 - Hf bool -} - -func NewSignal2XH1FilamentState() *Signal2XH1FilamentState { - return &Signal2XH1FilamentState{Lf: true, Hf: true} -} - -// NewSignal2XH1CdcState 出段(场)信号机 -func NewSignal2XH1CdcState() *Signal2XH1State { - return &Signal2XH1State{DDJ: false, LXJ: false, DJ: true, L: false, H: true} -} - -// NewSignal2XH1CzqzState 出站区间阻挡信号机 -func NewSignal2XH1CzqzState() *Signal2XH1State { - return &Signal2XH1State{DDJ: true, LXJ: false, DJ: false, L: false, H: false} -} - -var Signal2XH1StateComponent = ecs.NewComponentType[Signal2XH1State]() -var Signal2XH1FilamentStateComponent = ecs.NewComponentType[Signal2XH1FilamentState]() -var signal2XH1Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal2XH1StateComponent)) - -type Signal2XH1System struct { -} - -func NewSignal2XH1System() *Signal2XH1System { - return &Signal2XH1System{} -} - -// Update world 执行 -func (me *Signal2XH1System) Update(w ecs.World) { - signal2XH1Query.Each(w, func(entry *ecs.Entry) { - state := Signal2XH1StateComponent.Get(entry) - filament := Signal2XH1FilamentStateComponent.Get(entry) - me.calculateL(state, filament) - me.calculateH(state, filament) - me.calculateDJ(w, entry, state, filament) - }) -} - -// Signal2XH1RelayActionEventProcessor 继电器动作事件处理 -// 将继电器动作的结果同步到系统 -var Signal2XH1RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //根据event来更新Signal2XH1State中对应继电器的状态 - signal2XH1Query.Each(w, func(e *ecs.Entry) { - signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := signalModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - if relayGroup == SIGNAL_2XH1 { - state := Signal2XH1StateComponent.Get(e) - switch relayName { - case SIGNAL_DDJ: - state.DDJ = event.Xh - case SIGNAL_DJ: - state.DJ = event.Xh - case SIGNAL_LXJ: - state.LXJ = event.Xh - default: - panic(fmt.Sprintf("Signal2XH1的模型[%s]中继电器功能名称[%s]无法识别", signalModel.Id(), relayName)) - } - } else { - panic(fmt.Sprintf("Signal2XH1的模型[%s]中继电器组合类型[%s]无法识别", signalModel.Id(), relayGroup)) - } - } - } else { - panic("Signal2XH1的模型未实现接口umi.IRelayCRoler") - } - }) -} - -func (me *Signal2XH1System) calculateL(state *Signal2XH1State, filament *Signal2XH1FilamentState) { - isL := !state.DDJ && state.LXJ && filament.Lf - state.L = isL -} -func (me *Signal2XH1System) calculateH(state *Signal2XH1State, filament *Signal2XH1FilamentState) { - isH := !state.DDJ && !state.LXJ && filament.Hf - state.H = isH -} -func (me *Signal2XH1System) calculateDJ(w ecs.World, e *ecs.Entry, state *Signal2XH1State, filament *Signal2XH1FilamentState) { - isDJ := !state.DDJ && state.LXJ && filament.Lf || !state.DDJ && !state.LXJ && filament.Hf - //通知继电器进行动作 - if state.DJ != isDJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_2XH1, SIGNAL_DJ, isDJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/signal_3xh1_system.go b/deprecated/system/signal_3xh1_system.go deleted file mode 100644 index 472de90..0000000 --- a/deprecated/system/signal_3xh1_system.go +++ /dev/null @@ -1,195 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// 信号机电路继电器组合类型和功能名称常量 -// 其他信号机的一并定义于此 -const ( - //继电器组合类型 - SIGNAL_3XH1 = "3XH-1" - SIGNAL_3XH2 = "3XH-2" - SIGNAL_3XH3 = "3XH-3" - SIGNAL_3XH4 = "3XH-4" - SIGNAL_2XH1 = "2XH-1" - SIGNAL_JDXH = "JDXH" - SIGNAL_DCXH = "DCXH" - SIGNAL_JCKXH = "JCKXH" - //继电器功能名称 - SIGNAL_DDJ = "DDJ" - SIGNAL_DJ = "DJ" - SIGNAL_2DJ = "2DJ" - SIGNAL_LXJ = "LXJ" - SIGNAL_YXJ = "YXJ" - SIGNAL_ZXJ = "ZXJ" - SIGNAL_DXJ = "DXJ" -) - -// Signal3XH1State 电路状态:信号机3XH-1(红-绿-黄) 道岔防护信号机(三显示不封灯,有单黄显示、带引导) -type Signal3XH1State struct { - // 物理黄灯,true-亮 - U bool - // 物理绿灯,true-亮 - L bool - // 物理红灯,true-亮 - H bool - // 点灯继电器,true-吸合,常态落下表示逻辑点灯 - DDJ bool - //2DJ灯丝继电器,true-吸合 - EDJ bool - //灯丝继电器,true-吸合 - DJ bool - //列车信号继电器,true-吸合 - LXJ bool - //引导信号继电器,true-吸合 - YXJ bool - //开通正线信号继电器,true-吸合 - ZXJ bool -} - -// Signal3XH1FilamentState 信号机3XH-1 灯丝状态 -type Signal3XH1FilamentState struct { - // 物理黄灯,true-灯丝正常 - Uf bool - // 物理绿灯,true-灯丝正常 - Lf bool - // 物理红灯,true-灯丝正常 - Hf bool -} - -func NewSignal3XH1FilamentState() *Signal3XH1FilamentState { - return &Signal3XH1FilamentState{Uf: true, Lf: true, Hf: true} -} -func NewSignal3XH1State() *Signal3XH1State { - return &Signal3XH1State{ - U: false, - L: false, - H: false, - DDJ: true, - EDJ: false, - DJ: false, - LXJ: false, - YXJ: false, - ZXJ: false, - } -} - -// Signal3XH1StateComponent 信号机3XH-1电路状态组件 -var Signal3XH1StateComponent = ecs.NewComponentType[Signal3XH1State]() -var Signal3XH1FilamentStateComponent = ecs.NewComponentType[Signal3XH1FilamentState]() -var signal3XH1Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal3XH1StateComponent)) - -type Signal3XH1System struct { -} - -func NewSignal3XH1System() *Signal3XH1System { - return &Signal3XH1System{} -} - -// Signal3XH1RelayActionEventProcessor 继电器动作事件处理 -// 将继电器动作的结果同步到系统 -var Signal3XH1RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //根据event来更新Signal3XH1State中对应继电器的状态 - signal3XH1Query.Each(w, func(e *ecs.Entry) { - signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := signalModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - if relayGroup == SIGNAL_3XH1 { - state := Signal3XH1StateComponent.Get(e) - switch relayName { - case SIGNAL_DDJ: - state.DDJ = event.Xh - case SIGNAL_DJ: - state.DJ = event.Xh - case SIGNAL_2DJ: - state.EDJ = event.Xh - case SIGNAL_LXJ: - state.LXJ = event.Xh - case SIGNAL_YXJ: - state.YXJ = event.Xh - case SIGNAL_ZXJ: - state.ZXJ = event.Xh - default: - panic(fmt.Sprintf("Signal3XH1的模型[%s]中继电器功能名称[%s]无法识别", signalModel.Id(), relayName)) - } - } else { - panic(fmt.Sprintf("Signal3XH1的模型[%s]中继电器组合类型[%s]无法识别", signalModel.Id(), relayGroup)) - } - } - } else { - panic("Signal3XH1的模型未实现接口umi.IRelayCRoler") - } - }) -} - -// Update world 执行 -func (me *Signal3XH1System) Update(w ecs.World) { - signal3XH1Query.Each(w, func(e *ecs.Entry) { - signal3XH1State := Signal3XH1StateComponent.Get(e) - filament := Signal3XH1FilamentStateComponent.Get(e) - // - me.calculateU(w, signal3XH1State, filament) - me.calculateL(w, signal3XH1State, filament) - me.calculateH(w, signal3XH1State, filament) - me.calculateDJ(w, e, signal3XH1State, filament) - me.calculate2DJ(w, e, signal3XH1State, filament) - }) -} - -// 黄灯点灯电路 -// 开放引导信号,黄灯亮且红灯亮 -// 开放列车信号且开通侧向,只黄灯亮 -func (me *Signal3XH1System) calculateU(w ecs.World, state *Signal3XH1State, filament *Signal3XH1FilamentState) { - //引导信号 - isY := !state.DDJ && !state.LXJ && state.DJ && state.YXJ - //侧向行车信号 - isLC := !state.DDJ && state.LXJ && !state.ZXJ - state.U = filament.Uf && (isY || isLC) -} - -// 绿灯点灯电路 -// 开放正线行车信号,只亮绿灯 -func (me *Signal3XH1System) calculateL(w ecs.World, state *Signal3XH1State, filament *Signal3XH1FilamentState) { - isL := !state.DDJ && state.LXJ && state.ZXJ - state.L = filament.Lf && isL -} - -// 红灯点灯电路 -// 列车信号禁止时,亮红灯 -func (me *Signal3XH1System) calculateH(w ecs.World, state *Signal3XH1State, filament *Signal3XH1FilamentState) { - isH := !state.DDJ && !state.LXJ - state.H = filament.Hf && isH -} - -// DJ 灯丝继电器电路 -func (me *Signal3XH1System) calculateDJ(w ecs.World, e *ecs.Entry, state *Signal3XH1State, filament *Signal3XH1FilamentState) { - _DJ := state.DJ - isDj := filament.Lf && !state.DDJ && state.LXJ && state.ZXJ || - filament.Uf && !state.DDJ && state.LXJ && !state.ZXJ || - filament.Hf && !state.DDJ && !state.LXJ - //通知继电器进行动作 - if _DJ != isDj { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_3XH1, SIGNAL_DJ, isDj); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} - -// 2DJ 灯丝继电器电路 -func (me *Signal3XH1System) calculate2DJ(w ecs.World, e *ecs.Entry, state *Signal3XH1State, filament *Signal3XH1FilamentState) { - _2DJ := state.EDJ - // - is2DJ := filament.Uf && !state.DDJ && !state.LXJ && state.DJ && state.YXJ - //通知继电器进行动作 - if _2DJ != is2DJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_3XH1, SIGNAL_2DJ, is2DJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/signal_3xh2_system.go b/deprecated/system/signal_3xh2_system.go deleted file mode 100644 index 8addd57..0000000 --- a/deprecated/system/signal_3xh2_system.go +++ /dev/null @@ -1,141 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// Signal3XH2State 电路状态:信号机3XH-2(红-绿-黄) 道岔防护信号机(三显示不封灯、无单黄显示、带引导) -// 引导信号:红黄 -type Signal3XH2State struct { - // 物理黄灯,true-亮 - U bool - // 物理绿灯,true-亮 - L bool - // 物理红灯,true-亮 - H bool - // 点灯继电器,true-吸合,常态落下表示逻辑点灯 - DDJ bool - //2DJ灯丝继电器,true-吸合 - EDJ bool - //灯丝继电器,true-吸合 - DJ bool - //列车信号继电器,true-吸合 - LXJ bool - //引导信号继电器,true-吸合 - YXJ bool -} - -// Signal3XH2FilamentState 信号机3XH-2 灯丝状态 -type Signal3XH2FilamentState struct { - // 物理黄灯,true-灯丝正常 - Uf bool - // 物理绿灯,true-灯丝正常 - Lf bool - // 物理红灯,true-灯丝正常 - Hf bool -} - -// Signal3XH2StateComponent 信号机3XH-2状态组件 -var Signal3XH2StateComponent = ecs.NewComponentType[Signal3XH2State]() -var Signal3XH2FilamentStateComponent = ecs.NewComponentType[Signal3XH2FilamentState]() -var signal3XH2Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal3XH2StateComponent)) - -func NewSignal3XH2State() *Signal3XH2State { - return &Signal3XH2State{DDJ: true, EDJ: false, DJ: false, LXJ: false, YXJ: false, U: false, L: false, H: false} -} -func NewSignal3XH2FilamentState() *Signal3XH2FilamentState { - return &Signal3XH2FilamentState{Uf: true, Lf: true, Hf: true} -} - -type Signal3XH2System struct { -} - -func NewSignal3XH2System() *Signal3XH2System { - return &Signal3XH2System{} -} - -// Update world 执行 -func (me *Signal3XH2System) Update(w ecs.World) { - signal3XH2Query.Each(w, func(e *ecs.Entry) { - state := Signal3XH2StateComponent.Get(e) - filament := Signal3XH2FilamentStateComponent.Get(e) - me.calculateU(w, state, filament) - me.calculateL(w, state, filament) - me.calculateH(w, state, filament) - me.calculateDJ(w, e, state, filament) - me.calculate2DJ(w, e, state, filament) - }) -} - -// Signal3XH2RelayActionEventProcessor 继电器动作事件处理 -var Signal3XH2RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //根据event来更新Signal3XH1State中对应继电器的状态 - signal3XH2Query.Each(w, func(e *ecs.Entry) { - signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := signalModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - if relayGroup == SIGNAL_3XH2 { - state := Signal3XH2StateComponent.Get(e) - switch relayName { - case SIGNAL_DDJ: - state.DDJ = event.Xh - case SIGNAL_DJ: - state.DJ = event.Xh - case SIGNAL_2DJ: - state.EDJ = event.Xh - case SIGNAL_LXJ: - state.LXJ = event.Xh - case SIGNAL_YXJ: - state.YXJ = event.Xh - default: - panic(fmt.Sprintf("Signal3XH2的模型[%s]中继电器功能名称[%s]无法识别", signalModel.Id(), relayName)) - } - } else { - panic(fmt.Sprintf("Signal3XH2的模型[%s]中继电器组合类型[%s]无法识别", signalModel.Id(), relayGroup)) - } - } - } else { - panic("Signal3XH2的模型未实现接口umi.IRelayCRoler") - } - }) -} - -func (me *Signal3XH2System) calculateU(w ecs.World, state *Signal3XH2State, filament *Signal3XH2FilamentState) { - isU := filament.Uf && !state.DDJ && !state.LXJ && state.DJ && state.YXJ - state.U = isU -} - -func (me *Signal3XH2System) calculateL(w ecs.World, state *Signal3XH2State, filament *Signal3XH2FilamentState) { - isL := filament.Lf && !state.DDJ && state.LXJ - state.L = isL -} - -func (me *Signal3XH2System) calculateH(w ecs.World, state *Signal3XH2State, filament *Signal3XH2FilamentState) { - isH := filament.Hf && !state.DDJ && !state.LXJ - state.H = isH -} - -func (me *Signal3XH2System) calculateDJ(w ecs.World, e *ecs.Entry, state *Signal3XH2State, filament *Signal3XH2FilamentState) { - isDJ := filament.Lf && !state.DDJ && state.LXJ || filament.Hf && !state.DDJ && !state.LXJ - //通知继电器进行动作 - if isDJ != state.DJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_3XH2, SIGNAL_DJ, isDJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} - -func (me *Signal3XH2System) calculate2DJ(w ecs.World, e *ecs.Entry, state *Signal3XH2State, filament *Signal3XH2FilamentState) { - is2DJ := filament.Uf && !state.DDJ && !state.LXJ && state.DJ && state.YXJ - //通知继电器进行动作 - if is2DJ != state.EDJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_3XH2, SIGNAL_2DJ, is2DJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/signal_3xh3_system.go b/deprecated/system/signal_3xh3_system.go deleted file mode 100644 index be5692c..0000000 --- a/deprecated/system/signal_3xh3_system.go +++ /dev/null @@ -1,128 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// Signal3XH3State 电路状态:信号机3XH-3(红-绿-黄) 道岔防护信号机(三显示封绿灯、有单黄显示、带引导) -// 引导信号:红黄 -type Signal3XH3State struct { - // 物理黄灯,true-亮 - U bool - // 物理红灯,true-亮 - H bool - // 点灯继电器,true-吸合,常态落下表示逻辑点灯 - DDJ bool - //2DJ灯丝继电器,true-吸合 - EDJ bool - //灯丝继电器,true-吸合 - DJ bool - //列车信号继电器,true-吸合 - LXJ bool - //引导信号继电器,true-吸合 - YXJ bool -} - -// Signal3XH3FilamentState 信号机3XH-3 灯丝状态 -type Signal3XH3FilamentState struct { - // 物理黄灯,true-灯丝正常 - Uf bool - // 物理红灯,true-灯丝正常 - Hf bool -} - -func NewSignal3XH3State() *Signal3XH3State { - return &Signal3XH3State{U: false, H: false, DDJ: true, EDJ: false, DJ: false, LXJ: false, YXJ: false} -} - -func NewSignal3XH3FilamentState() *Signal3XH3FilamentState { - return &Signal3XH3FilamentState{Uf: true, Hf: true} -} - -var Signal3XH3StateComponent = ecs.NewComponentType[Signal3XH3State]() -var Signal3XH3FilamentStateComponent = ecs.NewComponentType[Signal3XH3FilamentState]() -var signal3XH3Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal3XH3StateComponent)) - -type Signal3XH3System struct { -} - -func NewSignal3XH3System() *Signal3XH3System { - return &Signal3XH3System{} -} - -// Update world 执行 -func (me *Signal3XH3System) Update(w ecs.World) { - signal3XH3Query.Each(w, func(e *ecs.Entry) { - state := Signal3XH3StateComponent.Get(e) - filament := Signal3XH3FilamentStateComponent.Get(e) - // - me.calculateU(w, state, filament) - me.calculateH(w, state, filament) - me.calculateDJ(w, e, state, filament) - me.calculate2DJ(w, e, state, filament) - }) -} - -// Signal3XH3RelayActionEventProcessor 继电器动作事件处理 -var Signal3XH3RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //根据event来更新Signal3XH3State中对应继电器的状态 - signal3XH3Query.Each(w, func(e *ecs.Entry) { - signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := signalModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - if relayGroup == SIGNAL_3XH3 { - state := Signal3XH3StateComponent.Get(e) - switch relayName { - case SIGNAL_DDJ: - state.DDJ = event.Xh - case SIGNAL_DJ: - state.DJ = event.Xh - case SIGNAL_2DJ: - state.EDJ = event.Xh - case SIGNAL_LXJ: - state.LXJ = event.Xh - case SIGNAL_YXJ: - state.YXJ = event.Xh - default: - panic(fmt.Sprintf("Signal3XH3的模型[%s]中继电器功能名称[%s]无法识别", signalModel.Id(), relayName)) - } - } else { - panic(fmt.Sprintf("Signal3XH3的模型[%s]中继电器组合类型[%s]无法识别", signalModel.Id(), relayGroup)) - } - } - } else { - panic("Signal3XH3的模型未实现接口umi.IRelayCRoler") - } - }) -} - -func (me *Signal3XH3System) calculateU(w ecs.World, state *Signal3XH3State, filament *Signal3XH3FilamentState) { - isU := filament.Uf && (!state.DDJ && !state.LXJ && state.DJ && state.YXJ || !state.DDJ && state.LXJ) - state.U = isU - -} -func (me *Signal3XH3System) calculateH(w ecs.World, state *Signal3XH3State, filament *Signal3XH3FilamentState) { - isH := filament.Hf && !state.DDJ && !state.LXJ - state.H = isH -} -func (me *Signal3XH3System) calculateDJ(w ecs.World, e *ecs.Entry, state *Signal3XH3State, filament *Signal3XH3FilamentState) { - isDJ := filament.Uf && !state.DDJ && state.LXJ || filament.Hf && !state.DDJ && !state.LXJ - if isDJ != state.DJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_3XH3, SIGNAL_DJ, isDJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} -func (me *Signal3XH3System) calculate2DJ(w ecs.World, e *ecs.Entry, state *Signal3XH3State, filament *Signal3XH3FilamentState) { - is2DJ := filament.Uf && !state.DDJ && !state.LXJ && state.DJ && state.YXJ - if is2DJ != state.EDJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_3XH3, SIGNAL_2DJ, is2DJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/signal_3xh4_system.go b/deprecated/system/signal_3xh4_system.go deleted file mode 100644 index 76b0b87..0000000 --- a/deprecated/system/signal_3xh4_system.go +++ /dev/null @@ -1,126 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// Signal3XH4State 电路状态:信号机3XH-4(红-绿-黄) 出站兼道岔防护信号机(三显示不封灯、有单黄显示、无引导) -type Signal3XH4State struct { - // 物理黄灯,true-亮 - U bool - // 物理绿灯,true-亮 - L bool - // 物理红灯,true-亮 - H bool - // 点灯继电器,true-吸合,常态落下表示逻辑点灯 - DDJ bool - //灯丝继电器,true-吸合 - DJ bool - //列车信号继电器,true-吸合 - LXJ bool - //开通正线信号继电器,true-吸合 - ZXJ bool -} - -// Signal3XH4FilamentState 信号机3XH-2 灯丝状态 -type Signal3XH4FilamentState struct { - // 物理黄灯,true-灯丝正常 - Uf bool - // 物理绿灯,true-灯丝正常 - Lf bool - // 物理红灯,true-灯丝正常 - Hf bool -} - -func NewSignal3XH4State() *Signal3XH4State { - return &Signal3XH4State{DDJ: true, DJ: false, LXJ: false, ZXJ: false, U: false, L: false, H: false} -} -func NewSignal3XH4FilamentState() *Signal3XH4FilamentState { - return &Signal3XH4FilamentState{Uf: false, Lf: false, Hf: false} -} - -var Signal3XH4StateComponent = ecs.NewComponentType[Signal3XH4State]() -var Signal3XH4FilamentStateComponent = ecs.NewComponentType[Signal3XH4FilamentState]() -var signal3XH4Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal3XH4StateComponent)) - -type Signal3XH4System struct { -} - -func NewSignal3XH4System() *Signal3XH4System { - return &Signal3XH4System{} -} - -// Update world 执行 -func (me *Signal3XH4System) Update(w ecs.World) { - signal3XH4Query.Each(w, func(e *ecs.Entry) { - state := Signal3XH4StateComponent.Get(e) - filament := Signal3XH4FilamentStateComponent.Get(e) - // - me.calculateU(w, state, filament) - me.calculateL(w, state, filament) - me.calculateH(w, state, filament) - me.calculateDJ(w, e, state, filament) - }) -} - -// Signal3XH4RelayActionEventProcessor 继电器动作事件处理 -var Signal3XH4RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //根据event来更新Signal3XH4State中对应继电器的状态 - signal3XH4Query.Each(w, func(e *ecs.Entry) { - signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := signalModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - if relayGroup == SIGNAL_3XH4 { - state := Signal3XH4StateComponent.Get(e) - switch relayName { - case SIGNAL_DDJ: - state.DDJ = event.Xh - case SIGNAL_DJ: - state.DJ = event.Xh - case SIGNAL_LXJ: - state.LXJ = event.Xh - case SIGNAL_ZXJ: - state.ZXJ = event.Xh - default: - panic(fmt.Sprintf("Signal3XH4的模型[%s]中继电器功能名称[%s]无法识别", signalModel.Id(), relayName)) - } - } else { - panic(fmt.Sprintf("Signal3XH4的模型[%s]中继电器组合类型[%s]无法识别", signalModel.Id(), relayGroup)) - } - } - } else { - panic("Signal3XH4的模型未实现接口umi.IRelayCRoler") - } - }) -} - -func (me *Signal3XH4System) calculateU(w ecs.World, state *Signal3XH4State, filament *Signal3XH4FilamentState) { - isU := filament.Uf && !state.DDJ && state.LXJ && !state.ZXJ - state.U = isU -} - -func (me *Signal3XH4System) calculateL(w ecs.World, state *Signal3XH4State, filament *Signal3XH4FilamentState) { - isL := filament.Lf && !state.DDJ && state.LXJ && state.ZXJ - state.L = isL -} - -func (me *Signal3XH4System) calculateH(w ecs.World, state *Signal3XH4State, filament *Signal3XH4FilamentState) { - isH := filament.Hf && !state.DDJ && !state.LXJ - state.H = isH -} - -func (me *Signal3XH4System) calculateDJ(w ecs.World, e *ecs.Entry, state *Signal3XH4State, filament *Signal3XH4FilamentState) { - isDJ := filament.Uf && !state.DDJ && state.LXJ && !state.ZXJ || - filament.Lf && !state.DDJ && state.LXJ && state.ZXJ || - filament.Hf && !state.DDJ && !state.LXJ - if isDJ != state.DJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_3XH3, SIGNAL_DJ, isDJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/signal_dcxh_system.go b/deprecated/system/signal_dcxh_system.go deleted file mode 100644 index 47ae420..0000000 --- a/deprecated/system/signal_dcxh_system.go +++ /dev/null @@ -1,105 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// SignalDCXHState 电路状态:信号机DCXH(蓝-白) 调车信号机 -type SignalDCXHState struct { - // 物理白灯,true-亮 - B bool - // 物理蓝灯,true-亮 - A bool - //灯丝继电器,true-吸合 - DJ bool - //调车信号继电器,true-吸合 - DXJ bool -} - -// SignalDCXHFilamentState 信号机3XH-2 灯丝状态 -type SignalDCXHFilamentState struct { - // 物理白灯,true-灯丝正常 - Bf bool - // 物理蓝灯,true-灯丝正常 - Af bool -} -type SignalDCXHSystem struct { -} - -func NewSignalDCXHSystem() *SignalDCXHSystem { - return &SignalDCXHSystem{} -} -func NewSignalDCXHState() *SignalDCXHState { - return &SignalDCXHState{DJ: true, DXJ: false, A: true, B: false} -} -func NewSignalDCXHFilamentState() *SignalDCXHFilamentState { - return &SignalDCXHFilamentState{Bf: true, Af: true} -} - -var SignalDCXHStateComponent = ecs.NewComponentType[SignalDCXHState]() -var SignalDCXHFilamentStateComponent = ecs.NewComponentType[SignalDCXHFilamentState]() -var signalDCXHQuery = ecs.NewQuery(filter.Contains(EntityIdentityComponent, SignalDCXHStateComponent)) - -// Update world 执行 -func (me *SignalDCXHSystem) Update(w ecs.World) { - signalDCXHQuery.Each(w, func(e *ecs.Entry) { - state := SignalDCXHStateComponent.Get(e) - filament := SignalDCXHFilamentStateComponent.Get(e) - // - me.calculateA(w, state, filament) - me.calculateB(w, state, filament) - me.calculateDJ(w, e, state, filament) - }) - -} - -// SignalDCXHRelayActionEventProcessor 继电器动作事件处理 -var SignalDCXHRelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //根据event来更新SignalDCXHState中对应继电器的状态 - signalDCXHQuery.Each(w, func(e *ecs.Entry) { - signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := signalModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - if relayGroup == SIGNAL_DCXH { - state := SignalDCXHStateComponent.Get(e) - switch relayName { - case SIGNAL_DJ: - state.DJ = event.Xh - case SIGNAL_DXJ: - state.DXJ = event.Xh - default: - panic(fmt.Sprintf("SignalDCXH的模型[%s]中继电器功能名称[%s]无法识别", signalModel.Id(), relayName)) - } - } else { - panic(fmt.Sprintf("SignalDCXH的模型[%s]中继电器组合类型[%s]无法识别", signalModel.Id(), relayGroup)) - } - } - } else { - panic("SignalDCXH的模型未实现接口umi.IRelayCRoler") - } - }) -} - -func (me *SignalDCXHSystem) calculateB(w ecs.World, state *SignalDCXHState, filament *SignalDCXHFilamentState) { - isB := filament.Bf && state.DXJ - state.B = isB -} - -func (me *SignalDCXHSystem) calculateA(w ecs.World, state *SignalDCXHState, filament *SignalDCXHFilamentState) { - isA := filament.Af && !state.DXJ - state.A = isA -} - -func (me *SignalDCXHSystem) calculateDJ(w ecs.World, e *ecs.Entry, state *SignalDCXHState, filament *SignalDCXHFilamentState) { - isDJ := filament.Bf && state.DXJ || filament.Af && !state.DXJ - if isDJ != state.DJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_DCXH, SIGNAL_DJ, isDJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/signal_jckxh_system.go b/deprecated/system/signal_jckxh_system.go deleted file mode 100644 index 6546bec..0000000 --- a/deprecated/system/signal_jckxh_system.go +++ /dev/null @@ -1,119 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// SignalJCKXHState 电路状态:信号机JCKXH(红-白-黄) 进/出库列车兼调车信号机(三显示不封灯、有单黄显示、无引导) -type SignalJCKXHState struct { - // 物理黄灯,true-亮 - U bool - // 物理白灯,true-亮 - B bool - // 物理红灯,true-亮 - H bool - //灯丝继电器,true-吸合 - DJ bool - //调车信号继电器,true-吸合 - DXJ bool - //列车信号继电器,true-吸合 - LXJ bool -} - -// SignalJCKXHFilamentState 信号机3XH-2 灯丝状态 -type SignalJCKXHFilamentState struct { - // 物理黄灯,true-灯丝正常 - Uf bool - // 物理白灯,true-灯丝正常 - Bf bool - // 物理红灯,true-灯丝正常 - Hf bool -} - -type SignalJCKXHSystem struct { -} - -func NewSignalJCKXHState() *SignalJCKXHState { - return &SignalJCKXHState{DJ: true, LXJ: false, DXJ: false, U: false, B: false, H: true} -} -func NewSignalJCKXHFilamentState() *SignalJCKXHFilamentState { - return &SignalJCKXHFilamentState{Uf: true, Bf: true, Hf: true} -} -func NewSignalJCKXHSystem() *SignalJCKXHSystem { - return &SignalJCKXHSystem{} -} - -var SignalJCKXHStateComponent = ecs.NewComponentType[SignalJCKXHState]() -var SignalJCKXHFilamentStateComponent = ecs.NewComponentType[SignalJCKXHFilamentState]() -var signalJCKXHQuery = ecs.NewQuery(filter.Contains(EntityIdentityComponent, SignalJCKXHStateComponent)) - -// Update world 执行 -func (me *SignalJCKXHSystem) Update(w ecs.World) { - signalJCKXHQuery.Each(w, func(e *ecs.Entry) { - state := SignalJCKXHStateComponent.Get(e) - filament := SignalJCKXHFilamentStateComponent.Get(e) - // - me.calculateU(w, state, filament) - me.calculateB(w, state, filament) - me.calculateH(w, state, filament) - me.calculateDJ(w, e, state, filament) - }) -} - -// SignalJCKXHRelayActionEventProcessor 继电器动作事件处理 -var SignalJCKXHRelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //根据event来更新SignalJCKXHState中对应继电器的状态 - signalJCKXHQuery.Each(w, func(e *ecs.Entry) { - signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := signalModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - if relayGroup == SIGNAL_JCKXH { - state := SignalJCKXHStateComponent.Get(e) - switch relayName { - case SIGNAL_DJ: - state.DJ = event.Xh - case SIGNAL_DXJ: - state.DXJ = event.Xh - case SIGNAL_LXJ: - state.LXJ = event.Xh - default: - panic(fmt.Sprintf("SignalJCKXH的模型[%s]中继电器功能名称[%s]无法识别", signalModel.Id(), relayName)) - } - } else { - panic(fmt.Sprintf("SignalJCKXH的模型[%s]中继电器组合类型[%s]无法识别", signalModel.Id(), relayGroup)) - } - } - } else { - panic("SignalJCKXH的模型未实现接口umi.IRelayCRoler") - } - }) -} - -func (me *SignalJCKXHSystem) calculateU(w ecs.World, state *SignalJCKXHState, filament *SignalJCKXHFilamentState) { - isU := filament.Uf && state.LXJ - state.U = isU -} - -func (me *SignalJCKXHSystem) calculateB(w ecs.World, state *SignalJCKXHState, filament *SignalJCKXHFilamentState) { - isB := filament.Bf && !state.LXJ && state.DXJ - state.B = isB -} - -func (me *SignalJCKXHSystem) calculateH(w ecs.World, state *SignalJCKXHState, filament *SignalJCKXHFilamentState) { - isH := filament.Bf && !state.LXJ && state.DXJ - state.H = isH -} - -func (me *SignalJCKXHSystem) calculateDJ(w ecs.World, e *ecs.Entry, state *SignalJCKXHState, filament *SignalJCKXHFilamentState) { - isDJ := filament.Uf && state.LXJ || filament.Bf && !state.LXJ && state.DXJ || filament.Bf && !state.LXJ && state.DXJ - if isDJ != state.DJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_JCKXH, SIGNAL_DJ, isDJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/signal_jdxh_system.go b/deprecated/system/signal_jdxh_system.go deleted file mode 100644 index df9a042..0000000 --- a/deprecated/system/signal_jdxh_system.go +++ /dev/null @@ -1,131 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// SignalJDXHState 电路状态:信号机JDXH(红-绿-黄) 进段信号机(三显示不封灯、无单黄显示、带引导) -type SignalJDXHState struct { - // 物理黄灯,true-亮 - U bool - // 物理绿灯,true-亮 - L bool - // 物理红灯,true-亮 - H bool - // 2DJ灯丝继电器,true-吸合 - EDJ bool - //灯丝继电器,true-吸合 - DJ bool - //列车信号继电器,true-吸合 - LXJ bool - //引导信号继电器,true-吸合 - YXJ bool -} - -// SignalJDXHFilamentState 信号机3XH-2 灯丝状态 -type SignalJDXHFilamentState struct { - // 物理黄灯,true-灯丝正常 - Uf bool - // 物理绿灯,true-灯丝正常 - Lf bool - // 物理红灯,true-灯丝正常 - Hf bool -} -type SignalJDXHSystem struct { -} - -func NewSignalJDXHSystem() *SignalJDXHSystem { - return &SignalJDXHSystem{} -} -func NewSignalJDXHState() *SignalJDXHState { - return &SignalJDXHState{LXJ: false, YXJ: false, DJ: true, EDJ: false, H: true, U: false, L: false} -} -func NewSignalJDXHFilamentState() *SignalJDXHFilamentState { - return &SignalJDXHFilamentState{Uf: true, Lf: true, Hf: true} -} - -var SignalJDXHStateComponent = ecs.NewComponentType[SignalJDXHState]() -var SignalJDXHFilamentStateComponent = ecs.NewComponentType[SignalJDXHFilamentState]() -var signalJDXHQuery = ecs.NewQuery(filter.Contains(EntityIdentityComponent, SignalJDXHStateComponent)) - -// Update world 执行 -func (me *SignalJDXHSystem) Update(w ecs.World) { - signalJDXHQuery.Each(w, func(e *ecs.Entry) { - state := SignalJDXHStateComponent.Get(e) - filament := SignalJDXHFilamentStateComponent.Get(e) - // - me.calculateL(w, state, filament) - me.calculateU(w, state, filament) - me.calculateH(w, state, filament) - me.calculateDJ(w, e, state, filament) - me.calculate2DJ(w, e, state, filament) - }) -} - -// SignalJDXHRelayActionEventProcessor 继电器动作事件处理 -var SignalJDXHRelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //根据event来更新SignalJDXHState中对应继电器的状态 - signalJDXHQuery.Each(w, func(e *ecs.Entry) { - signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := signalModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - if relayGroup == SIGNAL_JDXH { - state := SignalJDXHStateComponent.Get(e) - switch relayName { - case SIGNAL_DJ: - state.DJ = event.Xh - case SIGNAL_2DJ: - state.EDJ = event.Xh - case SIGNAL_LXJ: - state.LXJ = event.Xh - case SIGNAL_YXJ: - state.YXJ = event.Xh - default: - panic(fmt.Sprintf("SignalJDXH的模型[%s]中继电器功能名称[%s]无法识别", signalModel.Id(), relayName)) - } - } else { - panic(fmt.Sprintf("SignalJDXH的模型[%s]中继电器组合类型[%s]无法识别", signalModel.Id(), relayGroup)) - } - } - } else { - panic("SignalJDXH的模型未实现接口umi.IRelayCRoler") - } - }) -} - -func (me *SignalJDXHSystem) calculateU(w ecs.World, state *SignalJDXHState, filament *SignalJDXHFilamentState) { - isU := filament.Uf && !state.LXJ && state.DJ && state.YXJ - state.U = isU -} - -func (me *SignalJDXHSystem) calculateL(w ecs.World, state *SignalJDXHState, filament *SignalJDXHFilamentState) { - isL := filament.Lf && state.LXJ - state.L = isL -} - -func (me *SignalJDXHSystem) calculateH(w ecs.World, state *SignalJDXHState, filament *SignalJDXHFilamentState) { - isH := filament.Hf && !state.LXJ - state.H = isH -} - -func (me *SignalJDXHSystem) calculateDJ(w ecs.World, e *ecs.Entry, state *SignalJDXHState, filament *SignalJDXHFilamentState) { - isDJ := filament.Lf && state.LXJ || filament.Hf && !state.LXJ - if isDJ != state.DJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_JDXH, SIGNAL_DJ, isDJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} -func (me *SignalJDXHSystem) calculate2DJ(w ecs.World, e *ecs.Entry, state *SignalJDXHState, filament *SignalJDXHFilamentState) { - is2DJ := filament.Uf && !state.LXJ && state.DJ && state.YXJ - if is2DJ != state.EDJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(e).Id, SIGNAL_JDXH, SIGNAL_2DJ, is2DJ); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} diff --git a/deprecated/system/spks_system.go b/deprecated/system/spks_system.go deleted file mode 100644 index f0fc3c9..0000000 --- a/deprecated/system/spks_system.go +++ /dev/null @@ -1,126 +0,0 @@ -package system - -import ( - "joylink.club/ecs" - "joylink.club/ecs/filter" -) - -// SpksCircuitState 车站人员防护开关电路 -type SpksCircuitState struct { - //ture-按钮开关接通常开点 - SPKSX1JA bool - //ture-按钮开关接通常开点 - SPKSX3JA bool - //ture-按钮开关接通常开点 - SPKSS2JA bool - //ture-按钮开关接通常开点 - SPKSS4JA bool - //ture-按钮开关接通常开点 - SPKSXPLA bool - //ture-按钮开关接通常开点 - SPKSSPLA bool - //true-灯亮 - SPKSX1D bool - //true-灯亮 - SPKSX3D bool - //true-灯亮 - SPKSS2D bool - //true-灯亮 - SPKSS4D bool - //true-灯亮 - SPKSXPLAD bool - //true-灯亮 - SPKSSPLAD bool - //ture-按钮开关接通常开点 - SDA bool - //ture-继电器吸起,接通常开点 - SPKSX1J bool - //ture-继电器吸起,接通常开点 - SPKSX3J bool - //ture-继电器吸起,接通常开点 - SPKSS2J bool - //ture-继电器吸起,接通常开点 - SPKSS4J bool - //ture-继电器吸起,接通常开点 - SPKSXPLAJ bool - //ture-继电器吸起,接通常开点 - SPKSSPLAJ bool -} -type SpksCircuitSystem struct { - query *ecs.Query -} - -var ( - SpksCircuitStateComponent = ecs.NewComponentType[SpksCircuitState]() -) - -func NewSpksCircuitSystem() *SpksCircuitSystem { - return &SpksCircuitSystem{query: ecs.NewQuery(filter.Contains(SpksCircuitStateComponent))} -} -func NewSpksCircuitState() *SpksCircuitState { - return &SpksCircuitState{ - SPKSX1JA: true, - SPKSX3JA: true, - SPKSS2JA: true, - SPKSS4JA: true, - SPKSXPLA: false, - SPKSSPLA: false, - SPKSX1D: false, - SPKSX3D: false, - SPKSS2D: false, - SPKSS4D: false, - SPKSXPLAD: false, - SPKSSPLAD: false, - SDA: false, - SPKSX1J: true, - SPKSX3J: true, - SPKSS2J: true, - SPKSS4J: true, - SPKSXPLAJ: false, - SPKSSPLAJ: false, - } -} - -// Update world 执行 -func (me *SpksCircuitSystem) Update(w ecs.World) { - me.query.Each(w, func(e *ecs.Entry) { - state := SpksCircuitStateComponent.Get(e) - _state := *state - // - me.calculateSpksD(state) - me.calculateSPKSXJ(state) - me.calculateSPKSSJ(state) - me.calculateSPKSPLAJ(state) - me.calculateChange(state, &_state) - }) -} - -// 亮灯运算 -func (me *SpksCircuitSystem) calculateSpksD(state *SpksCircuitState) { - state.SPKSX1D = state.SDA || !state.SPKSX1J - state.SPKSX3D = state.SDA || !state.SPKSX3J - state.SPKSS2D = state.SDA || !state.SPKSS2J - state.SPKSS4D = state.SDA || !state.SPKSS4J - state.SPKSXPLAD = state.SDA || state.SPKSXPLAJ - state.SPKSSPLAD = state.SDA || state.SPKSSPLAJ -} - -func (me *SpksCircuitSystem) calculateSPKSXJ(state *SpksCircuitState) { - state.SPKSX1J = state.SPKSX1JA || state.SPKSXPLAJ - state.SPKSX3J = state.SPKSX3JA || state.SPKSXPLAJ -} -func (me *SpksCircuitSystem) calculateSPKSSJ(state *SpksCircuitState) { - state.SPKSS2J = state.SPKSS2JA || state.SPKSSPLAJ - state.SPKSS4J = state.SPKSS4JA || state.SPKSSPLAJ -} -func (me *SpksCircuitSystem) calculateSPKSPLAJ(state *SpksCircuitState) { - state.SPKSXPLAJ = state.SPKSXPLA - state.SPKSSPLAJ = state.SPKSSPLA -} - -// 状态改变运算,通过pre与cur比较,如果某个状态改变则发送对应事件 -func (me *SpksCircuitSystem) calculateChange(curState *SpksCircuitState, preState *SpksCircuitState) { - if curState.SPKSX1J != preState.SPKSX1J { - //继电器状态需要改变 - } -} diff --git a/deprecated/system/switch_2jzdj9_system.go b/deprecated/system/switch_2jzdj9_system.go deleted file mode 100644 index bc9f9ff..0000000 --- a/deprecated/system/switch_2jzdj9_system.go +++ /dev/null @@ -1,804 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// --------联锁驱动----------------- - -// Switch2jZdj9DriveYc 联锁驱动YCJ -func Switch2jZdj9DriveYc(w ecs.World, switchId string, xh bool) bool { - return DriveRelay(w, switchId, SJZDJ9_TDC, SJZDJ9_YCJ, xh) -} - -// Switch2jZdj9DriveFc 联锁驱动FCJ -func Switch2jZdj9DriveFc(w ecs.World, switchId string, xh bool) bool { - return DriveRelay(w, switchId, SJZDJ9_TDC, SJZDJ9_FCJ, xh) -} - -// Switch2jZdj9DriveDc 联锁驱动DCJ -func Switch2jZdj9DriveDc(w ecs.World, switchId string, xh bool) bool { - return DriveRelay(w, switchId, SJZDJ9_TDC, SJZDJ9_DCJ, xh) -} - -////////////////////////////////////////////////////////////////// - -// Switch2jZdj9State 双机ZDJ9道岔电路系统状态定义 -// 继电器: true-吸合;false-未吸合 -type Switch2jZdj9State struct { - //定操继电器 - DCJ bool - //反操继电器 - FCJ bool - //允许操作继电器 - YCJ bool - //总定表继电器 - ZDBJ bool - //总反表继电器 - ZFBJ bool - //道岔第一启动继电器 - J1_1DQJ bool - //道岔保护继电器 - J1_BHJ bool - //道岔第二启动继电器 - //true-吸起即1-3通;false-打落即1-2通 - J1_2DQJ bool - //true-2DQJ由落下转换到吸起,即定操 - J1_2DQJ_ToD bool - //true-2DQJ由吸起转换到落下,即反操 - J1_2DQJ_ToF bool - //道岔第一启动继电器复示继电器 - J1_1DQJF bool - //断相保护器 - J1_DBQ DBQState - //定位表示继电器 - J1_DBJ bool - //true-当道岔转换到定位时,转辙机内端子9与电路接通;false-转辙机内端子9断开切断电路 - J1_DB_K9 bool - //转辙机内部自动开闭器 - //true-接通1、3排表示电路,用于定操;false-接通2、4排表示电路,用于反操 - J1_AKB bool - //道岔电机1的电源 - J1_Power Switch380ACPower - //电机线圈相电流 - J1_U1 Switch380ACPhase - J1_V1 Switch380ACPhase - J1_W1 Switch380ACPhase - //电机输出牵引力,大于0表示正转即定操,小于0表示反转即反操,等于0表示不转 - J1_Traction int8 - //反位表示继电器 - J1_FBJ bool - //true-当道岔转换到反位时,转辙机内端子10与电路接通;false-转辙机内端子10断开切断电路 - J1_FB_K10 bool - //道岔启动切断继电器 - J1_QDJ bool - //道岔启动切断继电器的LC震荡电路保磁剩余时间,单位ms - //最长保持时长3000ms - J1_QDJ_LcTime int64 - //总保护继电器 - J1_ZBHJ bool - //道岔第一启动继电器 - J2_1DQJ bool - //道岔保护继电器 - J2_BHJ bool - //道岔第二启动继电器 - //true-吸起即1-3通;false-打落即1-2通 - J2_2DQJ bool - //true-2DQJ由落下转换到吸起,即定操 - J2_2DQJ_ToD bool - //true-2DQJ由吸起转换到落下,即反操 - J2_2DQJ_ToF bool - //道岔第一启动继电器复示继电器 - J2_1DQJF bool - //断相保护器 - J2_DBQ DBQState - //定位表示继电器 - J2_DBJ bool - //true-当道岔转换到定位时,转辙机内端子9与电路接通;false-转辙机内端子9断开切断电路 - J2_DB_K9 bool - //反位表示继电器 - J2_FBJ bool - //true-当道岔转换到反位时,转辙机内端子10与电路接通;false-转辙机内端子10断开切断电路 - J2_FB_K10 bool - //转辙机内部自动开闭器 - //true-接通1、3排表示电路,用于定操;false-接通2、4排表示电路,用于反操 - J2_AKB bool - //道岔电机2的电源 - J2_Power Switch380ACPower - //电机线圈相电流 - J2_U1 Switch380ACPhase - J2_V1 Switch380ACPhase - J2_W1 Switch380ACPhase - //电机转速,大于0表示正转即定操,小于0表示反转即反操,等于0表示不转 - J2_Traction int8 -} - -// IsTurning 道岔物理实际状态而非采集状态:道岔是否在转动过程中 -func (me *Switch2jZdj9State) IsTurning() bool { - return !me.J1_DB_K9 && !me.J1_FB_K10 || !me.J2_DB_K9 && !me.J2_FB_K10 -} - -// IsNormal 道岔物理实际状态而非采集状态:道岔是否在定位 -func (me *Switch2jZdj9State) IsNormal() bool { - return me.J1_DB_K9 && !me.J1_FB_K10 && me.J2_DB_K9 && !me.J2_FB_K10 -} - -// IsReverse 道岔物理实际状态而非采集状态:道岔是否在反位 -func (me *Switch2jZdj9State) IsReverse() bool { - return !me.J1_DB_K9 && me.J1_FB_K10 && !me.J2_DB_K9 && me.J2_FB_K10 -} - -// NewSwitch2jZdj9State 创建ZDJ9道岔状态并初始化 -func NewSwitch2jZdj9State() *Switch2jZdj9State { - return &Switch2jZdj9State{ - DCJ: false, - FCJ: false, - YCJ: false, - ZDBJ: true, - ZFBJ: false, - J1_1DQJ: false, - J1_BHJ: false, - J1_2DQJ: true, - J1_2DQJ_ToD: false, - J1_2DQJ_ToF: false, - J1_1DQJF: false, - J1_DBQ: DBQState{PhaseLoss: true, LimitedTime: 0, Dc24Voltage: false}, - J1_DBJ: true, - J1_DB_K9: true, - J1_AKB: true, - J1_Power: Switch380ACPower{Active: false, PhaseA: false, PhaseB: false, PhaseC: false}, - J1_U1: ACPahseN, - J1_V1: ACPahseN, - J1_W1: ACPahseN, - J1_Traction: 0, - J1_FBJ: false, - J1_FB_K10: false, - J1_QDJ: true, - J1_QDJ_LcTime: 0, - J1_ZBHJ: false, - J2_1DQJ: false, - J2_BHJ: false, - J2_2DQJ: true, - J2_2DQJ_ToD: false, - J2_2DQJ_ToF: false, - J2_1DQJF: false, - J2_DBQ: DBQState{PhaseLoss: true, LimitedTime: 0, Dc24Voltage: false}, - J2_DBJ: true, - J2_DB_K9: true, - J2_FBJ: false, - J2_FB_K10: false, - J2_AKB: true, - J2_Power: Switch380ACPower{Active: false, PhaseA: false, PhaseB: false, PhaseC: false}, - J2_U1: ACPahseN, - J2_V1: ACPahseN, - J2_W1: ACPahseN, - J2_Traction: 0, - } -} - -// DBQState 带限时功能断相保护器 -// 限时13秒 -type DBQState struct { - //是否缺相,true-缺相,false-三相电正常未缺相 - PhaseLoss bool - //剩余限时时间,单位ms - LimitedTime int64 - //当三相电正常时,断相保护器内的24V直流整流电路会正常输出24V直流电 - //当三相电不正常如缺相时,断相保护器内的24V直流整流电路不会输出24V直流电 - //BHJ道岔保护继电器的励磁线圈由该24V直流供电 - Dc24Voltage bool -} - -// SwitchBB 表示电路变压器,变压比2:1,将220V交流电变压后作为为道岔表示电路的电源 -// 0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压 -type SwitchBB struct { - //true-变压器初级输入正常 - InDj220V bool - //次级输出电压 - //0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压 - OutBb int8 -} - -// Switch380ACPower 道岔380V动力交流电源 -type Switch380ACPower struct { - //true-激活 - Active bool - //true-A相电正常输出 - PhaseA bool - //true-B相电正常输出 - PhaseB bool - //true-C相电正常输出 - PhaseC bool -} - -// Switch380ACPhase 道岔380V动力交流电相位定义 -type Switch380ACPhase int8 - -const ( - ACPahseN Switch380ACPhase = iota //不存在相位交流电 - ACPahseA //存在A相位交流电 - ACPahseB //存在B相位交流电 - ACPahseC //存在C相位交流电 -) - -// 继电器常量定义 -const ( - QDJ_LC_TIME int64 = 3000 //QDJ 电源切断继电器LC震荡电路有效震荡时间ms - DBQ_LIMITED_TIME = 13 * 1000 //断相保护器限时,单位ms -) - -// Switch2jZdj9StateComponent 道岔ZDJ9电路状态组件 -var Switch2jZdj9StateComponent = ecs.NewComponentType[Switch2jZdj9State]() - -// zdj9查询 -var zdj9Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Switch2jZdj9StateComponent)) - -// Switch2jZdj9System 双机ZDJ9道岔系统 -type Switch2jZdj9System struct { -} - -// NewSwitch2jZdj9System 双机ZDJ9道岔系统 -func NewSwitch2jZdj9System() *Switch2jZdj9System { - return &Switch2jZdj9System{} -} - -// Update world 执行 -func (me *Switch2jZdj9System) Update(w ecs.World) { - zdj9Query.Each(w, func(e *ecs.Entry) { - zdj9State := Switch2jZdj9StateComponent.Get(e) - //电机电源 - me.calculateJPower(w, e, zdj9State) - //断相保护器电路 - me.calculateDBQ(w, e, zdj9State) - //断相保护继电器励磁电路 - me.calculateBHJ(w, e, zdj9State) - //总保护继电器励磁电路 - me.calculateZBHJ(w, e, zdj9State) - //道岔转换启动切断继电器励磁电路 - me.calculateQDJ(w, e, zdj9State) - //道岔第一启动继电器励磁电路 - me.calculate1DQJ(w, e, zdj9State) - //道岔第一启动继电器复示继电器励磁电路 - me.calculate1DQJF(w, e, zdj9State) - //道岔第二启动继电器励磁电路 - me.calculate2DQJ(w, e, zdj9State) - //转辙机内自动开闭器 - me.calculateAKB(w, e, zdj9State) - //道岔转辙机定表反表继电器励磁电路 - me.calculateDBJ(w, e, zdj9State) - me.calculateFBJ(w, e, zdj9State) - //总定表/总反表继电器励磁电路 - me.calculateZDBJ(w, e, zdj9State) - me.calculateZFBJ(w, e, zdj9State) - //道岔转辙机内电机驱动电路 - me.calculateMotor(w, e, zdj9State) - me.calculateMove(w, e, zdj9State) - me.calculateK9K10(w, e, zdj9State) - }) -} - -// SJZDJ9双机zdj9 -const ( - SJZDJ9_TDC = "TDC" //继电器组合类型 - SJZDJ9_TDFJ1 = "TDFJ1" - SJZDJ9_TDFJ2 = "TDFJ2" - - SJZDJ9_1DQJ = "1DQJ" //继电器功能名称 - SJZDJ9_BHJ = "BHJ" - SJZDJ9_2DQJ = "2DQJ" - SJZDJ9_1DQJF = "1DQJF" - SJZDJ9_DBJ = "DBJ" - SJZDJ9_FBJ = "FBJ" - SJZDJ9_QDJ = "QDJ" - SJZDJ9_ZBHJ = "ZBHJ" - SJZDJ9_DCJ = "DCJ" - SJZDJ9_FCJ = "FCJ" - SJZDJ9_YCJ = "YCJ" - SJZDJ9_ZDBJ = "ZDBJ" - SJZDJ9_ZFBJ = "ZFBJ" -) - -func Switch2jzdj9AddListeners(w ecs.World) { - sysEvent.RelayActionEventBus.Subscribe(w, Switch2jzdj9RelayActionEventProcessor) -} - -// Switch2jzdj9RelayActionEventProcessor 接收继电器动作事件 -var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) { - //log.Println("==>>收到继电器动作事件:id = ", event.ButtonCode, " xh = ", event.Xh) - zdj9Query.Each(w, func(e *ecs.Entry) { - switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id) - roler, ok := switchModel.(IRelayCRole) - if ok { - if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find { - state := Switch2jZdj9StateComponent.Get(e) - switch relayGroup { - case SJZDJ9_TDC: - { - switch relayName { - case SJZDJ9_DCJ: - state.DCJ = event.Xh - case SJZDJ9_FCJ: - state.FCJ = event.Xh - case SJZDJ9_YCJ: - state.YCJ = event.Xh - case SJZDJ9_ZDBJ: - state.ZDBJ = event.Xh - case SJZDJ9_ZFBJ: - state.ZFBJ = event.Xh - default: - panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", switchModel.Id(), relayName)) - } - } - case SJZDJ9_TDFJ1: - { - switch relayName { - case SJZDJ9_1DQJ: - state.J1_1DQJ = event.Xh - case SJZDJ9_BHJ: - state.J1_BHJ = event.Xh - case SJZDJ9_2DQJ: - { - state.J1_2DQJ_ToD = !state.J1_2DQJ && event.Xh - state.J1_2DQJ_ToF = state.J1_2DQJ && !event.Xh - state.J1_2DQJ = event.Xh - } - case SJZDJ9_1DQJF: - state.J1_1DQJF = event.Xh - case SJZDJ9_DBJ: - state.J1_DBJ = event.Xh - case SJZDJ9_FBJ: - state.J1_FBJ = event.Xh - case SJZDJ9_QDJ: - state.J1_QDJ = event.Xh - case SJZDJ9_ZBHJ: - state.J1_ZBHJ = event.Xh - default: - panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", switchModel.Id(), relayName)) - } - } - case SJZDJ9_TDFJ2: - { - switch relayName { - case SJZDJ9_1DQJ: - state.J2_1DQJ = event.Xh - case SJZDJ9_BHJ: - state.J2_BHJ = event.Xh - case SJZDJ9_2DQJ: - { - state.J2_2DQJ_ToD = !state.J2_2DQJ && event.Xh - state.J2_2DQJ_ToF = state.J2_2DQJ && !event.Xh - state.J2_2DQJ = event.Xh - } - case SJZDJ9_1DQJF: - state.J2_1DQJF = event.Xh - case SJZDJ9_DBJ: - state.J2_DBJ = event.Xh - case SJZDJ9_FBJ: - state.J2_FBJ = event.Xh - default: - panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", switchModel.Id(), relayName)) - } - } - default: - panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器组合类型[%s]无法识别", switchModel.Id(), relayGroup)) - } - - } - } else { - panic("SwitchZdj9的模型未实现接口umi.IRelayCRoler") - } - }) -} - -// 发送继电器需要改变事件 -func (me *Switch2jZdj9System) publishRelayNeedChangeEvent(w ecs.World, switchEntry *ecs.Entry, relayGroup string, relayName string, needXh bool) { - switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(switchEntry).Id) - relayRole, _ := switchModel.(IRelayCRole) - relayModel := relayRole.FindRelayModelByCRole(relayGroup, relayName) - sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.(IDeviceModel).Id(), Xh: needXh}) -} - -// 断相保护电路运算 -func (me *Switch2jZdj9System) calculateDBQ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - if state.J1_DBQ.LimitedTime > 0 { - state.J1_DBQ.LimitedTime -= int64(w.Tick()) - if state.J1_DBQ.LimitedTime < 0 { - state.J1_DBQ.LimitedTime = 0 - } - } - // - state.J1_DBQ.PhaseLoss = !state.J1_Power.PhaseA || !state.J1_Power.PhaseB || !state.J1_Power.PhaseC - // - state.J1_DBQ.Dc24Voltage = !state.J1_DBQ.PhaseLoss - /////////////////////////////////////////////////// - if state.J2_DBQ.LimitedTime > 0 { - state.J2_DBQ.LimitedTime -= int64(w.Tick()) - if state.J2_DBQ.LimitedTime < 0 { - state.J2_DBQ.LimitedTime = 0 - } - } - // - state.J2_DBQ.PhaseLoss = !state.J2_Power.PhaseA || !state.J2_Power.PhaseB || !state.J2_Power.PhaseC - // - state.J2_DBQ.Dc24Voltage = !state.J2_DBQ.PhaseLoss -} - -// 转辙机内自动开闭器动作实现 -// 暂时规定:自动开闭器跟随2DQJ -func (me *Switch2jZdj9System) calculateAKB(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - state.J1_AKB = state.J1_2DQJ - state.J2_AKB = state.J2_2DQJ -} - -// 断相保护继电器运算 -// BHJ JWXC-1700无极缓放继电器 -func (me *Switch2jZdj9System) calculateBHJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - _J1_BHJ := state.J1_DBQ.Dc24Voltage - _J2_BHJ := state.J2_DBQ.Dc24Voltage - if _J1_BHJ != state.J1_BHJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_BHJ, _J1_BHJ) - } - if _J2_BHJ != state.J2_BHJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_BHJ, _J2_BHJ) - } -} - -// 总保护继电器运算 -// ZBHJ JWXC-1700无极缓放继电器 -func (me *Switch2jZdj9System) calculateZBHJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - //励磁 - method := state.J1_BHJ && state.J2_BHJ - //自闭 - self := state.J1_ZBHJ && (state.J1_BHJ || state.J2_BHJ) - // - _J1_ZBHJ := method || self - //为总保护继电器励磁 - if _J1_ZBHJ != state.J1_ZBHJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_ZBHJ, _J1_ZBHJ) - } -} - -// 道岔转换启动切断继电器运算 -// QDJ JWXC-1700无极缓放继电器 -func (me *Switch2jZdj9System) calculateQDJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - //LC震荡电路运算 - fullLc := (!state.J1_BHJ && !state.J2_BHJ) || state.J1_ZBHJ - if fullLc { - state.J1_QDJ_LcTime = QDJ_LC_TIME - } else { - if state.J1_QDJ_LcTime > 0 { - state.J1_QDJ_LcTime -= int64(w.Tick()) - if state.J1_QDJ_LcTime < 0 { - state.J1_QDJ_LcTime = 0 - } - } - } - //自闭励磁电路 - self := state.J1_QDJ && state.J1_ZBHJ - //为启动切断继电器励磁 - _J1_QDJ := self || fullLc || state.J1_QDJ_LcTime > 0 - if _J1_QDJ != state.J1_QDJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_QDJ, _J1_QDJ) - } -} - -// 道岔第一启动继电器运算 -// 1DQJ JWJXC-H125/80无极加强缓放继电器 -// J1先启动J2后启动 -func (me *Switch2jZdj9System) calculate1DQJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - //自闭电路 - j2DqjSelf := state.J1_QDJ && state.J2_BHJ && state.J2_1DQJ - //励磁电路 - j2DqjMethod1 := state.YCJ && state.J1_1DQJ && (!state.J2_2DQJ && state.DCJ || state.J2_2DQJ && state.FCJ) - // - j2DqjIs := j2DqjMethod1 || j2DqjSelf - //为J2第一启动继电器励磁 - if j2DqjIs != state.J2_1DQJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_1DQJ, j2DqjIs) - } - // --------------- - //励磁电路 - j1DqjMethod1 := state.YCJ && (!state.J1_2DQJ && state.DCJ || state.J1_2DQJ && state.FCJ) - //自闭电路 - j1DqjSelf := state.J1_QDJ && state.J1_BHJ && state.J1_1DQJ - // - j1DqjIs := j1DqjMethod1 || j1DqjSelf - //为J1第一启动继电器励磁 - if j1DqjIs != state.J1_1DQJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_1DQJ, j1DqjIs) - } -} - -// 道岔第一启动继电器复示继电器运算 -// 1DQJF JWJXC-480无极继电器 -func (me *Switch2jZdj9System) calculate1DQJF(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - _J1_1DQJF := state.J1_1DQJ - _J2_1DQJF := state.J2_1DQJ - if _J1_1DQJF != state.J1_1DQJF { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_1DQJF, _J1_1DQJF) - } - if _J2_1DQJF != state.J2_1DQJF { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_1DQJF, _J2_1DQJF) - } -} - -// 道岔第二启动继电器运算 -// 2DQJ JYJXC-160/260有极加强继电器 -// 2DQJ为有极继电器,根据线圈中电流极性不同具有 定位和反位 两种稳定状态,这两种稳定状态当线圈中电流消失时仍能继续保持; -// 在线圈中通以规定极性的电流时,继电器吸起,断电后仍保持在吸起位置;通以反方向电流时,继电器打落,断电后保持在打落位置; -// 断电保持由磁路系统中的一块长条形永久磁铁取代了大部分轭铁来实现; -// 电流3->4吸起,电流2->1打落,如果21和34同时通过电流时磁场相互抵消则继电器保持原来状态不变 -func (me *Switch2jZdj9System) calculate2DQJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - //J1-2DQJ - j1_2dqj_21 := state.J1_1DQJF && state.FCJ - j1_2dqj_34 := state.J1_1DQJF && state.DCJ - //磁通量,矢量 - var j12dqj int8 = 0 - if j1_2dqj_34 { - j12dqj++ - } - if j1_2dqj_21 { - j12dqj-- - } - if j12dqj != 0 { - _J1_2DQJ := j12dqj > 0 - if _J1_2DQJ != state.J1_2DQJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_2DQJ, _J1_2DQJ) - } - } - //J2-2DQJ - j2_2dqj_21 := state.J2_1DQJF && state.FCJ - j2_2dqj_34 := state.J2_1DQJF && state.DCJ - //磁通量,矢量 - var j22dqj int8 = 0 - if j2_2dqj_34 { - j22dqj++ - } - if j2_2dqj_21 { - j22dqj-- - } - if j22dqj != 0 { - _J2_2DQJ := j22dqj > 0 - if _J2_2DQJ != state.J2_2DQJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_2DQJ, _J2_2DQJ) - } - } -} - -// 道岔总定表继电器运算 -// ZDBJ JPXC-1000 偏极继电器是为了鉴别信号电路中的电流极性而设计 -// 继电器在磁路中增加一个偏极磁钢,使衔铁受永磁力的作用而偏于落下位置。衔铁的吸起与线圈中的电流的极性有关, -// 通过线圈的电流为规定的方向时,衔铁才吸起,而电流的方向相反时,衔铁保持不动。 -// 它只具有一种稳定状态,即衔铁靠电磁力吸起后,断电即落下,始终偏向落下的定位状态 -func (me *Switch2jZdj9System) calculateZDBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - _ZDBJ := state.J1_DBJ && state.J2_DBJ - if _ZDBJ != state.ZDBJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDC, SJZDJ9_ZDBJ, _ZDBJ) - } -} -func (me *Switch2jZdj9System) calculateZFBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - _ZFBJ := state.J1_FBJ && state.J2_FBJ - if _ZFBJ != state.ZFBJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDC, SJZDJ9_ZFBJ, _ZFBJ) - } -} - -// 道岔定表继电器运算 -// DBJ JPXC-1000 偏极继电器 -// BB的负半周期提供DBJ的励磁电流 -func (me *Switch2jZdj9System) calculateDBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - //j1 DBJ励磁 - j1DbjLc := state.J1_2DQJ && state.J1_AKB && state.J1_DB_K9 && !state.J1_1DQJ - if j1DbjLc != state.J1_DBJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_DBJ, j1DbjLc) - } - //j2 DBJ励磁 - j2DbjLc := state.J2_2DQJ && state.J2_AKB && state.J2_DB_K9 && !state.J2_1DQJ - if j2DbjLc != state.J2_DBJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_DBJ, j2DbjLc) - } -} - -// 道岔反表继电器运算 -// FBJ JPXC-1000 偏极继电器 -// BB的正半周期提供FBJ的励磁流 -func (me *Switch2jZdj9System) calculateFBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - //j1 FBJ励磁 - j1FbjLc := !state.J1_2DQJ && !state.J1_AKB && state.J1_FB_K10 && !state.J1_1DQJ - if j1FbjLc != state.J1_FBJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_FBJ, j1FbjLc) - } - //j2 - j2FbjLc := !state.J2_2DQJ && !state.J2_AKB && state.J2_FB_K10 && !state.J2_1DQJ - if j2FbjLc != state.J2_FBJ { - me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_FBJ, j2FbjLc) - } -} - -// 道岔转动运算 -// j1 完全转动须4000ms -> v=25/ms -// j2 完全转动须5000ms -> v=20/ms -// j.Value 0-反位 jRange-定位 -func (me *Switch2jZdj9System) calculateMove(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - j1 := PercentageDeviceState1Component.Get(switchEntry) - j1.V = int64(state.J1_Traction) * 25 - // - j2 := PercentageDeviceState2Component.Get(switchEntry) - j2.V = int64(state.J2_Traction) * 20 -} - -// 转辙机对外端子9、10运算 -func (me *Switch2jZdj9System) calculateK9K10(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - j1 := PercentageDeviceState1Component.Get(switchEntry) - j2 := PercentageDeviceState2Component.Get(switchEntry) - // - state.J1_DB_K9 = j1.isToM() - state.J1_FB_K10 = j1.isToL() - // - state.J2_DB_K9 = j2.isToM() - state.J2_FB_K10 = j2.isToL() -} - -// 转辙机电源控制 -// 1DQj启动继电器吸合时接通电源 -func (me *Switch2jZdj9System) calculateJPower(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - //超时断电 - j1csdd := state.J1_Power.Active && state.J1_DBQ.LimitedTime <= 0 - //转换到位断电 - j1zhdwdd := state.J1_2DQJ_ToD && state.J1_DB_K9 || state.J1_2DQJ_ToF && state.J1_FB_K10 - if j1csdd || j1zhdwdd { - state.J1_Power.PhaseA = false - state.J1_Power.PhaseB = false - state.J1_Power.PhaseC = false - state.J1_2DQJ_ToD = false - state.J1_2DQJ_ToF = false - } - //第一启动继电器落下 - if !state.J1_1DQJ { - state.J1_Power.Active = false - } - //接通电源 - if state.J1_1DQJ && !state.J1_Power.Active { - state.J1_Power.Active = true - state.J1_Power.PhaseA = true - state.J1_Power.PhaseB = true - state.J1_Power.PhaseC = true - state.J1_DBQ.LimitedTime = DBQ_LIMITED_TIME - } - //---------------- - //超时断电 - j2csdd := state.J2_Power.Active && state.J2_DBQ.LimitedTime <= 0 - //转换到位断电 - j2zhdwdd := state.J2_2DQJ_ToD && state.J2_DB_K9 || state.J2_2DQJ_ToF && state.J2_FB_K10 - if j2csdd || j2zhdwdd { - state.J2_Power.PhaseA = false - state.J2_Power.PhaseB = false - state.J2_Power.PhaseC = false - state.J2_2DQJ_ToD = false - state.J2_2DQJ_ToF = false - } - //第一启动继电器落下 - if !state.J2_1DQJ { - state.J2_Power.Active = false - } - //接通电源 - if state.J2_1DQJ && !state.J2_Power.Active { - state.J2_Power.Active = true - state.J2_Power.PhaseA = true - state.J2_Power.PhaseB = true - state.J2_Power.PhaseC = true - state.J2_DBQ.LimitedTime = DBQ_LIMITED_TIME - } -} - -// 道岔转辙机电机内线圈电路运算 -// ABC三相电,电机线圈UVW, -// 定位到反位U-A V-C W-B 即U->W->V电机反转,反操接通2、4排表示电路 -// 反位到定位U-A V-B W-C 即U->V->W电机正转,定操接通1、3排表示电路 -func (me *Switch2jZdj9System) calculateMotor(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) { - //电机1 - state.J1_U1 = ACPahseN - state.J1_V1 = ACPahseN - state.J1_W1 = ACPahseN - state.J1_Traction = 0 - //A相电 - if state.J1_Power.PhaseA && state.J1_1DQJ { - state.J1_U1 = ACPahseA - } - //B相电 - if state.J1_Power.PhaseB && state.J1_1DQJF { - if state.J1_2DQJ { - if state.J1_AKB { - state.J1_V1 = ACPahseB - } - } else { - if !state.J1_AKB { - state.J1_W1 = ACPahseB - } - } - } - //C相电 - if state.J1_Power.PhaseC && state.J1_1DQJF { - if state.J1_2DQJ { - if state.J1_AKB { - state.J1_W1 = ACPahseC - } - } else { - if !state.J1_AKB { - state.J1_V1 = ACPahseC - } - } - } - //牵引力 - if state.J1_U1 == ACPahseA { - switch { - case state.J1_V1 == ACPahseB: //U-A V-B W-C - { - if state.J1_W1 == ACPahseC { - state.J1_Traction = 1 - } - } - case state.J1_V1 == ACPahseC: //U-A W-B V-C - { - if state.J1_W1 == ACPahseB { - state.J1_Traction = -1 - } - } - } - } - ///////////// - //电机2 - state.J2_U1 = ACPahseN - state.J2_V1 = ACPahseN - state.J2_W1 = ACPahseN - state.J2_Traction = 0 - //A相电 - if state.J2_Power.PhaseA && state.J2_1DQJ { - state.J2_U1 = ACPahseA - } - //B相电 - if state.J2_Power.PhaseB && state.J2_1DQJF { - if state.J2_2DQJ { - if state.J2_AKB { - state.J2_V1 = ACPahseB - } - } else { - if !state.J2_AKB { - state.J2_W1 = ACPahseB - } - } - } - //C相电 - if state.J2_Power.PhaseC && state.J2_1DQJF { - if state.J2_2DQJ { - if state.J2_AKB { - state.J2_W1 = ACPahseC - } - } else { - if !state.J2_AKB { - state.J2_V1 = ACPahseC - } - } - } - //牵引力 - if state.J2_U1 == ACPahseA { - switch { - case state.J2_V1 == ACPahseB: //U-A V-B W-C - { - if state.J2_W1 == ACPahseC { - state.J2_Traction = 1 - } - } - case state.J2_V1 == ACPahseC: //U-A W-B V-C - { - if state.J2_W1 == ACPahseB { - state.J2_Traction = -1 - } - } - } - } -} diff --git a/deprecated/system/system.go b/deprecated/system/system.go deleted file mode 100644 index 47e5d0a..0000000 --- a/deprecated/system/system.go +++ /dev/null @@ -1,126 +0,0 @@ -package system - -import ( - "fmt" - - "joylink.club/rtsssimulation/deprecated/simulation" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - sysEvent "joylink.club/rtsssimulation/deprecated/system/event" -) - -// EntityIdentity 实体身份定义 -type EntityIdentity struct { - Id string -} - -// EntityIdentityComponent 实体身份组件 -var EntityIdentityComponent = ecs.NewComponentType[EntityIdentity]() - -func FindEntityById(world ecs.World, id string) *ecs.Entry { - query := ecs.NewQuery(filter.Contains(EntityIdentityComponent)) - return QueryEntityById(world, query, id) -} -func QueryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry { - var entry *ecs.Entry = nil - func() { - defer simpleRecover() - q.Each(world, func(e *ecs.Entry) { - if id == EntityIdentityComponent.Get(e).Id { - entry = e - panic(fmt.Sprintf("找到实体[%s],结束查找", id)) - } - }) - }() - // - return entry -} - -var modelStorageQuery = ecs.NewQuery(filter.Contains(ModelStorageComponent)) - -// 测试用 -var XXDebug = false - -// FindModelStorage 获取模型仓库 -func FindModelStorage(world ecs.World) IModelManager { - if XXDebug { - e, _ := modelStorageQuery.First(world) - return ModelStorageComponent.Get(e).ModelManager - } else { - return simulation.FindSimulation(world.Id()).Repo() - } -} - -// 捕获panic并恢复执行 -func simpleRecover() { - recover() -} - -///////////////////////////////////////////////////////// - -// EntityTag 实体标签 -type EntityTag = ecs.IComponentType - -type EntityTagHandler struct { - Tag EntityTag -} - -func NewTag() EntityTag { - return ecs.NewComponentType[struct{}]() -} -func NewEntityTagHandler() *EntityTagHandler { - h := &EntityTagHandler{Tag: NewTag()} - return h -} - -var EntityTagHandlerComponent = ecs.NewComponentType[EntityTagHandler]() - -///////////////////////////////////////////////////////// - -// ModelStorageRef 模型仓库引用 -// 用于world内使用,查询模型 -type ModelStorageRef struct { - ModelManager IModelManager -} - -// ModelStorageComponent 模型仓库组件 -var ModelStorageComponent = ecs.NewComponentType[ModelStorageRef]() - -///////////////////////////////////////////////////////// - -// DriveRelay 驱动继电器 -// circuitModelId-如道岔模型id -// relayGroup-继电器组合类型 -// relayName-继电器功能名称 -// xh-true:吸合,false:落下 -func DriveRelay(w ecs.World, circuitModelId string, relayGroup string, relayName string, xh bool) bool { - if swModel := FindModelStorage(w).FindById(circuitModelId); swModel != nil { - if roler, isCr := swModel.(IRelayCRole); isCr { - if relayModel := roler.FindRelayModelByCRole(relayGroup, relayName); relayModel != nil { - if deviceModel, isDm := relayModel.(IDeviceModel); isDm { - relayId := deviceModel.Id() - sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayId, Xh: xh}) - return true - } - } - } - } - // - return false -} - -func createRelayNeedChangeEvent(w ecs.World, circuitModelId string, relayGroup string, relayName string, xh bool) (*sysEvent.RelayNeedChangeEvent, bool) { - if swModel := FindModelStorage(w).FindById(circuitModelId); swModel != nil { - if roler, isCr := swModel.(IRelayCRole); isCr { - if relayModel := roler.FindRelayModelByCRole(relayGroup, relayName); relayModel != nil { - if deviceModel, isDm := relayModel.(IDeviceModel); isDm { - relayId := deviceModel.Id() - return &sysEvent.RelayNeedChangeEvent{Id: relayId, Xh: xh}, true - } - } - } - } - // - return nil, false -} diff --git a/deprecated/system/timer_system.go b/deprecated/system/timer_system.go deleted file mode 100644 index 7b15256..0000000 --- a/deprecated/system/timer_system.go +++ /dev/null @@ -1,75 +0,0 @@ -package system - -import ( - "time" - - "joylink.club/ecs" - "joylink.club/ecs/filter" -) - -var SystemTimerComponent = ecs.NewComponentType[SystemTimer]() - -var timerQuery *ecs.Query = ecs.NewQuery(filter.Contains(SystemTimerComponent)) - -// TimerSystem 系统时钟操作 -type TimerSystem struct { -} - -func NewTimerSystem() *TimerSystem { - return &TimerSystem{} -} - -// Update world 执行 -func (me *TimerSystem) Update(w ecs.World) { - if e, ok := timerQuery.First(w); ok { - timer := SystemTimerComponent.Get(e) - timer.Tick(w.Tick()) - } -} - -// ResetWorldTimer 重置world时间 -func ResetWorldTimer(w ecs.World, time time.Time) { - if e, ok := timerQuery.First(w); ok { - timer := SystemTimerComponent.Get(e) - timer.ResetTime(time) - } -} - -// GetWorldNow 获取world当前时间 -func GetWorldNow(w ecs.World) *time.Time { - if e, ok := timerQuery.First(w); ok { - timer := SystemTimerComponent.Get(e) - now := timer.Now() - return &now - } - return nil -} - -///////////////////////////////////////////////////////////////// - -// SystemTimer 系统时钟,单例 -type SystemTimer struct { - timer *time.Time -} - -// NewSystemTimer 以指定时间构建 -func NewSystemTimer(time *time.Time) *SystemTimer { - return &SystemTimer{ - timer: time, - } -} - -// ResetTime 重置时间 -func (me *SystemTimer) ResetTime(time time.Time) { - *me.timer = time -} - -// Now 获取当前时间的副本 -func (me *SystemTimer) Now() time.Time { - return *me.timer -} - -// Tick tick系统时钟,单位ms -func (me *SystemTimer) Tick(tick int) { - *me.timer = me.timer.Add(time.Duration(tick) * time.Millisecond) -} diff --git a/deprecated/system/train_system.go b/deprecated/system/train_system.go deleted file mode 100644 index b48c469..0000000 --- a/deprecated/system/train_system.go +++ /dev/null @@ -1,12 +0,0 @@ -package system - -import "joylink.club/ecs" - -// TrainSystem 实现列车在link上运行的系统 -type TrainSystem struct { -} - -// Update world 执行 -func (me *TrainSystem) Update(world ecs.World) { - -} diff --git a/deprecated/system/type.go b/deprecated/system/type.go deleted file mode 100644 index c13a71c..0000000 --- a/deprecated/system/type.go +++ /dev/null @@ -1,10 +0,0 @@ -package system - -type Type int - -const ( - SWITCH_ZDJ9_2 Type = iota //ZDJ9双机牵引转辙机 - //SWITCH_ZDJ9_1 //ZDJ9单机牵引转辙机 - RELAY //继电器 - DEBUG -) diff --git a/deprecated/test1/main.go b/deprecated/test1/main.go deleted file mode 100644 index 21bc960..0000000 --- a/deprecated/test1/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "fmt" - - "joylink.club/rtsssimulation/repository/model/proto" -) - -func main() { - fmt.Println(proto.Relay_Model_name[int32(proto.Relay_JPXC_1700)]) -} diff --git a/deprecated/test1/sjzdj9/main.go b/deprecated/test1/sjzdj9/main.go deleted file mode 100644 index da59c3c..0000000 --- a/deprecated/test1/sjzdj9/main.go +++ /dev/null @@ -1,215 +0,0 @@ -package sjzdj9 - -import ( - "fmt" - "time" - - "joylink.club/rtsssimulation/deprecated/test1/tinit" - "joylink.club/rtsssimulation/repository/model/proto" - - "joylink.club/ecs" - "joylink.club/ecs/filter" - "joylink.club/rtsssimulation/deprecated/entities" - "joylink.club/rtsssimulation/deprecated/system" - "joylink.club/rtsssimulation/deprecated/test1/tmodel" - "joylink.club/rtsssimulation/deprecated/test1/tstorages" -) - -// Test 测试双机ZDJ9道岔 -func Test() { - system.XXDebug = true - //模型仓库 - modelStorage := tstorages.NewModelStorage() - addRelays(modelStorage) - addSwitchs(modelStorage) - worldStorage := &tstorages.WorldModelStorage{Share: modelStorage, Links: tstorages.NewModelStorage()} - // - worldConfig := tinit.WorldConfig{ - ModelManager: worldStorage, - Systems: []ecs.ISystem{system.NewSwitch2jZdj9System(), system.NewRelaySystem(), system.NewDebugSystem()}, - Tick: 200, - InitTime: time.Now(), - } - world := tinit.InitializeWorld(&worldConfig) - addEntities(world, modelStorage) - initComponents(world) - // - //ecs.EventsDebugEnable() - // - system.Switch2jzdj9AddListeners(world) - system.RelayAddListeners(world) - // - world.StartUp() - time.Sleep(1 * time.Second) - //联锁驱动反操 - system.Switch2jZdj9DriveYc(world, "sw1", true) - system.Switch2jZdj9DriveFc(world, "sw1", true) - // - time.Sleep(12 * time.Second) - - world.Close() -} - -func addEntities(w ecs.World, modelStorage *tstorages.ModelStorage) { - modelStorage.ForEachModelsByType(proto.DeviceType_DeviceType_Turnout, func(md tstorages.ModelData) { - entities.CreateSwitch2jzdj9Entity(w, md.Id()) - }) - modelStorage.ForEachModelsByType(proto.DeviceType_DeviceType_Relay, func(md tstorages.ModelData) { - entities.CreateRelayEntity(w, md.Id()) - }) -} - -// ////////////////////////////////////////////////////////////////// -func addRelays(modelStorage *tstorages.ModelStorage) { - //道岔sw1,双机zdj9 - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-dcj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-fcj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-ycj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-zdbj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-zfbj")) - - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-1dqj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-bhj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-2dqj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-1dqjf")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-dbj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-fbj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-qdj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j1-zbhj")) - - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-1dqj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-bhj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-2dqj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-1dqjf")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-dbj")) - modelStorage.AddModel(tmodel.NewRelayModel("sw1-sjzdj9-j2-fbj")) -} -func findRelayModel(modelStorage *tstorages.ModelStorage, id string) system.IDeviceModel { - return modelStorage.FindModelById(id) -} -func addSwitchs(modelStorage *tstorages.ModelStorage) { - sw1 := tmodel.NewSwitchModel("sw1") - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_DCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-dcj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_FCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-fcj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_YCJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-ycj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_ZDBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-zdbj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDC, RelayName: system.SJZDJ9_ZFBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-zfbj")}) - // - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_1DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-1dqj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_BHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-bhj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_2DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-2dqj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_1DQJF, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-1dqjf")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_DBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-dbj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_FBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-fbj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_QDJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-qdj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ1, RelayName: system.SJZDJ9_ZBHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j1-zbhj")}) - // - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_1DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-1dqj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_BHJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-bhj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_2DQJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-2dqj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_1DQJF, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-1dqjf")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_DBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-dbj")}) - sw1.AddRelay(&tmodel.SwitchRelay{RelayGroup: system.SJZDJ9_TDFJ2, RelayName: system.SJZDJ9_FBJ, Relay: findRelayModel(modelStorage, "sw1-sjzdj9-j2-fbj")}) - // - modelStorage.AddModel(sw1) -} - -// 初始化组件状态 -func initComponents(w ecs.World) { - //双机zdj9道岔相关继电器的状态初始化 - switchQuery := ecs.NewQuery(filter.Contains(system.Switch2jZdj9StateComponent)) - switchQuery.Each(w, func(e *ecs.Entry) { - swId := system.EntityIdentityComponent.Get(e).Id - swState := system.Switch2jZdj9StateComponent.Get(e) - swMd := system.FindModelStorage(w).FindById(swId).(*tmodel.SwitchModel) - for _, relay := range swMd.Relays { - relayId := relay.Relay.(system.IDeviceModel).Id() - relayEntry := system.FindEntityById(w, relayId) - relayState := system.RelayStateComponent.Get(relayEntry) - relayGroup := relay.RelayGroup - relayName := relay.RelayName - switch relayGroup { - case system.SJZDJ9_TDC: - { - switch relayName { - case system.SJZDJ9_DCJ: - relayState.Xh = swState.DCJ - relayState.ResetNeedXh() - case system.SJZDJ9_FCJ: - relayState.Xh = swState.FCJ - relayState.ResetNeedXh() - case system.SJZDJ9_YCJ: - relayState.Xh = swState.YCJ - relayState.ResetNeedXh() - case system.SJZDJ9_ZDBJ: - relayState.Xh = swState.ZDBJ - relayState.ResetNeedXh() - case system.SJZDJ9_ZFBJ: - relayState.Xh = swState.ZFBJ - relayState.ResetNeedXh() - default: - panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName)) - } - } - case system.SJZDJ9_TDFJ1: - { - switch relayName { - case system.SJZDJ9_1DQJ: - relayState.Xh = swState.J1_1DQJ - relayState.ResetNeedXh() - case system.SJZDJ9_BHJ: - relayState.Xh = swState.J1_BHJ - relayState.ResetNeedXh() - case system.SJZDJ9_2DQJ: - relayState.Xh = swState.J1_2DQJ - relayState.ResetNeedXh() - case system.SJZDJ9_1DQJF: - relayState.Xh = swState.J1_1DQJF - relayState.ResetNeedXh() - case system.SJZDJ9_DBJ: - relayState.Xh = swState.J1_DBJ - relayState.ResetNeedXh() - case system.SJZDJ9_FBJ: - relayState.Xh = swState.J1_FBJ - relayState.ResetNeedXh() - case system.SJZDJ9_QDJ: - relayState.Xh = swState.J1_QDJ - relayState.ResetNeedXh() - case system.SJZDJ9_ZBHJ: - relayState.Xh = swState.J1_ZBHJ - relayState.ResetNeedXh() - default: - panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName)) - } - } - case system.SJZDJ9_TDFJ2: - { - switch relayName { - case system.SJZDJ9_1DQJ: - relayState.Xh = swState.J2_1DQJ - relayState.ResetNeedXh() - case system.SJZDJ9_BHJ: - relayState.Xh = swState.J2_BHJ - relayState.ResetNeedXh() - case system.SJZDJ9_2DQJ: - relayState.Xh = swState.J2_2DQJ - relayState.ResetNeedXh() - case system.SJZDJ9_1DQJF: - relayState.Xh = swState.J2_1DQJF - relayState.ResetNeedXh() - case system.SJZDJ9_DBJ: - relayState.Xh = swState.J2_DBJ - relayState.ResetNeedXh() - case system.SJZDJ9_FBJ: - relayState.Xh = swState.J2_FBJ - relayState.ResetNeedXh() - default: - panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName)) - } - } - default: - panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器组合类型[%s]无法识别", swId, relayGroup)) - } - } //for - }) -} diff --git a/deprecated/test1/tinit/config.go b/deprecated/test1/tinit/config.go deleted file mode 100644 index 439aea1..0000000 --- a/deprecated/test1/tinit/config.go +++ /dev/null @@ -1,21 +0,0 @@ -package tinit - -import ( - "time" - - "joylink.club/rtsssimulation/deprecated/system" - - "joylink.club/ecs" -) - -// WorldConfig 仿真world配置 -type WorldConfig struct { - //模型管理器,接收模型仓库管理器实例的指针 - ModelManager system.IModelManager - //world 系统 - Systems []ecs.ISystem - //world tick - Tick int - //world 起始时间 - InitTime time.Time -} diff --git a/deprecated/test1/tinit/init.go b/deprecated/test1/tinit/init.go deleted file mode 100644 index e77260d..0000000 --- a/deprecated/test1/tinit/init.go +++ /dev/null @@ -1,25 +0,0 @@ -package tinit - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/deprecated/entities" - "joylink.club/rtsssimulation/deprecated/system" -) - -// InitializeWorld 初始化仿真world -func InitializeWorld(config *WorldConfig) ecs.World { - world := ecs.NewWorld(config.Tick) - // 添加系统 - world.AddSystem(system.NewTimerSystem()) - world.AddSystem(system.NewPercentageMovableSystem()) - for _, sys := range config.Systems { - world.AddSystem(sys) - } - // 添加内置实体 - entities.CreateSystemTimerEntity(world, config.InitTime) - if config.ModelManager != nil { - entities.CreateModelStorageEntity(world, config.ModelManager) - } - // - return world -} diff --git a/deprecated/test1/tmodel/device_model.go b/deprecated/test1/tmodel/device_model.go deleted file mode 100644 index 7d5cf87..0000000 --- a/deprecated/test1/tmodel/device_model.go +++ /dev/null @@ -1,20 +0,0 @@ -package tmodel - -import ( - "joylink.club/rtsssimulation/deprecated/system" -) - -// 设备模型基础信息 -type DeviceModel struct { - // 设备id - DevId string - // 设备类型 - DevType system.DeviceType -} - -func (me *DeviceModel) Id() string { - return me.DevId -} -func (me *DeviceModel) Type() system.DeviceType { - return me.DevType -} diff --git a/deprecated/test1/tmodel/relay_model.go b/deprecated/test1/tmodel/relay_model.go deleted file mode 100644 index 70b4ae4..0000000 --- a/deprecated/test1/tmodel/relay_model.go +++ /dev/null @@ -1,12 +0,0 @@ -package tmodel - -import "joylink.club/rtsssimulation/repository/model/proto" - -// 继电器模型 -type RelayModel struct { - DeviceModel -} - -func NewRelayModel(id string) *RelayModel { - return &RelayModel{DeviceModel: DeviceModel{DevId: id, DevType: proto.DeviceType_DeviceType_Relay}} -} diff --git a/deprecated/test1/tmodel/switch_model.go b/deprecated/test1/tmodel/switch_model.go deleted file mode 100644 index b8da1b6..0000000 --- a/deprecated/test1/tmodel/switch_model.go +++ /dev/null @@ -1,57 +0,0 @@ -package tmodel - -import ( - "joylink.club/rtsssimulation/deprecated/system" - "joylink.club/rtsssimulation/repository/model/proto" -) - -// 道岔电路系统中的继电器 -type SwitchRelay struct { - //继电器模型 - Relay system.IDeviceModel - //该继电器在该道岔电路系统中的组合类型 - RelayGroup string - //该继电器在该道岔电路系统中的功能名称 - RelayName string -} - -// 道岔 -type SwitchModel struct { - DeviceModel - //道岔电路系统中的继电器 - Relays []SwitchRelay -} - -func NewSwitchModel(id string) *SwitchModel { - return &SwitchModel{DeviceModel: DeviceModel{DevId: id, DevType: proto.DeviceType_DeviceType_Turnout}} -} -func (me *SwitchModel) AddRelay(relay *SwitchRelay) { - me.Relays = append(me.Relays, *relay) -} - -// FindCircuitRoleById 根据继电器id获取在具体电路中的电路角色 -// relayId-继电器id -// relayGroup-继电器组合类型 -// relayName-继电器在电路中的名称 -// find-true找到,false未找到 -func (me *SwitchModel) FindCircuitRoleById(relayId string) (relayGroup string, relayName string, find bool) { - for _, sr := range me.Relays { - id := sr.Relay.Id() - if id == relayId { - return sr.RelayGroup, sr.RelayName, true - } - } - return "", "", false -} - -// FindRelayModelByCRole 根据继电器具体电路角色来获取继电器设备模型 -// relayGroup-继电器组合类型 -// relayName-继电器在电路中的名称 -func (me *SwitchModel) FindRelayModelByCRole(relayGroup string, relayName string) system.IDeviceModel { - for _, sr := range me.Relays { - if sr.RelayGroup == relayGroup && sr.RelayName == relayName { - return sr.Relay - } - } - return nil -} diff --git a/deprecated/test1/tstorages/model_storage.go b/deprecated/test1/tstorages/model_storage.go deleted file mode 100644 index 23d3075..0000000 --- a/deprecated/test1/tstorages/model_storage.go +++ /dev/null @@ -1,84 +0,0 @@ -package tstorages - -import ( - "fmt" - - "joylink.club/rtsssimulation/deprecated/system" -) - -// 仿真模型数据定义 -type ModelData = system.IDeviceModel - -// 模型存储、管理仓库 -type ModelStorage struct { - //key-模型id,value-模型指针 - idModelMap map[string]ModelData - //key-设备类型,value-对应设备类型的所有模型数据的指针列表 - typeModelMap map[system.DeviceType][]ModelData -} - -func NewModelStorage() *ModelStorage { - return &ModelStorage{idModelMap: make(map[string]ModelData, 2048), typeModelMap: make(map[system.DeviceType][]ModelData, 128)} -} - -// 添加模型数据 -// m 为具体模型数据的指针 -func (me *ModelStorage) AddModel(m ModelData) error { - _, ok := me.idModelMap[m.Id()] - if ok { - return fmt.Errorf("模型[%s]已经存在", m.Id()) - } else { - me.idModelMap[m.Id()] = m - // - _, mdOk := me.typeModelMap[m.Type()] - if !mdOk { - me.typeModelMap[m.Type()] = make([]ModelData, 0, 512) - } - me.typeModelMap[m.Type()] = append(me.typeModelMap[m.Type()], m) - // - return nil - } -} - -// 根据设备类型获取该类型的所有设备数据 -func (me *ModelStorage) FindModelsByType(deviceType system.DeviceType) []ModelData { - models, ok := me.typeModelMap[deviceType] - if ok { - return models - } else { - return []ModelData{} - } -} - -// 根据设备id获取对应模型数据 -// 如果不存在返回nil -func (me *ModelStorage) FindModelById(id string) ModelData { - md, ok := me.idModelMap[id] - if ok { - return md - } else { - return nil - } -} - -// 遍历某个类型的所有设备 -func (me *ModelStorage) ForEachModelsByType(deviceType system.DeviceType, callback func(md ModelData)) { - mds := me.FindModelsByType(deviceType) - for _, modelData := range mds { - callback(modelData) - } -} - -// 根据id检测设备模型数据是否存在 -func (me *ModelStorage) HasModelById(id string) bool { - _, ok := me.idModelMap[id] - return ok -} - -// 获取当前模型数据总数量 -func (me *ModelStorage) AmountOfModels() int { - return len(me.idModelMap) -} -func (me *ModelStorage) AmountOfDeviceTypes() int { - return len(me.typeModelMap) -} diff --git a/deprecated/test1/tstorages/storage_manager.go b/deprecated/test1/tstorages/storage_manager.go deleted file mode 100644 index 5fa6512..0000000 --- a/deprecated/test1/tstorages/storage_manager.go +++ /dev/null @@ -1,74 +0,0 @@ -package tstorages - -import ( - "fmt" - - "joylink.club/rtsssimulation/deprecated/system" - "joylink.club/rtsssimulation/repository/model/proto" -) - -// 共享仓库映射 -var ShareStoragesMapper *ModelStoragesMapper = &ModelStoragesMapper{storages: make(map[string]*ModelStorage)} - -//////////////////////////////////////////////// - -type StorageKey struct { - LineId string - Version string -} - -func (me *StorageKey) Key() string { - return fmt.Sprintf("%s||%s", me.LineId, me.Version) -} - -//////////////////////////////////// - -type ModelStoragesMapper struct { - //共享模型仓库 - //key-StorageKey - storages map[string]*ModelStorage -} - -func (me *ModelStoragesMapper) FindShareModelStorage(skey StorageKey) *ModelStorage { - return me.storages[skey.Key()] -} -func (me *ModelStoragesMapper) AddShareModelStorage(skey StorageKey, storage *ModelStorage) { - me.storages[skey.Key()] = storage -} - -// 通过共享模型仓库创建world模型仓库 -func (me *ModelStoragesMapper) CreateWorldStorageWithShare(skey StorageKey, links *ModelStorage) *WorldModelStorage { - return &WorldModelStorage{Share: me.storages[skey.Key()], Links: links} -} - -/////////////////////////////////// - -// 仿真world的模型仓库 -type WorldModelStorage struct { - // 对公共模型的指针 - Share *ModelStorage - // 该world独享的轨道模型 - Links *ModelStorage -} - -// 根据模型的复合id获取模型数据 -func (me *WorldModelStorage) FindById(id string) system.IDeviceModel { - md := me.Links.FindModelById(id) - if md != nil { - return md - } - md = me.Share.FindModelById(id) - if md != nil { - return md - } - return nil -} - -// 获取某类型设备的所有模型数据 -func (me *WorldModelStorage) FindByType(deviceType system.DeviceType) []system.IDeviceModel { - if proto.DeviceType_DeviceType_Link == deviceType { - return me.Links.FindModelsByType(deviceType) - } else { - return me.Share.FindModelsByType(deviceType) - } -} diff --git a/examples/main.go b/examples/main.go index 1971e52..c43638b 100644 --- a/examples/main.go +++ b/examples/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - sim := rtss_simulation.NewSimulation(&repository.Repository{}) + sim, _ := rtss_simulation.NewSimulation(&repository.Repository{}) sim.StartUp() sim.SetSpeed(2) time.Sleep(1 * time.Second) diff --git a/examples/signal_2xh1/main.go b/examples/signal_2xh1/main.go index 9881e00..8fbae0c 100644 --- a/examples/signal_2xh1/main.go +++ b/examples/signal_2xh1/main.go @@ -1,6 +1,10 @@ package main import ( + "log/slog" + "os" + "time" + "joylink.club/ecs" rtss_simulation "joylink.club/rtsssimulation" "joylink.club/rtsssimulation/consts" @@ -9,9 +13,6 @@ import ( "joylink.club/rtsssimulation/fi" "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model/proto" - "log/slog" - "os" - "time" ) const ( @@ -29,7 +30,7 @@ func main() { proto.Version = "v1.0" addProtoSignal2XH1(proto) repo := repository.BuildRepositoryForSignalTest(proto) - sim := rtss_simulation.NewSimulation(repo) + sim, _ := rtss_simulation.NewSimulation(repo) loadEntities(sim, repo) sim.SetSpeed(0.1) sim.AddSystem(sigSys.NewSignalDebugSystem()) diff --git a/examples/signal_3xh1/main.go b/examples/signal_3xh1/main.go index 79fd99f..252b120 100644 --- a/examples/signal_3xh1/main.go +++ b/examples/signal_3xh1/main.go @@ -2,6 +2,10 @@ package main import ( "fmt" + "log/slog" + "os" + "time" + "joylink.club/ecs" rtss_simulation "joylink.club/rtsssimulation" "joylink.club/rtsssimulation/consts" @@ -10,9 +14,6 @@ import ( "joylink.club/rtsssimulation/fi" "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model/proto" - "log/slog" - "os" - "time" ) const ( @@ -29,7 +30,7 @@ func main() { proto.Version = "v1.0" addProtoSignal3XH1(proto) repo := repository.BuildRepositoryForSignalTest(proto) - sim := rtss_simulation.NewSimulation(repo) + sim, _ := rtss_simulation.NewSimulation(repo) loadEntities(sim, repo) sim.SetSpeed(1) sim.AddSystem(sigSys.NewSignalDebugSystem())