rts-sim-testing-service/message_server/train_control_ms.go

43 lines
1.2 KiB
Go

package message_server
import (
"fmt"
"joylink.club/bj-rtsts-server/dto/data_proto"
"joylink.club/bj-rtsts-server/dto/state_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"
"log/slog"
"time"
)
// 综合后备盘IBP消息服务
func NewTrainControlMs(vs *memory.VerifySimulation) ms_api.MsgTask {
var findMapId int32 = 0
for _, d := range vs.MapIds {
mapData := memory.QueryGiType(d)
if mapData == data_proto.PictureType_TrainControlCab {
findMapId = d
break
}
}
if findMapId == 0 {
slog.Error("未找到对应的列城控制图形")
return nil
}
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]列车控制", findMapId), func() error {
allTrainMap := &vs.Memory.Status.TrainStateMap
allTrainMap.Range(func(key, value any) bool {
trainId := fmt.Sprintf("%v", key)
ts := value.(*state_proto.TrainState)
err := mqtt.GetMsgClient().PubTrainControlState(vs.SimulationId, trainId, findMapId, ts.Tcc)
if err != nil {
slog.Error("发送列车控制mqtt失败", err)
}
return true
})
return nil
}, 200*time.Millisecond)
}