rts-sim-testing-service/third_party/axle_device/rssp_axle.go

79 lines
2.0 KiB
Go
Raw Normal View History

2023-11-06 18:10:15 +08:00
package axle_device
import "joylink.club/bj-rtsts-server/third_party/message"
//计轴设备与联锁系统安全通信应用层实现
type RsspAxle interface {
//Start 启动计轴设备与联锁系统安全通信服务
Start(amm AxleMessageManager) error
//Stop 停止计轴设备与联锁系统安全通信服务
Stop()
}
type AxleMessageManager interface {
2023-11-07 13:22:47 +08:00
//HandleSectionCmdMsg 计轴设备接收到联锁发送来的控制命令
HandleSectionCmdMsg(centralizedStation string, msg *message.SectionCmdMsgPack)
//CollectSectionStatus 收集仿真中计轴区段状态
CollectSectionStatus() []*message.SectionStatusMsg
2023-11-06 18:10:15 +08:00
}
type rsspAxle struct {
2023-11-07 13:22:47 +08:00
//所属集中站
centralizedStation string
2023-11-06 18:10:15 +08:00
//主安全通道
masterRssp *RsspChannel
//备安全通道
slaveRssp *RsspChannel
//收到应用层消息回调
messageManager AxleMessageManager
}
func NewRsspAxle(masterRssp *RsspChannel, slaveRssp *RsspChannel) RsspAxle {
return &rsspAxle{masterRssp: masterRssp, slaveRssp: slaveRssp}
}
// rssp 安全层执行
func (s *rsspAxle) rcvCmdMsg(data []byte) {
msg := &message.SectionCmdMsgPack{}
msg.Decode(data)
2023-11-07 13:22:47 +08:00
s.messageManager.HandleSectionCmdMsg(s.centralizedStation, msg)
2023-11-06 18:10:15 +08:00
}
func (s *rsspAxle) Start(amm AxleMessageManager) error {
s.messageManager = amm
//设置安全通道层
if s.masterRssp != nil {
s.masterRssp.handleUserData = s.rcvCmdMsg
s.masterRssp.Start()
}
if s.slaveRssp != nil {
s.slaveRssp.handleUserData = s.rcvCmdMsg
s.slaveRssp.Start()
}
//
return nil
}
func (s *rsspAxle) Stop() {
if s.masterRssp != nil {
s.masterRssp.Stop()
}
if s.slaveRssp != nil {
s.slaveRssp.Stop()
}
}
2023-11-07 13:22:47 +08:00
// 发送计轴区段状态给联锁
func (s *rsspAxle) sendStatusMsg(msg *message.SectionStatusMsgPack) {
2023-11-06 18:10:15 +08:00
data := msg.Encode()
//向备通道发送
if s.slaveRssp != nil {
data_s := make([]byte, len(data))
copy(data_s, data)
s.slaveRssp.sendUserData(data_s)
}
//向主通道发送
if s.masterRssp != nil {
s.masterRssp.sendUserData(data)
}
}