列车发送ws 调整
This commit is contained in:
parent
890ce83020
commit
a7edde37cd
@ -8,8 +8,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"joylink.club/bj-rtsts-server/dto/common_proto"
|
||||
|
||||
"joylink.club/bj-rtsts-server/dto/request_proto"
|
||||
"joylink.club/bj-rtsts-server/dto/state_proto"
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
@ -396,16 +394,17 @@ func convertTrainState(v *state_proto.TrainState) *state_proto.TrainMapState {
|
||||
RightDoorCloseCommand: v.VobcState.RightDoorCloseCommand,
|
||||
AllDoorClose: v.VobcState.AllDoorClose,
|
||||
VobcInterruption: v.VobcState.UdpInterruption,
|
||||
TrainEndsA: convertEnds(v.TrainEndsA),
|
||||
TrainEndsB: convertEnds(v.TrainEndsB),
|
||||
TrainEndsA: &state_proto.TrainEndsStateMqtt{},
|
||||
TrainEndsB: &state_proto.TrainEndsStateMqtt{},
|
||||
TrainDynamicConfig: &state_proto.TrainDynamicConfigMqtt{},
|
||||
}
|
||||
trainConfig := &state_proto.TrainDynamicConfigMqtt{}
|
||||
convertDynamicConfig(v.TrainDynamicConfig, trainConfig)
|
||||
t.TrainDynamicConfig = trainConfig
|
||||
convertDynamicConfig(v.TrainDynamicConfig, t.TrainDynamicConfig)
|
||||
convertDynamicConfig(v.TrainEndsA, t.TrainEndsA)
|
||||
convertDynamicConfig(v.TrainEndsB, t.TrainEndsB)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func convertDynamicConfig(config *common_proto.TrainDynamicConfig, dest *state_proto.TrainDynamicConfigMqtt) {
|
||||
func convertDynamicConfig(config, dest interface{}) {
|
||||
configType := reflect.TypeOf(config).Elem()
|
||||
for index := 0; index < configType.NumField(); index++ {
|
||||
field := configType.Field(index)
|
||||
@ -416,6 +415,17 @@ func convertDynamicConfig(config *common_proto.TrainDynamicConfig, dest *state_p
|
||||
}
|
||||
}
|
||||
|
||||
/*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) {
|
||||
destVal := reflect.ValueOf(dest).Elem().FieldByName(fieldName)
|
||||
sourceType := reflect.ValueOf(source).Elem().FieldByName(fieldName)
|
||||
@ -435,18 +445,19 @@ func setVal(source, dest interface{}, fieldName string) {
|
||||
}
|
||||
}
|
||||
|
||||
func convertEnds(ends *common_proto.TrainEndsState) *state_proto.TrainEndsStateMqtt {
|
||||
return &state_proto.TrainEndsStateMqtt{SpeedSensorEnableA: ends.SpeedSensorEnableA,
|
||||
SpeedSensorEnableB: ends.SpeedSensorEnableB,
|
||||
RadarEnable: ends.RadarEnable,
|
||||
RadarCheckSpeedDiff: floatToString(ends.RadarCheckSpeedDiff),
|
||||
RadarCheckTime: ends.RadarCheckTime,
|
||||
AccEnable: ends.AccEnable,
|
||||
AccCheckSpeedDiff: floatToString(ends.AccCheckSpeedDiff),
|
||||
AccCheckTime: ends.AccCheckTime,
|
||||
/*
|
||||
func convertEnds(ends *common_proto.TrainEndsState) *state_proto.TrainEndsStateMqtt {
|
||||
return &state_proto.TrainEndsStateMqtt{SpeedSensorEnableA: ends.SpeedSensorEnableA,
|
||||
SpeedSensorEnableB: ends.SpeedSensorEnableB,
|
||||
RadarEnable: ends.RadarEnable,
|
||||
RadarCheckSpeedDiff: floatToString(ends.RadarCheckSpeedDiff),
|
||||
RadarCheckTime: ends.RadarCheckTime,
|
||||
AccEnable: ends.AccEnable,
|
||||
AccCheckSpeedDiff: floatToString(ends.AccCheckSpeedDiff),
|
||||
AccCheckTime: ends.AccCheckTime,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
func floatToString(f float32) string {
|
||||
return fmt.Sprintf("%v", f)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user