折返速度调整

This commit is contained in:
tiger_zhou 2024-09-11 13:28:56 +08:00
parent 8b5ef2e597
commit 449162856b
6 changed files with 1094 additions and 1120 deletions

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit 15470e0e4aa2c5839be5c009d5a4239c9238b4ba Subproject commit 35c2c8e7748a4a30230ef4fcaedbfd7d2466299d

View File

@ -70,15 +70,13 @@ func (rd *TrainPcReciverData) receiverDataHandle(n int, data []byte) {
//case RECIVE_TRAIN_CREATE_REMOVE: //case RECIVE_TRAIN_CREATE_REMOVE:
// pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0]) // pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0])
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR: case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR:
rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(rd.aPort, rd.tcpClient, train, baseMsg.Data) rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(rd.aPort, rd.tcpClient, train, baseMsg.Data)
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK: case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK:
rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data) rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data)
case message.RECIVE_TRAIN_QUERY_STATUS: case message.RECIVE_TRAIN_QUERY_STATUS:
rd.pcSimManage.TrainBtmQuery2(train, baseMsg.Data, rd.aPort) rd.pcSimManage.TrainBtmQuery2(train, baseMsg.Data, rd.aPort)
case message.RECIVE_TRAIN_MOCK_DATA: //case message.RECIVE_TRAIN_MOCK_DATA:
rd.pcSimManage.TrainPcSimMockInfo(train, baseMsg.Data) // rd.pcSimManage.TrainPcSimMockInfo(train, baseMsg.Data)
//case RECIVE_TRAIN_DOOR_MODE: //case RECIVE_TRAIN_DOOR_MODE:
// pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0]) // pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0])

View File

@ -162,22 +162,23 @@ func pluseCountSpeed(wheelDiameter int32, speedMeter float32) uint32 {
return uint32(pluseCountData) return uint32(pluseCountData)
} }
func (d *trainPcSimService) pluseSpeed(sta *state_proto.TrainState) (uint32, float32) { func (d *trainPcSimService) pluseSpeed(pc *state_proto.SensorSpeedPulseCount, wheelDiameter int32) (uint32, float32) {
defer initLock.Unlock() defer initLock.Unlock()
initLock.Lock() initLock.Lock()
var sum float32 = 0 var sum float32 = 0
pcLen := len(sta.PluseCount.PulseCount3) pcLen := len(pc.PulseCount3)
if pcLen == 0 { if pcLen == 0 {
return 0, 0 return 0, 0
} }
for _, f := range sta.PluseCount.PulseCount3 { for _, f := range pc.PulseCount3 {
sum += f sum += f
} }
d.TrainPluseCountReset(sta) d.trainPluseCountReset(pc)
speed := sum / float32(pcLen) speed := sum / float32(pcLen)
return pluseCountSpeed(sta.WheelDiameter, speed*1000), speed return pluseCountSpeed(wheelDiameter, speed*1000), speed
} }
func (d *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) { func (d *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) {
defer initLock.Unlock() defer initLock.Unlock()
initLock.Lock() initLock.Lock()
@ -190,36 +191,29 @@ func (d *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2,
for _, sd := range d.findTrainAllConn(sta) { for _, sd := range d.findTrainAllConn(sta) {
if sd.speedPlace != nil { if sd.speedPlace != nil {
sd.speedPlace.PulseCount1 += sta.DynamicState.Displacement sd.speedPlace.PulseCount1 += sta.DynamicState.Displacement
} }
} }
for _, pc := range sta.PulseCountMap {
if sta.TrainRunUp { if sta.TrainRunUp {
if sta.TrainEndsA.SpeedSensorEnableA { if sta.TrainEndsA.SpeedSensorEnableA || sta.TrainEndsA.SpeedSensorEnableB {
sta.PluseCount.PulseCount1 = pluseCountSpeed(sta.WheelDiameter, h1) pc.PulseCount1 = pluseCountSpeed(sta.WheelDiameter, h1)
sta.PluseCount.PulseCount3 = append(sta.PluseCount.PulseCount3, h1) pc.PulseCount3 = append(pc.PulseCount3, h1)
}
if sta.TrainEndsA.SpeedSensorEnableB {
sta.PluseCount.PulseCount2 = pluseCountSpeed(sta.WheelDiameter, h2)
sta.PluseCount.PulseCount4 = append(sta.PluseCount.PulseCount3, h2)
} }
} else { } else {
if sta.TrainEndsB.SpeedSensorEnableA { if sta.TrainEndsB.SpeedSensorEnableA || sta.TrainEndsB.SpeedSensorEnableB {
sta.PluseCount.PulseCount1 = pluseCountSpeed(sta.WheelDiameter, t1) pc.PulseCount1 = pluseCountSpeed(sta.WheelDiameter, t1)
sta.PluseCount.PulseCount3 = append(sta.PluseCount.PulseCount3, t1) pc.PulseCount3 = append(pc.PulseCount3, t1)
}
if sta.TrainEndsB.SpeedSensorEnableB {
sta.PluseCount.PulseCount2 = pluseCountSpeed(sta.WheelDiameter, t2)
sta.PluseCount.PulseCount4 = append(sta.PluseCount.PulseCount3, t2)
} }
} }
} }
func (d *trainPcSimService) TrainPluseCountReset(sta *state_proto.TrainState) { }
sta.PluseCount.PulseCount1 = 0
sta.PluseCount.PulseCount2 = 0 func (d *trainPcSimService) trainPluseCountReset(pc *state_proto.SensorSpeedPulseCount) {
sta.PluseCount.PulseCount3 = make([]float32, 0) pc.PulseCount1 = 0
sta.PluseCount.PulseCount4 = make([]float32, 0) pc.PulseCount3 = make([]float32, 0)
} }
func (d *trainPcSimService) newCloseAllConn() { func (d *trainPcSimService) newCloseAllConn() {
@ -239,13 +233,7 @@ func (d *trainPcSimService) newCloseConn(clientKey string) {
rd.speedPlace = nil rd.speedPlace = nil
} }
} }
/*rd := d.newPcSimclientMap[clientKey]
if rd != nil {
rd.tcpClient.Close()
rd.tcpClient = nil
rd.train = nil
rd.speedPlace = nil
}*/
} }
func (d *trainPcSimService) findConfig(configName string) (*config.VehiclePCSimConfig, error) { func (d *trainPcSimService) findConfig(configName string) (*config.VehiclePCSimConfig, error) {
@ -393,7 +381,9 @@ func (d *trainPcSimService) initTrain(rd *TrainPcReciverData, train *state_proto
msgs := make([]message.TrainPcSimBaseMessage, 0) msgs := make([]message.TrainPcSimBaseMessage, 0)
sendMsg := make([]byte, 0) sendMsg := make([]byte, 0)
rd.speedPlace = &message.TrainSpeedPlaceReportMsg{} rd.speedPlace = &message.TrainSpeedPlaceReportMsg{}
train.PluseCount = &state_proto.SensorSpeedPulseCount{} train.PulseCountMap = make(map[int32]*state_proto.SensorSpeedPulseCount)
train.PulseCountMap[int32(state_proto.TrainState_PORT_A.Number())] = &state_proto.SensorSpeedPulseCount{}
train.PulseCountMap[int32(state_proto.TrainState_PORT_B.Number())] = &state_proto.SensorSpeedPulseCount{}
rd.train = train rd.train = train
tcc := train.Tcc tcc := train.Tcc
tcc.LineInitTimeStamp12PortA = 0 tcc.LineInitTimeStamp12PortA = 0
@ -440,9 +430,14 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
trains := d.trainPcSimManage.GetConnTrain2() trains := d.trainPcSimManage.GetConnTrain2()
for _, train := range trains { for _, train := range trains {
if train.ConnState.Conn && train.PluseCount != nil { if train.ConnState.Conn {
trainClients := d.newPcSimclientMap3[train.ConnState.TypeName] for numKey, pc := range train.PulseCountMap {
for _, trainClient := range trainClients { trainPort := state_proto.TrainState_TrainPort(numKey)
aPort := true
if trainPort == state_proto.TrainState_PORT_B {
aPort = false
}
trainClient, _ := d.findTrainConnForPort(train, aPort)
if trainClient.success { if trainClient.success {
if trainClient.speedPlace == nil || trainClient.tcpClient == nil { if trainClient.speedPlace == nil || trainClient.tcpClient == nil {
slog.Error(fmt.Sprintf("pc仿真速度位置脉冲对象为空 列车id:%v", train.Id)) slog.Error(fmt.Sprintf("pc仿真速度位置脉冲对象为空 列车id:%v", train.Id))
@ -454,27 +449,25 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
} else if trainClient.aPort == false && train.Tcc.Line12ConnErrPortB { } else if trainClient.aPort == false && train.Tcc.Line12ConnErrPortB {
connState = tpapi.ThirdPartyState_Broken connState = tpapi.ThirdPartyState_Broken
} }
/*if train.Tcc.Line12ConnErr {
connState = tpapi.ThirdPartyState_Broken
}*/
trainClient.updateState(connState) trainClient.updateState(connState)
s1, speed := d.pluseSpeed(train) s1, _ := d.pluseSpeed(pc, train.WheelDiameter)
runDir := uint16(2) runDir := uint16(2)
if train.VobcState.DirectionForward { if train.VobcState.DirectionForward {
runDir = 1 runDir = 1
} else if train.VobcState.DirectionBackward {
runDir = 0
} }
disPluse := pluseCountSpeed(train.WheelDiameter, trainClient.speedPlace.PulseCount1) disPluse := pluseCountSpeed(train.WheelDiameter, trainClient.speedPlace.PulseCount1)
data := trainClient.speedPlace.Encode(runDir, s1, disPluse) data := trainClient.speedPlace.Encode(runDir, s1, disPluse)
bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data} bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data}
dataCode := bm.Encode() dataCode := bm.Encode()
slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,A端:%v,列车速度:%v,计数脉冲: %v,累计里程: %v ,发送数据:%v", train.Id, trainClient.aPort, speed, s1, trainClient.speedPlace.PulseCount1, hex.EncodeToString(dataCode)), trainClient.aPort) //slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,A端:%v,列车速度:%v,计数脉冲: %v,累计里程: %v ,发送数据:%v", train.Id, trainClient.aPort, speed, s1, trainClient.speedPlace.PulseCount1, hex.EncodeToString(dataCode)), trainClient.aPort)
err := trainClient.tcpClient.Send(dataCode) err := trainClient.tcpClient.Send(dataCode)
if err != nil { if err != nil {
slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode))) slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
} }
} }
} }
} }
} }
} }

View File

@ -446,7 +446,7 @@ func handleTrainPositionFromDynamic(vs *VerifySimulation, info *message.Dynamics
} }
func pluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) { func pluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) {
if sta.PluseCount == nil { if sta.PulseCountMap == nil {
return return
} }
train_pc_sim.Default().TrainPluseCount(sta, h1, h2, t1, t2) train_pc_sim.Default().TrainPluseCount(sta, h1, h2, t1, t2)

View File

@ -16,7 +16,6 @@ import (
train_pc_sim "joylink.club/bj-rtsts-server/third_party/train_pc_sim" train_pc_sim "joylink.club/bj-rtsts-server/third_party/train_pc_sim"
"log/slog" "log/slog"
"math" "math"
"strings"
"time" "time"
) )
@ -745,12 +744,12 @@ func (s *VerifySimulation) reportTrainMockInitMsg2(aport, act, initConn bool, in
connErr = true connErr = true
} }
if state == 0 { if state == 0 {
slog.Info("列车紧急制动%v", aport) //slog.Info("列车紧急制动%v", aport)
jjzdBtn := tcc.Buttons[JJZD] jjzdBtn := tcc.Buttons[JJZD]
ebTce := controlEBBtn(train, true, jjzdBtn) ebTce := controlEBBtn(train, true, jjzdBtn)
tce = append(tce, ebTce...) tce = append(tce, ebTce...)
} else if message.GetBit(data1, 0) == 0 { } else if message.GetBit(data1, 0) == 0 {
slog.Info(fmt.Sprintf("列车紧切牵引%v ,state :%v", aport, state)) //slog.Info(fmt.Sprintf("列车紧切牵引%v ,state :%v", aport, state))
jjzdBtn := tcc.Buttons[JJZD] jjzdBtn := tcc.Buttons[JJZD]
ebTce := controlEBBtn(train, true, jjzdBtn) ebTce := controlEBBtn(train, true, jjzdBtn)
tce = append(tce, ebTce...) tce = append(tce, ebTce...)
@ -801,7 +800,7 @@ func trainAtoLevel(at3, at2, at1 bool) state_proto.TrainVobcState_AtoStepLevel {
func (s *VerifySimulation) shuziliang(aport bool, client *tcp.TcpClient, baseMessage []message.TrainPcSimBaseMessage) { func (s *VerifySimulation) shuziliang(aport bool, client *tcp.TcpClient, baseMessage []message.TrainPcSimBaseMessage) {
for _, msg := range baseMessage { for _, msg := range baseMessage {
dd := msg.Encode() dd := msg.Encode()
slog.Info(fmt.Sprintf("发送列车控制信息:%x", dd), aport) //slog.Info(fmt.Sprintf("发送列车控制信息:%x", dd), aport)
client.Send(dd) client.Send(dd)
} }
@ -810,18 +809,15 @@ func (s *VerifySimulation) shuziliang(aport bool, client *tcp.TcpClient, baseMes
// 4.4.1. 车载输出数字量信息报文内容 // 4.4.1. 车载输出数字量信息报文内容
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(aport bool, client *tcp.TcpClient, train *state_proto.TrainState, data []byte) bool { func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(aport bool, client *tcp.TcpClient, train *state_proto.TrainState, data []byte) bool {
dd := &strings.Builder{}
//slog.Info("开始接受atp输出模拟量==============%v", aport) //slog.Info("开始接受atp输出模拟量==============%v", aport)
/* for i, d := range data { /* for i, d := range data {
dd := &strings.Builder{}
for j := 0; j < 8; j++ { for j := 0; j < 8; j++ {
dd.WriteString(fmt.Sprintf(" bit%v val:%v , ", j, message.GetBit(d, uint(j)))) dd.WriteString(fmt.Sprintf(" bit%v val:%v , ", j, message.GetBit(d, uint(j))))
} }
slog.Info(fmt.Sprintf("接受atp模拟量id:%v,data:%b,bits:%v", i, d, dd.String())) slog.Info(fmt.Sprintf("接受atp模拟量id:%v,data:%b,bits:%v", i, d, dd.String()))
}*/ }*/
d := data[4]
for j := 0; j < 8; j++ {
dd.WriteString(fmt.Sprintf(" bit%v val:%v , ", j, message.GetBit(d, uint(j))))
}
//slog.Info(fmt.Sprintf("%v", dd.String()), aport) //slog.Info(fmt.Sprintf("%v", dd.String()), aport)
//slog.Info("结束接受atp输出模拟量eeeeeeeeeeeeeeeeee", aport) //slog.Info("结束接受atp输出模拟量eeeeeeeeeeeeeeeeee", aport)
@ -834,17 +830,9 @@ func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(aport bool, client *tc
train.Tcc.LineInitTimeStamp12PortA = ts train.Tcc.LineInitTimeStamp12PortA = ts
train.Tcc.TrainConnInitComplatePortA = initConn train.Tcc.TrainConnInitComplatePortA = initConn
train.Tcc.Line12ConnErrPortA = connErr train.Tcc.Line12ConnErrPortA = connErr
//slog.Info("发送数字量")
s.shuziliang(aport, client, tce) s.shuziliang(aport, client, tce)
} }
/* if initConn {
train.Tcc.TrainConnInitComplatePortB = initConn
train.Tcc.LineInitTimeStamp12PortB = ts
}
if train.Tcc.ActiveTrainA {
train.Tcc.ActiveTrainB = train.Tcc.ActiveTrainA
}
*/
if train.VobcState.Tc1Active { if train.VobcState.Tc1Active {
trainPcSimDigitalOutInfoHandleCode7_0(data[4], vobc) trainPcSimDigitalOutInfoHandleCode7_0(data[4], vobc)
trainPcSimDigitalOutInfoHandleCode15_8(data[3], vobc) trainPcSimDigitalOutInfoHandleCode15_8(data[3], vobc)
@ -1060,9 +1048,13 @@ func (s *VerifySimulation) TrainBtmQuery2(train *state_proto.TrainState, data []
balise.IsSend = true balise.IsSend = true
logstr = fmt.Sprintf("准备发送应答id:%v,接受时间:%v,发送时间:%v , 数据:%v 经过:%v,解报文:%v,接受应答器报文:%X", balise.BaliseId, ts, time.Now().UnixMilli(), balise.Telegram, bc, mc, data) logstr = fmt.Sprintf("准备发送应答id:%v,接受时间:%v,发送时间:%v , 数据:%v 经过:%v,解报文:%v,接受应答器报文:%X", balise.BaliseId, ts, time.Now().UnixMilli(), balise.Telegram, bc, mc, data)
} else { } else {
queryData := make([]byte, 0)
queryData = append(queryData, btmRepFrame.EncodeBtmAtp().Encode()...)
queryData = append(queryData, timeSyncF.EncodeBtmAtp().Encode()...)
train_pc_sim.Default().SendBaliseData(train, trainPort, message.RECIVE_TRAIN_BTM_NOT_DATA, queryData)
return return
} }
slog.Info(logstr) slog.Info(logstr, trainPort)
aliseData, _ := hex.DecodeString(balise.Telegram) aliseData, _ := hex.DecodeString(balise.Telegram)
stateRepFrame := btmRepFrame.EncodeBtmAtp() stateRepFrame := btmRepFrame.EncodeBtmAtp()
statusDataCf, statusDataCfOk := message.CreateBtmAtpDataRspFramesData(stateRepFrame, aliseData, false, balise.HasData, cl.BtmTk, cl.BtmTk, cl.BtmTk) statusDataCf, statusDataCfOk := message.CreateBtmAtpDataRspFramesData(stateRepFrame, aliseData, false, balise.HasData, cl.BtmTk, cl.BtmTk, cl.BtmTk)