60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package apiproto
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
|
"joylink.club/bj-rtsts-server/ats/verify/simulation"
|
|
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
|
|
"joylink.club/bj-rtsts-server/dto"
|
|
)
|
|
|
|
type SimulationPSLServer struct{}
|
|
|
|
// 返回通道格式
|
|
func (t *SimulationPSLServer) getChannelName() string {
|
|
return "simulation-psl-{sid}_{mid}_{psl}-status"
|
|
}
|
|
|
|
// 消息运行间隔
|
|
func (t *SimulationPSLServer) getInterval() time.Duration {
|
|
return 200 * time.Millisecond
|
|
}
|
|
|
|
// 定时发送数据
|
|
func (t *SimulationPSLServer) onTick() []TopicMsg {
|
|
simArr := simulation.GetSimulationArr()
|
|
var msgArr []TopicMsg
|
|
for _, v := range simArr {
|
|
for _, mapId := range v.MapIds {
|
|
mapType := memory.QueryGiType(mapId)
|
|
if mapType != graphicData.PictureType_StationLayout {
|
|
continue
|
|
}
|
|
mapData := memory.QueryGiData[*graphicData.RtssGraphicStorage](mapId)
|
|
idStr := strconv.Itoa(int(mapId))
|
|
for _, box := range mapData.GateBoxs {
|
|
channelName := handlerPSLChannelName(v.SimulationId, idStr, box.Common.Id, t.getChannelName())
|
|
b, err := proto.Marshal(v.GetAllPSLState(mapId, box.Common.Id))
|
|
if err != nil {
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
|
}
|
|
msgArr = append(msgArr, TopicMsg{channalName: channelName, data: b})
|
|
}
|
|
}
|
|
}
|
|
return msgArr
|
|
}
|
|
|
|
// 处理订阅通道名称
|
|
func handlerPSLChannelName(sid, mapId, psl string, format string) string {
|
|
var channelName string
|
|
channelName = strings.Replace(format, "{sid}", sid, 1)
|
|
channelName = strings.Replace(channelName, "{mid}", mapId, 1)
|
|
channelName = strings.Replace(channelName, "{psl}", psl, 1)
|
|
return channelName
|
|
}
|