diff --git a/third_party/train_pc_sim/train_pc_sim.go b/third_party/train_pc_sim/train_pc_sim.go index 9b2c1a3..35f1ae0 100644 --- a/third_party/train_pc_sim/train_pc_sim.go +++ b/third_party/train_pc_sim/train_pc_sim.go @@ -30,8 +30,7 @@ type TrainPcSim interface { // SendDriverActive Deprecated 发送驾驶端激活 //SendDriverActive(train *state_proto.TrainState) - // SendHandleSwitch 发送牵引制动手柄 - SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState) + // SendTrainDirection 列车运行方向 //因文档说明不清楚,在调用的时候目前是注释状态,现场调试可能会用到 SendTrainDirection(train *state_proto.TrainState, trainForward, trainBackward bool) @@ -130,17 +129,6 @@ func (d *trainPcSimService) findTrainConnForPort2(sta *state_proto.TrainState, t return nil, fmt.Errorf("") } -func (d *trainPcSimService) findTrainConn(sta *state_proto.TrainState) (*TrainPcReciverData, error) { - rds := d.newPcSimclientMap3[sta.ConnState.TypeName] - if rds == nil { - return nil, fmt.Errorf("") - } - if sta.VobcState.Tc1Active { - return rds[0], nil - } else { - return rds[1], nil - } -} func (d *trainPcSimService) findTrainAllConn(sta *state_proto.TrainState) []*TrainPcReciverData { rds := d.newPcSimclientMap3[sta.ConnState.TypeName] return rds @@ -305,7 +293,7 @@ func (d *trainPcSimService) connServer(open bool, ip string, port uint32, rd *Tr func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) { configs := pcSimManage.GetTrainPcSimConfig() - //d.newPcSimclientMap = make(map[string]*TrainPcReciverData) + d.newPcSimclientMap3 = make(map[string][]*TrainPcReciverData) if len(configs) <= 0 { slog.Info("车载pc仿真配置未开启") @@ -325,8 +313,6 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) { pcReceivers[i] = pcReciver } d.newPcSimclientMap3[ck] = pcReceivers - //d.newPcSimclientMap[ck] = pcReciver - } } if closedCount == len(configs) { @@ -442,6 +428,9 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) { for numKey, pc := range train.PulseCountMap { trainPort := state_proto.TrainState_TrainPort(numKey) trainClient, _ := d.findTrainConnForPort2(train, trainPort) + if trainClient == nil { + continue + } if trainClient.success { if trainClient.speedPlace == nil || trainClient.tcpClient == nil { slog.Error(fmt.Sprintf("pc仿真速度位置脉冲对象为空 列车id:%v", train.Id)) @@ -456,7 +445,7 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) { data := trainClient.speedPlace.Encode(runDir, s1, disPluse) bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data} dataCode := bm.Encode() - slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,列车服务端:%v,列车速度:%v,计数脉冲: %v,累计里程: %v ,发送数据:%X", train.Id, trainClient.RealTrainPort.String(), speed, s1, trainClient.speedPlace.PulseCount1, dataCode)) + //slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,列车服务端:%v,列车速度:%v,计数脉冲: %v,累计里程: %v ,发送数据:%X", train.Id, trainClient.RealTrainPort.String(), speed, s1, trainClient.speedPlace.PulseCount1, dataCode)) err := trainClient.tcpClient.Send(dataCode) if err != nil { slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode))) @@ -490,50 +479,9 @@ func (d *trainPcSimService) trainDirection(speed float32, train *state_proto.Tra return runDir } -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)) - return - } - tc := train.ConnState - if tc.Conn { - vobc := train.VobcState - msg := &message.TrainPcSimBaseMessage{} - newTraction := vobc.TractionForce - if tractionState { - if newTraction <= oldTraction && newTraction <= 0 { - //手柄取消前进 - msg.Type = message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD - } else { - //手柄前进 - msg.Type = message.SENDER_TRAIN_HAND_KEY_FORWARD - } - - } else { - /*if newBrake >= newOldBrakeForce && newBrake == 0 { - //手柄取消后退 - msg.Type = message.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD - } else if newBrake < newOldBrakeForce { - //手柄后退 - msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD - } else { - //手柄后退 - msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD - }*/ - msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD - } - da := msg.Encode() - //slog.Info("发送列车手柄消息", "msg", hex.EncodeToString(da)) - err := trainClient.tcpClient.Send(da) - //err := client.Send(da) - if err != nil { - slog.Error("发送列车手柄消息失败", "msg", hex.EncodeToString(da)) - } - } -} func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, trainForward, trainBackward bool) { - trainClient, trainDataErr := d.findTrainConn(train) + //trainClient, trainDataErr := d.findTrainConn(train) + trainClient, trainDataErr := d.findTrainConnForPort2(train, train.TrainPort) if trainDataErr != nil { slog.Error(fmt.Sprintf("发送列车方向失败,未找到列车连接,trainId:%s", train.Id)) return diff --git a/ts/simulation/wayside/memory/wayside_memory_train.go b/ts/simulation/wayside/memory/wayside_memory_train.go index 09564af..a7c3752 100644 --- a/ts/simulation/wayside/memory/wayside_memory_train.go +++ b/ts/simulation/wayside/memory/wayside_memory_train.go @@ -155,9 +155,10 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) { allTrainMap.Range(func(k, v any) bool { tmpTrain := v.(*state_proto.TrainState) connState := tmpTrain.ConnState - if connState.Conn { + + if connState.Conn && connState.TypeName == ct.TypeName { connTypeName := "半实物" - if connState.ConnType == state_proto.TrainConnState_PC_SIM && connState.TypeName == ct.TypeName { + if connState.ConnType == state_proto.TrainConnState_PC_SIM { connTypeName = fmt.Sprintf("车载pc仿真-%v", ct.TypeName) } panic(sys_error.New(fmt.Sprintf("列车[%s]已经连接 [%v],此列车无法连接", k, connTypeName))) diff --git a/ts/simulation/wayside/memory/wayside_simulation_train_pc.go b/ts/simulation/wayside/memory/wayside_simulation_train_pc.go index a43e435..b15c0f3 100644 --- a/ts/simulation/wayside/memory/wayside_simulation_train_pc.go +++ b/ts/simulation/wayside/memory/wayside_simulation_train_pc.go @@ -38,7 +38,7 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) { sta := data.(*state_proto.TrainState) vobc := sta.VobcState tcc := sta.Tcc - if ct.ControlType != request_proto.TrainControl_DRIVER_KEY_SWITCH && vobc.Tc1Active == false && vobc.Tc2Active == false { + if ct.ControlType != request_proto.TrainControl_DRIVER_KEY_SWITCH && sta.TrainPort == state_proto.TrainState_PORT_NONE { panic(sys_error.New("请先上驾驶端钥匙")) }