列车btm调整重构
This commit is contained in:
parent
98310f427b
commit
30c932f178
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
Subproject commit 73e7f83cfae775d13e60b6882231b69adab58b5c
|
||||
Subproject commit 12df28cc3716e39d24ddcada44d1d4a4233405d4
|
@ -1 +1 @@
|
||||
Subproject commit 61b489dcf80d992891e3266d0224fbe05fd49d0f
|
||||
Subproject commit ec6c571a37999ad7bab8f613deeb207b202468f0
|
83
third_party/can_btm/balise_btm.go
vendored
83
third_party/can_btm/balise_btm.go
vendored
@ -3,7 +3,6 @@ package can_btm
|
||||
import (
|
||||
"fmt"
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"joylink.club/bj-rtsts-server/const/balise_const"
|
||||
"joylink.club/bj-rtsts-server/dto/state_proto"
|
||||
"joylink.club/bj-rtsts-server/third_party/message"
|
||||
"joylink.club/bj-rtsts-server/third_party/udp"
|
||||
@ -11,7 +10,6 @@ import (
|
||||
"joylink.club/rtsssimulation/entity"
|
||||
"log/slog"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@ -55,61 +53,20 @@ type btmCanetClient struct {
|
||||
baliseDetector *BaliseDetector
|
||||
}
|
||||
|
||||
func (s *btmCanetClient) FindNotSendState() (state_proto.BTMState, bool) {
|
||||
func (s *btmCanetClient) FindNotSendState(train *state_proto.TrainState) (*state_proto.BTMState, byte, byte, byte) {
|
||||
s.baliseDetector.eqLock.Lock()
|
||||
defer s.baliseDetector.eqLock.Unlock()
|
||||
detector := s.baliseDetector
|
||||
for _, info := range detector.eq {
|
||||
if info != nil && !info.IsSend {
|
||||
info.IsSend = true
|
||||
return s.getStateFromDeta(info, uint32(detector.baliseCounter), uint32(detector.messageCounter), detector.aboveBalise), true
|
||||
cache := train.BtmBaliseCache
|
||||
for _, btmCache := range cache.BaliseList {
|
||||
if btmCache != nil && !btmCache.IsSend {
|
||||
|
||||
ndsn := BaliseCounterAdd(cache.Dsn)
|
||||
cache.Dsn = uint32(ndsn)
|
||||
return btmCache, ndsn, byte(cache.BaliseCount), byte(cache.MessageCounter)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return state_proto.BTMState{}, false
|
||||
}
|
||||
|
||||
/*
|
||||
func (s *btmCanetClient) GetAllData() {
|
||||
detector := s.baliseDetector
|
||||
for _, info := range detector.eq {
|
||||
slog.Info("获取应答器信息 id:%v,是否发送:%v", info.BaliseId)
|
||||
}
|
||||
}
|
||||
*/
|
||||
func (s *btmCanetClient) getStateFromDeta(info *BtmAntennaScanningBaliseInfo, bc, mc uint32, aboveBalise bool) state_proto.BTMState {
|
||||
var telegram string
|
||||
var tel128 string
|
||||
var dis int64
|
||||
var baliseId string
|
||||
|
||||
if /*detector.aboveBalise &&*/ info != nil && len(info.telegram) != 0 {
|
||||
telegram = fmt.Sprintf("%X", info.telegram)
|
||||
tel128 = fmt.Sprintf("%X", info.telegram128)
|
||||
dis = info.Distance
|
||||
baliseId = info.BaliseId
|
||||
} else {
|
||||
telegram = strings.Repeat("00", balise_const.UserTelegramByteLen)
|
||||
tel128 = strings.Repeat("00", balise_const.TelegramByteLen)
|
||||
}
|
||||
|
||||
return state_proto.BTMState{
|
||||
BaliseId: baliseId,
|
||||
DataSerialNumber: uint32(s.dsn),
|
||||
BaliseCount: bc,
|
||||
MessageCounter: mc,
|
||||
Telegram: telegram,
|
||||
Telegram128: tel128,
|
||||
Distance: dis,
|
||||
AboveBalise: aboveBalise,
|
||||
}
|
||||
}
|
||||
func (s *btmCanetClient) GetState() state_proto.BTMState {
|
||||
detector := s.baliseDetector
|
||||
info := detector.eq[len(detector.eq)-1]
|
||||
return s.getStateFromDeta(info, uint32(detector.baliseCounter), uint32(detector.messageCounter), detector.aboveBalise)
|
||||
|
||||
return nil, 0, 0, 0
|
||||
}
|
||||
|
||||
type BtmClock struct {
|
||||
@ -127,12 +84,9 @@ type BtmCanetClient interface {
|
||||
Stop()
|
||||
//HandleTrainHeadPositionInfo 处理收到列车位置信息
|
||||
HandleTrainHeadPositionInfo(w ecs.World, vobcBtm *state_proto.VobcBtmState, h *TrainHeadPositionInfo)
|
||||
// GetState 获取BTM显示状态 + btm最新的状态
|
||||
//
|
||||
// Deprecated 请从列车的btmBaliseCache中获取
|
||||
GetState() state_proto.BTMState
|
||||
//GetAllData()
|
||||
FindNotSendState() (state_proto.BTMState, bool)
|
||||
HandleTrainHeadPositionInfoForTrain(w ecs.World, train *state_proto.TrainBtmCache, h *TrainHeadPositionInfo)
|
||||
|
||||
FindNotSendState(train *state_proto.TrainState) (*state_proto.BTMState, byte, byte, byte)
|
||||
}
|
||||
|
||||
var (
|
||||
@ -148,6 +102,19 @@ func Default() BtmCanetClient {
|
||||
}
|
||||
return btmClient
|
||||
}
|
||||
func (s *btmCanetClient) HandleTrainHeadPositionInfoForTrain(w ecs.World, btmCache *state_proto.TrainBtmCache, h *TrainHeadPositionInfo) {
|
||||
wd := entity.GetWorldData(w)
|
||||
repo := wd.Repo
|
||||
h2 := &TrainHeadPositionInfo{
|
||||
TrainId: h.TrainId,
|
||||
Up: h.Up,
|
||||
Link: h.OldLink,
|
||||
LinkOffset: h.OldLinkOffset,
|
||||
Speed: h.Speed,
|
||||
Acceleration: h.Acceleration}
|
||||
s.baliseDetector.newDetect(wd, repo, h, h2, btmCache)
|
||||
//s.baliseDetector.detect2(wd, repo, h, h2, vobcBtm)
|
||||
}
|
||||
|
||||
// HandleTrainHeadPositionInfo 处理来自动力学的列车位置信息
|
||||
func (s *btmCanetClient) HandleTrainHeadPositionInfo(w ecs.World, vobcBtm *state_proto.VobcBtmState, h *TrainHeadPositionInfo) {
|
||||
|
70
third_party/can_btm/balise_detection.go
vendored
70
third_party/can_btm/balise_detection.go
vendored
@ -78,7 +78,37 @@ func (t *BaliseDetector) tryRebind(th *TrainHeadPositionInfo) {
|
||||
//slog.Debug(fmt.Sprintf("列车[%s]与CAN-BTM绑定", t.trianId))
|
||||
}
|
||||
}
|
||||
func (t *BaliseDetector) newDetect(wd *component.WorldData, repo *repository.Repository, th, th2 *TrainHeadPositionInfo, btmCache *state_proto.TrainBtmCache) {
|
||||
//BTM天线中心点运行信息
|
||||
curAntennaRi := t.createBtmAntennaRunningInfo(wd, repo, th) //目前车头
|
||||
curAntennaRi2 := t.createBtmAntennaRunningInfo(wd, repo, th2) //上次车头
|
||||
var startBalises []*repository.Transponder
|
||||
|
||||
//startBalises = t.searchBalisesFromBetweenLinkPosition(repo, th.Up, curAntennaRi2.LinkId, th2.LinkOffset, th.LinkOffset)
|
||||
startBalises = t.searchBalisesFromBetweenLinkPosition(repo, th2.Up, curAntennaRi2.LinkId, curAntennaRi2.LinkOffset, curAntennaRi.LinkOffset)
|
||||
|
||||
balises := make([]*repository.Transponder, 0)
|
||||
for _, balise := range startBalises {
|
||||
find := false
|
||||
for _, transponder := range balises {
|
||||
if transponder.Id() == balise.Id() {
|
||||
find = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !find {
|
||||
balises = append(balises, balise)
|
||||
}
|
||||
}
|
||||
if len(balises) > 0 {
|
||||
balise := balises[0]
|
||||
|
||||
telegram, utel := t.rcvTelegram(wd, balise.Id())
|
||||
|
||||
t.addNewExpectedBalise(balise, btmCache, telegram, utel)
|
||||
}
|
||||
|
||||
}
|
||||
func (t *BaliseDetector) detect2(wd *component.WorldData, repo *repository.Repository, th, th2 *TrainHeadPositionInfo, vobcBtm *state_proto.VobcBtmState) {
|
||||
t.tryRebind(th)
|
||||
|
||||
@ -198,6 +228,15 @@ func (t *BaliseDetector) baliseMessageCounterAdd1() {
|
||||
}
|
||||
}
|
||||
|
||||
func BaliseCounterAdd(counter uint32) byte {
|
||||
c := byte(counter)
|
||||
c++
|
||||
if c > 255 {
|
||||
c = 0
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// BTM天线接收应答器报文(线程不安全)
|
||||
func (t *BaliseDetector) rcvTelegram(wd *component.WorldData, baliseId string) ([]byte, []byte) {
|
||||
|
||||
@ -224,6 +263,37 @@ func (t *BaliseDetector) rcvTelegram(wd *component.WorldData, baliseId string) (
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
func (t *BaliseDetector) addNewExpectedBalise(balise *repository.Transponder, btmCache *state_proto.TrainBtmCache, telegram, userTelegram []byte) bool {
|
||||
t.eqLock.Lock()
|
||||
defer t.eqLock.Unlock()
|
||||
bl := btmCache.BaliseList
|
||||
for _, tt := range bl {
|
||||
if tt != nil && tt.BaliseId == balise.Id() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for i := 1; i < len(bl); i++ {
|
||||
bl[i-1] = bl[i]
|
||||
}
|
||||
unpack := false
|
||||
bc := BaliseCounterAdd(btmCache.BaliseCount)
|
||||
mc := btmCache.MessageCounter
|
||||
if userTelegram != nil && len(userTelegram) > 0 {
|
||||
mc = uint32(BaliseCounterAdd(mc))
|
||||
unpack = true
|
||||
}
|
||||
|
||||
btmCache.BaliseCount = uint32(bc)
|
||||
btmCache.MessageCounter = mc
|
||||
//存入队尾
|
||||
bl[len(bl)-1] = &state_proto.BTMState{BaliseId: balise.Id(),
|
||||
Telegram: fmt.Sprintf("%x", userTelegram),
|
||||
Telegram128: fmt.Sprintf("%x", telegram),
|
||||
Unpack: unpack,
|
||||
BaliseType: int32(balise.BaliseType().Number()),
|
||||
AboveBalise: true}
|
||||
return true
|
||||
}
|
||||
|
||||
// true-新增;false-更新
|
||||
func (t *BaliseDetector) addExpectedBalise(curExpect *BtmAntennaScanningBaliseInfo) bool {
|
||||
|
14
third_party/train_pc_sim/train_pc_sim.go
vendored
14
third_party/train_pc_sim/train_pc_sim.go
vendored
@ -48,8 +48,6 @@ type TrainPcSim interface {
|
||||
CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error
|
||||
// TrainPluseCount 计算列车脉冲
|
||||
TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32)
|
||||
|
||||
DsnAddAndReturn() byte
|
||||
}
|
||||
|
||||
type TrainPcSimManage interface {
|
||||
@ -77,7 +75,6 @@ type trainPcSimService struct {
|
||||
context context.Context
|
||||
trainPcSimManage TrainPcSimManage
|
||||
configs []config.VehiclePCSimConfig
|
||||
btmDsn uint8
|
||||
}
|
||||
|
||||
var (
|
||||
@ -111,13 +108,6 @@ func (d *trainPcSimService) TrueService() bool {
|
||||
func (d *trainPcSimService) ServiceDesc() string {
|
||||
return Name
|
||||
}
|
||||
func (d *trainPcSimService) DsnAddAndReturn() byte {
|
||||
defer initLock.Unlock()
|
||||
initLock.Lock()
|
||||
returnVal := d.btmDsn
|
||||
d.btmDsn = returnVal + 1
|
||||
return returnVal
|
||||
}
|
||||
|
||||
func FindTrainPcSimClientKey2(t *state_proto.TrainState) string {
|
||||
return t.ConnState.TypeName
|
||||
@ -455,14 +445,12 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
|
||||
func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState) {
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
if trainDataErr != nil {
|
||||
slog.Error(fmt.Sprintf("发送列车牵引知道失败,未找到对应的列车id:%v", train.Id))
|
||||
slog.Error(fmt.Sprintf("发送列车牵引失败,未找到对应的列车id:%v", train.Id))
|
||||
return
|
||||
}
|
||||
tc := train.ConnState
|
||||
if tc.Conn {
|
||||
|
||||
vobc := train.VobcState
|
||||
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
newTraction := vobc.TractionForce
|
||||
if tractionState {
|
||||
|
@ -100,6 +100,7 @@ func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, conf
|
||||
status.TailDeviceId = vs.GetComIdByUid(tailDeviceId)
|
||||
status.TailOffset = tailDeviceOffset
|
||||
status.TailDevicePort = tailDevicePort
|
||||
status.BtmBaliseCache = &state_proto.TrainBtmCache{BaliseList: make([]*state_proto.BTMState, 3)}
|
||||
//初始化列车参数状态
|
||||
createOrUpdateStateDynamicConfig(status, configTrainData, trainEndsA, trainEndsB)
|
||||
tl := configTrainData.TrainLoad
|
||||
@ -113,7 +114,7 @@ func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, conf
|
||||
//status.TrainActiveDirection = trainActDir
|
||||
|
||||
status.Tcc = initTrainTcc(vs)
|
||||
status.VobcBtm = &state_proto.VobcBtmState{TelegramState: make([]*state_proto.VobcBtmState_TelegramState, 0), History: make(map[uint32]*state_proto.VobcBtmState_VobcBtmHistoryState)}
|
||||
status.VobcBtm = &state_proto.VobcBtmState{TelegramState: make([]*state_proto.VobcBtmState_TelegramState, 3), History: make(map[uint32]*state_proto.VobcBtmState_VobcBtmHistoryState)}
|
||||
//slog.Debug("列车初始化", "trainIndex", trainIndex, "linkId", linkId, "loffset", loffset)
|
||||
linkIdInt, _ := strconv.Atoi(linkId)
|
||||
err := dynamics.Default().RequestAddTrain(&message.InitTrainInfo{
|
||||
@ -343,9 +344,7 @@ func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *mess
|
||||
sta.OldLinkOffset = outLinkOffset
|
||||
sta.OldLink = outLinkId
|
||||
}
|
||||
if sta.BtmBaliseCache == nil {
|
||||
sta.BtmBaliseCache = make([]*state_proto.BTMState, 0)
|
||||
}
|
||||
|
||||
updateTrainBtmPosition(vs, info, sta, outLinkId, outLinkOffset)
|
||||
//slog.Info(fmt.Sprintf("动力学,当前速度(米/秒):%v,加速度:%v,位移距离:%v", info.Speed, info.Acceleration, info.Displacement))
|
||||
if sta.OldLink != outLinkId {
|
||||
@ -412,8 +411,7 @@ func updateTrainActiveDirFromDynamic(vs *VerifySimulation, info *message.Dynamic
|
||||
func updateTrainBtmPosition(vs *VerifySimulation, info *message.DynamicsTrainInfo, sta *state_proto.TrainState, outLinkId string, outLinkOffset int64) {
|
||||
// 更新BTM中列车位置信息
|
||||
//isup := sta.TrainActiveDirection == 1
|
||||
|
||||
can_btm.Default().HandleTrainHeadPositionInfo(vs.World, sta.VobcBtm, &fi.TrainHeadPositionInfo{
|
||||
can_btm.Default().HandleTrainHeadPositionInfoForTrain(vs.World, sta.BtmBaliseCache, &fi.TrainHeadPositionInfo{
|
||||
TrainId: sta.Id,
|
||||
Up: info.Up,
|
||||
Link: outLinkId,
|
||||
@ -423,10 +421,20 @@ func updateTrainBtmPosition(vs *VerifySimulation, info *message.DynamicsTrainInf
|
||||
OldLinkOffset: sta.OldLinkOffset,
|
||||
OldLink: sta.OldLink,
|
||||
})
|
||||
state := can_btm.Default().GetState()
|
||||
/*can_btm.Default().HandleTrainHeadPositionInfo(vs.World, sta.VobcBtm, &fi.TrainHeadPositionInfo{
|
||||
TrainId: sta.Id,
|
||||
Up: info.Up,
|
||||
Link: outLinkId,
|
||||
LinkOffset: outLinkOffset,
|
||||
Speed: info.Speed,
|
||||
Acceleration: info.Acceleration,
|
||||
OldLinkOffset: sta.OldLinkOffset,
|
||||
OldLink: sta.OldLink,
|
||||
})*/
|
||||
/* state := can_btm.Default().GetState()
|
||||
if sta.BtmState == nil || sta.BtmState.BaliseId != state.BaliseId {
|
||||
sta.BtmState = &state
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
@ -490,28 +498,6 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
|
||||
return fi.RemoveTrainFromWorld(vs.World, trainId)
|
||||
}
|
||||
|
||||
// 删除列车状态
|
||||
/*func RemoveTrainState(vs *VerifySimulation, id string) {
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
d, ok := allTrainMap.Load(id)
|
||||
if ok {
|
||||
t := d.(*state_proto.TrainState)
|
||||
trainIndex, _ := strconv.ParseUint(id, 10, 16)
|
||||
err := dynamics.Default().RequestRemoveTrain(&message.RemoveTrainReq{
|
||||
TrainIndex: uint16(trainIndex),
|
||||
})
|
||||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DynamicsError, Message: err.Error()})
|
||||
}
|
||||
// 从仿真内存中移除列车
|
||||
t.Show = false
|
||||
// 移除车
|
||||
fi.RemoveTrainFromWorld(vs.World, id)
|
||||
allTrainMap.Store(id, t)
|
||||
} else {
|
||||
panic(fmt.Sprintf("列车【%s】不存在", id))
|
||||
}
|
||||
}*/
|
||||
func RemoveTrainState(vs *VerifySimulation, id string) {
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
d, ok := allTrainMap.Load(id)
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
uuid2 "github.com/google/uuid"
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"joylink.club/bj-rtsts-server/const/balise_const"
|
||||
"joylink.club/bj-rtsts-server/dto/data_proto"
|
||||
"joylink.club/bj-rtsts-server/dto/request_proto"
|
||||
"joylink.club/bj-rtsts-server/dto/state_proto"
|
||||
@ -17,7 +16,6 @@ import (
|
||||
train_pc_sim "joylink.club/bj-rtsts-server/third_party/train_pc_sim"
|
||||
"log/slog"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -512,7 +510,7 @@ func (s *VerifySimulation) reportTrainMockInitMsg(train *state_proto.TrainState,
|
||||
ebTce := controlEBBtn(vobc, true, jjzdBtn)
|
||||
tce = append(tce, ebTce...)
|
||||
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
|
||||
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_TRACTION_CUTED, 1}})
|
||||
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_TRACTION_CUTED, 1}})
|
||||
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.NOT_BREAK, 0}})
|
||||
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{0x38, 0}})
|
||||
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD})
|
||||
@ -706,11 +704,11 @@ func (s *VerifySimulation) TrainBtmQuery(train *state_proto.TrainState, data []b
|
||||
slog.Error("列车btm查询报文长度错误:", len(data))
|
||||
return
|
||||
}
|
||||
if train.BtmState == nil {
|
||||
slog.Warn(fmt.Sprintf("列车暂时未获取到应答器信息,无法进行btm查询列车id:%v", train.Id))
|
||||
balise, dsn, bc, mc := can_btm.Default().FindNotSendState(train)
|
||||
/*if balise == nil {
|
||||
//slog.Warn(fmt.Sprintf("列车暂时未获取到应答器信息,无法进行btm查询列车id:%v", train.Id))
|
||||
return
|
||||
}
|
||||
notSendBtm, ok := can_btm.Default().FindNotSendState()
|
||||
}*/
|
||||
trainAtm := message.NewBtmHeadFrame(data)
|
||||
atpReq := &message.AtpRequestFrame{}
|
||||
|
||||
@ -720,18 +718,17 @@ func (s *VerifySimulation) TrainBtmQuery(train *state_proto.TrainState, data []b
|
||||
}
|
||||
|
||||
cl := clock(atpReq)
|
||||
dsn := train_pc_sim.Default().DsnAddAndReturn()
|
||||
//btmRepFrame := createBtmStatus(trainAtm.CanId.ID4, train.BtmState, atpReq, cl, dsn)
|
||||
btmRepFrame := createBtmStatus(trainAtm.CanId.ID4, ¬SendBtm, atpReq, cl, dsn)
|
||||
//slog.Info(fmt.Sprintf("id1:%x,id2:%x,id3:%x,id4:%x,resendRequest:%v,reqTime:%v,dsn:%v", trainAtm.CanId.ID1, trainAtm.CanId.ID2, trainAtm.CanId.ID3, trainAtm.CanId.ID4, atpReq.ResendRequest, atpReq.Time, dsn))
|
||||
|
||||
btmRepFrame := createBtmStatus(trainAtm.CanId.ID4, balise, atpReq, cl, dsn, bc, mc)
|
||||
|
||||
if atpReq.ResendRequest == 2 {
|
||||
slog.Info(fmt.Sprintf("rrrrrrrrrrrrrrrrr:%v", atpReq.String()))
|
||||
//重新发送
|
||||
//if len(train.BtmState.BaliseTelegramForPcSimResend) > 0 {
|
||||
if len(notSendBtm.BaliseTelegramForPcSimResend) > 0 {
|
||||
if len(balise.BaliseTelegramForPcSimResend) > 0 {
|
||||
slog.Info(fmt.Sprintf("rrrrrrrrrrrrrrrrr111111111:%v", atpReq.String()))
|
||||
//dd, _ := hex.DecodeString(train.BtmState.BaliseTelegramForPcSimResend)
|
||||
dd, _ := hex.DecodeString(notSendBtm.BaliseTelegramForPcSimResend)
|
||||
dd, _ := hex.DecodeString(balise.BaliseTelegramForPcSimResend)
|
||||
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_HAS_DATA, dd)
|
||||
} else {
|
||||
slog.Info(fmt.Sprintf("rrrrrrrrrrrrrrrrr2222222222222:%v", atpReq.String()))
|
||||
@ -744,31 +741,20 @@ func (s *VerifySimulation) TrainBtmQuery(train *state_proto.TrainState, data []b
|
||||
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_NOT_DATA, queryData)
|
||||
}
|
||||
} else {
|
||||
|
||||
timeSyncF := message.NewBtmTimeSyncCheckFrame(trainAtm.CanId.ID4)
|
||||
timeSyncF.T2 = cl.BtmTk
|
||||
timeSyncF.T3 = cl.TkNow()
|
||||
//telCount := strings.Count(train.BtmState.Telegram, "00")
|
||||
telCount := strings.Count(notSendBtm.Telegram, "00")
|
||||
//if telCount >= balise_const.UserTelegramByteLen || train.BtmState.IsSend {
|
||||
if !ok && (notSendBtm.Telegram == "" || telCount >= balise_const.UserTelegramByteLen) {
|
||||
//slog.Info(fmt.Sprintf("准备发送无数据应答器id:%v", train.BtmState.BaliseId))
|
||||
|
||||
if balise == nil {
|
||||
//无应答器数据
|
||||
queryData := make([]byte, 0)
|
||||
queryData = append(queryData, btmRepFrame.EncodeBtmAtp().Encode()...)
|
||||
queryData = append(queryData, timeSyncF.EncodeBtmAtp().Encode()...)
|
||||
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_NOT_DATA, queryData)
|
||||
//train.BtmState.IsSend = true
|
||||
} else /*if !train.BtmState.IsSend*/
|
||||
if !notSendBtm.IsSend {
|
||||
slog.Info(fmt.Sprintf("准备发送应答id:%v,uuid :%v,接受时间:%v,发送时间:%v , 数据:%v 经过:%v,解报文:%v", notSendBtm.BaliseId, uuid, ts, time.Now().UnixMilli(), notSendBtm.Telegram, notSendBtm.BaliseCount, notSendBtm.MessageCounter))
|
||||
//slog.Info(fmt.Sprintf("准备发送应答id:%v,uuid :%v,消耗时间:%v , 数据:%v", train.BtmState.BaliseId, uuid, ts-time.Now().UnixMilli(), train.BtmState.Telegram))
|
||||
/* defer func() {
|
||||
train.BtmState.IsSend = true
|
||||
}()*/
|
||||
//有数据
|
||||
//aliseData, _ := hex.DecodeString(train.BtmState.Telegram)
|
||||
aliseData, _ := hex.DecodeString(notSendBtm.Telegram)
|
||||
|
||||
} else if !balise.IsSend {
|
||||
balise.IsSend = true
|
||||
slog.Info(fmt.Sprintf("准备发送应答id:%v,uuid :%v,接受时间:%v,发送时间:%v , 数据:%v 经过:%v,解报文:%v", balise.BaliseId, uuid, ts, time.Now().UnixMilli(), balise.Telegram, bc, mc))
|
||||
aliseData, _ := hex.DecodeString(balise.Telegram)
|
||||
stateRepFrame := btmRepFrame.EncodeBtmAtp()
|
||||
statusDataCf, statusDataCfOk := message.CreateBtmAtpDataRspFramesData(stateRepFrame, aliseData, false, cl.BtmTk, cl.BtmTk, cl.BtmTk)
|
||||
if statusDataCfOk {
|
||||
@ -778,7 +764,7 @@ func (s *VerifySimulation) TrainBtmQuery(train *state_proto.TrainState, data []b
|
||||
queryData = append(queryData, stateRepFrame.Encode()...)
|
||||
queryData = append(queryData, timeSyncF.EncodeBtmAtp().Encode()...)
|
||||
queryData = append(queryData, statusDataCf...) //数据帧包含结束帧
|
||||
train.BtmState.BaliseTelegramForPcSimResend = fmt.Sprintf("%X", statusDataCf)
|
||||
balise.BaliseTelegramForPcSimResend = fmt.Sprintf("%X", statusDataCf)
|
||||
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_HAS_DATA, queryData)
|
||||
} else {
|
||||
slog.Error("列车pc仿真 BtmCanetClient应答帧、数据帧编码失败")
|
||||
@ -787,22 +773,22 @@ func (s *VerifySimulation) TrainBtmQuery(train *state_proto.TrainState, data []b
|
||||
}
|
||||
}
|
||||
|
||||
func createBtmStatus(canIdSn byte, btmState *state_proto.BTMState, atpReq *message.AtpRequestFrame, cl can_btm.BtmClock, dsn byte) *message.BtmStatusRspFrame {
|
||||
func createBtmStatus(canIdSn byte, btmState *state_proto.BTMState, atpReq *message.AtpRequestFrame, cl can_btm.BtmClock, dsn, baliseCount, messageCount byte) *message.BtmStatusRspFrame {
|
||||
statusF := message.NewBtmStatusRspFrame(canIdSn)
|
||||
statusF.PowerAmplifierOn = true
|
||||
statusF.PowerAmplifierFailure = false
|
||||
statusF.AtpReqCrcCheckWrong = !atpReq.Crc16CheckOk
|
||||
statusF.AntennaFault = false
|
||||
statusF.BaliseCounter = byte(btmState.BaliseCount)
|
||||
statusF.MessageCounter = byte(btmState.MessageCounter)
|
||||
statusF.BaliseCounter = baliseCount
|
||||
statusF.MessageCounter = messageCount
|
||||
//statusF.TkTimeA = cl.TkNow()
|
||||
statusF.TkTimeA = cl.BtmTk
|
||||
statusF.DetailedCode = 0
|
||||
if btmState.AboveBalise {
|
||||
if btmState != nil && btmState.AboveBalise {
|
||||
statusF.DetailedCode = 0x07
|
||||
}
|
||||
|
||||
btmState.DataSerialNumber = uint32(dsn)
|
||||
//btmState.DataSerialNumber = uint32(dsn)
|
||||
statusF.Dsn = dsn
|
||||
return statusF
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user