rts-sim-testing-service/message_server/psl_ms.go

70 lines
2.4 KiB
Go
Raw Normal View History

package message_server
import (
"fmt"
"joylink.club/bj-rtsts-server/dto/state_proto"
"time"
"joylink.club/bj-rtsts-server/dto/data_proto"
"joylink.club/bj-rtsts-server/message_server/ms_api"
2023-12-20 10:37:54 +08:00
"joylink.club/bj-rtsts-server/mqtt"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
2023-12-20 10:37:54 +08:00
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
2023-12-20 10:37:54 +08:00
func NewPSLMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
mapData := memory.QueryGiData[*data_proto.RtssGraphicStorage](mapId)
2023-12-26 13:27:09 +08:00
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]综合门控箱按钮状态", mapId), func() error {
2023-12-20 10:37:54 +08:00
for _, box := range mapData.GateBoxs {
did := memory.GetMapElementId(box.Common)
data_proto, err := collectGateBoxPSLState(vs.World, mapId, box)
2023-12-20 10:37:54 +08:00
if err != nil {
return err
}
mqtt.GetMsgClient().PubPSLState(vs.SimulationId, mapId, did, data_proto)
}
2023-12-20 10:37:54 +08:00
return nil
}, 200*time.Millisecond)
}
func collectGateBoxPSLState(world ecs.World, mapId int32, box *data_proto.GatedBox) (*state_proto.PushedDevicesStatus, error) {
did := memory.GetMapElementId(box.Common)
2023-12-20 10:37:54 +08:00
uidStructure := memory.QueryUidStructure[*memory.StationUidStructure](mapId)
2024-02-20 09:20:52 +08:00
boxUid := uidStructure.PslIds[did].Uid
mkxEntry, ok := entity.GetEntityByUid(world, boxUid)
if !ok {
return nil, fmt.Errorf("[id:%s]的门控箱实体找不到", boxUid)
}
mkx := component.MkxType.Get(mkxEntry)
var buttonStateArr []*state_proto.ButtonState
if ok {
_, pslStorage := memory.QueryGiDataByName[*data_proto.PslGraphicStorage](box.RefGatedBoxMapCode)
2023-12-14 13:04:48 +08:00
btnUidMap := make(map[string]uint32, len(pslStorage.PslButtons))
for _, button := range pslStorage.PslButtons {
btnUidMap[boxUid+"_"+button.Code] = memory.GetMapElementId(button.Common)
}
btnArr := []*ecs.Entry{mkx.PCB, mkx.PCBPL, mkx.POB, mkx.POBPL, mkx.PAB, mkx.PABPL, mkx.WRZF, mkx.WRZFPL,
mkx.QKQR, mkx.QKQRPL, mkx.MPL, mkx.JXTCPL}
for _, btn := range btnArr {
if btn == nil {
continue
}
btnState := component.BitStateType.Get(btn)
buttonStateArr = append(buttonStateArr, &state_proto.ButtonState{
2023-12-14 13:04:48 +08:00
Id: btnUidMap[component.UidType.Get(btn).Id],
Down: btnState.Val,
Active: btnState.Val,
2024-02-06 10:49:46 +08:00
//Bypass: btnState.BypassEnable,
})
}
}
return &state_proto.PushedDevicesStatus{
All: true,
AllStatus: &state_proto.AllDevicesStatus{
ButtonState: buttonStateArr,
},
}, nil
}