【修改联锁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 {
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e21995b69537f1ac0efbfeefc8517df3fbe9477e
|
||||
Subproject commit b0608320d3eac6eb3a892a753e4e74bb56b5b095
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue