2023-10-26 16:41:18 +08:00
|
|
|
package message_server
|
|
|
|
|
2023-10-27 14:57:37 +08:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2023-10-26 16:41:18 +08:00
|
|
|
// PSL或门控箱消息服务
|
|
|
|
type PslMs struct {
|
2023-10-27 14:57:37 +08:00
|
|
|
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
|
2023-10-26 16:41:18 +08:00
|
|
|
}
|