This commit is contained in:
xzb 2023-09-28 10:58:01 +08:00
parent af36695fdf
commit e0bcb22435

View File

@ -3,6 +3,7 @@ package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
)
// PsdCircuitState 站台门控制电路状态Psd为车站所有屏蔽门子门的集合
@ -10,10 +11,16 @@ import (
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-吸合
@ -22,10 +29,16 @@ type PsdCircuitState struct {
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-吸合
@ -127,204 +140,209 @@ const (
// Update world 执行
func (me *PsdsCircuitSystem) Update(w ecs.World) {
//
psdCellQuery.Each(w, func(cellEntry *ecs.Entry) {
me.calculateCellMove(w, cellEntry)
})
//
psdCircuitQuery.Each(w, func(psdCircuitEntry *ecs.Entry) {
me.calculateSMG(w, psdCircuitEntry)
me.calculateXMG(w, psdCircuitEntry)
me.calculateSGM(w, psdCircuitEntry)
me.calculateXGM(w, psdCircuitEntry)
me.calculate4SKM(w, psdCircuitEntry)
me.calculate4XKM(w, psdCircuitEntry)
me.calculate8SKM(w, psdCircuitEntry)
me.calculate8XKM(w, psdCircuitEntry)
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, cellEntry *ecs.Entry) {
move := PercentageDeviceStateComponent.Get(cellEntry)
cell := PsdCellStateComponent.Get(cellEntry)
cell.Rate = move.GetRate()
if cell.actOpening {
move.V = 50
if cell.Rate >= PsdCellRateOpened { //开门到位
move.V = 0
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 cell.actClosing {
move.V = -50
if cell.Rate <= PsdCellRateClosed { //关门到位
move.V = 0
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 !cell.actOpening && !cell.actClosing {
move.V = 0
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) calculateRelayLc(w ecs.World, psdCircuitEntry *ecs.Entry) {
//psd := PsdCircuitStateComponent.Get(psdCircuitEntry)
func (me *PsdsCircuitSystem) calculateMG(w ecs.World, psdCircuitEntry *ecs.Entry) {
state := PsdCircuitStateComponent.Get(psdCircuitEntry)
psdTags := PsdTagsComponent.Get(psdCircuitEntry)
//
}
// 车站上行侧所有屏蔽门子门关运算
func (me *PsdsCircuitSystem) calculateSMG(w ecs.World, psdCircuitEntry *ecs.Entry) {
tags := PsdTagsComponent.Get(psdCircuitEntry)
isSMG := true
tags.psdCellsQuery(tags.STag).Each(w, func(cellEntry *ecs.Entry) {
if isSMG {
cell := PsdCellStateComponent.Get(cellEntry)
isSMG = cell.Rate <= PsdCellRateClosed
}
})
PsdCircuitStateComponent.Get(psdCircuitEntry).SMGJ = isSMG
}
// 车站下行侧所有屏蔽门子门关运算
func (me *PsdsCircuitSystem) calculateXMG(w ecs.World, psdCircuitEntry *ecs.Entry) {
tags := PsdTagsComponent.Get(psdCircuitEntry)
isXMG := true
tags.psdCellsQuery(tags.XTag).Each(w, func(cellEntry *ecs.Entry) {
psdTags.psdCellsQuery(psdTags.XTag).Each(w, func(cellEntry *ecs.Entry) {
if isXMG {
cell := PsdCellStateComponent.Get(cellEntry)
isXMG = cell.Rate <= PsdCellRateClosed
cellState := PsdCellStateComponent.Get(cellEntry)
if cellState.Rate > PsdCellRateClosed {
isXMG = false
}
}
})
PsdCircuitStateComponent.Get(psdCircuitEntry).XMGJ = isXMG
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
}
}
// 车站上行侧关门操作运算
func (me *PsdsCircuitSystem) calculateSGM(w ecs.World, psdCircuitEntry *ecs.Entry) {
psd := PsdCircuitStateComponent.Get(psdCircuitEntry)
if psd.SGMJ && !psd.G4SKMJ && !psd.G8SKMJ {
tags := PsdTagsComponent.Get(psdCircuitEntry)
tags.psdCellsQuery(tags.STag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = cell.Rate > PsdCellRateClosed
cell.actOpening = false
})
}
}
// 车站下行侧关门操作运算
func (me *PsdsCircuitSystem) calculateXGM(w ecs.World, psdCircuitEntry *ecs.Entry) {
psd := PsdCircuitStateComponent.Get(psdCircuitEntry)
if psd.XGMJ && !psd.G4XKMJ && !psd.G8XKMJ {
tags := PsdTagsComponent.Get(psdCircuitEntry)
tags.psdCellsQuery(tags.XTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = cell.Rate > PsdCellRateClosed
cell.actOpening = false
})
}
}
// 车站上行侧4编组开门操作运算
func (me *PsdsCircuitSystem) calculate4SKM(w ecs.World, psdCircuitEntry *ecs.Entry) {
psd := PsdCircuitStateComponent.Get(psdCircuitEntry)
if psd.G4SKMJ && !psd.G8SKMJ && !psd.SGMJ && psd.SOpenCode != OpenCodeNon {
tags := PsdTagsComponent.Get(psdCircuitEntry)
switch {
case psd.SOpenCode == OpenCodeUp:
{
tags.psdCellsQuery(tags.S4KmUpTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = false
cell.actOpening = cell.Rate < PsdCellRateOpened
})
}
case psd.SOpenCode == OpenCodeDown:
{
tags.psdCellsQuery(tags.S4KmDownTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = false
cell.actOpening = cell.Rate < PsdCellRateOpened
})
}
if isSMG != state.SMGJ {
if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_SMGJ, isSMG); ok {
sysEvent.RelayNeedChangeEventBus.Publish(w, event)
}
}
}
// 车站下行侧4编组开门操作运算
func (me *PsdsCircuitSystem) calculate4XKM(w ecs.World, psdCircuitEntry *ecs.Entry) {
psd := PsdCircuitStateComponent.Get(psdCircuitEntry)
if psd.G4XKMJ && !psd.G8XKMJ && !psd.XGMJ && psd.XOpenCode != OpenCodeNon {
tags := PsdTagsComponent.Get(psdCircuitEntry)
switch {
case psd.XOpenCode == OpenCodeUp:
{
tags.psdCellsQuery(tags.X4KmUpTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = false
cell.actOpening = cell.Rate < PsdCellRateOpened
})
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)
}
case psd.XOpenCode == OpenCodeDown:
{
tags.psdCellsQuery(tags.X4KmDownTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = false
cell.actOpening = cell.Rate < PsdCellRateOpened
})
}
if isSGM != state.SGMJ {
if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_SGMJ, isSGM); ok {
sysEvent.RelayNeedChangeEventBus.Publish(w, event)
}
}
}
// 车站上行侧8编组开门操作运算
func (me *PsdsCircuitSystem) calculate8SKM(w ecs.World, psdCircuitEntry *ecs.Entry) {
psd := PsdCircuitStateComponent.Get(psdCircuitEntry)
if !psd.G4SKMJ && psd.G8SKMJ && !psd.SGMJ && psd.SOpenCode != OpenCodeNon {
tags := PsdTagsComponent.Get(psdCircuitEntry)
switch {
case psd.SOpenCode == OpenCodeUp:
{
tags.psdCellsQuery(tags.S8KmUpTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = false
cell.actOpening = cell.Rate < PsdCellRateOpened
})
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)
}
case psd.SOpenCode == OpenCodeDown:
{
tags.psdCellsQuery(tags.S8KmDownTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = false
cell.actOpening = cell.Rate < PsdCellRateOpened
})
}
if is4SKM != state.G4SKMJ {
if event, ok := createRelayNeedChangeEvent(w, EntityIdentityComponent.Get(psdCircuitEntry).Id, PSD_GT, PSD_4SKMJ, is4SKM); ok {
sysEvent.RelayNeedChangeEventBus.Publish(w, event)
}
}
}
// 车站下行侧8编组开门操作运算
func (me *PsdsCircuitSystem) calculate8XKM(w ecs.World, psdCircuitEntry *ecs.Entry) {
psd := PsdCircuitStateComponent.Get(psdCircuitEntry)
if !psd.G4XKMJ && psd.G8XKMJ && !psd.XGMJ && psd.XOpenCode != OpenCodeNon {
tags := PsdTagsComponent.Get(psdCircuitEntry)
switch {
case psd.XOpenCode == OpenCodeUp:
{
tags.psdCellsQuery(tags.X8KmUpTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = false
cell.actOpening = cell.Rate < PsdCellRateOpened
})
}
case psd.XOpenCode == OpenCodeDown:
{
tags.psdCellsQuery(tags.X8KmDownTag).Each(w, func(cellEntry *ecs.Entry) {
cell := PsdCellStateComponent.Get(cellEntry)
cell.actClosing = false
cell.actOpening = cell.Rate < PsdCellRateOpened
})
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)
}
}
}