rts-sim-testing-service/message_server/psl_ms.go
thesai 6f327f751b 【新增】防淹门模型构建(暂时与车库门用相同模型)
【修改】因车库门PSL盘对象被删除,修改相应的构建逻辑
2024-03-29 14:59:20 +08:00

126 lines
4.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package message_server
import (
"fmt"
"joylink.club/bj-rtsts-server/dto/state_proto"
"log/slog"
"time"
"joylink.club/bj-rtsts-server/dto/data_proto"
"joylink.club/bj-rtsts-server/message_server/ms_api"
"joylink.club/bj-rtsts-server/mqtt"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
func NewPSLMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
mapData := memory.QueryGiData[*data_proto.RtssGraphicStorage](mapId)
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]PSL按钮状态", mapId), func() error {
for _, box := range mapData.GateBoxs {
did := memory.GetMapElementId(box.Common)
data, err := collectGateBoxPSLState(vs.World, mapId, box)
if err != nil {
return err
}
sendMsg(vs, mapId, did, data)
}
for _, ckm := range mapData.GarageDoors {
did := memory.GetMapElementId(ckm.Common)
data, err := collectGarageDoorBoxPSLState(vs.World, mapId, ckm)
if err != nil {
return err
}
sendMsg(vs, mapId, did, data)
}
return nil
}, 200*time.Millisecond)
}
func sendMsg(vs *memory.VerifySimulation, mapId int32, pslId uint32, data *state_proto.PushedDevicesStatus) {
err := mqtt.GetMsgClient().PubPSLState(vs.SimulationId, mapId, pslId, data)
if err != nil {
slog.Error(fmt.Sprintf("发送PSL状态出错%s", err.Error()))
}
}
func collectGateBoxPSLState(world ecs.World, mapId int32, box *data_proto.GatedBox) (*state_proto.PushedDevicesStatus, error) {
did := memory.GetMapElementId(box.Common)
uidStructure := memory.QueryUidStructure[*memory.StationUidStructure](mapId)
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)
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{
Id: btnUidMap[component.UidType.Get(btn).Id],
Down: btnState.Val,
Active: btnState.Val,
//Bypass: btnState.BypassEnable,
})
}
}
return &state_proto.PushedDevicesStatus{
All: true,
AllStatus: &state_proto.AllDevicesStatus{
ButtonState: buttonStateArr,
},
}, nil
}
func collectGarageDoorBoxPSLState(world ecs.World, mapId int32, box *data_proto.GarageDoor) (*state_proto.PushedDevicesStatus, error) {
return nil, nil
//did := memory.GetMapElementId(box.Common)
//uidStructure := memory.QueryUidStructure[*memory.StationUidStructure](mapId)
//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)
// 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{
// Id: btnUidMap[component.UidType.Get(btn).Id],
// Down: btnState.Val,
// Active: btnState.Val,
// //Bypass: btnState.BypassEnable,
// })
// }
//}
//return &state_proto.PushedDevicesStatus{
// All: true,
// AllStatus: &state_proto.AllDevicesStatus{
// ButtonState: buttonStateArr,
// },
//}, nil
}