应答器修改

This commit is contained in:
tiger_zhou 2024-08-13 09:09:25 +08:00
parent 4044b7f4c2
commit 06a4331135
7 changed files with 1199 additions and 1233 deletions

View File

@ -48,13 +48,13 @@ func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
authed.GET("/:id/getMapKilometerRange", getMapKilometerRange) authed.GET("/:id/getMapKilometerRange", getMapKilometerRange)
authed.POST("/psl/operation", pslBtnOperation) //1 authed.POST("/psl/operation", pslBtnOperation) //1
authed.POST("/psd/operation", psdOperation) authed.POST("/psd/operation", psdOperation)
authed.PUT("/balisecodec/position/modify", balisePositionModify) authed.PUT("/balise/position/modify", balisePositionModify)
authed.PUT("/balisecodec/position/reset", balisePositionReset) authed.PUT("/balise/position/reset", balisePositionReset)
authed.PUT("/balisecodec/telegram/modify", baliseTelegramModify) authed.PUT("/balise/telegram/modify", baliseTelegramModify)
authed.PUT("/balisecodec/telegram/reset", baliseTelegramReset) authed.PUT("/balise/telegram/reset", baliseTelegramReset)
authed.PUT("/balisecodec/telegram/stop", baliseTelegramStop) authed.PUT("/balise/telegram/stop", baliseTelegramStop)
authed.PUT("/balisecodec/telegram/send", baliseTelegramSend) authed.PUT("/balise/telegram/send", baliseTelegramSend)
authed.PUT("/balisecodec/reset", baliseReset) authed.PUT("/balise/reset", baliseReset)
authed.PUT("/ckm/operation", ckmOperation) authed.PUT("/ckm/operation", ckmOperation)
authed.PUT("/xcj/operation", xcjOperation) authed.PUT("/xcj/operation", xcjOperation)
//authed.POST("/bypass/operation", bypassBtnOrKeyOperation) //authed.POST("/bypass/operation", bypassBtnOrKeyOperation)

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit 74bea4e9955524f7254876c90af08d963f666585 Subproject commit 61b489dcf80d992891e3266d0224fbe05fd49d0f

View File

@ -127,7 +127,9 @@ type BtmCanetClient interface {
Stop() Stop()
//HandleTrainHeadPositionInfo 处理收到列车位置信息 //HandleTrainHeadPositionInfo 处理收到列车位置信息
HandleTrainHeadPositionInfo(w ecs.World, vobcBtm *state_proto.VobcBtmState, h *TrainHeadPositionInfo) HandleTrainHeadPositionInfo(w ecs.World, vobcBtm *state_proto.VobcBtmState, h *TrainHeadPositionInfo)
//获取BTM显示状态 + btm最新的状态 // GetState 获取BTM显示状态 + btm最新的状态
//
// Deprecated 请从列车的btmBaliseCache中获取
GetState() state_proto.BTMState GetState() state_proto.BTMState
//GetAllData() //GetAllData()
FindNotSendState() (state_proto.BTMState, bool) FindNotSendState() (state_proto.BTMState, bool)

View File

@ -8,6 +8,7 @@ import (
"joylink.club/rtsssimulation/fi" "joylink.club/rtsssimulation/fi"
"joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/repository/model/proto"
"log/slog"
"math" "math"
"sort" "sort"
"sync" "sync"
@ -85,17 +86,9 @@ func (t *BaliseDetector) detect2(wd *component.WorldData, repo *repository.Repos
curAntennaRi := t.createBtmAntennaRunningInfo(wd, repo, th) //目前车头 curAntennaRi := t.createBtmAntennaRunningInfo(wd, repo, th) //目前车头
curAntennaRi2 := t.createBtmAntennaRunningInfo(wd, repo, th2) //上次车头 curAntennaRi2 := t.createBtmAntennaRunningInfo(wd, repo, th2) //上次车头
var startBalises []*repository.Transponder var startBalises []*repository.Transponder
var endBalises []*repository.Transponder
//startBalises = t.searchBalisesFromBetweenLinkPosition(repo, th.Up, curAntennaRi2.LinkId, th2.LinkOffset, th.LinkOffset) //startBalises = t.searchBalisesFromBetweenLinkPosition(repo, th.Up, curAntennaRi2.LinkId, th2.LinkOffset, th.LinkOffset)
startBalises = t.searchBalisesFromBetweenLinkPosition(repo, th.Up, curAntennaRi2.LinkId, curAntennaRi2.LinkOffset, curAntennaRi.LinkOffset) startBalises = t.searchBalisesFromBetweenLinkPosition(repo, th2.Up, curAntennaRi2.LinkId, curAntennaRi2.LinkOffset, curAntennaRi.LinkOffset)
//endBalises = t.searchBalisesFromBetweenLinkPosition(repo, !th.Up, curAntennaRi.LinkId, curAntennaRi.LinkOffset, curAntennaRi2.LinkOffset)
/* if th.Up {
startBalises = t.searchBalisesFromBetweenLinkPosition(repo, th.Up, curAntennaRi2.LinkId, curAntennaRi2.LinkOffset, curAntennaRi.LinkOffset)
endBalises = t.searchBalisesFromBetweenLinkPosition(repo, !th.Up, curAntennaRi.LinkId, curAntennaRi.LinkOffset, curAntennaRi2.LinkOffset)
} else {
startBalises = t.searchBalisesFromBetweenLinkPosition(repo, th.Up, curAntennaRi2.LinkId, curAntennaRi.LinkOffset, curAntennaRi2.LinkOffset)
endBalises = t.searchBalisesFromBetweenLinkPosition(repo, !th.Up, curAntennaRi.LinkId, curAntennaRi2.LinkOffset, curAntennaRi.LinkOffset)
}*/
balises := make([]*repository.Transponder, 0) balises := make([]*repository.Transponder, 0)
for _, balise := range startBalises { for _, balise := range startBalises {
@ -108,31 +101,15 @@ func (t *BaliseDetector) detect2(wd *component.WorldData, repo *repository.Repos
} }
if !find { if !find {
balises = append(balises, balise) balises = append(balises, balise)
//slog.Info(fmt.Sprintf("start baliseId:%v,Distance:%v,up:%v", balisecodec.Id(), balisecodec.LinkPosition(), curAntennaRi.Up))
}
}
for _, balise := range endBalises {
find := false
for _, transponder := range balises {
if transponder.Id() == balise.Id() {
find = true
break
}
}
if !find {
//slog.Info(fmt.Sprintf("end baliseId:%v,Distance:%v,up:%v", balisecodec.Id(), balisecodec.LinkPosition(), curAntennaRi.Up))
balises = append(balises, balise)
} }
} }
if len(balises) > 0 { if len(balises) > 0 {
balise := balises[0] balise := balises[0]
baliseInfo := &BtmAntennaScanningBaliseInfo{BaliseId: balise.Id(), BaliseType: balise.BaliseType()} baliseInfo := &BtmAntennaScanningBaliseInfo{BaliseId: balise.Id(), BaliseType: balise.BaliseType()}
/*uuid := uuid2.NewString() //uuid := uuid2.NewString()
for _, transponder := range balises { //slog.Info(fmt.Sprintf("uid :%v,baliseId:%v,Distance:%v,up:%v", uuid, balise.Id(), baliseInfo.Distance, curAntennaRi.Up))
slog.Info(fmt.Sprintf("uid :%v,baliseId:%v,Distance:%v,up:%v", uuid, transponder.Id(), baliseInfo.Distance, curAntennaRi.Up))
}*/
telegram, utel := t.rcvTelegram2(wd, balise.Id()) telegram, utel := t.rcvTelegram(wd, balise.Id())
if utel != nil && t.addExpectedBalise(baliseInfo) { if utel != nil && t.addExpectedBalise(baliseInfo) {
t.baliseCounterAdd1() //应答器计数器 t.baliseCounterAdd1() //应答器计数器
if len(telegram) > 0 { if len(telegram) > 0 {
@ -222,41 +199,28 @@ func (t *BaliseDetector) baliseMessageCounterAdd1() {
} }
// BTM天线接收应答器报文(线程不安全) // BTM天线接收应答器报文(线程不安全)
func (t *BaliseDetector) rcvTelegram2(wd *component.WorldData, baliseId string) ([]byte, []byte) { func (t *BaliseDetector) rcvTelegram(wd *component.WorldData, baliseId string) ([]byte, []byte) {
if entry, ok := wd.EntityMap[baliseId]; ok { if entry, ok := wd.EntityMap[baliseId]; ok {
workedState := component.BaliseWorkStateType.Get(entry) workedState := component.BaliseWorkStateType.Get(entry)
if !workedState.Work { fixBalise := component.BaliseFixedTelegramType.Get(entry)
return nil, nil
}
//hasVar := entry.HasComponent(component.BaliseVariableTelegramType)
//hexFix := entry.HasComponent(component.BaliseFixedTelegramType)
if entry.HasComponent(component.BaliseVariableTelegramType) { if entry.HasComponent(component.BaliseVariableTelegramType) {
baliseVar := component.BaliseVariableTelegramType.Get(entry) baliseVar := component.BaliseVariableTelegramType.Get(entry)
//slog.Info(fmt.Sprintf("find_baliseId:%v ,work:%v,var:%v,fix:%v,tel:%v,usertel:%v", baliseId, workedState.Work, hasVar, hexFix, hex.EncodeToString(baliseVar.Telegram), hex.EncodeToString(baliseVar.UserTelegram))) if !workedState.Work {
return baliseVar.Telegram, baliseVar.UserTelegram return fixBalise.Telegram, fixBalise.UserTelegram
} else if entry.HasComponent(component.BaliseFixedTelegramType) { } else if baliseVar.UserTelegram == nil || len(baliseVar.UserTelegram) == 0 {
fixBalise := component.BaliseFixedTelegramType.Get(entry) slog.Warn(fmt.Sprintf("BTM天线未接受到应答器可变报文即将使用对应的固定报文, baliseId: %v", baliseId))
//slog.Info(fmt.Sprintf("find_baliseId:%v ,work:%v,var:%v,fix:%v,tel:%v,usertel:%v", baliseId, workedState.Work, hasVar, hexFix, hex.EncodeToString(tel), hex.EncodeToString(utel))) return fixBalise.Telegram, fixBalise.UserTelegram
} else {
return baliseVar.Telegram, baliseVar.UserTelegram
}
} else if workedState.Work {
return fixBalise.Telegram, fixBalise.UserTelegram return fixBalise.Telegram, fixBalise.UserTelegram
} else {
slog.Warn(fmt.Sprintf("BTM天线未接受到应答器报文应答器未工作 baliseId: %v", baliseId))
} }
} } else {
slog.Warn(fmt.Sprintf("BTM天线接收应答器报文未找到 baliseId: %v", baliseId))
return nil, nil
}
// BTM天线接收应答器报文(线程不安全)
func (t *BaliseDetector) rcvTelegram(wd *component.WorldData, baliseId string) ([]byte, []byte) {
entry, ok := wd.EntityMap[baliseId]
if ok {
if component.BaliseWorkStateType.Get(entry).Work {
tel := component.BaliseFixedTelegramType.Get(entry).Telegram
utel := component.BaliseFixedTelegramType.Get(entry).UserTelegram
return tel, utel
//return component.BaliseFixedTelegramType.Get(entry).Telegram
}
} }
return nil, nil return nil, nil
} }
@ -351,6 +315,57 @@ func (t *BaliseDetector) calculateBtmAntennaScanNextBaliseTime(curTime time.Time
return curTime, false return curTime, false
} }
// 获取车载BTM天线中心点运行方向最近的1个应答器
func (t *BaliseDetector) findBaliseWillScanByBtmAntenna2(wd *component.WorldData, repo *repository.Repository, ba *BtmAntennaRunningInfo) *BtmAntennaToBaliseInfo {
//BTM天线中心点所在轨道
baLink := repo.FindLink(ba.LinkId)
rs1 := t.searchBalisesFromLinkPosition(repo, ba.LinkId, ba.Up, ba.LinkOffset)
if ba.Up {
if len(rs1) > 0 {
rs := rs1[0]
return &BtmAntennaToBaliseInfo{BaliseId: rs.Id(), Distance: rs.LinkPosition().Offset() - ba.LinkOffset, BaliseType: rs.BaliseType()}
} else {
nextLinkPort := t.getNextLink(wd, repo, ba.LinkId, ba.Up)
if nextLinkPort != nil {
if nextLinkPort.IsPortA() {
rs2 := t.searchBalisesFromLinkPosition(repo, nextLinkPort.Link().Id(), true, 0)
if len(rs2) > 0 {
rs := rs2[0]
return &BtmAntennaToBaliseInfo{BaliseId: rs.Id(), Distance: baLink.Length() - ba.LinkOffset + rs.LinkPosition().Offset(), BaliseType: rs.BaliseType()}
}
} else {
rs2 := t.searchBalisesFromLinkPosition(repo, nextLinkPort.Link().Id(), false, nextLinkPort.Link().Length())
if len(rs2) > 0 {
rs := rs2[0]
return &BtmAntennaToBaliseInfo{BaliseId: rs.Id(), Distance: baLink.Length() - ba.LinkOffset + nextLinkPort.Link().Length() - rs.LinkPosition().Offset(), BaliseType: rs.BaliseType()}
}
}
}
}
} else {
if len(rs1) > 0 {
return &BtmAntennaToBaliseInfo{BaliseId: rs1[0].Id(), Distance: ba.LinkOffset - rs1[0].LinkPosition().Offset()}
} else {
nextLinkPort := t.getNextLink(wd, repo, ba.LinkId, ba.Up)
if nextLinkPort != nil {
if nextLinkPort.IsPortA() {
rs2 := t.searchBalisesFromLinkPosition(repo, nextLinkPort.Link().Id(), true, 0)
if len(rs2) > 0 {
return &BtmAntennaToBaliseInfo{BaliseId: rs2[0].Id(), Distance: ba.LinkOffset + rs2[0].LinkPosition().Offset()}
}
} else {
rs2 := t.searchBalisesFromLinkPosition(repo, nextLinkPort.Link().Id(), false, nextLinkPort.Link().Length())
if len(rs2) > 0 {
return &BtmAntennaToBaliseInfo{BaliseId: rs2[0].Id(), Distance: ba.LinkOffset + nextLinkPort.Link().Length() - rs2[0].LinkPosition().Offset()}
}
}
}
}
}
return nil
}
// 获取车载BTM天线中心点运行方向最近的1个应答器 // 获取车载BTM天线中心点运行方向最近的1个应答器
func (t *BaliseDetector) findBaliseWillScanByBtmAntenna(wd *component.WorldData, repo *repository.Repository, ba *BtmAntennaRunningInfo) *BtmAntennaToBaliseInfo { func (t *BaliseDetector) findBaliseWillScanByBtmAntenna(wd *component.WorldData, repo *repository.Repository, ba *BtmAntennaRunningInfo) *BtmAntennaToBaliseInfo {
//BTM天线中心点所在轨道 //BTM天线中心点所在轨道
@ -421,7 +436,7 @@ func (t *BaliseDetector) searchBalisesFromBetweenLinkPosition(repo *repository.R
return rs[j].LinkPosition().Offset() < rs[i].LinkPosition().Offset() return rs[j].LinkPosition().Offset() < rs[i].LinkPosition().Offset()
}) })
for _, r := range rs { for _, r := range rs {
//slog.Info(fmt.Sprintf("down id:%v,offset:%v,from:%v,to:%v", r.Id(), r.LinkPosition().Offset(), fromOffset, toOffset))
if r.LinkPosition().Offset() <= toOffset { if r.LinkPosition().Offset() <= toOffset {
cha := int64(math.Abs(float64(toOffset - fromOffset))) cha := int64(math.Abs(float64(toOffset - fromOffset)))
cha2 := int64(math.Abs(float64(toOffset - r.LinkPosition().Offset()))) cha2 := int64(math.Abs(float64(toOffset - r.LinkPosition().Offset())))
@ -453,7 +468,6 @@ func (t *BaliseDetector) searchBalisesFromLinkPosition(repo *repository.Reposito
return rs[j].LinkPosition().Offset() < rs[i].LinkPosition().Offset() return rs[j].LinkPosition().Offset() < rs[i].LinkPosition().Offset()
}) })
for i, r := range rs { for i, r := range rs {
//slog.Info(fmt.Sprintf("id:%v,offset:%v,from:%v", r.Id(), r.LinkPosition().Offset(), fromOffset))
if r.LinkPosition().Offset() <= fromOffset { if r.LinkPosition().Offset() <= fromOffset {
return rs[i:] return rs[i:]
} }

View File

@ -218,6 +218,7 @@ func (d *trainPcSimService) newCloseConn(clientKey string) {
rd.train = nil rd.train = nil
rd.speedPlace = nil rd.speedPlace = nil
rd.trainInit = false rd.trainInit = false
//d.cancleContextFun()
} }
} }
@ -379,6 +380,10 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
slog.Error(fmt.Sprintf("pc仿真速度位置未找到对应的列车 id:%v", train.Id)) slog.Error(fmt.Sprintf("pc仿真速度位置未找到对应的列车 id:%v", train.Id))
continue continue
} }
if trainClient.speedPlace == nil {
slog.Error(fmt.Sprintf("pc仿真速度位置脉冲对象为空 列车id:%v", train.Id))
continue
}
connState := tpapi.ThirdPartyState_Normal connState := tpapi.ThirdPartyState_Normal
if train.Tcc.Line12ConnErr { if train.Tcc.Line12ConnErr {

View File

@ -343,6 +343,9 @@ func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *mess
sta.OldLinkOffset = outLinkOffset sta.OldLinkOffset = outLinkOffset
sta.OldLink = outLinkId sta.OldLink = outLinkId
} }
if sta.BtmBaliseCache == nil {
sta.BtmBaliseCache = make([]*state_proto.BTMState, 0)
}
updateTrainBtmPosition(vs, info, sta, outLinkId, outLinkOffset) updateTrainBtmPosition(vs, info, sta, outLinkId, outLinkOffset)
//slog.Info(fmt.Sprintf("动力学,当前速度(米/秒):%v,加速度:%v,位移距离:%v", info.Speed, info.Acceleration, info.Displacement)) //slog.Info(fmt.Sprintf("动力学,当前速度(米/秒):%v,加速度:%v,位移距离:%v", info.Speed, info.Acceleration, info.Displacement))
if sta.OldLink != outLinkId { if sta.OldLink != outLinkId {
@ -466,19 +469,14 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
TrainIndex: uint16(trainIndex), TrainIndex: uint16(trainIndex),
}) })
if err != nil { if err != nil {
return err slog.Warn("列车移除失败,动力学请求失败", err)
} }
thirdConn := train.ConnState thirdConn := train.ConnState
if thirdConn.Conn { if thirdConn.Conn {
thirdConn.Conn = false thirdConn.Conn = false
err = TrainPcSimConnOrRemoveHandle(train, false) err = TrainPcSimConnOrRemoveHandle(train, false)
if err != nil { thirdConn.ConnType = state_proto.TrainConnState_NONE
train.ConnState.Conn = true thirdConn.TypeName = ""
return err
} else {
thirdConn.ConnType = state_proto.TrainConnState_NONE
thirdConn.TypeName = ""
}
} }
if train.VobcState != nil { if train.VobcState != nil {
vobc := train.VobcState vobc := train.VobcState