60 lines
1.8 KiB
Go
60 lines
1.8 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 SimulationIBPServer struct{}
|
|
|
|
// 返回通道格式
|
|
func (t *SimulationIBPServer) getChannelName() string {
|
|
return "simulation-ibp-{sid}_{mid}_{station}-status"
|
|
}
|
|
|
|
// 消息运行间隔
|
|
func (t *SimulationIBPServer) getInterval() time.Duration {
|
|
return 200 * time.Millisecond
|
|
}
|
|
|
|
// 定时发送数据
|
|
func (t *SimulationIBPServer) 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 _, station := range mapData.Stations {
|
|
channelName := handlerIBPChannelName(v.SimulationId, idStr, station.Common.Id, t.getChannelName())
|
|
b, err := proto.Marshal(v.GetAllIBPState(mapId, station.Common.Id, station.RefIbpMapCode))
|
|
if err != nil {
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
|
}
|
|
msgArr = append(msgArr, TopicMsg{channalName: channelName, data: b})
|
|
}
|
|
}
|
|
}
|
|
return msgArr
|
|
}
|
|
|
|
// 处理订阅通道名称
|
|
func handlerIBPChannelName(sid, mapId, station 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, "{station}", station, 1)
|
|
return channelName
|
|
}
|