From 0887ac8d685eb2d0541c1e6ccdd321514489d21e Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Tue, 7 Nov 2023 17:47:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E8=BD=B4rssp=20=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rtss_simulation | 2 +- third_party/axle_device/rssp_axle.go | 10 +- .../wayside/memory/wayside_simulation.go | 110 +++++++++++++----- ts/test_simulation_manage.go | 4 + 4 files changed, 92 insertions(+), 34 deletions(-) diff --git a/rtss_simulation b/rtss_simulation index a6dfa6f..45b4f4f 160000 --- a/rtss_simulation +++ b/rtss_simulation @@ -1 +1 @@ -Subproject commit a6dfa6fffb7ecfe6630280a838092d208c0e3c1a +Subproject commit 45b4f4f0fe4eaf1eae6f31cca8d0b14237596bf1 diff --git a/third_party/axle_device/rssp_axle.go b/third_party/axle_device/rssp_axle.go index 957c891..a16bced 100644 --- a/third_party/axle_device/rssp_axle.go +++ b/third_party/axle_device/rssp_axle.go @@ -13,12 +13,16 @@ type RsspAxle interface { type AxleMessageManager interface { //HandleSectionCmdMsg 计轴设备接收到联锁发送来的控制命令 - HandleSectionCmdMsg(centralizedStation string, msg *message.SectionCmdMsgPack) + HandleSectionCmdMsg(city string, lineId string, centralizedStation string, msg *message.SectionCmdMsgPack) //CollectSectionStatus 收集仿真中计轴区段状态 - CollectSectionStatus() []*message.SectionStatusMsg + CollectSectionStatus(city string, lineId string, centralizedStation string) ([]*message.SectionStatusMsg, error) } type rsspAxle struct { + //所属城市 + city string + //所属线路 + lineId string //所属集中站 centralizedStation string //主安全通道 @@ -37,7 +41,7 @@ func NewRsspAxle(masterRssp *RsspChannel, slaveRssp *RsspChannel) RsspAxle { func (s *rsspAxle) rcvCmdMsg(data []byte) { msg := &message.SectionCmdMsgPack{} msg.Decode(data) - s.messageManager.HandleSectionCmdMsg(s.centralizedStation, msg) + s.messageManager.HandleSectionCmdMsg(s.city, s.lineId, s.centralizedStation, msg) } func (s *rsspAxle) Start(amm AxleMessageManager) error { s.messageManager = amm diff --git a/ts/simulation/wayside/memory/wayside_simulation.go b/ts/simulation/wayside/memory/wayside_simulation.go index 727222a..d574746 100644 --- a/ts/simulation/wayside/memory/wayside_simulation.go +++ b/ts/simulation/wayside/memory/wayside_simulation.go @@ -148,6 +148,57 @@ func (s *VerifySimulation) GetComIdByUid(uid string) string { return es[uid].CommonId } +// CollectSectionStatus 收集仿真中计轴区段状态 +func (s *VerifySimulation) CollectSectionStatus(city string, lineId string, centralizedStation string) ([]*message.SectionStatusMsg, error) { + stationUid := GenerateElementUid(city, lineId, nil, centralizedStation) + ref := s.Repo.GetCentralizedStationRef(stationUid) + if ref == nil { + return nil, fmt.Errorf("没有找到GetCentralizedStationRef [%s]", stationUid) + } + // + codePoints := ref.SectionCodePoints + if len(codePoints) <= 0 { + return nil, fmt.Errorf("没有找到GetCentralizedStationRef[%s]的区段码表为空", stationUid) + } + // + var msg []*message.SectionStatusMsg + var axleSectionIds []string + for _, section := range codePoints { + axleSectionIds = append(axleSectionIds, section.SectionId) + } + // + as, e := fi.FindAxleSectionsStatus(s.World, axleSectionIds) + if e != nil { //从仿真中收集计轴区段状态的失败列表 + return nil, e + } + // + stateMap := make(map[string]*fi.AxleSectionState) + for _, a := range as { + stateMap[a.Id] = a + } + // + sort.SliceStable(codePoints, func(i, j int) bool { + return codePoints[i].Row < codePoints[j].Row + }) + // + for _, codePoint := range codePoints { + sectionState, find := stateMap[codePoint.SectionId] + if find { + state := &message.SectionStatusMsg{} + state.Rac = sectionState.Rac + state.Rjt = sectionState.Rjt + state.Rjo = sectionState.Rjo + state.Occ = sectionState.Occ + state.Clr = sectionState.Clr + msg = append(msg, state) + } else { + return nil, fmt.Errorf("仿真中没有对应区段[%s]的状态", codePoint.SectionId) + } + } + // + return msg, nil +} + // 采集动力学道岔状态 func (s *VerifySimulation) CollectDynamicsTurnoutInfo() []*message.DynamicsTurnoutInfo { var turnoutStates []*message.DynamicsTurnoutInfo @@ -171,38 +222,37 @@ func (s *VerifySimulation) CollectDynamicsTurnoutInfo() []*message.DynamicsTurno } // HandleSectionCmdMsg 计轴设备接收到联锁发送来的控制命令 -func (s *VerifySimulation) HandleSectionCmdMsg(centralizedStation string, msg *message.SectionCmdMsgPack) { - +func (s *VerifySimulation) HandleSectionCmdMsg(city string, lineId string, centralizedStation string, msg *message.SectionCmdMsgPack) { + stationUid := GenerateElementUid(city, lineId, nil, centralizedStation) + ref := s.Repo.GetCentralizedStationRef(stationUid) + if ref == nil { + slog.Warn(fmt.Sprintf("没有找到GetCentralizedStationRef [%s]", stationUid)) + return + } + // + codePoints := ref.SectionCodePoints + if len(codePoints) != len(msg.Scs) { + slog.Warn(fmt.Sprintf("本地配置区段码表个数[%d] != 联锁发送集中站[%s]的区段命令个数[%d]", len(codePoints), stationUid, len(msg.Scs))) + return + } + // + var cpSectionMap = make(map[int]*proto.CiSectionCodePoint) + for _, cp := range codePoints { + cpSectionMap[int(cp.Row)] = cp + } + // + var cmds []*fi.AxleSectionCmd + for index, cmdMsg := range msg.Scs { + cp := cpSectionMap[index] + cmd := &fi.AxleSectionCmd{} + cmd.SectionId = cp.SectionId + cmd.Drst = cmdMsg.Drst + cmd.Pdrst = cmdMsg.Pdrst + cmds = append(cmds, cmd) + } + fi.AxleSectionRstDrive(s.World, cmds) } -// CollectSectionStatus 收集仿真中计轴区段状态 -func (s *VerifySimulation) CollectSectionStatus() []*message.SectionStatusMsg { - var msg []*message.SectionStatusMsg - var axleSectionIds []string - for _, section := range s.Repo.PhysicalSectionList() { - if is, _ := section.IsAxleSection(); is { - axleSectionIds = append(axleSectionIds, section.Id()) - } - } - if len(axleSectionIds) <= 0 { - return []*message.SectionStatusMsg{} - } else { - as, e := fi.FindAxleSectionsStatus(s.World, axleSectionIds) - if e != nil { //从仿真中收集计轴区段状态的失败列表 - slog.Warn(e.Error()) - } - for _, a := range as { - state := &message.SectionStatusMsg{} - state.Rac = a.Rac - state.Rjt = a.Rjt - state.Rjo = a.Rjo - state.Occ = a.Occ - state.Clr = a.Clr - msg = append(msg, state) - } - return msg - } -} func handlerDynamicsTurnoutState(w ecs.World, uid string) *message.DynamicsTurnoutInfo { entry, ok := entity.GetEntityByUid(w, uid) if !ok { diff --git a/ts/test_simulation_manage.go b/ts/test_simulation_manage.go index 7733aec..057429a 100644 --- a/ts/test_simulation_manage.go +++ b/ts/test_simulation_manage.go @@ -99,6 +99,10 @@ func initWorld(s *memory.VerifySimulation) error { // 运行仿真第三方模块 func runThirdParty(s *memory.VerifySimulation) error { + //测试 + if s != nil { + return nil + } // 动力学启动 err := dynamics.Default().Start(s) if err != nil {