btm
This commit is contained in:
parent
5a20d78aa3
commit
f66960b9f4
30
third_party/can_btm/balise_btm.go
vendored
30
third_party/can_btm/balise_btm.go
vendored
@ -43,6 +43,8 @@ type btmCanetClient struct {
|
||||
btmTime btmClock
|
||||
//数据流水号
|
||||
dsn byte
|
||||
//重发的数据
|
||||
resendData *resendData
|
||||
}
|
||||
type btmClock struct {
|
||||
btmTk uint32 //与ATP系统同步的时间ms
|
||||
@ -172,6 +174,14 @@ func (s *btmCanetClient) dealWithAptReq(f *message.CanetFrame) {
|
||||
// 当收到应答器报文时响应:时间同步帧、状态应答帧、数据帧
|
||||
// 当未收到应答器报文时响应:时间同步帧、状态应答帧
|
||||
func (s *btmCanetClient) rspToAtp(isResendRequest bool) {
|
||||
//重发上一报文处理
|
||||
if isResendRequest && s.resendData != nil && s.resendData.canResend() {
|
||||
s.resendData.countAdd1()
|
||||
s.sendCanetFrame(s.resendData.data)
|
||||
return
|
||||
} else {
|
||||
s.resendData = nil
|
||||
}
|
||||
//BTM状态
|
||||
statusF := message.NewBtmStatusRspFrame(s.atpReqSn)
|
||||
btmStatus, btmStatusErr := fi.FindTrainBaliseBtmStatus(s.bcm.EvnWorld())
|
||||
@ -207,6 +217,7 @@ func (s *btmCanetClient) rspToAtp(isResendRequest bool) {
|
||||
timeSyncF.T3 = s.btmTime.tkNow()
|
||||
s.sendCanetFrame(timeSyncF.Encode().Encode())
|
||||
//
|
||||
s.resendData = newResendData(statusDataCf)
|
||||
s.sendCanetFrame(statusDataCf)
|
||||
} else {
|
||||
slog.Warn("BtmCanetClient应答帧、数据帧编码失败")
|
||||
@ -234,6 +245,25 @@ func (s *btmCanetClient) dsnAdd1() {
|
||||
}
|
||||
}
|
||||
|
||||
// 准备重发的状态应答帧和报文数据帧
|
||||
type resendData struct {
|
||||
data []byte //重发的数据
|
||||
count int //重发次数
|
||||
}
|
||||
|
||||
func newResendData(data []byte) *resendData {
|
||||
return &resendData{
|
||||
data: data,
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
func (r *resendData) canResend() bool {
|
||||
return r.count <= 3
|
||||
}
|
||||
func (r *resendData) countAdd1() {
|
||||
r.count++
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 处理接收的状态应答帧
|
||||
|
Loading…
Reference in New Issue
Block a user