diff --git a/go/vehicle-gateway/internal/realtime/snapshot_writer.go b/go/vehicle-gateway/internal/realtime/snapshot_writer.go index b7bf8c40..d1da9c78 100644 --- a/go/vehicle-gateway/internal/realtime/snapshot_writer.go +++ b/go/vehicle-gateway/internal/realtime/snapshot_writer.go @@ -35,6 +35,9 @@ func (w *SnapshotWriter) Update(ctx context.Context, env envelope.FrameEnvelope) if vehicleKey == "" || strings.HasSuffix(vehicleKey, ":unknown") { return nil } + if !hasRealtimePayload(env) { + return nil + } fieldsJSON, err := marshalObject(env.Fields) if err != nil { return err @@ -82,6 +85,16 @@ func nullableTime(ms int64) any { return time.UnixMilli(ms) } +func hasRealtimePayload(env envelope.FrameEnvelope) bool { + if len(env.Fields) > 0 { + return true + } + if _, ok := env.Parsed["data_units"]; ok { + return true + } + return false +} + const realtimeSnapshotTableSQL = `CREATE TABLE IF NOT EXISTS vehicle_realtime_snapshot ( id BIGINT PRIMARY KEY AUTO_INCREMENT, protocol VARCHAR(32) NOT NULL, diff --git a/go/vehicle-gateway/internal/realtime/snapshot_writer_test.go b/go/vehicle-gateway/internal/realtime/snapshot_writer_test.go index 243e6792..48374c39 100644 --- a/go/vehicle-gateway/internal/realtime/snapshot_writer_test.go +++ b/go/vehicle-gateway/internal/realtime/snapshot_writer_test.go @@ -75,6 +75,29 @@ func TestSnapshotWriterSkipsUnknownVehicleKey(t *testing.T) { } } +func TestSnapshotWriterSkipsGB32960HeartbeatWithoutRealtimePayload(t *testing.T) { + exec := &recordingSnapshotExec{} + writer := NewSnapshotWriter(exec) + + if err := writer.Update(context.Background(), envelope.FrameEnvelope{ + Protocol: envelope.ProtocolGB32960, + MessageID: "0x07", + VIN: "ABCDE600000000009", + Parsed: map[string]any{ + "header": map[string]any{ + "vin": "ABCDE600000000009", + "command": "0x07", + "actual_body_length": 0, + }, + }, + }); err != nil { + t.Fatalf("Update() error = %v", err) + } + if len(exec.calls) != 0 { + t.Fatalf("exec calls = %d, want 0", len(exec.calls)) + } +} + type recordingSnapshotExec struct { calls []snapshotExecCall }