重新划分屏蔽门系统组件并实现门控箱控制屏蔽门逻辑(ecs)
This commit is contained in:
parent
ebc2bc7cc6
commit
7170a695ab
|
@ -1 +1 @@
|
|||
Subproject commit 596dd059206c803559d0a7f8c0ae1cd4fcfec939
|
||||
Subproject commit ebfb67be9c57e2bf9b3e4b8887f028911b9dba96
|
|
@ -2,6 +2,9 @@ package message_server
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
"joylink.club/rtsssimulation/entity"
|
||||
"time"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
@ -21,20 +24,20 @@ func NewPSLMs(vs *memory.VerifySimulation, mapId int32) *PslMs {
|
|||
return &PslMs{vs: vs, mapId: mapId}
|
||||
}
|
||||
|
||||
func (r *PslMs) GetChannel() string {
|
||||
func (p *PslMs) GetChannel() string {
|
||||
return "simulation-psl-%s_%d_%s-status"
|
||||
}
|
||||
|
||||
func (r *PslMs) GetInterval() time.Duration {
|
||||
func (p *PslMs) GetInterval() time.Duration {
|
||||
return 200 * time.Millisecond
|
||||
}
|
||||
|
||||
func (r *PslMs) OnTick() ([]*ms_api.TopicMsg, error) {
|
||||
func (p *PslMs) OnTick() ([]*ms_api.TopicMsg, error) {
|
||||
var msgArr []*ms_api.TopicMsg
|
||||
mapData := memory.QueryGiData[*graphicData.RtssGraphicStorage](r.mapId)
|
||||
mapData := memory.QueryGiData[*graphicData.RtssGraphicStorage](p.mapId)
|
||||
for _, box := range mapData.GateBoxs {
|
||||
channel := r.handlerPSLChannelName(box.Common.Id)
|
||||
state, err := r.collectGateBoxPSLState(box)
|
||||
channel := p.handlerPSLChannelName(box.Common.Id)
|
||||
state, err := p.collectGateBoxPSLState(box)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -47,40 +50,40 @@ func (r *PslMs) OnTick() ([]*ms_api.TopicMsg, error) {
|
|||
return msgArr, nil
|
||||
}
|
||||
|
||||
func (r *PslMs) OnError(err error) {}
|
||||
func (p *PslMs) OnError(err error) {}
|
||||
|
||||
// 处理订阅通道名称
|
||||
func (r *PslMs) handlerPSLChannelName(gateBoxId string) string {
|
||||
return fmt.Sprintf(r.GetChannel(), r.vs.SimulationId, r.mapId, gateBoxId)
|
||||
func (p *PslMs) handlerPSLChannelName(gateBoxId string) string {
|
||||
return fmt.Sprintf(p.GetChannel(), p.vs.SimulationId, p.mapId, gateBoxId)
|
||||
}
|
||||
|
||||
func (r *PslMs) collectGateBoxPSLState(gatedBox *graphicData.GatedBox) (*state.PushedDevicesStatus, error) {
|
||||
//world := s.GetSimulationWorld()
|
||||
//uidStructure := queryUidStructure[*StationUidStructure](mapId)
|
||||
//boxUid := uidStructure.GateBoxIds[boxId].Uid
|
||||
//mkxEntry, ok := entity.GetEntityByUid(world, boxUid)
|
||||
//var buttonStateArr []*state.ButtonState
|
||||
//if ok {
|
||||
// mkxCircuit := component.MkxCircuitType.Get(mkxEntry)
|
||||
// var boxArr []*ecs.Entry
|
||||
// boxArr = append(boxArr, mkxCircuit.PcbList...)
|
||||
// boxArr = append(boxArr, mkxCircuit.PobList...)
|
||||
// boxArr = append(boxArr, mkxCircuit.PabList...)
|
||||
// for _, mkxBoxEntry := range boxArr {
|
||||
// mkxBox := component.MkxBoxType.Get(mkxBoxEntry)
|
||||
// uid := component.UidType.Get(mkxBox.Btn).Id
|
||||
// down := component.BitStateType.Get(mkxBox.Btn).Val
|
||||
// buttonStateArr = append(buttonStateArr, &state.ButtonState{
|
||||
// Id: uid,
|
||||
// Down: down,
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
//return &state.PushedDevicesStatus{
|
||||
// All: true,
|
||||
// AllStatus: &state.AllDevicesStatus{
|
||||
// ButtonState: buttonStateArr,
|
||||
// },
|
||||
//}
|
||||
return nil, nil
|
||||
func (p *PslMs) collectGateBoxPSLState(box *graphicData.GatedBox) (*state.PushedDevicesStatus, error) {
|
||||
world := p.vs.World
|
||||
uidStructure := memory.QueryUidStructure[*memory.StationUidStructure](p.mapId)
|
||||
boxUid := uidStructure.GateBoxIds[box.Common.Id].Uid
|
||||
mkxEntry, ok := entity.GetEntityByUid(world, boxUid)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("[id:%s]的门控箱实体找不到", boxUid)
|
||||
}
|
||||
mkx := component.MkxType.Get(mkxEntry)
|
||||
var buttonStateArr []*state.ButtonState
|
||||
if ok {
|
||||
btnArr := []*ecs.Entry{mkx.PCB, mkx.POB, mkx.PAB}
|
||||
for _, btn := range btnArr {
|
||||
if btn == nil {
|
||||
continue
|
||||
}
|
||||
buttonStateArr = append(buttonStateArr, &state.ButtonState{
|
||||
Id: component.UidType.Get(btn).Id,
|
||||
Down: component.BitStateType.Get(btn).Val,
|
||||
Active: component.BitStateType.Get(btn).Val,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &state.PushedDevicesStatus{
|
||||
All: true,
|
||||
AllStatus: &state.AllDevicesStatus{
|
||||
ButtonState: buttonStateArr,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -97,19 +97,11 @@ func (ms *SfpMs) collectPsdStates() ([]*state.PsdState, error) {
|
|||
uid := uidStructure.PsdIds[door.Common.Id].Uid
|
||||
psdEntry, ok := entity.GetEntityByUid(world, uid)
|
||||
if ok {
|
||||
var amount int32
|
||||
psdState := component.PsdStateType.Get(psdEntry)
|
||||
if psdState.Km8 {
|
||||
amount = 8
|
||||
} else if psdState.Km4 {
|
||||
amount = 4
|
||||
} else {
|
||||
amount = 0
|
||||
}
|
||||
start, end := getStartEndCodeByGroup(door, amount)
|
||||
var openSubDoor []int32
|
||||
for i := start; i <= end; i++ {
|
||||
openSubDoor = append(openSubDoor, i)
|
||||
for i, asd := range component.AsdListType.Get(psdEntry).List {
|
||||
if !component.AsdMotorStateType.Get(asd).MG {
|
||||
openSubDoor = append(openSubDoor, int32(i+1))
|
||||
}
|
||||
}
|
||||
psdStateArr = append(psdStateArr, &state.PsdState{
|
||||
Id: door.Common.Id,
|
||||
|
@ -120,15 +112,6 @@ func (ms *SfpMs) collectPsdStates() ([]*state.PsdState, error) {
|
|||
return psdStateArr, nil
|
||||
}
|
||||
|
||||
func getStartEndCodeByGroup(door *graphicData.ScreenDoor, groupAmount int32) (int32, int32) {
|
||||
for _, group := range door.ScreenDoorGroupList {
|
||||
if group.TrainGroupAmount == groupAmount {
|
||||
return group.StartSmallDoor, group.EndSmallDoor
|
||||
}
|
||||
}
|
||||
return 0, -1
|
||||
}
|
||||
|
||||
// 收集区段状态
|
||||
func (ms *SfpMs) collectSectionStates() ([]*state.SectionState, error) {
|
||||
uidMap := memory.QueryMapUidMapByType(ms.mapId, &graphicData.Section{})
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b0608320d3eac6eb3a892a753e4e74bb56b5b095
|
||||
Subproject commit a8cb4228f5266ff6630b696598554f263920abc4
|
|
@ -617,17 +617,18 @@ func buildAndRelateElectronicComponent(repo *proto.Repository, relayGi *graphicD
|
|||
}
|
||||
for _, group := range station.ElectronicGroup {
|
||||
if group.Code == "MKX" {
|
||||
var componentIds []string
|
||||
for _, component := range group.Components {
|
||||
relay := relayMap[component.Id]
|
||||
if strings.Contains(relay.GetCode(), s) {
|
||||
componentIds = append(componentIds, relay.Id)
|
||||
if strings.Contains(relay.GetCode(), "PCB") {
|
||||
mkx.PcbjId = relay.Id
|
||||
} else if strings.Contains(relay.GetCode(), "POB") {
|
||||
mkx.PobjId = relay.Id
|
||||
} else if strings.Contains(relay.GetCode(), "PAB") {
|
||||
mkx.PabjId = relay.Id
|
||||
}
|
||||
}
|
||||
}
|
||||
mkx.ElectronicComponentGroups = append(mkx.ElectronicComponentGroups, &proto.ElectronicComponentGroup{
|
||||
Code: group.Code,
|
||||
ComponentIds: componentIds,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -943,17 +944,12 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi
|
|||
}
|
||||
}
|
||||
//门控箱
|
||||
gateBoxMap := make(map[string]*proto.Mkx)
|
||||
for _, data := range storage.GateBoxs {
|
||||
mkx, ok := gateBoxMap[data.RefScreenDoor]
|
||||
if !ok {
|
||||
mkx = &proto.Mkx{
|
||||
Id: uidsMap.GateBoxIds[data.Common.Id].Uid,
|
||||
PsdId: uidsMap.PsdIds[data.RefScreenDoor].Uid,
|
||||
}
|
||||
repo.Mkxs = append(repo.Mkxs, mkx)
|
||||
gateBoxMap[data.RefScreenDoor] = mkx
|
||||
mkx := &proto.Mkx{
|
||||
Id: uidsMap.GateBoxIds[data.Common.Id].Uid,
|
||||
PsdId: uidsMap.PsdIds[data.RefScreenDoor].Uid,
|
||||
}
|
||||
repo.Mkxs = append(repo.Mkxs, mkx)
|
||||
pslMapId := QueryGiId(data.RefGatedBoxMapCode)
|
||||
pslStorage := QueryGiData[*graphicData.PslGraphicStorage](pslMapId)
|
||||
for _, button := range pslStorage.PslButtons {
|
||||
|
@ -966,11 +962,11 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi
|
|||
repo.Buttons = append(repo.Buttons, repoButton)
|
||||
switch button.Code {
|
||||
case "PCB":
|
||||
mkx.PcbButtonIds = append(mkx.PcbButtonIds, repoButton.Id)
|
||||
mkx.PcbButtonId = repoButton.Id
|
||||
case "POB":
|
||||
mkx.PobButtonIds = append(mkx.PobButtonIds, repoButton.Id)
|
||||
mkx.PobButtonId = repoButton.Id
|
||||
case "PAB":
|
||||
mkx.PabButtonIds = append(mkx.PabButtonIds, repoButton.Id)
|
||||
mkx.PabButtonId = repoButton.Id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -988,8 +984,18 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi
|
|||
}
|
||||
//屏蔽门
|
||||
for _, data := range storage.ScreenDoors {
|
||||
var asdGroups []*proto.AsdGroup
|
||||
for _, group := range data.ScreenDoorGroupList {
|
||||
asdGroups = append(asdGroups, &proto.AsdGroup{
|
||||
Group: group.TrainGroupAmount,
|
||||
Start: group.StartSmallDoor,
|
||||
End: group.EndSmallDoor,
|
||||
})
|
||||
}
|
||||
psd := &proto.Psd{
|
||||
Id: uidsMap.PsdIds[data.Common.Id].Uid,
|
||||
AsdAmount: data.SonDoorAmount,
|
||||
AsdGroups: asdGroups,
|
||||
PlatformId: uidsMap.PlatformIds[data.RefPlatformId].Uid,
|
||||
}
|
||||
repo.Psds = append(repo.Psds, psd)
|
||||
|
|
Loading…
Reference in New Issue