2024-03-19 08:28:50 +08:00
|
|
|
package message_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"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消息服务
|
2024-03-19 14:49:44 +08:00
|
|
|
func NewTrainControlMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
|
|
|
|
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]列车控制", mapId), func() error {
|
2024-03-19 08:28:50 +08:00
|
|
|
allTrainMap := &vs.Memory.Status.TrainStateMap
|
|
|
|
allTrainMap.Range(func(key, value any) bool {
|
|
|
|
trainId := fmt.Sprintf("%v", key)
|
|
|
|
ts := value.(*state_proto.TrainState)
|
2024-03-19 11:00:19 +08:00
|
|
|
err := mqtt.GetMsgClient().PubTrainControlState(vs.SimulationId, trainId, ts.Tcc)
|
2024-03-19 08:28:50 +08:00
|
|
|
if err != nil {
|
|
|
|
slog.Error("发送列车控制mqtt失败", err)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}, 200*time.Millisecond)
|
|
|
|
}
|