btm vobc 模块功能

This commit is contained in:
tiger_zhou 2024-06-06 18:56:25 +08:00
parent a58a4350c2
commit 31180597a5
4 changed files with 55 additions and 20 deletions

View File

@ -12,7 +12,6 @@ import (
"joylink.club/bj-rtsts-server/dto/state_proto"
"joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/udp"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
"log/slog"
"math"
"reflect"
@ -25,6 +24,9 @@ import (
type BtmVobcManage interface {
GetBtmVobcConfig() config.BtmVobcConfig
GetAllTrain() []*state_proto.TrainState
GetConnVobcTrain() *state_proto.TrainState
}
type BtmVobcService interface {
Start(btmVobcManage BtmVobcManage)
@ -138,38 +140,27 @@ func (b *BtmVobcClient) checkTrainTTLIsOver(ctx context.Context) {
return
default:
}
slog.Info("检测网络中断情况 前沿ttl 超时...")
if time.Now().UnixMilli()-reviceTimeStamp < 1000 {
return
}
vs, ok := b.manage.(*memory.VerifySimulation)
if !ok {
slog.Error("vobc btm 模块管理端初始化错误...")
return
}
slog.Info("检测网络中断情况 前沿ttl 超时...")
newTel := make([]*state_proto.VobcBtmState_TelegramState, 0)
vs.Memory.Status.TrainStateMap.Range(func(k, v any) bool {
train := v.(*state_proto.TrainState)
for _, train := range b.manage.GetAllTrain() {
for _, state := range train.VobcBtm.TelegramState {
if time.Now().UnixMilli()-state.ArriveTime < 1000 {
newTel = append(newTel, state)
}
}
train.VobcBtm.TelegramState = newTel
return true
})
}
time.Sleep(time.Second * 1)
}
}
func (b *BtmVobcClient) handleBtmVobcFrames(cfs []byte) {
reviceTimeStamp = time.Now().UnixMilli()
vs, ok := b.manage.(*memory.VerifySimulation)
if !ok {
slog.Error("vobc btm 模块管理端初始化错误...")
return
}
train := vs.FindConnTrain(state_proto.TrainConnState_VOBC)
train := b.manage.GetConnVobcTrain()
if train == nil {
slog.Error("vobc btm 未找到VOBC连接的列车...")
return
@ -280,6 +271,8 @@ func (b *BtmVobcClient) unmarshalJson(jsonStr string, obj any) error {
}
return nil
}
// 有应答器报文
func (b *BtmVobcClient) balisePackets(requestId string, tel *state_proto.VobcBtmState_TelegramState, receiveTime int64, decodePayMicoTime int64, vobcLifeNum uint32, autoCommandId byte, vobcbtm *state_proto.VobcBtmState) {
data, e := hex.DecodeString(tel.Telegram)
@ -329,10 +322,12 @@ func (b *BtmVobcClient) balisePackets(requestId string, tel *state_proto.VobcBtm
}
return
}
// 无应答器报文
func (b *BtmVobcClient) balisePacketsFree(requestId string, receiveTime int64, vobcLifeNum uint32, autoCommandId byte, vobcbtm *state_proto.VobcBtmState) {
repTimeMicro := (receiveTime - time.Now().UnixMicro()) / 100
data := createFreeBalisePackets()
freeMsg := &message.BtmVobcMsgFree{BtmStatus: message.BTM_STSTUS_NORMAL, WorkTemperature: 10, Fun1: uint16(0), Fun2: uint16(0), Fun3: uint16(0), Fun4: uint16(0),
freeMsg := &message.BtmVobcMsgFree{BtmStatus: message.BTM_STSTUS_NORMAL, Fun1: 0xffff, Fun2: 0x00CF, Fun3: uint16(0), Fun4: uint16(0),
FreeMsg: data, RespTime: byte(repTimeMicro), MsgSerial: message.GetAutoMessageId(), VobcLifeNum: vobcLifeNum, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: autoCommandId}}
u32MsgId := uint32(freeMsg.MsgSerial)
jsonArr, _ := json.Marshal(freeMsg)

View File

@ -143,3 +143,22 @@ func TestDecode232(t *testing.T) {
fmt.Println(hex.EncodeToString(arr))
}
func TestDecode2311(t *testing.T) {
var data uint16 // 初始化为0
// 将第0, 1, 2, 3位设置为1二进制中的1111
data |= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)
// 第4-5位设置为0不需要操作因为初始就是0
// 但如果需要明确设置,可以这样做:
// data &= ^((1 << 4) | (1 << 5)) // 使用按位取反和按位与来清除这些位
// 第6-7位设置为3二进制中的11
data |= (3 << 6)
// 打印结果
fmt.Printf("The modified data is: %04X\n", data)
fmt.Printf("The modified data is: %b\n", data)
}

View File

@ -738,7 +738,8 @@ func (b *BtmVobcMsgFree) Encode() []byte {
binary.Write(buf, binary.BigEndian, byte(0)) //保留
binary.Write(buf, binary.BigEndian, b.MsgSerial)
binary.Write(buf, binary.BigEndian, b.BtmStatus)
binary.Write(buf, binary.BigEndian, b.WorkTemperature)
//binary.Write(buf, binary.BigEndian, b.WorkTemperature)
binary.Write(buf, binary.BigEndian, byte(35))
binary.Write(buf, binary.BigEndian, yuliu3)
binary.Write(buf, binary.BigEndian, b.Fun1)
binary.Write(buf, binary.BigEndian, b.Fun2)

View File

@ -151,6 +151,26 @@ func (s *VerifySimulation) GetBtmCanetConfig() config.BtmCanetConfig {
return s.runConfig.BtmCanet
}
func (s *VerifySimulation) GetAllTrain() []*state_proto.TrainState {
return s.collectorAllTrain()
}
func (s *VerifySimulation) collectorAllTrain() []*state_proto.TrainState {
allTrain := make([]*state_proto.TrainState, 0)
s.Memory.Status.TrainStateMap.Range(func(k, v any) bool {
train := v.(*state_proto.TrainState)
if train.Show {
allTrain = append(allTrain, train)
}
return true
})
return allTrain
}
func (s *VerifySimulation) GetConnVobcTrain() *state_proto.TrainState {
return s.FindConnTrain(state_proto.TrainConnState_VOBC)
}
// GetBtmVobcConfig 获取11 号线 btm vobc配置信息
func (s *VerifySimulation) GetBtmVobcConfig() config.BtmVobcConfig {
return s.runConfig.BtmVobc