66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
|
package semi_physical_train
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"joylink.club/bj-rtsts-server/config"
|
||
|
"joylink.club/bj-rtsts-server/third_party/message"
|
||
|
"joylink.club/bj-rtsts-server/third_party/udp"
|
||
|
)
|
||
|
|
||
|
// 半实物仿真列车通信接口
|
||
|
type SemiPhysicalTrain interface {
|
||
|
// 启动半实物仿真消息处理
|
||
|
Start(manager SemiPhysicalMessageManager)
|
||
|
// 停止半实物仿真消息处理
|
||
|
Stop()
|
||
|
}
|
||
|
|
||
|
type SemiPhysicalMessageManager interface {
|
||
|
// 处理半实物仿真列车控制消息
|
||
|
HandleSemiPhysicalTrainControlMsg(msg *message.TrainControlMsg)
|
||
|
}
|
||
|
|
||
|
type semiPhysicalTrainImpl struct {
|
||
|
trainControlUdpServer udp.UdpServer
|
||
|
trainSpeedInfoUdpClient udp.UdpClient
|
||
|
|
||
|
manager SemiPhysicalMessageManager
|
||
|
}
|
||
|
|
||
|
var _default SemiPhysicalTrain
|
||
|
|
||
|
func Default() SemiPhysicalTrain {
|
||
|
if !config.Config.Vobc.Open {
|
||
|
panic("半实物仿真接口模块未开启")
|
||
|
}
|
||
|
return _default
|
||
|
}
|
||
|
|
||
|
func Init() {
|
||
|
if !config.Config.Vobc.Open {
|
||
|
return
|
||
|
}
|
||
|
_default = newSemiPhysicalTrain()
|
||
|
}
|
||
|
|
||
|
func newSemiPhysicalTrain() SemiPhysicalTrain {
|
||
|
s := &semiPhysicalTrainImpl{
|
||
|
trainSpeedInfoUdpClient: udp.NewClient("127.0.0.1:7777"),
|
||
|
}
|
||
|
s.trainControlUdpServer = udp.NewServer(fmt.Sprintf(":%d", config.Config.Dynamics.UdpLocalPort), s.handleTrainControlMsg)
|
||
|
return s
|
||
|
}
|
||
|
|
||
|
func (s *semiPhysicalTrainImpl) handleTrainControlMsg(b []byte) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (s *semiPhysicalTrainImpl) Start(manager SemiPhysicalMessageManager) {
|
||
|
s.manager = manager
|
||
|
}
|
||
|
|
||
|
func (s *semiPhysicalTrainImpl) Stop() {
|
||
|
s.manager = nil
|
||
|
}
|