【修改联锁udp客户端初始化逻辑】
This commit is contained in:
parent
6730a45c46
commit
4e110e94fe
|
@ -1 +1 @@
|
||||||
Subproject commit 8afde905e5b5376dc0bce29c099fb5fef2576e02
|
Subproject commit 596dd059206c803559d0a7f8c0ae1cd4fcfec939
|
|
@ -52,10 +52,10 @@ type centrifugo struct {
|
||||||
|
|
||||||
// 第三方配置结构
|
// 第三方配置结构
|
||||||
type ThridPartyConfig struct {
|
type ThridPartyConfig struct {
|
||||||
Id int32 `json:"id"`
|
Id int32 `json:"id"`
|
||||||
Dynamics DynamicsConfig `json:"dynamics"`
|
Dynamics DynamicsConfig `json:"dynamics"`
|
||||||
Vobc VobcConfig `json:"vobc"`
|
Vobc VobcConfig `json:"vobc"`
|
||||||
Interlock InterlockConfig `json:"interlock"`
|
Interlocks []InterlockConfig `json:"interlock"`
|
||||||
}
|
}
|
||||||
type DynamicsConfig struct {
|
type DynamicsConfig struct {
|
||||||
Ip string `json:"ip"`
|
Ip string `json:"ip"`
|
||||||
|
@ -76,6 +76,7 @@ type InterlockConfig struct {
|
||||||
LocalPort int `json:"localPort"`
|
LocalPort int `json:"localPort"`
|
||||||
RemotePort int `json:"remotePort"`
|
RemotePort int `json:"remotePort"`
|
||||||
Open bool `json:"open"`
|
Open bool `json:"open"`
|
||||||
|
Code string `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var Config AppConfig
|
var Config AppConfig
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v4.23.1
|
// protoc v4.23.1
|
||||||
// source: request.proto
|
// source: request.proto
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit e21995b69537f1ac0efbfeefc8517df3fbe9477e
|
Subproject commit b0608320d3eac6eb3a892a753e4e74bb56b5b095
|
|
@ -15,9 +15,8 @@ import (
|
||||||
|
|
||||||
// 联锁代理通信接口
|
// 联锁代理通信接口
|
||||||
type InterlockMessageManager interface {
|
type InterlockMessageManager interface {
|
||||||
CollectInterlockRelayInfo() []*message.InterlockSendMsgPkg
|
CollectInterlockRelayInfo(code string) *message.InterlockSendMsgPkg
|
||||||
HandleInterlockDriverInfo(b []byte)
|
HandleInterlockDriverInfo(code string, b []byte)
|
||||||
GetInterlockRunConfig() *config.InterlockConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 联锁接口
|
// 联锁接口
|
||||||
|
@ -30,16 +29,16 @@ type InterlockProxy interface {
|
||||||
SendCollectMessage(b []byte)
|
SendCollectMessage(b []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _default InterlockProxy
|
var interlockMap = make(map[string]InterlockProxy)
|
||||||
var initMutex sync.Mutex
|
var initMutex sync.Mutex
|
||||||
|
|
||||||
func Default() InterlockProxy {
|
func Default(c *config.InterlockConfig) InterlockProxy {
|
||||||
initMutex.Lock()
|
initMutex.Lock()
|
||||||
defer initMutex.Unlock()
|
defer initMutex.Unlock()
|
||||||
if _default == nil { // TODO
|
if interlockMap[c.Code] == nil {
|
||||||
_default = &interlockProxy{}
|
interlockMap[c.Code] = &interlockProxy{runConfig: c}
|
||||||
}
|
}
|
||||||
return _default
|
return interlockMap[c.Code]
|
||||||
}
|
}
|
||||||
|
|
||||||
type interlockProxy struct {
|
type interlockProxy struct {
|
||||||
|
@ -55,21 +54,20 @@ type interlockProxy struct {
|
||||||
func (i *interlockProxy) handleDriverInfo(b []byte) {
|
func (i *interlockProxy) handleDriverInfo(b []byte) {
|
||||||
handler := i.manager
|
handler := i.manager
|
||||||
if handler != nil {
|
if handler != nil {
|
||||||
handler.HandleInterlockDriverInfo(b)
|
handler.HandleInterlockDriverInfo(i.runConfig.Code, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *interlockProxy) Start(manager InterlockMessageManager) {
|
func (i *interlockProxy) Start(manager InterlockMessageManager) {
|
||||||
|
if i.runConfig == nil || i.runConfig.Ip == "" || !i.runConfig.Open {
|
||||||
|
return
|
||||||
|
}
|
||||||
if manager == nil {
|
if manager == nil {
|
||||||
panic("启动联锁消息服务错误: InterlockMessageManager不能为nil")
|
panic("启动联锁消息服务错误: InterlockMessageManager不能为nil")
|
||||||
}
|
}
|
||||||
if i.manager != nil {
|
if i.manager != nil {
|
||||||
panic("启动联锁消息服务错误: 存在正在运行的任务")
|
panic("启动联锁消息服务错误: 存在正在运行的任务")
|
||||||
}
|
}
|
||||||
i.runConfig = manager.GetInterlockRunConfig()
|
|
||||||
if i.runConfig == nil || i.runConfig.Ip == "" || !i.runConfig.Open {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
i.manager = manager
|
i.manager = manager
|
||||||
// 初始化客户端、服务端
|
// 初始化客户端、服务端
|
||||||
i.initInterlockProxy()
|
i.initInterlockProxy()
|
||||||
|
@ -98,11 +96,11 @@ func (i *interlockProxy) collectInfoStateTask(ctx context.Context) {
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
collectInfoStates := i.manager.CollectInterlockRelayInfo()
|
collectInfoState := i.manager.CollectInterlockRelayInfo(i.runConfig.Code)
|
||||||
for _, state := range collectInfoStates {
|
if collectInfoState != nil {
|
||||||
serialNumber++
|
serialNumber++
|
||||||
state.Header.SerialNumber = serialNumber
|
collectInfoState.Header.SerialNumber = serialNumber
|
||||||
i.sendCollectUdpClient.SendMsg(state)
|
i.sendCollectUdpClient.SendMsg(collectInfoState)
|
||||||
}
|
}
|
||||||
time.Sleep(time.Millisecond * InterlockMessageSendInterval)
|
time.Sleep(time.Millisecond * InterlockMessageSendInterval)
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,9 +87,9 @@ func boolsToByte(flags [8]bool) byte {
|
||||||
|
|
||||||
// 收到联锁发来的驱动数据
|
// 收到联锁发来的驱动数据
|
||||||
type InterlockReceiveMsgPkg struct {
|
type InterlockReceiveMsgPkg struct {
|
||||||
toagent_len int32
|
toagent_len int
|
||||||
et_out_num int32
|
et_out_num int
|
||||||
tcc_output_len int32
|
tcc_output_len int
|
||||||
Header *InterlockMsgPkgHeader // 包头
|
Header *InterlockMsgPkgHeader // 包头
|
||||||
SyncZone []byte // 同步区状态
|
SyncZone []byte // 同步区状态
|
||||||
DriveInfo []bool // 驱动数据
|
DriveInfo []bool // 驱动数据
|
||||||
|
@ -106,7 +106,7 @@ type InterlockResponderMsgPkg struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ET_OUT_NUM、TOAGENTLEN、TCC_OUTPUT_LEN(应答器数量*131)的具体数值取决于数据配置。
|
// ET_OUT_NUM、TOAGENTLEN、TCC_OUTPUT_LEN(应答器数量*131)的具体数值取决于数据配置。
|
||||||
func NewInterlockReceiveMsgPkg(tlen, etLen, tccLen int32) *InterlockReceiveMsgPkg {
|
func NewInterlockReceiveMsgPkg(tlen, etLen, tccLen int) *InterlockReceiveMsgPkg {
|
||||||
return &InterlockReceiveMsgPkg{
|
return &InterlockReceiveMsgPkg{
|
||||||
toagent_len: tlen,
|
toagent_len: tlen,
|
||||||
et_out_num: etLen,
|
et_out_num: etLen,
|
||||||
|
@ -117,7 +117,7 @@ func NewInterlockReceiveMsgPkg(tlen, etLen, tccLen int32) *InterlockReceiveMsgPk
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error {
|
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])
|
t.Header.Decode(buf[preIndex:lastIndex])
|
||||||
// 同步区状态
|
// 同步区状态
|
||||||
|
@ -137,7 +137,7 @@ func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error {
|
||||||
return nil
|
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++ {
|
for i := start; i < end; i++ {
|
||||||
b := buf[i]
|
b := buf[i]
|
||||||
for bit := 7; bit >= 0; bit-- {
|
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
|
var msgs []*InterlockResponderMsgPkg
|
||||||
for i := start; i < end; i = i + 128 {
|
for i := start; i < end; i = i + 128 {
|
||||||
b := buf[i : i+128]
|
b := buf[i : i+128]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v4.23.1
|
// protoc v4.23.1
|
||||||
// source: ibpGraphics.proto
|
// source: ibpGraphics.proto
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v4.23.1
|
// protoc v4.23.1
|
||||||
// source: picture.proto
|
// source: picture.proto
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v4.23.1
|
// protoc v4.23.1
|
||||||
// source: pslGraphics.proto
|
// source: pslGraphics.proto
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v4.23.1
|
// protoc v4.23.1
|
||||||
// source: relayCabinetLayoutGraphics.proto
|
// source: relayCabinetLayoutGraphics.proto
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v4.23.1
|
// protoc v4.23.1
|
||||||
// source: stationLayoutGraphics.proto
|
// source: stationLayoutGraphics.proto
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v4.23.1
|
// protoc v4.23.1
|
||||||
// source: device_state.proto
|
// source: device_state.proto
|
||||||
|
|
||||||
|
|
|
@ -326,30 +326,55 @@ func (s *VerifySimulation) GetSemiPhysicalRunConfig() *config.VobcConfig {
|
||||||
return &s.runConfig.Vobc
|
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) {
|
func (s *VerifySimulation) HandleInterlockDriverInfo(code string, b []byte) {
|
||||||
driverMsg := message.NewInterlockReceiveMsgPkg(0, 128, 8*131)
|
for _, m := range s.Repo.CentralizedList() { // 获取继电器地图信息
|
||||||
driverMsg.Decode(b)
|
if m.StationId != code {
|
||||||
driveState := driverMsg.DriveInfo
|
continue
|
||||||
for x, lenght := 0, len(driveState); x < lenght/32; x++ {
|
}
|
||||||
for y := 0; y < 32; y++ {
|
driverMsg := message.NewInterlockReceiveMsgPkg(0, len(m.QdList), 8*131)
|
||||||
fi.DriveCircuitStateChange(s.World, x, y, driveState[x*32+y])
|
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 {
|
func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.InterlockSendMsgPkg {
|
||||||
var msgPkgs []*message.InterlockSendMsgPkg
|
|
||||||
for _, m := range s.Repo.CentralizedList() { // 获取继电器地图信息
|
for _, m := range s.Repo.CentralizedList() { // 获取继电器地图信息
|
||||||
if len(m.CjList) == 0 {
|
if m.StationId != code {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if len(m.CjList) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
collectInfo := make([]bool, len(m.CjList))
|
collectInfo := make([]bool, len(m.CjList))
|
||||||
for i, l := range m.CjList {
|
for i, l := range m.CjList {
|
||||||
if l == nil || len(l.RefRelays) == 0 {
|
if l == nil || len(l.RefRelays) == 0 {
|
||||||
|
@ -365,9 +390,9 @@ func (s *VerifySimulation) CollectInterlockRelayInfo() []*message.InterlockSendM
|
||||||
}
|
}
|
||||||
collectInfo[i] = rs
|
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
|
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 {
|
func (s *VerifySimulation) initRepository() error {
|
||||||
// 构建Repository
|
// 构建Repository
|
||||||
|
|
|
@ -106,7 +106,9 @@ func runThirdParty(s *memory.VerifySimulation) error {
|
||||||
// 半实物启动
|
// 半实物启动
|
||||||
semi_physical_train.Default().Start(s)
|
semi_physical_train.Default().Start(s)
|
||||||
// 联锁启动
|
// 联锁启动
|
||||||
interlock.Default().Start(s)
|
for _, c := range s.GetInterlockCodes() {
|
||||||
|
interlock.Default(c).Start(s)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +119,9 @@ func stopThirdParty(s *memory.VerifySimulation) {
|
||||||
// 停止半实物
|
// 停止半实物
|
||||||
semi_physical_train.Default().Stop()
|
semi_physical_train.Default().Stop()
|
||||||
// 联锁启动
|
// 联锁启动
|
||||||
interlock.Default().Stop()
|
for _, c := range s.GetInterlockCodes() {
|
||||||
|
interlock.Default(c).Stop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSimulationId(projectId int32) string {
|
func createSimulationId(projectId int32) string {
|
||||||
|
|
Loading…
Reference in New Issue