From a7edde37cde151dcfdd149a763ea5b11e547c5d7 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Tue, 30 Jan 2024 13:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BD=A6=E5=8F=91=E9=80=81ws=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- message_server/sfp_ms.go | 51 ++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/message_server/sfp_ms.go b/message_server/sfp_ms.go index 1559b26..e5359de 100644 --- a/message_server/sfp_ms.go +++ b/message_server/sfp_ms.go @@ -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) }