修改屏蔽门ecs逻辑
This commit is contained in:
parent
3ce9306624
commit
9554930705
@ -14,8 +14,9 @@ var PsdCircuitType = ecs.NewComponentType[PsdCircuit]()
|
||||
type PsdCircuit struct {
|
||||
//屏蔽门驱动继电器
|
||||
GMJ *ecs.Entry
|
||||
KMJ4 *ecs.Entry
|
||||
KMJ8 *ecs.Entry
|
||||
//KMJ4 *ecs.Entry
|
||||
//KMJ8 *ecs.Entry
|
||||
KMJMap map[int32]*ecs.Entry //开门继电器,k-编组
|
||||
//屏蔽门表示继电器
|
||||
MGJ *ecs.Entry
|
||||
MPLJ *ecs.Entry
|
||||
@ -86,8 +87,9 @@ type Mkx struct {
|
||||
var PscType = ecs.NewComponentType[Psc]()
|
||||
|
||||
type Psc struct {
|
||||
InterlockKM4 bool
|
||||
InterlockKM8 bool
|
||||
//InterlockKM4 bool
|
||||
//InterlockKM8 bool
|
||||
InterlockKmGroup map[int32]bool //开门编组。k-编组 v-设置开门
|
||||
InterlockGM bool
|
||||
InterlockMPL bool
|
||||
|
||||
|
@ -44,7 +44,7 @@ func loadPsdCircuit(world ecs.World, entry *ecs.Entry, psd *repository.Psd, entr
|
||||
if len(psd.ComponentGroups()) == 0 {
|
||||
return
|
||||
}
|
||||
circuit := &component.PsdCircuit{}
|
||||
circuit := &component.PsdCircuit{KMJMap: make(map[int32]*ecs.Entry)}
|
||||
for _, group := range psd.ComponentGroups() {
|
||||
for _, ec := range group.Components() {
|
||||
relay := ec.(*repository.Relay)
|
||||
@ -52,9 +52,9 @@ func loadPsdCircuit(world ecs.World, entry *ecs.Entry, psd *repository.Psd, entr
|
||||
case "XGMJ", "SGMJ":
|
||||
circuit.GMJ = NewRelayEntity(world, relay, entryMap)
|
||||
case "4XKMJ", "4SKMJ":
|
||||
circuit.KMJ4 = NewRelayEntity(world, relay, entryMap)
|
||||
circuit.KMJMap[4] = NewRelayEntity(world, relay, entryMap)
|
||||
case "8XKMJ", "8SKMJ":
|
||||
circuit.KMJ8 = NewRelayEntity(world, relay, entryMap)
|
||||
circuit.KMJMap[8] = NewRelayEntity(world, relay, entryMap)
|
||||
case "XMGJ", "SMGJ":
|
||||
circuit.MGJ = NewRelayEntity(world, relay, entryMap)
|
||||
case "XMPLJ", "SMPLJ":
|
||||
|
170
fi/psd.go
170
fi/psd.go
@ -1,6 +1,7 @@
|
||||
package fi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
@ -8,63 +9,29 @@ import (
|
||||
"joylink.club/rtsssimulation/entity"
|
||||
)
|
||||
|
||||
func SetInterlockKm4(world ecs.World, id string) error {
|
||||
func SetInterlockKm(world ecs.World, psdId string, group int32) error {
|
||||
result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] {
|
||||
wd := entity.GetWorldData(world)
|
||||
entry, ok := wd.EntityMap[id]
|
||||
entry, ok := wd.EntityMap[psdId]
|
||||
if ok {
|
||||
err := setInterlockKm(wd, entry, 4)
|
||||
err := setInterlockKm(wd, entry, group)
|
||||
if err != nil {
|
||||
return ecs.NewErrResult(err)
|
||||
}
|
||||
} else {
|
||||
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id))
|
||||
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", psdId))
|
||||
}
|
||||
return ecs.NewOkEmptyResult()
|
||||
})
|
||||
return result.Err
|
||||
}
|
||||
|
||||
func CancelInterlockKm4(world ecs.World, id string) error {
|
||||
func CancelInterlockKm(world ecs.World, id string, group int32) error {
|
||||
result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] {
|
||||
wd := entity.GetWorldData(world)
|
||||
entry, ok := wd.EntityMap[id]
|
||||
if ok {
|
||||
err := cancelInterlockKm(wd, entry, 4)
|
||||
if err != nil {
|
||||
return ecs.NewErrResult(err)
|
||||
}
|
||||
} else {
|
||||
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id))
|
||||
}
|
||||
return ecs.NewOkEmptyResult()
|
||||
})
|
||||
return result.Err
|
||||
}
|
||||
|
||||
func SetInterlockKm8(world ecs.World, id string) error {
|
||||
result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] {
|
||||
wd := entity.GetWorldData(world)
|
||||
entry, ok := wd.EntityMap[id]
|
||||
if ok {
|
||||
err := setInterlockKm(wd, entry, 8)
|
||||
if err != nil {
|
||||
return ecs.NewErrResult(err)
|
||||
}
|
||||
} else {
|
||||
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id))
|
||||
}
|
||||
return ecs.NewOkEmptyResult()
|
||||
})
|
||||
return result.Err
|
||||
}
|
||||
|
||||
func CancelInterlockKm8(world ecs.World, id string) error {
|
||||
result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] {
|
||||
wd := entity.GetWorldData(world)
|
||||
entry, ok := wd.EntityMap[id]
|
||||
if ok {
|
||||
err := cancelInterlockKm(wd, entry, 8)
|
||||
err := cancelInterlockKm(wd, entry, group)
|
||||
if err != nil {
|
||||
return ecs.NewErrResult(err)
|
||||
}
|
||||
@ -273,45 +240,35 @@ func setQDTC(wd *component.WorldData, psdEntry *ecs.Entry) error {
|
||||
}
|
||||
|
||||
// 设置联锁开门
|
||||
func setInterlockKm(wd *component.WorldData, psdEntry *ecs.Entry, group int) error {
|
||||
func setInterlockKm(wd *component.WorldData, psdEntry *ecs.Entry, group int32) error {
|
||||
if psdEntry.HasComponent(component.PsdCircuitType) { //有联锁区段电路
|
||||
circuit := component.PsdCircuitType.Get(psdEntry)
|
||||
switch group {
|
||||
case 4:
|
||||
return setInterlockDriveKm4(wd, circuit)
|
||||
case 8:
|
||||
return setInterlockDriveKm8(wd, circuit)
|
||||
kmj := circuit.KMJMap[group]
|
||||
if kmj == nil {
|
||||
id := component.UidType.Get(psdEntry).Id
|
||||
return errors.New(fmt.Sprintf("屏蔽门[id:%s]不支持[%d]编组操作", id, group))
|
||||
}
|
||||
return setRelayDriveKm(wd, circuit, group)
|
||||
} else {
|
||||
psc := component.PscType.Get(psdEntry)
|
||||
switch group {
|
||||
case 4:
|
||||
setPscKm4(psc)
|
||||
case 8:
|
||||
setPscKm8(psc)
|
||||
}
|
||||
psc.InterlockKmGroup[group] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 取消联锁开门
|
||||
func cancelInterlockKm(wd *component.WorldData, psdEntry *ecs.Entry, group int) error {
|
||||
func cancelInterlockKm(wd *component.WorldData, psdEntry *ecs.Entry, group int32) error {
|
||||
if psdEntry.HasComponent(component.PsdCircuitType) { //有联锁区段电路
|
||||
circuit := component.PsdCircuitType.Get(psdEntry)
|
||||
switch group {
|
||||
case 4:
|
||||
return wd.SetQdBit(component.UidType.Get(circuit.KMJ4).Id, false)
|
||||
case 8:
|
||||
return wd.SetQdBit(component.UidType.Get(circuit.KMJ8).Id, false)
|
||||
kmj := circuit.KMJMap[group]
|
||||
if kmj == nil {
|
||||
id := component.UidType.Get(psdEntry).Id
|
||||
return errors.New(fmt.Sprintf("屏蔽门[id:%s]不支持[%d]编组操作", id, group))
|
||||
}
|
||||
return cancelRelayDriveKm(wd, circuit, group)
|
||||
} else {
|
||||
psc := component.PscType.Get(psdEntry)
|
||||
switch group {
|
||||
case 4:
|
||||
psc.InterlockKM4 = false
|
||||
case 8:
|
||||
psc.InterlockKM8 = false
|
||||
}
|
||||
psc.InterlockKmGroup[group] = false
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -320,19 +277,22 @@ func cancelInterlockKm(wd *component.WorldData, psdEntry *ecs.Entry, group int)
|
||||
func setInterlockGm(wd *component.WorldData, psdEntry *ecs.Entry) error {
|
||||
if psdEntry.HasComponent(component.PsdCircuitType) { //有联锁区段电路
|
||||
circuit := component.PsdCircuitType.Get(psdEntry)
|
||||
return setInterlockDriveGm(wd, circuit)
|
||||
return setRelayDriveGm(wd, circuit)
|
||||
} else {
|
||||
psc := component.PscType.Get(psdEntry)
|
||||
setPscGm(psc)
|
||||
for i, _ := range psc.InterlockKmGroup {
|
||||
psc.InterlockKmGroup[i] = false
|
||||
}
|
||||
psc.InterlockGM = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 取消联锁关门
|
||||
func cancelInterlockGm(wd *component.WorldData, psdEntry *ecs.Entry) error {
|
||||
if psdEntry.HasComponent(component.PsdCircuitType) {
|
||||
if psdEntry.HasComponent(component.PsdCircuitType) { //有联锁区段电路
|
||||
circuit := component.PsdCircuitType.Get(psdEntry)
|
||||
return wd.SetQdBit(component.UidType.Get(circuit.GMJ).Id, false)
|
||||
return cancelRelayDriveGm(wd, circuit)
|
||||
} else {
|
||||
psc := component.PscType.Get(psdEntry)
|
||||
psc.InterlockGM = false
|
||||
@ -340,50 +300,46 @@ func cancelInterlockGm(wd *component.WorldData, psdEntry *ecs.Entry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 联锁驱动4编组开门
|
||||
func setInterlockDriveKm4(wd *component.WorldData, circuit *component.PsdCircuit) error {
|
||||
return wd.SetQdBits([]*component.QdBitParam{
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, false),
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.KMJ4).Id, true),
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.KMJ8).Id, false),
|
||||
})
|
||||
// 设置继电器驱动开门
|
||||
func setRelayDriveKm(wd *component.WorldData, circuit *component.PsdCircuit, group int32) error {
|
||||
var params []*component.QdBitParam
|
||||
params = append(params, component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, false))
|
||||
for g, entry := range circuit.KMJMap {
|
||||
if g == group {
|
||||
params = append(params, component.NewQdBitParam(component.UidType.Get(entry).Id, true))
|
||||
} else {
|
||||
params = append(params, component.NewQdBitParam(component.UidType.Get(entry).Id, false))
|
||||
}
|
||||
}
|
||||
|
||||
return wd.SetQdBits(params)
|
||||
}
|
||||
|
||||
// 联锁驱动8编组开门
|
||||
func setInterlockDriveKm8(wd *component.WorldData, circuit *component.PsdCircuit) error {
|
||||
return wd.SetQdBits([]*component.QdBitParam{
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, false),
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.KMJ4).Id, false),
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.KMJ8).Id, true),
|
||||
})
|
||||
// 取消继电器驱动开门
|
||||
func cancelRelayDriveKm(wd *component.WorldData, circuit *component.PsdCircuit, group int32) error {
|
||||
var params []*component.QdBitParam
|
||||
for _, entry := range circuit.KMJMap {
|
||||
params = append(params, component.NewQdBitParam(component.UidType.Get(entry).Id, false))
|
||||
}
|
||||
|
||||
return wd.SetQdBits(params)
|
||||
}
|
||||
|
||||
// 联锁驱动关门
|
||||
func setInterlockDriveGm(wd *component.WorldData, circuit *component.PsdCircuit) error {
|
||||
return wd.SetQdBits([]*component.QdBitParam{
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, true),
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.KMJ4).Id, false),
|
||||
component.NewQdBitParam(component.UidType.Get(circuit.KMJ8).Id, false),
|
||||
})
|
||||
// 设置继电器驱动关门
|
||||
func setRelayDriveGm(wd *component.WorldData, circuit *component.PsdCircuit) error {
|
||||
var params []*component.QdBitParam
|
||||
params = append(params, component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, true))
|
||||
for _, entry := range circuit.KMJMap {
|
||||
params = append(params, component.NewQdBitParam(component.UidType.Get(entry).Id, false))
|
||||
}
|
||||
|
||||
return wd.SetQdBits(params)
|
||||
}
|
||||
|
||||
// 直接设置PSC的状态4编组开门。在无屏蔽门电路时使用
|
||||
func setPscKm4(psc *component.Psc) {
|
||||
psc.InterlockKM4 = true
|
||||
psc.InterlockKM8 = false
|
||||
psc.InterlockGM = false
|
||||
}
|
||||
// 取消继电器驱动关门
|
||||
func cancelRelayDriveGm(wd *component.WorldData, circuit *component.PsdCircuit) error {
|
||||
var params []*component.QdBitParam
|
||||
params = append(params, component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, false))
|
||||
|
||||
// 直接设置PSC的状态8编组开门。在无屏蔽门电路时使用
|
||||
func setPscKm8(psc *component.Psc) {
|
||||
psc.InterlockKM4 = false
|
||||
psc.InterlockKM8 = true
|
||||
psc.InterlockGM = false
|
||||
}
|
||||
|
||||
// 直接设置PSC的状态关门。在无屏蔽门电路时使用
|
||||
func setPscGm(psc *component.Psc) {
|
||||
psc.InterlockKM4 = false
|
||||
psc.InterlockKM8 = false
|
||||
psc.InterlockGM = true
|
||||
return wd.SetQdBits(params)
|
||||
}
|
||||
|
@ -29,14 +29,15 @@ func (p *PsdSys) Update(world ecs.World) {
|
||||
if entry.HasComponent(component.PsdCircuitType) { //有屏蔽门电路
|
||||
psdCircuit := component.PsdCircuitType.Get(entry)
|
||||
//屏蔽门驱动
|
||||
if psdCircuit.GMJ != nil && psdCircuit.KMJ4 != nil && psdCircuit.KMJ8 != nil {
|
||||
if psdCircuit.GMJ != nil {
|
||||
p.exciteGMJ(worldData, psdCircuit)
|
||||
p.exciteKMJ4(worldData, psdCircuit)
|
||||
p.exciteKMJ8(worldData, psdCircuit)
|
||||
psc.InterlockGM = component.BitStateType.Get(psdCircuit.GMJ).Val
|
||||
psc.InterlockKM4 = component.BitStateType.Get(psdCircuit.KMJ4).Val
|
||||
psc.InterlockKM8 = component.BitStateType.Get(psdCircuit.KMJ8).Val
|
||||
}
|
||||
for group, kmj := range psdCircuit.KMJMap {
|
||||
p.exciteKMJ(worldData, psdCircuit, kmj)
|
||||
psc.InterlockKmGroup[group] = component.BitStateType.Get(kmj).Val
|
||||
}
|
||||
|
||||
if psdCircuit.MGJ != nil {
|
||||
p.exciteMGJ(psdCircuit, asdList)
|
||||
psdState.Close = component.BitStateType.Get(psdCircuit.MGJ).Val
|
||||
@ -96,12 +97,13 @@ func (p *PsdSys) Update(world ecs.World) {
|
||||
} else if !psc.InterlockMPL { //联锁操作没有被旁路
|
||||
if psc.InterlockGM {
|
||||
p.gm(asdList)
|
||||
} else if psc.InterlockKM8 {
|
||||
group := psd.FindAsdGroup(8)
|
||||
p.km(group.Start, group.End, asdList)
|
||||
} else if psc.InterlockKM4 {
|
||||
group := psd.FindAsdGroup(4)
|
||||
p.km(group.Start, group.End, asdList)
|
||||
} else {
|
||||
for group, km := range psc.InterlockKmGroup {
|
||||
if km {
|
||||
asdGroup := psd.FindAsdGroup(group)
|
||||
p.km(asdGroup.Start, asdGroup.End, asdList)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -127,56 +129,41 @@ func (p *PsdSys) exciteGMJ(data *component.WorldData, circuit *component.PsdCirc
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
gmj := component.BitStateType.Get(circuit.GMJ)
|
||||
kmj4 := component.BitStateType.Get(circuit.KMJ4)
|
||||
kmj8 := component.BitStateType.Get(circuit.KMJ8)
|
||||
if bit { //驱动
|
||||
component.RelayDriveType.Get(circuit.GMJ).Td = true
|
||||
} else if gmj.Val { //自保持
|
||||
if !kmj4.Val && !kmj8.Val {
|
||||
component.RelayDriveType.Get(circuit.GMJ).Td = true
|
||||
} else {
|
||||
} else if component.BitStateType.Get(circuit.GMJ).Val { //判断自保持
|
||||
for _, entry := range circuit.KMJMap {
|
||||
if component.BitStateType.Get(entry).Val { //无法自保持
|
||||
component.RelayDriveType.Get(circuit.GMJ).Td = false
|
||||
return
|
||||
}
|
||||
}
|
||||
//自保持
|
||||
component.RelayDriveType.Get(circuit.GMJ).Td = true
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PsdSys) exciteKMJ4(data *component.WorldData, circuit *component.PsdCircuit) {
|
||||
bit, err := data.QueryQdBit(component.UidType.Get(circuit.KMJ4).Id)
|
||||
func (p *PsdSys) exciteKMJ(data *component.WorldData, circuit *component.PsdCircuit, kmj *ecs.Entry) {
|
||||
bit, err := data.QueryQdBit(component.UidType.Get(kmj).Id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
kmj4 := component.BitStateType.Get(circuit.KMJ4)
|
||||
gmj := component.BitStateType.Get(circuit.GMJ)
|
||||
kmj8 := component.BitStateType.Get(circuit.KMJ8)
|
||||
if bit { //驱动
|
||||
component.RelayDriveType.Get(circuit.KMJ4).Td = true
|
||||
} else if kmj4.Val { //自保持
|
||||
if !gmj.Val && !kmj8.Val {
|
||||
component.RelayDriveType.Get(circuit.KMJ4).Td = true
|
||||
} else {
|
||||
component.RelayDriveType.Get(circuit.KMJ4).Td = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PsdSys) exciteKMJ8(data *component.WorldData, circuit *component.PsdCircuit) {
|
||||
bit, err := data.QueryQdBit(component.UidType.Get(circuit.KMJ8).Id)
|
||||
if err != nil {
|
||||
component.RelayDriveType.Get(kmj).Td = true
|
||||
} else if component.BitStateType.Get(kmj).Val { //判断自保持
|
||||
if component.BitStateType.Get(circuit.GMJ).Val {
|
||||
component.RelayDriveType.Get(kmj).Td = false
|
||||
return
|
||||
}
|
||||
kmj8 := component.BitStateType.Get(circuit.KMJ8)
|
||||
gmj := component.BitStateType.Get(circuit.GMJ)
|
||||
kmj4 := component.BitStateType.Get(circuit.KMJ4)
|
||||
if bit { //驱动
|
||||
component.RelayDriveType.Get(circuit.KMJ8).Td = true
|
||||
} else if kmj8.Val { //自保持
|
||||
if !gmj.Val && !kmj4.Val {
|
||||
component.RelayDriveType.Get(circuit.KMJ8).Td = true
|
||||
} else {
|
||||
component.RelayDriveType.Get(circuit.KMJ8).Td = false
|
||||
for _, entry := range circuit.KMJMap {
|
||||
if entry != kmj && component.BitStateType.Get(entry).Val {
|
||||
component.RelayDriveType.Get(kmj).Td = false
|
||||
return
|
||||
}
|
||||
}
|
||||
//自保持
|
||||
component.RelayDriveType.Get(kmj).Td = true
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PsdSys) exciteMGJ(psdCircuit *component.PsdCircuit, asdList *component.AsdList) {
|
||||
|
Loading…
Reference in New Issue
Block a user