From 4e110e94fefb080375c24c0dd8635a4b0bc3a6e8 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 31 Oct 2023 15:23:29 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=81=94=E9=94=81ud?= =?UTF-8?q?p=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bj-rtss-message | 2 +- config/config.go | 9 +-- dto/request_proto/request.pb.go | 2 +- rtss_simulation | 2 +- third_party/interlock/interlock.go | 32 +++++---- third_party/message/interlock.go | 14 ++-- ts/protos/graphicData/ibpGraphics.pb.go | 2 +- ts/protos/graphicData/picture.pb.go | 2 +- ts/protos/graphicData/pslGraphics.pb.go | 2 +- .../relayCabinetLayoutGraphics.pb.go | 2 +- .../graphicData/stationLayoutGraphics.pb.go | 2 +- ts/protos/state/device_state.pb.go | 2 +- .../wayside/memory/wayside_simulation.go | 67 ++++++++++++++----- ts/test_simulation_manage.go | 8 ++- 14 files changed, 92 insertions(+), 56 deletions(-) diff --git a/bj-rtss-message b/bj-rtss-message index 8afde90..596dd05 160000 --- a/bj-rtss-message +++ b/bj-rtss-message @@ -1 +1 @@ -Subproject commit 8afde905e5b5376dc0bce29c099fb5fef2576e02 +Subproject commit 596dd059206c803559d0a7f8c0ae1cd4fcfec939 diff --git a/config/config.go b/config/config.go index f8b5ac6..42f32c7 100644 --- a/config/config.go +++ b/config/config.go @@ -52,10 +52,10 @@ type centrifugo struct { // 第三方配置结构 type ThridPartyConfig struct { - Id int32 `json:"id"` - Dynamics DynamicsConfig `json:"dynamics"` - Vobc VobcConfig `json:"vobc"` - Interlock InterlockConfig `json:"interlock"` + Id int32 `json:"id"` + Dynamics DynamicsConfig `json:"dynamics"` + Vobc VobcConfig `json:"vobc"` + Interlocks []InterlockConfig `json:"interlock"` } type DynamicsConfig struct { Ip string `json:"ip"` @@ -76,6 +76,7 @@ type InterlockConfig struct { LocalPort int `json:"localPort"` RemotePort int `json:"remotePort"` Open bool `json:"open"` + Code string `json:"code"` } var Config AppConfig diff --git a/dto/request_proto/request.pb.go b/dto/request_proto/request.pb.go index 325442c..8bee4fb 100644 --- a/dto/request_proto/request.pb.go +++ b/dto/request_proto/request.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.28.1 // protoc v4.23.1 // source: request.proto diff --git a/rtss_simulation b/rtss_simulation index e21995b..b060832 160000 --- a/rtss_simulation +++ b/rtss_simulation @@ -1 +1 @@ -Subproject commit e21995b69537f1ac0efbfeefc8517df3fbe9477e +Subproject commit b0608320d3eac6eb3a892a753e4e74bb56b5b095 diff --git a/third_party/interlock/interlock.go b/third_party/interlock/interlock.go index dd702e3..28b04fb 100644 --- a/third_party/interlock/interlock.go +++ b/third_party/interlock/interlock.go @@ -15,9 +15,8 @@ import ( // 联锁代理通信接口 type InterlockMessageManager interface { - CollectInterlockRelayInfo() []*message.InterlockSendMsgPkg - HandleInterlockDriverInfo(b []byte) - GetInterlockRunConfig() *config.InterlockConfig + CollectInterlockRelayInfo(code string) *message.InterlockSendMsgPkg + HandleInterlockDriverInfo(code string, b []byte) } // 联锁接口 @@ -30,16 +29,16 @@ type InterlockProxy interface { SendCollectMessage(b []byte) } -var _default InterlockProxy +var interlockMap = make(map[string]InterlockProxy) var initMutex sync.Mutex -func Default() InterlockProxy { +func Default(c *config.InterlockConfig) InterlockProxy { initMutex.Lock() defer initMutex.Unlock() - if _default == nil { // TODO - _default = &interlockProxy{} + if interlockMap[c.Code] == nil { + interlockMap[c.Code] = &interlockProxy{runConfig: c} } - return _default + return interlockMap[c.Code] } type interlockProxy struct { @@ -55,21 +54,20 @@ type interlockProxy struct { func (i *interlockProxy) handleDriverInfo(b []byte) { handler := i.manager if handler != nil { - handler.HandleInterlockDriverInfo(b) + handler.HandleInterlockDriverInfo(i.runConfig.Code, b) } } func (i *interlockProxy) Start(manager InterlockMessageManager) { + if i.runConfig == nil || i.runConfig.Ip == "" || !i.runConfig.Open { + return + } if manager == nil { panic("启动联锁消息服务错误: InterlockMessageManager不能为nil") } if i.manager != nil { panic("启动联锁消息服务错误: 存在正在运行的任务") } - i.runConfig = manager.GetInterlockRunConfig() - if i.runConfig == nil || i.runConfig.Ip == "" || !i.runConfig.Open { - return - } i.manager = manager // 初始化客户端、服务端 i.initInterlockProxy() @@ -98,11 +96,11 @@ func (i *interlockProxy) collectInfoStateTask(ctx context.Context) { return default: } - collectInfoStates := i.manager.CollectInterlockRelayInfo() - for _, state := range collectInfoStates { + collectInfoState := i.manager.CollectInterlockRelayInfo(i.runConfig.Code) + if collectInfoState != nil { serialNumber++ - state.Header.SerialNumber = serialNumber - i.sendCollectUdpClient.SendMsg(state) + collectInfoState.Header.SerialNumber = serialNumber + i.sendCollectUdpClient.SendMsg(collectInfoState) } time.Sleep(time.Millisecond * InterlockMessageSendInterval) } diff --git a/third_party/message/interlock.go b/third_party/message/interlock.go index 3868239..3ab5669 100644 --- a/third_party/message/interlock.go +++ b/third_party/message/interlock.go @@ -87,9 +87,9 @@ func boolsToByte(flags [8]bool) byte { // 收到联锁发来的驱动数据 type InterlockReceiveMsgPkg struct { - toagent_len int32 - et_out_num int32 - tcc_output_len int32 + toagent_len int + et_out_num int + tcc_output_len int Header *InterlockMsgPkgHeader // 包头 SyncZone []byte // 同步区状态 DriveInfo []bool // 驱动数据 @@ -106,7 +106,7 @@ type InterlockResponderMsgPkg struct { } // ET_OUT_NUM、TOAGENTLEN、TCC_OUTPUT_LEN(应答器数量*131)的具体数值取决于数据配置。 -func NewInterlockReceiveMsgPkg(tlen, etLen, tccLen int32) *InterlockReceiveMsgPkg { +func NewInterlockReceiveMsgPkg(tlen, etLen, tccLen int) *InterlockReceiveMsgPkg { return &InterlockReceiveMsgPkg{ toagent_len: tlen, et_out_num: etLen, @@ -117,7 +117,7 @@ func NewInterlockReceiveMsgPkg(tlen, etLen, tccLen int32) *InterlockReceiveMsgPk } func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error { - var preIndex, lastIndex int32 = 0, 6 + var preIndex, lastIndex int = 0, 6 // 包头 t.Header.Decode(buf[preIndex:lastIndex]) // 同步区状态 @@ -137,7 +137,7 @@ func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error { return nil } -func (t *InterlockReceiveMsgPkg) parseByte(r []bool, buf []byte, start, end int32) { +func (t *InterlockReceiveMsgPkg) parseByte(r []bool, buf []byte, start, end int) { for i := start; i < end; i++ { b := buf[i] for bit := 7; bit >= 0; bit-- { @@ -146,7 +146,7 @@ func (t *InterlockReceiveMsgPkg) parseByte(r []bool, buf []byte, start, end int3 } } -func parseResponder(buf []byte, start, end int32) []*InterlockResponderMsgPkg { +func parseResponder(buf []byte, start, end int) []*InterlockResponderMsgPkg { var msgs []*InterlockResponderMsgPkg for i := start; i < end; i = i + 128 { b := buf[i : i+128] diff --git a/ts/protos/graphicData/ibpGraphics.pb.go b/ts/protos/graphicData/ibpGraphics.pb.go index 90d7633..ed3142d 100644 --- a/ts/protos/graphicData/ibpGraphics.pb.go +++ b/ts/protos/graphicData/ibpGraphics.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.28.1 // protoc v4.23.1 // source: ibpGraphics.proto diff --git a/ts/protos/graphicData/picture.pb.go b/ts/protos/graphicData/picture.pb.go index 32a004e..c59a50e 100644 --- a/ts/protos/graphicData/picture.pb.go +++ b/ts/protos/graphicData/picture.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.28.1 // protoc v4.23.1 // source: picture.proto diff --git a/ts/protos/graphicData/pslGraphics.pb.go b/ts/protos/graphicData/pslGraphics.pb.go index de96dad..43d468d 100644 --- a/ts/protos/graphicData/pslGraphics.pb.go +++ b/ts/protos/graphicData/pslGraphics.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.28.1 // protoc v4.23.1 // source: pslGraphics.proto diff --git a/ts/protos/graphicData/relayCabinetLayoutGraphics.pb.go b/ts/protos/graphicData/relayCabinetLayoutGraphics.pb.go index 883af1b..52442f4 100644 --- a/ts/protos/graphicData/relayCabinetLayoutGraphics.pb.go +++ b/ts/protos/graphicData/relayCabinetLayoutGraphics.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.28.1 // protoc v4.23.1 // source: relayCabinetLayoutGraphics.proto diff --git a/ts/protos/graphicData/stationLayoutGraphics.pb.go b/ts/protos/graphicData/stationLayoutGraphics.pb.go index 48b933f..43eb347 100644 --- a/ts/protos/graphicData/stationLayoutGraphics.pb.go +++ b/ts/protos/graphicData/stationLayoutGraphics.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.28.1 // protoc v4.23.1 // source: stationLayoutGraphics.proto diff --git a/ts/protos/state/device_state.pb.go b/ts/protos/state/device_state.pb.go index 610e7a5..ed2dd5d 100644 --- a/ts/protos/state/device_state.pb.go +++ b/ts/protos/state/device_state.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.28.1 // protoc v4.23.1 // source: device_state.proto diff --git a/ts/simulation/wayside/memory/wayside_simulation.go b/ts/simulation/wayside/memory/wayside_simulation.go index dca7636..69d7719 100644 --- a/ts/simulation/wayside/memory/wayside_simulation.go +++ b/ts/simulation/wayside/memory/wayside_simulation.go @@ -326,30 +326,55 @@ func (s *VerifySimulation) GetSemiPhysicalRunConfig() *config.VobcConfig { return &s.runConfig.Vobc } +// 获取所有联锁配置唯一Code +func (s *VerifySimulation) GetInterlockCodes() []*config.InterlockConfig { + stationMap := make(map[string]string) + for _, station := range s.Repo.StationList() { + stationMap[station.GetCode()] = station.Id() + } + var configs []*config.InterlockConfig + for _, c := range s.runConfig.Interlocks { + if stationMap[c.Code] == "" || !c.Open { + continue + } + configs = append(configs, &config.InterlockConfig{ + Code: stationMap[c.Code], + Ip: c.Ip, + LocalPort: c.LocalPort, + RemotePort: c.RemotePort, + Open: c.Open, + }) + } + return configs +} + // 处理接到的联锁消息 -func (s *VerifySimulation) HandleInterlockDriverInfo(b []byte) { - driverMsg := message.NewInterlockReceiveMsgPkg(0, 128, 8*131) - driverMsg.Decode(b) - driveState := driverMsg.DriveInfo - for x, lenght := 0, len(driveState); x < lenght/32; x++ { - for y := 0; y < 32; y++ { - fi.DriveCircuitStateChange(s.World, x, y, driveState[x*32+y]) +func (s *VerifySimulation) HandleInterlockDriverInfo(code string, b []byte) { + for _, m := range s.Repo.CentralizedList() { // 获取继电器地图信息 + if m.StationId != code { + continue + } + driverMsg := message.NewInterlockReceiveMsgPkg(0, len(m.QdList), 8*131) + driverMsg.Decode(b) + driveState := driverMsg.DriveInfo + for i, r := range m.QdList { + ds := driveState[i] + for _, b := range r.RefRelays { + slog.Debug("继电器位【%s】获取到驱动状态【%v】", b, ds) + } } } } -// 获取联锁配置 -func (s *VerifySimulation) GetInterlockRunConfig() *config.InterlockConfig { - return &s.runConfig.Interlock -} - // 采集联锁中的继电器消息 -func (s *VerifySimulation) CollectInterlockRelayInfo() []*message.InterlockSendMsgPkg { - var msgPkgs []*message.InterlockSendMsgPkg +func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.InterlockSendMsgPkg { for _, m := range s.Repo.CentralizedList() { // 获取继电器地图信息 - if len(m.CjList) == 0 { + if m.StationId != code { continue } + if len(m.CjList) == 0 { + return nil + } collectInfo := make([]bool, len(m.CjList)) for i, l := range m.CjList { if l == nil || len(l.RefRelays) == 0 { @@ -365,9 +390,9 @@ func (s *VerifySimulation) CollectInterlockRelayInfo() []*message.InterlockSendM } collectInfo[i] = rs } - msgPkgs = append(msgPkgs, &message.InterlockSendMsgPkg{Info: collectInfo}) + return &message.InterlockSendMsgPkg{Info: collectInfo} } - return msgPkgs + return nil } // 初始化仿真运行配置 @@ -393,6 +418,14 @@ func (s *VerifySimulation) GetRunConfigId() int32 { return s.runConfig.Id } +// 获取所有联锁配置 +func (s *VerifySimulation) GetRunConfigInterlocks() []config.InterlockConfig { + if s.runConfig == nil { + return nil + } + return s.runConfig.Interlocks +} + // 初始化运行资源 func (s *VerifySimulation) initRepository() error { // 构建Repository diff --git a/ts/test_simulation_manage.go b/ts/test_simulation_manage.go index 11f4026..9a30c9a 100644 --- a/ts/test_simulation_manage.go +++ b/ts/test_simulation_manage.go @@ -106,7 +106,9 @@ func runThirdParty(s *memory.VerifySimulation) error { // 半实物启动 semi_physical_train.Default().Start(s) // 联锁启动 - interlock.Default().Start(s) + for _, c := range s.GetInterlockCodes() { + interlock.Default(c).Start(s) + } return nil } @@ -117,7 +119,9 @@ func stopThirdParty(s *memory.VerifySimulation) { // 停止半实物 semi_physical_train.Default().Stop() // 联锁启动 - interlock.Default().Stop() + for _, c := range s.GetInterlockCodes() { + interlock.Default(c).Stop() + } } func createSimulationId(projectId int32) string {