fix(go): normalize gb32960 realtime vendor fragments
This commit is contained in:
@@ -294,6 +294,9 @@ func mergeParsedForProtocol(protocol envelope.Protocol, existing map[string]any,
|
||||
for _, key := range replaceParsedKeys(protocol, incoming) {
|
||||
out[key] = cloneAny(incoming[key])
|
||||
}
|
||||
if protocol == envelope.ProtocolGB32960 {
|
||||
normalizeGB32960RealtimeParsed(out)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -404,6 +407,59 @@ func strconvAny(value any) string {
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeGB32960RealtimeParsed(parsed map[string]any) {
|
||||
units, ok := asAnySlice(parsed["data_units"])
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
for _, unit := range units {
|
||||
unitMap, ok := unit.(map[string]any)
|
||||
if !ok || strings.TrimSpace(strconvAny(unitMap["name"])) != "gd_fc_stack" {
|
||||
continue
|
||||
}
|
||||
value, ok := unitMap["value"].(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
collapseGDFCStackValue(value)
|
||||
}
|
||||
}
|
||||
|
||||
func collapseGDFCStackValue(value map[string]any) {
|
||||
summaries, ok := asAnySlice(value["summaries"])
|
||||
if !ok || len(summaries) == 0 {
|
||||
return
|
||||
}
|
||||
collapsed := map[string]any{}
|
||||
for _, item := range summaries {
|
||||
summary, ok := item.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for key, fieldValue := range summary {
|
||||
if isGDFCStackFragmentField(key) {
|
||||
continue
|
||||
}
|
||||
collapsed[key] = cloneAny(fieldValue)
|
||||
}
|
||||
}
|
||||
if len(collapsed) == 0 {
|
||||
delete(value, "summaries")
|
||||
return
|
||||
}
|
||||
value["stack_count"] = 1
|
||||
value["summaries"] = []any{collapsed}
|
||||
}
|
||||
|
||||
func isGDFCStackFragmentField(key string) bool {
|
||||
switch key {
|
||||
case "frame_cell_start", "frame_cell_count", "frame_max_cell_voltage_v", "frame_min_cell_voltage_v":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func fieldTimes(fields map[string]any, eventMS int64) map[string]int64 {
|
||||
out := make(map[string]int64, len(fields))
|
||||
for key := range fields {
|
||||
|
||||
Reference in New Issue
Block a user