修改列车删除或更改连接时电机继续转动的情况

This commit is contained in:
tiger_zhou 2024-06-07 13:26:46 +08:00
parent 31180597a5
commit ed4dc9a224
4 changed files with 20 additions and 11 deletions

View File

@ -24,7 +24,7 @@ type ElectricMachinery interface {
Stop() // 停止电机转速消息处理
SendElectricMachineryMessage(emMap map[int]*message.ElectricMachinery) // 发送电机转速消息
SendElectricMachineryMessage2(info *message.DynamicsTrainInfo, trainState *state_proto.TrainState) // 发送电机转速消息
ClearOrRemoveTrain(trainState *state_proto.TrainState)
}
type ElectricMachineryMessageManager interface {
@ -75,7 +75,17 @@ func (s *electricalMachineryImpl) Stop() {
}
s.manager = nil
}
func (s *electricalMachineryImpl) ClearOrRemoveTrain(trainState *state_proto.TrainState) {
collectSpeedMap := initEMMsg(trainState)
if trainState.VobcState.Tc1Active {
collectSpeed(0, 0, trainState.TrainEndsA, collectSpeedMap)
} else if trainState.VobcState.Tc2Active {
collectSpeed(0, 0, trainState.TrainEndsB, collectSpeedMap)
}
// 更新电机转速
s.SendElectricMachineryMessage(collectSpeedMap)
}
func (s *electricalMachineryImpl) SendElectricMachineryMessage(emMap map[int]*message.ElectricMachinery) {
for key, em := range emMap {
client := s.electricalMachineryUdpClientMap[key]

View File

@ -184,15 +184,10 @@ func TrainUnConn(vs *VerifySimulation, trainId string) {
panic(sys_error.New(fmt.Sprintf("列车【%s】不存在", trainId)))
}
train := data.(*state_proto.TrainState)
oldType := train.ConnState.ConnType
train.ConnState.Conn = false
//train.ConnState.ConnType = state_proto.TrainConnState_NONE
if oldType == state_proto.TrainConnState_PC_SIM_A || oldType == state_proto.TrainConnState_PC_SIM_B {
err := TrainPcSimConnOrRemoveHandle(train)
if err != nil {
panic(sys_error.New("未连接车载PC仿真无法断开连接"))
}
}
train.ConnState.Conn = false
train.ConnState.ConnType = state_proto.TrainConnState_NONE
}

View File

@ -524,7 +524,7 @@ func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.Inter
// 获取列车可用连接半实物类型
func (s *VerifySimulation) FindTrainConnTypes() []dto.TrainConnTypeConfigDto {
typeConfig := make([]dto.TrainConnTypeConfigDto, 0)
if s.runConfig.Vobc.Open /*&& s.runConfig.Vobc.Ip != ""*/ {
if /*s.runConfig.Vobc.Open &&*/ s.runConfig.Vobc.Ip != "" {
typeConfig = append(typeConfig, dto.TrainConnTypeConfigDto{ConnType: state_proto.TrainConnState_VOBC})
}

View File

@ -11,6 +11,7 @@ import (
"joylink.club/bj-rtsts-server/dto/state_proto"
"joylink.club/bj-rtsts-server/sys_error"
"joylink.club/bj-rtsts-server/third_party/can_btm"
"joylink.club/bj-rtsts-server/third_party/electrical_machinery"
"joylink.club/bj-rtsts-server/third_party/message"
train_pc_sim "joylink.club/bj-rtsts-server/third_party/train_pc_sim"
"log/slog"
@ -463,13 +464,16 @@ func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState) error {
if train.ConnState.Conn == false {
data = 0x00
}
if train.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A || train.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_B {
connState := train.ConnState
if connState.ConnType == state_proto.TrainConnState_PC_SIM_A || connState.ConnType == state_proto.TrainConnState_PC_SIM_B {
crErr := train_pc_sim.Default().CreateOrRemoveTrain(train, train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE, []byte{data})
if crErr != nil {
return crErr
}
train_pc_sim.Default().CreateOrRemoveSpeedPLace(train)
} else if connState.ConnType == state_proto.TrainConnState_VOBC {
electrical_machinery.Default().ClearOrRemoveTrain(train)
}
return nil
}