From 139a5abfaf572edd16d09db82a3a460bfe163b50 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Fri, 22 Sep 2023 14:39:36 +0800 Subject: [PATCH] psd --- entities/psd_entity.go | 44 +---------- repository/model.go | 25 ++++++ system/model_umi.go | 15 +--- system/psd_system.go | 175 ++++++++++++++--------------------------- 4 files changed, 88 insertions(+), 171 deletions(-) diff --git a/entities/psd_entity.go b/entities/psd_entity.go index f58eead..2c4ecde 100644 --- a/entities/psd_entity.go +++ b/entities/psd_entity.go @@ -1,49 +1,13 @@ package entities import ( - "github.com/yohamta/donburi" "joylink.club/ecs" "joylink.club/rtsssimulation/system" ) -// CreateStationPsdsCircuitEntity 创建车站屏蔽门电路实体 -func CreateStationPsdsCircuitEntity(w ecs.World, stationId string, psds []system.IPsdModel) *ecs.Entry { - circuit := w.Create(system.EntityIdentityComponent, system.StationPsdsCircuitStateComponent, system.PsdTagHandlerComponent) - system.EntityIdentityComponent.Set(circuit, &system.EntityIdentity{Id: stationId}) - system.StationPsdsCircuitStateComponent.Set(circuit, system.NewStationPsdsCircuitState()) - system.PsdTagHandlerComponent.Set(circuit, system.NewPsdTagHandler()) - tags := system.PsdTagHandlerComponent.Get(circuit) +// CreatePsdCircuitEntity 创建车站屏蔽门电路实体 +func CreatePsdCircuitEntity(w ecs.World, psdCircuitId string, psd system.IPsdModel) *ecs.Entry { + //e:=w.Create(system.EntityIdentityComponent,) // - for _, psd := range psds { - cc := make([]donburi.IComponentType, 6) - cc = append(cc, system.EntityIdentityComponent) - cc = append(cc, system.PsdStateComponent) - cc = append(cc, system.PercentageDeviceStateComponent) - if psd.IsS() { - cc = append(cc, tags.STag) - } - if psd.IsS4() { - cc = append(cc, tags.S4Tag) - } - if psd.IsS8() { - cc = append(cc, tags.S8Tag) - } - if psd.IsX() { - cc = append(cc, tags.XTag) - } - if psd.IsX4() { - cc = append(cc, tags.X4Tag) - } - if psd.IsX8() { - cc = append(cc, tags.X8Tag) - } - psdEntry := w.Create(cc...) - // - psdId := psd.(system.IDeviceModel).Id() - system.EntityIdentityComponent.Set(psdEntry, &system.EntityIdentity{Id: psdId}) - system.PsdStateComponent.Set(psdEntry, system.NewPsdState()) - system.PercentageDeviceStateComponent.Set(psdEntry, system.NewPercentageDeviceStateL()) - } - // - return circuit + return nil } diff --git a/repository/model.go b/repository/model.go index f830c19..ea1fda6 100644 --- a/repository/model.go +++ b/repository/model.go @@ -47,3 +47,28 @@ type IModelManager interface { //FindByType 获取某类型设备的所有模型数据 FindByType(deviceType proto.DeviceType) []Identity } + +// IPsdModel 仿真底层屏蔽门模型 +// 用户所有屏蔽门模型定义须实现该接口 +type IPsdModel interface { + //FindSPsdCells 获取车站上行侧所有屏蔽门子门 + FindSPsdCells() []Identity + //FindS4KmUpPsdCells 4编组运行方向为上行且在车站上行侧时,对应所有屏蔽门子门 + FindS4KmUpPsdCells() []Identity + //FindS8KmUpPsdCells 8编组运行方向为上行且在车站上行侧时,对应所有屏蔽门子门 + FindS8KmUpPsdCells() []Identity + //FindS4KmDownPsdCells 4编组运行方向为下行且在车站上行侧时,对应所有屏蔽门子门 + FindS4KmDownPsdCells() []Identity + //FindS8KmDownPsdCells 8编组运行方向为下行且在车站上行侧时,对应所有屏蔽门子门 + FindS8KmDownPsdCells() []Identity + //FindXPsdCells 获取车站上行侧所有屏蔽门子门 + FindXPsdCells() []Identity + //FindX4KmUpPsdCells 4编组运行方向为上行且在车站下行侧时,对应所有屏蔽门子门 + FindX4KmUpPsdCells() []Identity + //FindX8KmUpPsdCells 8编组运行方向为上行且在车站下行侧时,对应所有屏蔽门子门 + FindX8KmUpPsdCells() []Identity + //FindX4KmDownPsdCells 4编组运行方向为下行且在车站下行侧时,对应所有屏蔽门子门 + FindX4KmDownPsdCells() []Identity + //FindX8KmDownPsdCells 8编组运行方向为下行且在车站下行侧时,对应所有屏蔽门子门 + FindX8KmDownPsdCells() []Identity +} diff --git a/system/model_umi.go b/system/model_umi.go index 5fcbdff..4631cb1 100644 --- a/system/model_umi.go +++ b/system/model_umi.go @@ -27,17 +27,4 @@ type IModelManager = repository.IModelManager // IPsdModel 仿真底层屏蔽门模型 // 用户所有屏蔽门模型定义须实现该接口 -type IPsdModel interface { - //IsS true-上行 - IsS() bool - //IsS4 true-上行4编组 - IsS4() bool - //IsS8 true-上行8编组 - IsS8() bool - //IsX true-下行 - IsX() bool - //IsX4 true-下行4编组 - IsX4() bool - //IsX8 true-下行8编组 - IsX8() bool -} +type IPsdModel = repository.IPsdModel diff --git a/system/psd_system.go b/system/psd_system.go index af7aa34..7aef870 100644 --- a/system/psd_system.go +++ b/system/psd_system.go @@ -3,12 +3,11 @@ package system import ( "github.com/yohamta/donburi/filter" "joylink.club/ecs" - sysEvent "joylink.club/rtsssimulation/system/event" ) -// StationPsdsCircuitState 站台门控制电路状态 +// PsdCircuitState 站台门控制电路状态,Psd为车站所有屏蔽门子门的集合 // 旁路继电器的工作原理是,当电路中的电流超过预定的阈值时,旁路继电器会自动断开电路,从而防止电路发生短路或过载等故障。 -type StationPsdsCircuitState struct { +type PsdCircuitState struct { //关门继电器,true-吸合 XGMJ bool //4编组开门继电器,true-吸合 @@ -19,6 +18,8 @@ type StationPsdsCircuitState struct { XMGJ bool //门旁路继电器,true-吸合 XMPLJ bool + //车站下行侧屏蔽门开门码 + XOpenCode OpenCode //关门继电器,true-吸合 SGMJ bool //4编组开门继电器,true-吸合 @@ -29,10 +30,12 @@ type StationPsdsCircuitState struct { SMGJ bool //门旁路继电器,true-吸合 SMPLJ bool + //车站上行侧屏蔽门开门码 + SOpenCode OpenCode } -// PsdState 站台一侧屏蔽门由多个Psd构成 -type PsdState struct { +// PsdCellState 车站屏蔽门子门 +type PsdCellState struct { //屏蔽门打开的百分比,则0-完全关闭,100-完全打开 Rate int //关门操作被激活 @@ -41,53 +44,64 @@ type PsdState struct { actOpening bool } -// PsdTagHandler 屏蔽门标签,用于ecs query -type PsdTagHandler struct { - //上行标签 - STag EntityTag - //上行4编组标签 - S4Tag EntityTag - //上行8编组标签 - S8Tag EntityTag - //下行标签 - XTag EntityTag - //下行4编组标签 - X4Tag EntityTag - //下行8编组标签 - X8Tag EntityTag +// 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 } -// StationPsdsCircuitSystem 站台门电路系统 -type StationPsdsCircuitSystem struct { +// PsdCellsQuery 屏蔽门子门查询 +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] } -func NewStationPsdsCircuitSystem() *StationPsdsCircuitSystem { - return &StationPsdsCircuitSystem{} -} -func NewPsdTagHandler() *PsdTagHandler { - return &PsdTagHandler{STag: NewTag(), S4Tag: NewTag(), S8Tag: NewTag(), XTag: NewTag(), X4Tag: NewTag(), X8Tag: NewTag()} -} -func NewStationPsdsCircuitState() *StationPsdsCircuitState { - return &StationPsdsCircuitState{} -} -func NewPsdState() *PsdState { - return &PsdState{Rate: PSD_CLOSED_RATE} +// PsdsCircuitSystem 站台门电路系统 +type PsdsCircuitSystem struct { } -var StationPsdsCircuitStateComponent = ecs.NewComponentType[StationPsdsCircuitState]() -var PsdTagHandlerComponent = ecs.NewComponentType[PsdTagHandler]() -var PsdStateComponent = ecs.NewComponentType[PsdState]() -var psdsQuery = ecs.NewQuery(filter.Contains(PsdStateComponent, PercentageDeviceStateComponent)) -var psdsCircuitQuery = ecs.NewQuery(filter.Contains(StationPsdsCircuitStateComponent)) +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} +} -// PSD -const ( - PSD_CLOSED int64 = 0 //psd 完全关闭 - PSD_OPENED int64 = 2000 //psd 完全打开 +var ( + PsdCircuitStateComponent = ecs.NewComponentType[PsdCircuitState]() + PsdCellStateComponent = ecs.NewComponentType[PsdCellState]() + PsdTagsComponent = ecs.NewComponentType[PsdTags]() ) + +// OpenCode 开门码 +type OpenCode int8 + +// 开门码枚举 const ( - PSD_CLOSED_RATE = 0 - PSD_OPENED_RATE = 100 + OpenCodeNon OpenCode = iota + 1 //无效开门码 + OpenCodeUp //运行方向为上行的开门码 + OpenCodeDown //运行方向为下行的开门码 ) // PSD组合类型和继电器功能名称 @@ -106,79 +120,6 @@ const ( ) // Update world 执行 -func (me *StationPsdsCircuitSystem) Update(w ecs.World) { - me.psdUpdate(w) - me.circuitUpdate(w) -} - -// 车站上下行屏蔽门电路运算 -func (me *StationPsdsCircuitSystem) circuitUpdate(w ecs.World) { - psdsCircuitQuery.Each(w, func(e *ecs.Entry) { - me.calculateMG(w, e) - me.calculateActGM(w, e) - }) -} - -// 关门动作运算 -func (me *StationPsdsCircuitSystem) calculateActGM(w ecs.World, circuitEntry *ecs.Entry) { - circuit := StationPsdsCircuitStateComponent.Get(circuitEntry) - tags := PsdTagHandlerComponent.Get(circuitEntry) - //上行 - isActSGm := circuit.SGMJ && !circuit.G4SKMJ && !circuit.G8SKMJ - sQuery := ecs.NewQuery(filter.Contains(tags.STag)) - sQuery.Each(w, func(sPsd *ecs.Entry) { - sPsdState := PsdStateComponent.Get(sPsd) - sPsdState.actClosing = isActSGm - }) - //下行 - isActXGm := circuit.XGMJ && !circuit.G4XKMJ && !circuit.G8XKMJ - xQuery := ecs.NewQuery(filter.Contains(tags.XTag)) - xQuery.Each(w, func(xPsd *ecs.Entry) { - xPsdState := PsdStateComponent.Get(xPsd) - xPsdState.actClosing = isActXGm - }) -} - -// 4编组开门动作运算 -func (me *StationPsdsCircuitSystem) calculateAct4KM(w ecs.World, circuitEntry *ecs.Entry) { - -} - -// 门关状态运算 -func (me *StationPsdsCircuitSystem) calculateMG(w ecs.World, circuitEntry *ecs.Entry) { - tags := PsdTagHandlerComponent.Get(circuitEntry) - circuit := StationPsdsCircuitStateComponent.Get(circuitEntry) - //上行 - isSMg := true - sQuery := ecs.NewQuery(filter.Contains(tags.STag)) - sQuery.Each(w, func(sPsd *ecs.Entry) { - if isSMg { - isSMg = PsdStateComponent.Get(sPsd).Rate == PSD_CLOSED_RATE - } - }) - if isSMg != circuit.SMGJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(circuitEntry).Id, PSD_GT, PSD_SMGJ, isSMg); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } - //下行 - isXMg := true - xQuery := ecs.NewQuery(filter.Contains(tags.XTag)) - xQuery.Each(w, func(xPsd *ecs.Entry) { - if isXMg { - isXMg = PsdStateComponent.Get(xPsd).Rate == PSD_CLOSED_RATE - } - }) - if isXMg != circuit.XMGJ { - if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(circuitEntry).Id, PSD_GT, PSD_XMGJ, isSMg); ok { - sysEvent.RelayNeedChangeEventBus.Publish(w, event) - } - } -} - -////////////////////////////////////////////////////////////////////// - -// 单个屏蔽门运算 -func (me *StationPsdsCircuitSystem) psdUpdate(w ecs.World) { +func (me *PsdsCircuitSystem) Update(w ecs.World) { }