列车连接三方服务调整
This commit is contained in:
parent
15bdc45892
commit
c6cfc42774
68
third_party/train_pc_sim/train_pc_sim.go
vendored
68
third_party/train_pc_sim/train_pc_sim.go
vendored
@ -30,8 +30,7 @@ type TrainPcSim interface {
|
|||||||
|
|
||||||
// SendDriverActive Deprecated 发送驾驶端激活
|
// SendDriverActive Deprecated 发送驾驶端激活
|
||||||
//SendDriverActive(train *state_proto.TrainState)
|
//SendDriverActive(train *state_proto.TrainState)
|
||||||
// SendHandleSwitch 发送牵引制动手柄
|
|
||||||
SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState)
|
|
||||||
// SendTrainDirection 列车运行方向
|
// SendTrainDirection 列车运行方向
|
||||||
//因文档说明不清楚,在调用的时候目前是注释状态,现场调试可能会用到
|
//因文档说明不清楚,在调用的时候目前是注释状态,现场调试可能会用到
|
||||||
SendTrainDirection(train *state_proto.TrainState, trainForward, trainBackward bool)
|
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("")
|
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 {
|
func (d *trainPcSimService) findTrainAllConn(sta *state_proto.TrainState) []*TrainPcReciverData {
|
||||||
rds := d.newPcSimclientMap3[sta.ConnState.TypeName]
|
rds := d.newPcSimclientMap3[sta.ConnState.TypeName]
|
||||||
return rds
|
return rds
|
||||||
@ -305,7 +293,7 @@ func (d *trainPcSimService) connServer(open bool, ip string, port uint32, rd *Tr
|
|||||||
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||||
|
|
||||||
configs := pcSimManage.GetTrainPcSimConfig()
|
configs := pcSimManage.GetTrainPcSimConfig()
|
||||||
//d.newPcSimclientMap = make(map[string]*TrainPcReciverData)
|
|
||||||
d.newPcSimclientMap3 = make(map[string][]*TrainPcReciverData)
|
d.newPcSimclientMap3 = make(map[string][]*TrainPcReciverData)
|
||||||
if len(configs) <= 0 {
|
if len(configs) <= 0 {
|
||||||
slog.Info("车载pc仿真配置未开启")
|
slog.Info("车载pc仿真配置未开启")
|
||||||
@ -325,8 +313,6 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
|||||||
pcReceivers[i] = pcReciver
|
pcReceivers[i] = pcReciver
|
||||||
}
|
}
|
||||||
d.newPcSimclientMap3[ck] = pcReceivers
|
d.newPcSimclientMap3[ck] = pcReceivers
|
||||||
//d.newPcSimclientMap[ck] = pcReciver
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if closedCount == len(configs) {
|
if closedCount == len(configs) {
|
||||||
@ -442,6 +428,9 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
|||||||
for numKey, pc := range train.PulseCountMap {
|
for numKey, pc := range train.PulseCountMap {
|
||||||
trainPort := state_proto.TrainState_TrainPort(numKey)
|
trainPort := state_proto.TrainState_TrainPort(numKey)
|
||||||
trainClient, _ := d.findTrainConnForPort2(train, trainPort)
|
trainClient, _ := d.findTrainConnForPort2(train, trainPort)
|
||||||
|
if trainClient == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
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))
|
||||||
@ -456,7 +445,7 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
|||||||
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,列车服务端:%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)
|
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)))
|
||||||
@ -490,50 +479,9 @@ func (d *trainPcSimService) trainDirection(speed float32, train *state_proto.Tra
|
|||||||
return runDir
|
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) {
|
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 {
|
if trainDataErr != nil {
|
||||||
slog.Error(fmt.Sprintf("发送列车方向失败,未找到列车连接,trainId:%s", train.Id))
|
slog.Error(fmt.Sprintf("发送列车方向失败,未找到列车连接,trainId:%s", train.Id))
|
||||||
return
|
return
|
||||||
|
@ -155,9 +155,10 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
|
|||||||
allTrainMap.Range(func(k, v any) bool {
|
allTrainMap.Range(func(k, v any) bool {
|
||||||
tmpTrain := v.(*state_proto.TrainState)
|
tmpTrain := v.(*state_proto.TrainState)
|
||||||
connState := tmpTrain.ConnState
|
connState := tmpTrain.ConnState
|
||||||
if connState.Conn {
|
|
||||||
|
if connState.Conn && connState.TypeName == ct.TypeName {
|
||||||
connTypeName := "半实物"
|
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)
|
connTypeName = fmt.Sprintf("车载pc仿真-%v", ct.TypeName)
|
||||||
}
|
}
|
||||||
panic(sys_error.New(fmt.Sprintf("列车[%s]已经连接 [%v],此列车无法连接", k, connTypeName)))
|
panic(sys_error.New(fmt.Sprintf("列车[%s]已经连接 [%v],此列车无法连接", k, connTypeName)))
|
||||||
|
@ -38,7 +38,7 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
|
|||||||
sta := data.(*state_proto.TrainState)
|
sta := data.(*state_proto.TrainState)
|
||||||
vobc := sta.VobcState
|
vobc := sta.VobcState
|
||||||
tcc := sta.Tcc
|
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("请先上驾驶端钥匙"))
|
panic(sys_error.New("请先上驾驶端钥匙"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user