feat: parse gb32960 guangdong fuel cell blocks

This commit is contained in:
lingniu
2026-07-01 22:27:34 +08:00
parent 796d79dd30
commit a15de91912
2 changed files with 287 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package gb32960
import (
"encoding/hex"
"fmt"
"math"
"testing"
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
@@ -102,6 +103,9 @@ func TestParseFrameKeepsParsingRealFuelCellReportUntilUnknownExtension(t *testin
assertFloatField(t, env, "fuel_cell_hydrogen_consumption_kg_per_100km", 1.8)
assertFloatField(t, env, envelope.FieldLongitude, 120.800326)
assertFloatField(t, env, envelope.FieldLatitude, 31.634907)
assertFloatField(t, env, "gd_fc_stack_hydrogen_inlet_pressure_kpa", 97.0)
assertFloatField(t, env, "gd_fc_vehicle_hydrogen_mass_kg", 4.3)
assertIntField(t, env, "gd_fc_demo_stack_temp_c", 65)
units, ok := env.Parsed["data_units"].([]map[string]any)
if !ok {
@@ -111,7 +115,7 @@ func TestParseFrameKeepsParsingRealFuelCellReportUntilUnknownExtension(t *testin
for _, unit := range units {
gotTypes = append(gotTypes, fmt.Sprint(unit["type"]))
}
wantTypes := []string{"0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x30"}
wantTypes := []string{"0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x30", "0x31", "0x32", "0x33", "0x34", "0x80", "0x83"}
if fmt.Sprint(gotTypes) != fmt.Sprint(wantTypes) {
t.Fatalf("unit types = %v, want %v", gotTypes, wantTypes)
}
@@ -121,8 +125,18 @@ func TestParseFrameKeepsParsingRealFuelCellReportUntilUnknownExtension(t *testin
if units[2]["name"] != "fuel_cell" {
t.Fatalf("unexpected fuel cell unit: %#v", units[2])
}
if units[9]["parse"] != "unknown_unit" {
t.Fatalf("unexpected unknown unit: %#v", units[9])
if units[9]["name"] != "gd_fc_stack" {
t.Fatalf("unexpected gd stack unit: %#v", units[9])
}
if units[10]["name"] != "gd_fc_auxiliary" {
t.Fatalf("unexpected gd auxiliary unit: %#v", units[10])
}
if units[15]["name"] != "gd_fc_vendor_tlv" {
t.Fatalf("unexpected gd vendor tlv unit: %#v", units[15])
}
tlv := units[15]["value"].(map[string]any)
if tlv["declared_length"] != 36 {
t.Fatalf("unexpected vendor tlv: %#v", tlv)
}
}
@@ -132,6 +146,17 @@ func assertFloatField(t *testing.T, env envelope.FrameEnvelope, key string, want
if !ok {
t.Fatalf("field %s missing or not float64: %#v", key, env.Fields[key])
}
if math.Abs(got-want) > 0.000001 {
t.Fatalf("field %s = %v, want %v", key, got, want)
}
}
func assertIntField(t *testing.T, env envelope.FrameEnvelope, key string, want int) {
t.Helper()
got, ok := env.Fields[key].(int)
if !ok {
t.Fatalf("field %s missing or not int: %#v", key, env.Fields[key])
}
if got != want {
t.Fatalf("field %s = %v, want %v", key, got, want)
}