列车发送ws 调整
This commit is contained in:
parent
c2a2332ff1
commit
890ce83020
|
@ -2,7 +2,9 @@ package message_server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -409,18 +411,30 @@ func convertDynamicConfig(config *common_proto.TrainDynamicConfig, dest *state_p
|
||||||
field := configType.Field(index)
|
field := configType.Field(index)
|
||||||
if field.IsExported() {
|
if field.IsExported() {
|
||||||
fieldName := field.Name
|
fieldName := field.Name
|
||||||
destVal := reflect.ValueOf(dest).Elem().FieldByName(fieldName)
|
setVal(config, dest, fieldName)
|
||||||
sourceData := reflect.ValueOf(config).Elem().FieldByName(fieldName).Interface()
|
|
||||||
|
|
||||||
if destVal.Kind() == reflect.String {
|
|
||||||
destVal.Set(reflect.ValueOf(fmt.Sprintf("%v", sourceData)))
|
|
||||||
} else {
|
|
||||||
destVal.Set(reflect.ValueOf(sourceData))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setVal(source, dest interface{}, fieldName string) {
|
||||||
|
destVal := reflect.ValueOf(dest).Elem().FieldByName(fieldName)
|
||||||
|
sourceType := reflect.ValueOf(source).Elem().FieldByName(fieldName)
|
||||||
|
sourceData := sourceType.Interface()
|
||||||
|
defer func() {
|
||||||
|
err := recover()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error(fieldName, "赋值失败,源数据类型", sourceType.Kind().String(), "目标数据类型:", destVal.Kind().String(), " 异常错误提示:", err)
|
||||||
|
debug.PrintStack()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if destVal.Kind() == reflect.String {
|
||||||
|
destVal.Set(reflect.ValueOf(fmt.Sprintf("%v", sourceData)))
|
||||||
|
} else {
|
||||||
|
destVal.Set(reflect.ValueOf(sourceData))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func convertEnds(ends *common_proto.TrainEndsState) *state_proto.TrainEndsStateMqtt {
|
func convertEnds(ends *common_proto.TrainEndsState) *state_proto.TrainEndsStateMqtt {
|
||||||
return &state_proto.TrainEndsStateMqtt{SpeedSensorEnableA: ends.SpeedSensorEnableA,
|
return &state_proto.TrainEndsStateMqtt{SpeedSensorEnableA: ends.SpeedSensorEnableA,
|
||||||
SpeedSensorEnableB: ends.SpeedSensorEnableB,
|
SpeedSensorEnableB: ends.SpeedSensorEnableB,
|
||||||
|
|
Loading…
Reference in New Issue