Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
thesai 2024-06-12 17:49:13 +08:00
commit f1e406a678
3 changed files with 32 additions and 14 deletions

View File

@ -50,6 +50,7 @@ type accVobcService struct {
func (acc *accVobcService) Start(accManager AccVobcManager) { func (acc *accVobcService) Start(accManager AccVobcManager) {
config := accManager.GetRunAccConfig() config := accManager.GetRunAccConfig()
if config.RemoteIp == "" || config.RemotePort <= 0 || !config.Open { if config.RemoteIp == "" || config.RemotePort <= 0 || !config.Open {
return
} }
acc.vobcClient = udp.NewClient(fmt.Sprintf("%v:%v", config.RemoteIp, config.RemotePort)) acc.vobcClient = udp.NewClient(fmt.Sprintf("%v:%v", config.RemoteIp, config.RemotePort))
acc.radarVobcManager = accManager acc.radarVobcManager = accManager

View File

@ -143,16 +143,19 @@ func (b *BtmVobcClient) checkTrainTTLIsOver(ctx context.Context) {
if time.Now().UnixMilli()-reviceTimeStamp < 1000 { if time.Now().UnixMilli()-reviceTimeStamp < 1000 {
return return
} }
trains := b.manage.GetAllTrain()
slog.Info("检测网络中断情况 前沿ttl 超时...") if len(trains) > 0 {
newTel := make([]*state_proto.VobcBtmState_TelegramState, 0) slog.Info("检测网络中断情况 前沿ttl 超时...")
for _, train := range b.manage.GetAllTrain() { newTel := make([]*state_proto.VobcBtmState_TelegramState, 0)
for _, state := range train.VobcBtm.TelegramState { for _, train := range b.manage.GetAllTrain() {
if time.Now().UnixMilli()-state.ArriveTime < 1000 { for _, state := range train.VobcBtm.TelegramState {
newTel = append(newTel, state) if time.Now().UnixMilli()-state.ArriveTime < 1000 {
newTel = append(newTel, state)
}
} }
} }
} }
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
} }
@ -178,13 +181,13 @@ func (b *BtmVobcClient) handleBtmVobcFrames(cfs []byte) {
idCommand := &message.BtmVobcIdCommand{} idCommand := &message.BtmVobcIdCommand{}
idCommand.Decode(dataText) idCommand.Decode(dataText)
slog.Info(fmt.Sprintf("成功接受btm vobc的id命令帧,requestId:%v,接受时间(微秒):%v", requestId, receiveDataTime)) slog.Info(fmt.Sprintf("成功接受btm vobc的id命令帧,requestId:%v,接受时间(微秒):%v", requestId, receiveDataTime))
b.packets(requestId, idCommand, receiveDataTime, decodePayMicoTime, train.VobcBtm) b.packets(requestId, idCommand.VobcLifeNum, idCommand.AutoIdFrame, receiveDataTime, decodePayMicoTime, train.VobcBtm)
} else if frameType == message.REQUEST_TYPE { } else if frameType == message.REQUEST_TYPE {
slog.Info(fmt.Sprintf("成功接受btm vobc的请求帧,requestId:%v,接受时间(微秒):%v", requestId, receiveDataTime)) slog.Info(fmt.Sprintf("成功接受btm vobc的请求帧,requestId:%v,接受时间(微秒):%v", requestId, receiveDataTime))
req := &message.BtmVobcReq{} req := &message.BtmVobcReq{}
req.Decode(dataText) req.Decode(dataText)
b.RequestFramePackets(requestId, receiveDataTime, decodePayMicoTime, req, train.VobcBtm) b.RequestFramePackets(req.VobcLifeNum, req.AutoIdFrame, requestId, receiveDataTime, decodePayMicoTime, req, train.VobcBtm)
} else { } else {
slog.Error(fmt.Sprintf("btm vobc 解析未知命令帧类型:0x%v,原始数据:%v,长度:%v,requestId:%v", strconv.FormatInt(int64(frameType), 16), hex.EncodeToString(cfs), len(cfs), requestId)) slog.Error(fmt.Sprintf("btm vobc 解析未知命令帧类型:0x%v,原始数据:%v,长度:%v,requestId:%v", strconv.FormatInt(int64(frameType), 16), hex.EncodeToString(cfs), len(cfs), requestId))
return return
@ -202,12 +205,12 @@ func createFreeBalisePackets() []byte {
const MAX_SEND_COUNT = 3 const MAX_SEND_COUNT = 3
// 请求帧 // 请求帧
func (b *BtmVobcClient) RequestFramePackets(requestId string, receiveTime int64, decodePayMicoTime int64, req *message.BtmVobcReq, vobcbtm *state_proto.VobcBtmState) { func (b *BtmVobcClient) RequestFramePackets(vobcLifeNum uint32, autoId byte, requestId string, receiveTime int64, decodePayMicoTime int64, req *message.BtmVobcReq, vobcbtm *state_proto.VobcBtmState) {
if req.FrameStatus == message.REQ_FRAME_STATUS_BOOT && req.MessageType == message.REQ_PACKETS_TYPE_BOOT { if req.FrameStatus == message.REQ_FRAME_STATUS_BOOT && req.MessageType == message.REQ_PACKETS_TYPE_BOOT {
slog.Info(fmt.Sprintf("接受请求帧,准备发送空闲帧数据 帧状态:0x%v,消息类型:0x%v ,requestId:%v", strconv.FormatInt(int64(req.FrameStatus), 16), strconv.FormatInt(int64(req.MessageType), 16), requestId)) slog.Info(fmt.Sprintf("接受请求帧,准备发送空闲帧数据 帧状态:0x%v,消息类型:0x%v ,requestId:%v", strconv.FormatInt(int64(req.FrameStatus), 16), strconv.FormatInt(int64(req.MessageType), 16), requestId))
vobcbtm.TelegramState = make([]*state_proto.VobcBtmState_TelegramState, 0) vobcbtm.TelegramState = make([]*state_proto.VobcBtmState_TelegramState, 0)
vobcbtm.History = make(map[uint32]*state_proto.VobcBtmState_VobcBtmHistoryState) vobcbtm.History = make(map[uint32]*state_proto.VobcBtmState_VobcBtmHistoryState)
b.packets(requestId, nil, receiveTime, decodePayMicoTime, vobcbtm) b.packets(requestId, vobcLifeNum, autoId, receiveTime, decodePayMicoTime, vobcbtm)
} else if req.FrameStatus == message.REQ_FRAME_STATUS_OK { } else if req.FrameStatus == message.REQ_FRAME_STATUS_OK {
//帧正确,删除之前发送的数据 //帧正确,删除之前发送的数据
@ -344,12 +347,12 @@ func (b *BtmVobcClient) balisePacketsFree(requestId string, receiveTime int64, v
} }
// 应答器报文或空报文 // 应答器报文或空报文
func (b *BtmVobcClient) packets(requestId string, idCommand *message.BtmVobcIdCommand, receiveTime int64, decodePayMicoTime int64, vobcbtm *state_proto.VobcBtmState) { func (b *BtmVobcClient) packets(requestId string, vobcLifeNum uint32, autoIdFrame byte, receiveTime int64, decodePayMicoTime int64, vobcbtm *state_proto.VobcBtmState) {
if len(vobcbtm.TelegramState) == 0 { if len(vobcbtm.TelegramState) == 0 {
b.balisePacketsFree(requestId, receiveTime, idCommand.VobcLifeNum, idCommand.AutoIdFrame, vobcbtm) b.balisePacketsFree(requestId, receiveTime, vobcLifeNum, autoIdFrame, vobcbtm)
} else { } else {
b.balisePackets(requestId, vobcbtm.TelegramState[0], receiveTime, decodePayMicoTime, idCommand.VobcLifeNum, idCommand.AutoIdFrame, vobcbtm) b.balisePackets(requestId, vobcbtm.TelegramState[0], receiveTime, decodePayMicoTime, vobcLifeNum, autoIdFrame, vobcbtm)
} }
} }

View File

@ -6,8 +6,10 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"joylink.club/bj-rtsts-server/third_party/message" "joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/udp"
"sync/atomic" "sync/atomic"
"testing" "testing"
"time"
) )
const ( const (
@ -17,6 +19,18 @@ const (
var message_id atomic.Uint32 var message_id atomic.Uint32
func TestConn(t *testing.T) {
source := ":fffee601804f004d00c1b401002a00e7ae839c4b59b2bf912275000000000000000000000000000001b4bf00000000000000000000dc4902d6e431fffd"
d, _ := hex.DecodeString(source)
udpClient := udp.NewClient(fmt.Sprintf("%v:%d", "127.0.0.1", 49491))
err := udpClient.Send(d)
if err != nil {
fmt.Println(err)
return
}
time.Sleep(time.Second * 2)
udpClient.Close()
}
func TestDecode(t *testing.T) { func TestDecode(t *testing.T) {
fmt.Println(code1[:4]) fmt.Println(code1[:4])
d, _ := hex.DecodeString(code1) d, _ := hex.DecodeString(code1)