列车发送ws 调整
This commit is contained in:
parent
c2a2332ff1
commit
890ce83020
|
@ -2,7 +2,9 @@ package message_server
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -409,16 +411,28 @@ func convertDynamicConfig(config *common_proto.TrainDynamicConfig, dest *state_p
|
|||
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)
|
||||
sourceData := reflect.ValueOf(config).Elem().FieldByName(fieldName).Interface()
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue