This commit is contained in:
xzb 2023-11-23 15:04:46 +08:00
parent 5628bf8eb8
commit 8fdc707a97
2 changed files with 63 additions and 3 deletions

View File

@ -30,6 +30,15 @@ func (t *TrainPositionInfo) ToString() string {
type TrainBaliseTelegram struct {
BaliseId string //应答器ID
Telegram []byte //一个应答器同一时刻只有一条报文处于激活有效状态
sent bool //true-已经向车载ATP发送过
}
func NewTrainBaliseTelegram(baliseId string, telegram []byte) *TrainBaliseTelegram {
return &TrainBaliseTelegram{
BaliseId: baliseId,
Telegram: telegram,
sent: false,
}
}
// TrainBtm 列车应答器传输模块
@ -44,10 +53,57 @@ type TrainBtm struct {
AboveBalise bool
//列车在运行方向顺序扫描到的应答器
ScannedBalises []*TrainBaliseTelegram
//最近经过的应答器id
viaBaliseId string
}
func (t *TrainBtm) Scanning(aboveBalise bool, tbt *TrainBaliseTelegram) {
// 应答器计数器加1[0,255]
func (t *TrainBtm) baliseCounterAdd1() {
t.BaliseCounter++
if t.BaliseCounter > 255 {
t.BaliseCounter = 0
}
}
// 报文计数器加1[0,255]
func (t *TrainBtm) baliseMessageCounterAdd1() {
t.MessageCounter++
if t.MessageCounter > 255 {
t.MessageCounter = 0
}
}
const scannedBalisesMax = 3
// Scanning BTM通过车载应答器天线接收到应答器报文
func (t *TrainBtm) Scanning(aboveBalise bool, aboveBaliseId string, telegram *TrainBaliseTelegram) {
t.AboveBalise = aboveBalise
//BTM此时在一个新的应答器上方
if t.AboveBalise && t.viaBaliseId != aboveBaliseId {
t.viaBaliseId = aboveBaliseId
t.baliseCounterAdd1()
}
//
if telegram == nil {
return
}
//过滤掉同一个应答器
for _, tbt := range t.ScannedBalises {
if tbt.BaliseId == telegram.BaliseId {
return
}
}
//一个新的应答器的报文
if len(t.ScannedBalises) < scannedBalisesMax {
t.ScannedBalises = append(t.ScannedBalises, telegram)
} else {
//move left
for i := 1; i < scannedBalisesMax; i++ {
t.ScannedBalises[i-1] = t.ScannedBalises[i]
}
t.ScannedBalises[scannedBalisesMax-1] = telegram
}
t.baliseMessageCounterAdd1()
}
var (

View File

@ -33,7 +33,11 @@ func (s *BaliseDetectSystem) Update(w ecs.World) {
detectedBalise := s.detect(wd, tp, balises)
//列车应答器天线扫描到应答器,获取应答器报文发送给BTM
tbt := s.findBaliseTelegram(wd, detectedBalise)
btm.Scanning(detectedBalise != nil, tbt)
var detectedBaliseId string
if detectedBalise != nil {
detectedBaliseId = detectedBalise.Id()
}
btm.Scanning(detectedBalise != nil, detectedBaliseId, tbt)
})
}
@ -47,7 +51,7 @@ func (s *BaliseDetectSystem) findBaliseTelegram(wd *component.WorldData, detecte
if baliseEntry != nil {
baliseState := component.BaliseStateType.Get(baliseEntry)
if len(baliseState.ValidTelegram) > 0 {
return &component.TrainBaliseTelegram{BaliseId: detectedBalise.Id(), Telegram: baliseState.ValidTelegram}
return component.NewTrainBaliseTelegram(detectedBalise.Id(), baliseState.ValidTelegram)
}
} else {
slog.Warn(fmt.Sprintf("应答器[%s]实体不存在", detectedBalise.Id()))