From 016ce0e8bb66d001dbd48a0cff95907636b068d5 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Mon, 12 Aug 2024 15:18:52 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]=E8=AE=BE=E5=A4=87=E7=8A=B6?= =?UTF-8?q?=E6=80=81proto=E6=B6=88=E6=81=AF=E4=B8=AD=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=AE=A1=E8=BD=B4=E5=8C=BA=E6=AE=B5=E7=8A=B6=E6=80=81=EF=BC=8C?= =?UTF-8?q?=E5=8E=9F=E2=80=9C=E6=89=80=E6=9C=89=E5=8C=BA=E6=AE=B5=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E2=80=9D=E6=94=B9=E4=B8=BA=E7=89=A9=E7=90=86=E5=8C=BA?= =?UTF-8?q?=E6=AE=B5=E7=8A=B6=E6=80=81=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rts-sim-testing-message | 2 +- third_party/interlock/beijing11/msg.go | 6 +- third_party/interlock/beijing11/repo.go | 8 +-- third_party/interlock/beijing11/service.go | 84 ++++++++++++++++------ 4 files changed, 72 insertions(+), 28 deletions(-) diff --git a/rts-sim-testing-message b/rts-sim-testing-message index a5ebb68..4a126b5 160000 --- a/rts-sim-testing-message +++ b/rts-sim-testing-message @@ -1 +1 @@ -Subproject commit a5ebb6869d51969e5887f1dfceaffe8fcdc27312 +Subproject commit 4a126b57ac6bb950d764851a27a5ddf4caad0b2a diff --git a/third_party/interlock/beijing11/msg.go b/third_party/interlock/beijing11/msg.go index 171cb9c..a8c2702 100644 --- a/third_party/interlock/beijing11/msg.go +++ b/third_party/interlock/beijing11/msg.go @@ -239,12 +239,12 @@ func (t *ToInterlockFrame) encode() []byte { //扣车,数量0 data = binary.BigEndian.AppendUint16(data, 0) //信号机状态 - binary.BigEndian.AppendUint16(data, uint16(len(t.SignalStates))) + data = binary.BigEndian.AppendUint16(data, uint16(len(t.SignalStates))) for _, state := range t.SignalStates { data = state.encode(data) } //计轴区段 - binary.BigEndian.AppendUint16(data, uint16(len(t.AxleSectionStates))) + data = binary.BigEndian.AppendUint16(data, uint16(len(t.AxleSectionStates))) for _, state := range t.AxleSectionStates { data = state.encode(data) } @@ -259,6 +259,8 @@ func (t *ToInterlockFrame) encode() []byte { } //车库门,数量0 data = binary.BigEndian.AppendUint16(data, 0) + //填充报文长度 + binary.BigEndian.PutUint16(data[1:3], uint16(len(data))) return data } diff --git a/third_party/interlock/beijing11/repo.go b/third_party/interlock/beijing11/repo.go index 2b963dc..6c80be9 100644 --- a/third_party/interlock/beijing11/repo.go +++ b/third_party/interlock/beijing11/repo.go @@ -3,7 +3,7 @@ package beijing11 // StationDeviceIndexTable 联锁站设备索引表 type StationDeviceIndexTable struct { StationName string //地图数据中车站的Code属性 - WaysideCode string //通信数据中的“轨旁编号” + InterlockCode uint16 //通信数据中的“联锁编号” TurnoutMap map[uint16]*Row PsdMap map[uint16]*Row EsbMap map[uint16]*Row @@ -17,10 +17,10 @@ type StationDeviceIndexTable struct { XcjMap map[uint16]*Row } -func NewStationDeviceIndexTable() *StationDeviceIndexTable { +func NewStationDeviceIndexTable(stationName string, interlockCode uint16) *StationDeviceIndexTable { return &StationDeviceIndexTable{ - StationName: "", - WaysideCode: "", + StationName: stationName, + InterlockCode: interlockCode, TurnoutMap: make(map[uint16]*Row), PsdMap: make(map[uint16]*Row), EsbMap: make(map[uint16]*Row), diff --git a/third_party/interlock/beijing11/service.go b/third_party/interlock/beijing11/service.go index 5112e0b..92bfeba 100644 --- a/third_party/interlock/beijing11/service.go +++ b/third_party/interlock/beijing11/service.go @@ -23,8 +23,9 @@ var ( ) var ( - mu = sync.Mutex{} //启动任务时使用,避免重复启动任务 - serviceContextMap = make(map[string]*serviceContext) //每个集中站的服务上下文,key-集中站code + mu = sync.Mutex{} //启动任务时使用,避免重复启动任务 + serviceContextMap = make(map[string]*serviceContext) //每个集中站的服务上下文,key-集中站code + waysideCode uint16 = 0x6301 ) type serviceContext struct { @@ -115,11 +116,29 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI } uids := memory.QueryUidStructure[*memory.StationUidStructure](mapId) - table := NewStationDeviceIndexTable() + var table *StationDeviceIndexTable + for _, station := range stationGi.Stations { + if station.StationName != stationCode { + continue + } + for _, lianSuoIndexData := range stationGi.LianSuoData.Stations { + if lianSuoIndexData.Id == station.Common.Id { + table = NewStationDeviceIndexTable(station.StationName, uint16(lianSuoIndexData.Index)) + break + } + } + break + } + if table == nil { + panic(fmt.Sprintf("联锁配置车站[%s]在地图中没有对应的车站或联锁编号数据", stationCode)) + } //道岔 for _, data := range stationGi.LianSuoData.Switchs { + if data.Index <= 0 { + continue + } for _, station := range uids.TurnoutIds[data.Id].CentralizedStations { - if station.Code == stationCode { + if station.StationName == stationCode { table.TurnoutMap[uint16(data.Id)] = &Row{ commonId: data.Id, uid: uids.TurnoutIds[data.Id].Uid, @@ -131,8 +150,11 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI } //屏蔽门 for _, data := range stationGi.LianSuoData.ScreenDoors { + if data.Index <= 0 { + continue + } for _, station := range uids.PsdIds[data.Id].CentralizedStations { - if station.Code == stationCode { + if station.StationName == stationCode { relateDeviceMap := make(map[string]string) for _, mkx := range sim.Repo.MkxList() { if mkx.Psd().Id() == uids.PsdIds[data.Id].Uid { @@ -152,8 +174,11 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI } //紧急停车 for _, data := range stationGi.LianSuoData.EsbButtons { + if data.Index <= 0 { + continue + } for _, station := range uids.EsbIds[data.Id].CentralizedStations { - if station.Code == stationCode { + if station.StationName == stationCode { table.EsbMap[uint16(data.Id)] = &Row{ commonId: data.Id, uid: uids.EsbIds[data.Id].Uid, @@ -166,8 +191,11 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI //扣车,实际数据中数量为0 //信号机 for _, data := range stationGi.LianSuoData.Signals { + if data.Index <= 0 { + continue + } for _, station := range uids.SignalIds[data.Id].CentralizedStations { - if station.Code == stationCode { + if station.StationName == stationCode { table.SignalMap[uint16(data.Id)] = &Row{ commonId: data.Id, uid: uids.SignalIds[data.Id].Uid, @@ -179,8 +207,14 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI } //计轴区段 for _, data := range stationGi.LianSuoData.Sections { + if data.Index <= 0 { + continue + } + if data.Index == 0 { //这是其它线的区段 + continue + } for _, station := range uids.PhysicalSectionIds[data.Id].CentralizedStations { - if station.Code == stationCode { + if station.StationName == stationCode { table.AxleSectionMap[uint16(data.Id)] = &Row{ commonId: data.Id, uid: uids.PhysicalSectionIds[data.Id].Uid, @@ -194,8 +228,11 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI //防淹门,实际数据中数量为0 //人员防护 for _, data := range stationGi.LianSuoData.SpksSwitchs { + if data.Index <= 0 { + continue + } for _, station := range uids.SpksIds[data.Id].CentralizedStations { - if station.Code == stationCode { + if station.StationName == stationCode { table.SpksMap[uint16(data.Id)] = &Row{ commonId: data.Id, uid: uids.SpksIds[data.Id].Uid, @@ -217,27 +254,32 @@ func (s *serviceContext) runCollectTask(ctx context.Context) { defer func() { if err := recover(); err != nil { logger().Error("状态收集任务出错,记录后重启", "error", err, "stack", string(debug.Stack())) - s.runCollectTask(nil) + s.runCollectTask(ctx) } }() - }() - for range time.Tick(time.Duration(s.iConfig.Period) * time.Millisecond) { - select { - case <-ctx.Done(): - return - default: - frame := s.collectDeviceState() - err := s.client.Send(frame.encode()) - if err != nil { - logger().Error("向联锁发送数据失败", "error", err) + for range time.Tick(time.Duration(s.iConfig.Period) * time.Millisecond) { + select { + case <-ctx.Done(): + return + default: + frame := s.collectDeviceState() + data := frame.encode() + err := s.client.Send(data) + if err != nil { + logger().Error("向联锁发送数据失败", "error", err) + } else { + logger().Info(fmt.Sprintf("向联锁发送数据:%x", data)) + } } } - } + }() } func (s *serviceContext) collectDeviceState() *ToInterlockFrame { wd := entity.GetWorldData(s.sim.World) frame := &ToInterlockFrame{} + frame.WaysideCode = waysideCode + frame.InterlockCode = s.deviceTable.InterlockCode //道岔 for _, row := range s.deviceTable.TurnoutMap { entry := wd.EntityMap[row.uid]