计轴rssp 集成
This commit is contained in:
parent
b3c99665e9
commit
b7a31c1363
57
third_party/axle_device/rssp_axle.go
vendored
57
third_party/axle_device/rssp_axle.go
vendored
@ -1,6 +1,11 @@
|
||||
package axle_device
|
||||
|
||||
import "joylink.club/bj-rtsts-server/third_party/message"
|
||||
import (
|
||||
"context"
|
||||
"joylink.club/bj-rtsts-server/third_party/message"
|
||||
"log/slog"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
//计轴设备与联锁系统安全通信应用层实现
|
||||
|
||||
@ -31,10 +36,16 @@ type rsspAxle struct {
|
||||
slaveRssp *RsspChannel
|
||||
//收到应用层消息回调
|
||||
messageManager AxleMessageManager
|
||||
//
|
||||
cancelSendStatus context.CancelFunc
|
||||
}
|
||||
|
||||
func NewRsspAxle(masterRssp *RsspChannel, slaveRssp *RsspChannel) RsspAxle {
|
||||
return &rsspAxle{masterRssp: masterRssp, slaveRssp: slaveRssp}
|
||||
func NewRsspAxle(masterConfig *RsspConfig, slaveConfig *RsspConfig) RsspAxle {
|
||||
mr := &RsspChannel{}
|
||||
mr.Init(masterConfig)
|
||||
lr := &RsspChannel{}
|
||||
lr.Init(slaveConfig)
|
||||
return &rsspAxle{masterRssp: mr, slaveRssp: lr}
|
||||
}
|
||||
|
||||
// rssp 安全层执行
|
||||
@ -55,6 +66,10 @@ func (s *rsspAxle) Start(amm AxleMessageManager) error {
|
||||
s.slaveRssp.Start()
|
||||
}
|
||||
//
|
||||
sendContext, sendCancel := context.WithCancel(context.Background())
|
||||
go s.doTaskSendStatus(sendContext)
|
||||
s.cancelSendStatus = sendCancel
|
||||
//
|
||||
return nil
|
||||
}
|
||||
func (s *rsspAxle) Stop() {
|
||||
@ -64,6 +79,42 @@ func (s *rsspAxle) Stop() {
|
||||
if s.slaveRssp != nil {
|
||||
s.slaveRssp.Stop()
|
||||
}
|
||||
//
|
||||
if s.cancelSendStatus != nil {
|
||||
s.cancelSendStatus()
|
||||
}
|
||||
s.messageManager = nil
|
||||
}
|
||||
func (s *rsspAxle) doTaskSendStatus(sendContext context.Context) {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
slog.Error("定时发送计轴区段状态任务异常", "error", e, "stack", string(debug.Stack()))
|
||||
debug.PrintStack()
|
||||
}
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case <-sendContext.Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
if s.messageManager == nil {
|
||||
slog.Warn("定时发送计轴区段状态任务因messageManager不存在退出")
|
||||
return
|
||||
}
|
||||
//收集区段状态
|
||||
sectionStatusMsg, e := s.messageManager.CollectSectionStatus(s.city, s.lineId, s.centralizedStation)
|
||||
if e == nil {
|
||||
if sectionStatusMsg != nil {
|
||||
msgPack := &message.SectionStatusMsgPack{}
|
||||
msgPack.Ck = 0 //暂时无用
|
||||
msgPack.Sms = sectionStatusMsg
|
||||
s.sendStatusMsg(msgPack)
|
||||
}
|
||||
} else {
|
||||
slog.Debug(e.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 发送计轴区段状态给联锁
|
||||
|
Loading…
Reference in New Issue
Block a user