rts-sim-testing-service/message_server/psl_ms.go
weizhihong 172f65b14c 【删除废弃文件夹中代码】
【调整消息服务代码】
【删除多余代码】
【调整方法、结构体名称】
2023-10-27 14:57:37 +08:00

87 lines
2.5 KiB
Go

package message_server
import (
"fmt"
"time"
"google.golang.org/protobuf/proto"
"joylink.club/bj-rtsts-server/message_server/ms_api"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/protos/state"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
)
// PSL或门控箱消息服务
type PslMs struct {
vs *memory.VerifySimulation
mapId int32
}
func NewPSLMs(vs *memory.VerifySimulation, mapId int32) *PslMs {
return &PslMs{vs: vs, mapId: mapId}
}
func (r *PslMs) GetChannel() string {
return "simulation-psl-%s_%d_%s-status"
}
func (r *PslMs) GetInterval() time.Duration {
return 200 * time.Millisecond
}
func (r *PslMs) OnTick() ([]*ms_api.TopicMsg, error) {
var msgArr []*ms_api.TopicMsg
mapData := memory.QueryGiData[*graphicData.RtssGraphicStorage](r.mapId)
for _, box := range mapData.GateBoxs {
channel := r.handlerPSLChannelName(box.Common.Id)
state, err := r.collectGateBoxPSLState(box)
if err != nil {
return nil, err
}
b, err := proto.Marshal(state)
if err != nil {
return nil, fmt.Errorf("PSL设备状态消息服务数据序列化失败: %s", err)
}
msgArr = append(msgArr, ms_api.NewTopicMsg(channel, b))
}
return msgArr, nil
}
func (r *PslMs) OnError(err error) {}
// 处理订阅通道名称
func (r *PslMs) handlerPSLChannelName(gateBoxId string) string {
return fmt.Sprintf(r.GetChannel(), r.vs.SimulationId, r.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
}