列车pc仿真调整
All checks were successful
local-test分支打包构建docker并发布运行 / Docker-Build (push) Successful in 1m55s

This commit is contained in:
tiger_zhou 2024-04-16 17:26:37 +08:00
parent 117ff89562
commit 92d21d559f
8 changed files with 156 additions and 106 deletions

View File

@ -34,6 +34,8 @@ func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
authed.POST("/train/update", updateTrain) authed.POST("/train/update", updateTrain)
authed.POST("/train/control", controlTrain) authed.POST("/train/control", controlTrain)
authed.POST("/train/conn", trainConnThird) authed.POST("/train/conn", trainConnThird)
authed.POST("/train/unconn/:trainId/:id", trainUnConnThird)
authed.GET("/train/conn/type/:id", trainConnTypeList) authed.GET("/train/conn/type/:id", trainConnTypeList)
authed.POST("/switch/operation", turnoutOperation) authed.POST("/switch/operation", turnoutOperation)
@ -311,6 +313,30 @@ func trainConnThird(c *gin.Context) {
c.JSON(http.StatusOK, "ok") c.JSON(http.StatusOK, "ok")
} }
// ATS测试仿真-取消列车连接三方
//
// @Summary ATS测试仿真-取消列车连接三方
//
// @Security JwtAuth
//
// @Description ATS测试仿真-取消列车连接三方
// @Tags ATS测试仿真Api
// @Accept json
// @Produce json
// @Param Authorization header string true "JWT Token"
// @Param trainId path string true "列车id"
// @Param id path string true "仿真id"
// @Success 200 {object} dto.AddTrainRspDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/simulation/train/conn [post]
func trainUnConnThird(c *gin.Context) {
trainId := c.Param("trainId")
simId := c.Param("id")
simulation := checkDeviceDataAndReturn(simId)
memory.TrainUnConn(simulation, trainId)
c.JSON(http.StatusOK, "ok")
}
// ATS测试仿真-列车连接三方类型列表 // ATS测试仿真-列车连接三方类型列表
// //
// @Summary ATS测试仿真-列车连接三方类型列表 // @Summary ATS测试仿真-列车连接三方类型列表

View File

@ -525,17 +525,6 @@ func convertDynamicConfig(config, dest interface{}) {
} }
} }
/*func convertDynamicConfig(config *common_proto.TrainDynamicConfig, dest *state_proto.TrainDynamicConfigMqtt) {
configType := reflect.TypeOf(config).Elem()
for index := 0; index < configType.NumField(); index++ {
field := configType.Field(index)
if field.IsExported() {
fieldName := field.Name
setVal(config, dest, fieldName)
}
}
}*/
func setVal(source, dest interface{}, fieldName string) { func setVal(source, dest interface{}, fieldName string) {
destVal := reflect.ValueOf(dest).Elem().FieldByName(fieldName) destVal := reflect.ValueOf(dest).Elem().FieldByName(fieldName)
sourceType := reflect.ValueOf(source).Elem().FieldByName(fieldName) sourceType := reflect.ValueOf(source).Elem().FieldByName(fieldName)
@ -548,7 +537,7 @@ func setVal(source, dest interface{}, fieldName string) {
} }
}() }()
if destVal.Kind() == reflect.Invalid { if destVal.Kind() == reflect.Invalid {
slog.Warn(fieldName, "赋值失败,源数据类型", sourceType.Kind().String(), "目标数据类型:", destVal.Kind().String()) //slog.Warn(fieldName, "赋值失败,源数据类型", sourceType.Kind().String(), "目标数据类型:", destVal.Kind().String())
return return
} }
if destVal.Kind() == reflect.String { if destVal.Kind() == reflect.String {

@ -1 +1 @@
Subproject commit df112c429875bb39908c0a387f49ef095c82fabe Subproject commit acbfbf8b92d3702a9c0e6434f26fd6db2f57292d

View File

@ -90,11 +90,11 @@ func (tp *TrainSpeedPlaceReportMsg) ParsePulseCount1(s1, s2 uint32) {
} }
func (tp *TrainSpeedPlaceReportMsg) Encode(runDir bool, s1, s2 uint32) []byte { func (tp *TrainSpeedPlaceReportMsg) Encode(runDir bool, s1, s2 uint32) []byte {
data := make([]byte, 0) data := make([]byte, 0)
binary.BigEndian.AppendUint16(data, uint16(IsTrue(runDir))) data = binary.BigEndian.AppendUint16(data, uint16(IsTrue(runDir)))
binary.BigEndian.AppendUint32(data, s1) data = binary.BigEndian.AppendUint32(data, s1)
binary.BigEndian.AppendUint32(data, s2) data = binary.BigEndian.AppendUint32(data, s2)
binary.BigEndian.AppendUint32(data, tp.PulseCount1) data = binary.BigEndian.AppendUint32(data, tp.PulseCount1)
binary.BigEndian.AppendUint32(data, tp.PulseCount2) data = binary.BigEndian.AppendUint32(data, tp.PulseCount2)
now := time.Now().UTC() now := time.Now().UTC()
// 将时间转换为毫秒 // 将时间转换为毫秒
millis := now.UnixNano() / int64(time.Millisecond) millis := now.UnixNano() / int64(time.Millisecond)
@ -103,8 +103,8 @@ func (tp *TrainSpeedPlaceReportMsg) Encode(runDir bool, s1, s2 uint32) []byte {
second, _ := strconv.Atoi(string(strs[:len(strs)-3])) second, _ := strconv.Atoi(string(strs[:len(strs)-3]))
mm, _ := strconv.Atoi(string(strs[len(strs)-3:])) mm, _ := strconv.Atoi(string(strs[len(strs)-3:]))
binary.BigEndian.AppendUint32(data, uint32(second)) data = binary.BigEndian.AppendUint32(data, uint32(second))
binary.BigEndian.AppendUint16(data, uint16(mm)) data = binary.BigEndian.AppendUint16(data, uint16(mm))
return data return data
} }

View File

@ -36,7 +36,7 @@ func StartTcpClient(rAddr string, handler func(n int, data []byte), readErr func
l, err := conn.Read(data) l, err := conn.Read(data)
if err != nil { if err != nil {
if opErr, ok := err.(*net.OpError); ok { if opErr, ok := err.(*net.OpError); ok {
slog.Error(fmt.Sprintf("TCP客户端[rAddr:%s]读取数据异常", rAddr), opErr) slog.Error(fmt.Sprintf("TCP客户端[rAddr:%s]读取数据异常连接可能断开", rAddr), opErr)
readErr(err) readErr(err)
} }
if err == io.EOF { if err == io.EOF {
@ -57,11 +57,15 @@ func (c *TcpClient) Close() {
c.conn = nil c.conn = nil
} }
} }
func (c *TcpClient) Send(data []byte) error { func (c *TcpClient) Send(data []byte) {
if c.conn == nil {
slog.Error("tcp client send error,conn is nil")
return
}
_, err := c.conn.Write(data) _, err := c.conn.Write(data)
if err != nil { if err != nil {
slog.Error("udp client send error", "error", err) slog.Error("tcp client send error", "error", err)
return err
} }
return nil
} }

View File

@ -27,7 +27,10 @@ type TrainPcSim interface {
//发送驾驶端激活 //发送驾驶端激活
SendDriverActive(tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState) SendDriverActive(tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState)
//发送牵引制动手柄 //发送牵引制动手柄
SendHandleSwitch(oldTraction, oldBrakeForce int64, tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState) SendHandleSwitch(oldTraction, oldBrakeForce int64, isBrake bool, tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState)
//列车运行方向
//因文档说明不清楚,在调用的时候目前是注释状态,现场调试可能会用到
SendTrainDirection(trainForward, trainBackward bool)
//发送应答器信息数据 //发送应答器信息数据
SendBaliseData(msgType uint16, data []byte) SendBaliseData(msgType uint16, data []byte)
//发布列车控制的相关事件 //发布列车控制的相关事件
@ -87,6 +90,7 @@ type trainPcSimService struct {
cancleContext context.CancelFunc cancleContext context.CancelFunc
trainPcSimManage TrainPcSimManage trainPcSimManage TrainPcSimManage
speedPlace *message.TrainSpeedPlaceReportMsg speedPlace *message.TrainSpeedPlaceReportMsg
config config.VehiclePCSimConfig
} }
// 接受来自pc仿真的消息 // 接受来自pc仿真的消息
@ -94,6 +98,22 @@ func (d *trainPcSimService) readError(err error) {
slog.Error("连接车载pc仿真tcp服务断开", err) slog.Error("连接车载pc仿真tcp服务断开", err)
d.updateState(tpapi.ThirdPartyState_Broken) d.updateState(tpapi.ThirdPartyState_Broken)
d.pcSimClient.Close() d.pcSimClient.Close()
d.connTrainPcSim()
}
func (d *trainPcSimService) connTrainPcSim() {
reconnIndex := 0
for {
client, err := tcp.StartTcpClient(fmt.Sprintf("%v:%v", d.config.PcSimIp, d.config.PcSimPort), d.reivceData, d.readError)
if err != nil {
reconnIndex++
slog.Error("连接车载pc平台失败尝试=", reconnIndex, err)
d.updateState(tpapi.ThirdPartyState_Broken)
} else {
d.pcSimClient = client
return
}
time.Sleep(time.Second * 1)
}
} }
func (d *trainPcSimService) Start(wd ecs.World, pcSimManage TrainPcSimManage) { func (d *trainPcSimService) Start(wd ecs.World, pcSimManage TrainPcSimManage) {
config := pcSimManage.GetTrainPcSimConfig() config := pcSimManage.GetTrainPcSimConfig()
@ -101,14 +121,8 @@ func (d *trainPcSimService) Start(wd ecs.World, pcSimManage TrainPcSimManage) {
slog.Info("车载pc仿真配置未开启") slog.Info("车载pc仿真配置未开启")
return return
} }
d.config = config
client, err := tcp.StartTcpClient(fmt.Sprintf("%v:%v", config.PcSimIp, config.PcSimPort), d.reivceData, d.readError) d.connTrainPcSim()
if err != nil {
slog.Error("连接车载pc平台失败", err)
d.updateState(tpapi.ThirdPartyState_Broken)
return
}
d.pcSimClient = client
ctx, ctxFun := context.WithCancel(context.Background()) ctx, ctxFun := context.WithCancel(context.Background())
d.cancleContext = ctxFun d.cancleContext = ctxFun
d.trainPcSimManage = pcSimManage d.trainPcSimManage = pcSimManage
@ -161,13 +175,7 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
train.PluseCount.PulseCount1 = 0 train.PluseCount.PulseCount1 = 0
train.PluseCount.PulseCount2 = 0 train.PluseCount.PulseCount2 = 0
d.pcSimClient.Send(bm.Encode()) d.pcSimClient.Send(bm.Encode())
} /*else { }
m1 := "未找到对应连接车载pc仿真的列车"
if train != nil {
m1 = fmt.Sprintf("对应的列车没有连接上车载pc仿真列车ID%v", train.Id)
}
slog.Info(m1)
}*/
time.Sleep(time.Millisecond * 80) time.Sleep(time.Millisecond * 80)
} }
} }
@ -185,30 +193,46 @@ func (d *trainPcSimService) SendDriverActive(tc *state_proto.TrainConnState, vob
d.pcSimClient.Send(msg.Encode()) d.pcSimClient.Send(msg.Encode())
} }
} }
func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState) { func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, isBrake bool, tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState) {
if tc.Conn && tc.ConnType == state_proto.TrainConnState_PC_SIM { if tc.Conn && tc.ConnType == state_proto.TrainConnState_PC_SIM {
msg := &message.TrainPcSimBaseMessage{} msg := &message.TrainPcSimBaseMessage{}
newTraction := vobc.TractionForce newTraction := vobc.TractionForce
newBrake := vobc.BrakeForce newBrake := vobc.BrakeForce
if newTraction <= oldTraction && newTraction == 0 { if isBrake {
//手柄取消前进 if newBrake < oldBrakeForce && newBrake == 0 {
msg.Type = RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD //手柄取消后退
} else if newTraction > oldTraction { msg.Type = RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD
//手柄前进 } else if newBrake > oldBrakeForce {
msg.Type = SENDER_TRAIN_HAND_KEY_FORWARD //手柄后退
} else if newBrake >= oldBrakeForce && newBrake == 0 { msg.Type = RECIVE_TRAIN_HAND_KEY_BACKWARD
//手柄取消后退 }
msg.Type = RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD
} else if newBrake < oldBrakeForce {
//手柄后退
msg.Type = RECIVE_TRAIN_HAND_KEY_BACKWARD
} else { } else {
slog.Error("") if newTraction < oldTraction && newTraction == 0 {
return //手柄取消前进
msg.Type = RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD
} else if newTraction > oldTraction {
//手柄前进
msg.Type = SENDER_TRAIN_HAND_KEY_FORWARD
}
} }
d.pcSimClient.Send(msg.Encode()) d.pcSimClient.Send(msg.Encode())
} }
} }
func (d *trainPcSimService) SendTrainDirection(trainForward, trainBackward bool) {
baseMsgs := make([]*message.TrainPcSimBaseMessage, 0)
if !trainForward && !trainBackward {
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD})
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD})
} else if trainForward {
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: SENDER_TRAIN_HAND_KEY_FORWARD})
} else if trainBackward {
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: RECIVE_TRAIN_HAND_KEY_BACKWARD})
}
for _, msg := range baseMsgs {
d.pcSimClient.Send(msg.Encode())
}
}
func (d *trainPcSimService) SendBaliseData(msgType uint16, data []byte) { func (d *trainPcSimService) SendBaliseData(msgType uint16, data []byte) {
msg := &message.TrainPcSimBaseMessage{} msg := &message.TrainPcSimBaseMessage{}
@ -218,7 +242,6 @@ func (d *trainPcSimService) SendBaliseData(msgType uint16, data []byte) {
} }
func (d *trainPcSimService) trainControlEventHandle(w ecs.World, event TrainControlEvent) { func (d *trainPcSimService) trainControlEventHandle(w ecs.World, event TrainControlEvent) {
fmt.Println(event.Status)
msg := &message.TrainPcSimBaseMessage{} msg := &message.TrainPcSimBaseMessage{}
msg.Type = SENDER_TRAIN_OUTR_INFO msg.Type = SENDER_TRAIN_OUTR_INFO
data := []byte{event.Command, event.Status} data := []byte{event.Command, event.Status}

View File

@ -132,10 +132,7 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
panic(sys_error.New(fmt.Sprintf("列车【%s】不存在", ct.Id))) panic(sys_error.New(fmt.Sprintf("列车【%s】不存在", ct.Id)))
} }
train := data.(*state_proto.TrainState) train := data.(*state_proto.TrainState)
var conn = true
if ct.ConnType == state_proto.TrainConnState_NONE {
conn = false
}
if ct.ConnType != state_proto.TrainConnState_NONE { if ct.ConnType != state_proto.TrainConnState_NONE {
//列车连接 半实物或车载pc仿真 //列车连接 半实物或车载pc仿真
allTrainMap.Range(func(k, v any) bool { allTrainMap.Range(func(k, v any) bool {
@ -151,11 +148,27 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
return true return true
}) })
} }
train.ConnState.Conn = conn train.ConnState.Conn = true
train.ConnState.ConnType = ct.ConnType train.ConnState.ConnType = ct.ConnType
TrainPcSimConnOrRemoveHandle(train) if train.ConnState.ConnType == state_proto.TrainConnState_PC_SIM {
} TrainPcSimConnOrRemoveHandle(train)
}
}
func TrainUnConn(vs *VerifySimulation, trainId string) {
allTrainMap := &vs.Memory.Status.TrainStateMap
data, ok := allTrainMap.Load(trainId)
if !ok {
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 {
TrainPcSimConnOrRemoveHandle(train)
}
}
func createOrUpdateStateDynamicConfig(trainState *state_proto.TrainState, configTrainData dto.ConfigTrainData, trainEndsA dto.ConfigTrainEnds, func createOrUpdateStateDynamicConfig(trainState *state_proto.TrainState, configTrainData dto.ConfigTrainData, trainEndsA dto.ConfigTrainEnds,
trainEndsB dto.ConfigTrainEnds) { trainEndsB dto.ConfigTrainEnds) {
trainState.TrainDynamicConfig = service.TrainConfigToProtoConvert(&configTrainData) trainState.TrainDynamicConfig = service.TrainConfigToProtoConvert(&configTrainData)

View File

@ -37,33 +37,32 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
sta := data.(*state_proto.TrainState) sta := data.(*state_proto.TrainState)
var tce []train_pc_sim.TrainControlEvent = nil var tce []train_pc_sim.TrainControlEvent = nil
if ct.ControlType == request_proto.TrainControl_EMERGENT_BUTTON { if ct.ControlType == request_proto.TrainControl_EMERGENT_BUTTON {
trainControlEB(sta, ct.Button, ct.DeviceId, tccGraphicData) tce = trainControlEB(sta, ct.Button, ct.DeviceId, tccGraphicData)
} else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH { } else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH {
tce = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData) tce = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData)
train_pc_sim.Default().SendDriverActive(sta.ConnState, sta.VobcState) train_pc_sim.Default().SendDriverActive(sta.ConnState, sta.VobcState)
} else if ct.ControlType == request_proto.TrainControl_DIRECTION_KEY_SWITCH { } else if ct.ControlType == request_proto.TrainControl_DIRECTION_KEY_SWITCH {
trainControlDirKey(sta, ct.DirKey, ct.DeviceId, tccGraphicData) tce = trainControlDirKey(sta, ct.DirKey, ct.DeviceId, tccGraphicData)
} else if ct.ControlType == request_proto.TrainControl_HANDLER { } else if ct.ControlType == request_proto.TrainControl_HANDLER {
oldTraction := sta.VobcState.TractionForce oldTraction := sta.VobcState.TractionForce
oldBrakeForce := sta.VobcState.BrakeForce oldBrakeForce := sta.VobcState.BrakeForce
isBrake := ct.Handler.Val < 0 //是否制动
tce = trainControlHandle(sta, ct.Handler, ct.DeviceId, tccGraphicData) tce = trainControlHandle(sta, ct.Handler, ct.DeviceId, tccGraphicData)
train_pc_sim.Default().SendHandleSwitch(oldTraction, oldBrakeForce, sta.ConnState, sta.VobcState) train_pc_sim.Default().SendHandleSwitch(oldTraction, oldBrakeForce, isBrake, sta.ConnState, sta.VobcState)
} }
if sta.ConnState.Conn && sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM && tce != nil { if sta.ConnState.Conn && sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM && tce != nil {
train_pc_sim.Default().PublishTrainControlEvent(s.World, tce) train_pc_sim.Default().PublishTrainControlEvent(s.World, tce)
} }
//cm := &message.TrainControlMsg{TrainId: ct.TrainId, ControlInfo: sta.VobcState}
//dynamics.Default().SendTrainControl(cm)
} }
func trainControlEB(trainState *state_proto.TrainState, request *request_proto.TrainControl_EmergentButton, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) { func trainControlEB(trainState *state_proto.TrainState, request *request_proto.TrainControl_EmergentButton, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []train_pc_sim.TrainControlEvent {
_, find := findTrainTccGraphicDataButton(tccGraphic, deviceId) _, find := findTrainTccGraphicDataButton(tccGraphic, deviceId)
if !find { if !find {
slog.Error("未找到对应的紧急停车摁钮,deviceId:", deviceId) slog.Error("未找到对应的紧急停车摁钮,deviceId:", deviceId)
return return nil
} }
trainState.VobcState.EmergencyBrakingStatus = request.Active trainState.VobcState.EmergencyBrakingStatus = request.Active
if trainState.Tcc.Ebutton == nil { if trainState.Tcc.Ebutton == nil {
@ -71,17 +70,21 @@ func trainControlEB(trainState *state_proto.TrainState, request *request_proto.T
} else { } else {
trainState.Tcc.Ebutton.Passed = request.Active trainState.Tcc.Ebutton.Passed = request.Active
} }
return nil
//return []train_pc_sim.TrainControlEvent{{Command: message.KEY_STATE, Status: message.IsTrue(request.Val)}}
} }
// 列车方向 // 列车方向
func trainControlDirKey(trainState *state_proto.TrainState, request *request_proto.TrainControl_DirectionKeySwitch, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) { func trainControlDirKey(trainState *state_proto.TrainState, request *request_proto.TrainControl_DirectionKeySwitch, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []train_pc_sim.TrainControlEvent {
_, find := findTrainTccGraphicDataKey(tccGraphic, deviceId) _, find := findTrainTccGraphicDataKey(tccGraphic, deviceId)
if !find { if !find {
slog.Error("未找到对应的列车方向键deviceId:", deviceId) slog.Error("未找到对应的列车方向键deviceId:", deviceId)
return return nil
} }
trainState.VobcState.DirectionForward = false trainState.VobcState.DirectionForward = false
trainState.VobcState.DirectionBackward = false trainState.VobcState.DirectionBackward = false
if request.Val == 1 { if request.Val == 1 {
trainState.VobcState.DirectionForward = true trainState.VobcState.DirectionForward = true
} else if request.Val == 0 { } else if request.Val == 0 {
@ -92,7 +95,7 @@ func trainControlDirKey(trainState *state_proto.TrainState, request *request_pro
} else { } else {
trainState.Tcc.DirKey.Val = request.Val trainState.Tcc.DirKey.Val = request.Val
} }
return nil
} }
// 列车驾驶端激活 // 列车驾驶端激活
@ -102,9 +105,6 @@ func trainControlDriverKey(trainState *state_proto.TrainState, request *request_
slog.Error("未找到对应的驾驶端激活设备deviceId:", deviceId) slog.Error("未找到对应的驾驶端激活设备deviceId:", deviceId)
return nil return nil
} }
//trainState.VobcState.Tc1Active = false
//trainState.VobcState.Tc2Active = false
if obj.Code == "SKQYS1" { if obj.Code == "SKQYS1" {
trainState.VobcState.Tc1Active = request.Val trainState.VobcState.Tc1Active = request.Val
} else if obj.Code == "SKQYS2" { } else if obj.Code == "SKQYS2" {
@ -138,21 +138,20 @@ func trainControlHandle(trainState *state_proto.TrainState, request *request_pro
trainState.VobcState.TractionForce = 0 trainState.VobcState.TractionForce = 0
trainState.VobcState.BrakingStatus = false trainState.VobcState.BrakingStatus = false
trainState.VobcState.BrakeForce = 0 trainState.VobcState.BrakeForce = 0
trainState.VobcState.MaintainBrakeStatus = false
tce := make([]train_pc_sim.TrainControlEvent, 0) tce := make([]train_pc_sim.TrainControlEvent, 0)
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_FORWORD, Status: 0}) tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_FORWORD, Status: 0})
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_BACKWORD, Status: 0}) tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_BACKWORD, Status: 0})
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: 0}) tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: 0})
if request.Val > 0 { if request.Val > 0 {
trainState.VobcState.MaintainBrakeStatus = false
trainState.VobcState.TractionStatus = true trainState.VobcState.TractionStatus = true
trainState.VobcState.TractionForce = int64(request.Val * 180) trainState.VobcState.TractionForce = int64(request.Val * 180)
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_FORWORD, Status: 1}) tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_FORWORD, Status: 1})
} else if request.Val < 0 { } else if request.Val < 0 {
trainState.VobcState.MaintainBrakeStatus = true
trainState.VobcState.BrakingStatus = true trainState.VobcState.BrakingStatus = true
trainState.VobcState.BrakeForce = int64(-request.Val * 180) trainState.VobcState.BrakeForce = int64(-request.Val * 180)
//trainState.VobcState.BrakeForce = 19400
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_BACKWORD, Status: 1}) tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_BACKWORD, Status: 1})
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.TRAIN_BRAKE_STATE, Status: 1})
} else { } else {
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: 1}) tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: 1})
@ -290,14 +289,14 @@ func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(data []byte) {
//dynamics.Default().SendTrainControl(cm) //dynamics.Default().SendTrainControl(cm)
} }
func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobcState) {
vobc.MostUseBrake = message.IsTrueForByte(message.GetBit(d, 0)) //? //常用制动 vobc.MostUseBrake = message.IsTrueForByte(message.GetBit(d, 0)) //? 常用制动
vobc.SplittingOut = message.IsTrueForByte(message.GetBit(d, 1)) //? //过分相输出 vobc.SplittingOut = message.IsTrueForByte(message.GetBit(d, 1)) //? 过分相输出
vobc.ModeRelay = message.IsTrueForByte(message.GetBit(d, 2)) //? //模式继电器 vobc.ModeRelay = message.IsTrueForByte(message.GetBit(d, 2)) //? 模式继电器
vobc.TractionEffective = message.IsTrueForByte(message.GetBit(d, 3)) //? //牵引有效 vobc.TractionEffective = message.IsTrueForByte(message.GetBit(d, 3)) //? 牵引有效
vobc.BrakeEffective = message.IsTrueForByte(message.GetBit(d, 4)) //? //制动有效 vobc.BrakeEffective = message.IsTrueForByte(message.GetBit(d, 4)) //? 制动有效
vobc.LifeDoorState = message.IsTrueForByte(message.GetBit(d, 5)) //逃生门使能 vobc.LifeDoorState = message.IsTrueForByte(message.GetBit(d, 5)) //?逃生门使能
vobc.BrakeQuarantine = message.IsTrueForByte(message.GetBit(d, 6)) //? //制动隔离 vobc.BrakeQuarantine = message.IsTrueForByte(message.GetBit(d, 6)) //? 制动隔离
vobc.StopNotAllBrake = message.IsTrueForByte(message.GetBit(d, 7)) //? //停放制动缓解 vobc.StopNotAllBrake = message.IsTrueForByte(message.GetBit(d, 7)) //? 停放制动缓解
} }
func trainPcSimDigitalOutInfoHandleCode31_24(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode31_24(d byte, vobc *state_proto.TrainVobcState) {
@ -314,28 +313,28 @@ func trainPcSimDigitalOutInfoHandleCode31_24(d byte, vobc *state_proto.TrainVobc
func trainPcSimDigitalOutInfoHandleCode23_16(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode23_16(d byte, vobc *state_proto.TrainVobcState) {
vobc.DirectionForward = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1 vobc.DirectionForward = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1
vobc.DirectionBackward = message.IsTrueForByte(message.GetBit(d, 1)) //列车方向2 vobc.DirectionBackward = message.IsTrueForByte(message.GetBit(d, 1)) //列车方向2
vobc.AtoLazyCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?//ATO惰行命令输出 vobc.AtoLazyCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?ATO惰行命令输出
vobc.SleepBtn = message.IsTrueForByte(message.GetBit(d, 3)) //休眠指令 vobc.SleepBtn = message.IsTrueForByte(message.GetBit(d, 3)) //?休眠指令
vobc.WakeUpBtn = message.IsTrueForByte(message.GetBit(d, 4)) //唤醒指令 vobc.WakeUpBtn = message.IsTrueForByte(message.GetBit(d, 4)) //?唤醒指令
vobc.AtoSendTrainBtn = message.IsTrueForByte(message.GetBit(d, 5)) //ATO发车指示灯 vobc.AtoSendTrainBtn = message.IsTrueForByte(message.GetBit(d, 5)) //?ATO发车指示灯
vobc.TurnbackStatus = message.IsTrueForByte(message.GetBit(d, 6)) //?//AR灯命令 vobc.TurnbackStatus = message.IsTrueForByte(message.GetBit(d, 6)) //?AR灯命令
vobc.AtoAlwaysBrake = message.IsTrueForByte(message.GetBit(d, 7)) //? //ATO保持制动 vobc.AtoAlwaysBrake = message.IsTrueForByte(message.GetBit(d, 7)) //? ATO保持制动
} }
func trainPcSimDigitalOutInfoHandleCode15_8(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode15_8(d byte, vobc *state_proto.TrainVobcState) {
vobc.LocalAtpControl = message.IsTrueForByte(message.GetBit(d, 0)) //?//本端ATP控车 vobc.LocalAtpControl = message.IsTrueForByte(message.GetBit(d, 0)) //?本端ATP控车
vobc.Ato = message.IsTrueForByte(message.GetBit(d, 1)) //ATO模式 vobc.Ato = message.IsTrueForByte(message.GetBit(d, 1)) //ATO模式
vobc.AtoTractionCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?//ATO牵引命令输出 vobc.AtoTractionCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?ATO牵引命令输出
vobc.AtoTractionCommand1 = message.IsTrueForByte(message.GetBit(d, 3)) //?//ATO牵引指令1 vobc.AtoTractionCommand1 = message.IsTrueForByte(message.GetBit(d, 3)) //?ATO牵引指令1
vobc.AtoTractionCommand2 = message.IsTrueForByte(message.GetBit(d, 4)) //?//ATO牵引指令2 vobc.AtoTractionCommand2 = message.IsTrueForByte(message.GetBit(d, 4)) //?ATO牵引指令2
vobc.AtoTractionCommand3 = message.IsTrueForByte(message.GetBit(d, 5)) //?//ATO牵引指令3 vobc.AtoTractionCommand3 = message.IsTrueForByte(message.GetBit(d, 5)) //?ATO牵引指令3
vobc.AtoBrakeCommand = message.IsTrueForByte(message.GetBit(d, 6)) //?//ATO制动命令输出 vobc.AtoBrakeCommand = message.IsTrueForByte(message.GetBit(d, 6)) //?ATO制动命令输出
vobc.JumpStatus = message.IsTrueForByte(message.GetBit(d, 7)) //跳跃指令 vobc.JumpStatus = message.IsTrueForByte(message.GetBit(d, 7)) //跳跃指令
} }
func trainPcSimDigitalOutInfoHandleCode7_0(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode7_0(d byte, vobc *state_proto.TrainVobcState) {
vobc.TractionSafetyCircuit = message.IsTrueForByte(message.GetBit(d, 0)) //切牵引 vobc.TractionSafetyCircuit = message.IsTrueForByte(message.GetBit(d, 0)) //切牵引
vobc.TrainDoorOutLed = message.IsTrueForByte(message.GetBit(d, 1)) //? 说明暂无此属性 vobc.TrainDoorOutLed = message.IsTrueForByte(message.GetBit(d, 1)) //? 车门外指示灯
vobc.ParkingBrakeStatus = message.IsTrueForByte(message.GetBit(d, 2)) //停放制动施加 vobc.ParkingBrakeStatus = message.IsTrueForByte(message.GetBit(d, 2)) //停放制动施加
vobc.EmergencyBrakingStatus = message.IsTrueForByte(message.GetBit(d, 3)) //紧急制动 vobc.EmergencyBrakingStatus = message.IsTrueForByte(message.GetBit(d, 3)) //紧急制动
vobc.LeftDoorOpenCommand = message.IsTrueForByte(message.GetBit(d, 4)) //开左门允许 vobc.LeftDoorOpenCommand = message.IsTrueForByte(message.GetBit(d, 4)) //开左门允许
@ -373,10 +372,6 @@ func (s *VerifySimulation) TrainPcSimDigitalReportHandle(data []byte) {
// 创建/删除列车 // 创建/删除列车
func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState) { func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState) {
if train.ConnState.ConnType != state_proto.TrainConnState_PC_SIM {
slog.Error("创建移除列车类型不正确 conType:", train.ConnState.ConnType)
return
}
var data byte = 0x01 var data byte = 0x01
if train.ConnState.Conn == false { if train.ConnState.Conn == false {
data = 0x00 data = 0x00