列车btm vobc 连接功能

This commit is contained in:
tiger_zhou 2024-05-29 13:34:50 +08:00
parent 550218e9e0
commit 3a7795c875
4 changed files with 100 additions and 4 deletions

View File

@ -74,6 +74,7 @@ type ThridPartyConfig struct {
Acc AccConfig `json:"acc" description:"车载加速计"`
//PcSimConfig VehiclePCSimConfig `json:"pcSimConfig" description:"车载pc仿真平台通信"`
PcSimConfigs []VehiclePCSimConfig `json:"pcSimConfigs" description:"车载pc仿真平台通信"`
BtmVobc BtmVobcConfig `json:"btmVobc" description:"Btm Vobc 11号线相关配置"`
}
type RadarConfig struct {
Open bool `json:"open" description:"是否开启"`
@ -133,6 +134,14 @@ type ElectricMachineryConfig struct {
EndPointA bool `json:"endPointA" description:"一号电机"`
}
// BtmVobcConfig 11 号线 BTM vobc 网关设备配置
type BtmVobcConfig struct {
LocalUdpPort int `json:"localUdpPort" description:"本机监听接收UDP端口"`
RemoteIp string `json:"remoteIp" description:"btm串口设备IP配置"`
RemoteUdpPort int `json:"remoteUdpPort" description:"btm串口设备UDP端口"`
Open bool `json:"open" description:"是否开启"`
}
// BtmCanetConfig BTM CANET网关设备配置
type BtmCanetConfig struct {
LocalUdpPort int `json:"localUdpPort" description:"本机监听接收UDP端口"`

View File

@ -2,17 +2,29 @@ package btm_vobc
import (
"context"
"encoding/hex"
"fmt"
"joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/udp"
"log/slog"
"strconv"
"sync"
)
type BtmVobcManage interface {
GetBtmVobcConfig() config.BtmVobcConfig
}
type BtmVobcService interface {
Start()
Start(btmVobcManage BtmVobcManage)
Stop()
SendData(data []byte)
}
type BtmVobcClient struct {
calFun context.CancelFunc
client udp.UdpClient
server udp.UdpServer
manage BtmVobcManage
}
var (
@ -29,10 +41,75 @@ func Default() BtmVobcService {
}
return btmVobcClient
}
func (b *BtmVobcClient) Start() {
//ctx, calFun := context.WithCancel(context.Background())
func (b *BtmVobcClient) Start(btmVobcManage BtmVobcManage) {
cfg := btmVobcManage.GetBtmVobcConfig()
if !cfg.Open {
slog.Info("11号线 btm vobc配置未开启...")
return
}
udpServer := udp.NewServer(fmt.Sprintf(":%d", cfg.RemoteUdpPort), b.handleBtmVobcFrames)
err := udpServer.Listen()
if err != nil {
slog.Error("11号线 btm VOBC 服务启动失败...")
return
}
//
udpClient := udp.NewClient(fmt.Sprintf("%s:%d", cfg.RemoteIp, cfg.RemoteUdpPort))
b.manage = btmVobcManage
b.server = udpServer
b.client = udpClient
}
func (b *BtmVobcClient) handleBtmVobcFrames(cfs []byte) {
frameType, dataText, err := message.BtmVobcDecode(cfs)
if err != nil {
return
}
if frameType == message.COMMAND_TYPE {
idCommand := &message.BtmVobcIdCommand{}
idCommand.Decode(dataText)
slog.Info("成功接受btm vobc的id命令帧,原数据", hex.EncodeToString(cfs))
//userMsg, _ := hex.DecodeString(testUserBtmMsg)
//msg := &message.BtmVobcMessage{FontTtl: 5, BtmStatus: 0x00, DecodeTime: 10, BackTtl: 4, BtmMsg: userMsg, ResponseTime: 10,
// VobcLifeNum: idCommand.VobcLifeNum, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: idCommand.AutoIdFrame}}
//sendData := msg.Encode()
//fmt.Println("发送btm vobc len:", len(sendData), "报文:", hex.EncodeToString(sendData), "报文序列号:", msg.MsgSerial)
//btmCli.Send(sendData)
//freeMsg, _ := hex.DecodeString(freeBtmMsg)
//msg2 := &message.BtmVobcMsgFree{BtmStatus: 0x00, WorkTemperature: 10, Fun1: uint16(0), Fun2: uint16(0), Fun3: uint16(0), Fun4: uint16(0),
// FreeMsg: freeMsg, RespTime: 20, VobcLifeNum: idCommand.VobcLifeNum, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: idCommand.AutoIdFrame}}
//sendData2 := msg2.Encode()
//fmt.Println("发送btm vobc 空报文:", hex.EncodeToString(sendData2), "len:", len(sendData2), "报文序列号:", msg2.MsgSerial, "atoId=", idCommand.AutoIdFrame)
//btmCli.Send(sendData2)
} else if frameType == message.REQUEST_TYPE {
req := &message.BtmVobcReq{}
req.Decode(dataText)
fmt.Println(req, "========================")
} else {
slog.Error("btm vobc 解析未知命令帧类型", strconv.FormatInt(int64(frameType), 16), frameType, "原始数据:", hex.EncodeToString(cfs), "长度:", len(cfs))
return
}
}
func (b *BtmVobcClient) SendData(data []byte) {
if b.client != nil {
slog.Info("发送btm vobc 报文:", hex.EncodeToString(data), "长度:", len(data))
err := b.client.Send(data)
if err != nil {
slog.Error("发送btm vobc 报文失败:", err)
return
}
}
}
func (b *BtmVobcClient) Stop() {
if b.server != nil {
b.server.Close()
}
if b.client != nil {
b.client.Close()
}
}

View File

@ -150,6 +150,11 @@ func (s *VerifySimulation) GetComIdByUid(uid string) uint32 {
func (s *VerifySimulation) GetBtmCanetConfig() config.BtmCanetConfig {
return s.runConfig.BtmCanet
}
// GetBtmVobcConfig 获取11 号线 btm vobc配置信息
func (s *VerifySimulation) GetBtmVobcConfig() config.BtmVobcConfig {
return s.runConfig.BtmVobc
}
func (s *VerifySimulation) GetLineAllRsspAxleCfgs() []config.RsspAxleConfig {
return s.runConfig.RsspAxleCfgs
}

View File

@ -3,6 +3,7 @@ package ts
import (
"fmt"
"joylink.club/bj-rtsts-server/third_party/acc"
"joylink.club/bj-rtsts-server/third_party/btm_vobc"
"joylink.club/bj-rtsts-server/third_party/interlock/beijing12"
"joylink.club/bj-rtsts-server/third_party/radar"
"joylink.club/bj-rtsts-server/third_party/train_pc_sim"
@ -138,6 +139,8 @@ func runThirdParty(s *memory.VerifySimulation) error {
//列车加速计发送vobc
acc.Default().Start(s)
train_pc_sim.Default().Start(s)
//btm vobc
btm_vobc.Default().Start(s)
return nil
}
@ -165,6 +168,8 @@ func stopThirdParty(s *memory.VerifySimulation) {
acc.Default().Stop()
//列车PC仿真停止
train_pc_sim.Default().Stop()
btm_vobc.Default().Stop()
}
func createSimulationId(projectId int32) string {