From 4f2cded76074b30d8cb8ecb09d205c85da096387 Mon Sep 17 00:00:00 2001 From: lingniu Date: Thu, 2 Jul 2026 01:08:59 +0800 Subject: [PATCH] fix: treat yutong mqtt mileage as meters --- .../internal/protocol/yutongmqtt/parser.go | 5 +---- .../internal/protocol/yutongmqtt/parser_test.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/go/vehicle-gateway/internal/protocol/yutongmqtt/parser.go b/go/vehicle-gateway/internal/protocol/yutongmqtt/parser.go index 09f1f822..ebfc786c 100644 --- a/go/vehicle-gateway/internal/protocol/yutongmqtt/parser.go +++ b/go/vehicle-gateway/internal/protocol/yutongmqtt/parser.go @@ -197,8 +197,5 @@ func looksLikeVIN(value string) bool { } func normalizeTotalMileageKM(value float64) float64 { - if value > 1_000_000 { - return value / 1000 - } - return value + return value / 1000 } diff --git a/go/vehicle-gateway/internal/protocol/yutongmqtt/parser_test.go b/go/vehicle-gateway/internal/protocol/yutongmqtt/parser_test.go index 91b5ef54..7d56993f 100644 --- a/go/vehicle-gateway/internal/protocol/yutongmqtt/parser_test.go +++ b/go/vehicle-gateway/internal/protocol/yutongmqtt/parser_test.go @@ -36,7 +36,7 @@ func TestParseMessageMapsYutongPayloadToEnvelope(t *testing.T) { t.Fatalf("plate = %q", env.Plate) } assertFloatField(t, env, envelope.FieldSpeedKMH, 52.3) - assertFloatField(t, env, envelope.FieldTotalMileageKM, 123456.7) + assertFloatField(t, env, envelope.FieldTotalMileageKM, 123.4567) assertFloatField(t, env, envelope.FieldSOCPercent, 70) assertFloatField(t, env, envelope.FieldLongitude, 116.397128) assertFloatField(t, env, envelope.FieldLatitude, 39.916527) @@ -80,6 +80,19 @@ func TestParseMessageNormalizesProductionMileageMeters(t *testing.T) { } } +func TestParseMessageTreatsSmallYutongMileageAsMeters(t *testing.T) { + payload := []byte(`{ + "device":"LMRKH9AC3R1004101", + "time":"2026-07-02 01:02:04.085", + "data":{"TOTAL_MILEAGE":1024,"METER_SPEED":19} + }`) + env, err := ParseMessage("yutong", "/ytforward/shln/1", payload, 1782940000000) + if err != nil { + t.Fatalf("ParseMessage() error = %v", err) + } + assertFloatField(t, env, envelope.FieldTotalMileageKM, 1.024) +} + func TestParseMessageRejectsMalformedJSON(t *testing.T) { _, err := ParseMessage("endpoint-a", "/bad", []byte("{bad-json"), 1782745114999) if !errors.Is(err, ErrInvalidJSON) {