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

56 lines
1.5 KiB
Go
Raw Normal View History

package message_server
import (
"sync"
"joylink.club/bj-rtsts-server/message_server/ms_api"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
2023-10-26 17:16:07 +08:00
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
)
var smsMap sync.Map
// 仿真消息服务
// 管理仿真消息服务,整体可以作为一个消息服务,也可以每个消息子服务各自作为一个消息服务,暂时先按整体作为一个消息服务的方式使用
type SimulationMs struct {
2023-12-20 10:37:54 +08:00
vs *memory.VerifySimulation
tasks []ms_api.MsgTask
}
// 启动仿真所需的消息服务
func Start(vs *memory.VerifySimulation) {
_, ok := smsMap.Load(vs.SimulationId)
if !ok {
sms := &SimulationMs{
2023-12-20 10:37:54 +08:00
vs: vs,
tasks: []ms_api.MsgTask{},
}
for _, mapId := range vs.MapIds {
t := memory.QueryGiType(mapId)
switch t {
case graphicData.PictureType_StationLayout: // 平面布置图
// 添加车站关联的平面布置图、IBP、PSL信息
2023-12-20 10:37:54 +08:00
sms.tasks = append(sms.tasks, NewSfpMs(vs, mapId), NewIBPMs(vs, mapId), NewPSLMs(vs, mapId))
case graphicData.PictureType_RelayCabinetLayout: // 继电器柜
2023-12-20 10:37:54 +08:00
sms.tasks = append(sms.tasks, NewRccMs(vs, mapId))
}
}
2023-10-27 16:51:48 +08:00
// 启动仿真状态服务
2023-12-20 10:37:54 +08:00
sms.tasks = append(sms.tasks, NewStateMs(vs))
smsMap.Store(vs.SimulationId, sms)
}
}
// 关闭仿真消息服务
func Close(vs *memory.VerifySimulation) {
sms, ok := smsMap.Load(vs.SimulationId)
if ok {
2023-12-20 10:37:54 +08:00
ms := sms.(*SimulationMs)
for _, task := range ms.tasks {
task.Stop()
}
2023-12-20 10:37:54 +08:00
ms.tasks = nil
smsMap.Delete(vs.SimulationId)
}
2023-10-26 17:48:43 +08:00
}