This commit is contained in:
weizhihong 2023-11-01 16:55:28 +08:00
commit dffd941c80
4 changed files with 70 additions and 78 deletions

View File

@ -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
}

View File

@ -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 a612c78c4e06eaeef6ec5fe3054f30966d2f2647
Subproject commit a8cb4228f5266ff6630b696598554f263920abc4

View File

@ -614,17 +614,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,
})
}
}
}
@ -940,17 +941,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 {
@ -963,11 +959,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
}
}
}
@ -985,8 +981,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)