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

75 lines
1.8 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()
//SendStatusMsg 将计轴区段状态发生给联锁系统
SendStatusMsg(msg *message.SectionStatusMsgPack)
}
type AxleMessageManager interface {
//HandleCmdMsg 计轴设备接收到联锁发送来的控制命令
HandleCmdMsg(msg *message.SectionCmdMsgPack)
}
type rsspAxle struct {
//主安全通道
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)
s.messageManager.HandleCmdMsg(msg)
}
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()
}
}
func (s *rsspAxle) SendStatusMsg(msg *message.SectionStatusMsgPack) {
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)
}
}