From 7771fcd7777b56d5536e81c0695c46fc07853f99 Mon Sep 17 00:00:00 2001 From: Kevin Joiner <10265309+KevinJoiner@users.noreply.github.com> Date: Tue, 8 Oct 2024 23:05:46 -0400 Subject: [PATCH] remove device battery signal --- pkg/ruptela/multiplier-offset.go | 27 -------------- pkg/ruptela/payload-status_test.go | 1 - pkg/ruptela/schema/ruptela-definitions.yaml | 15 ++++---- pkg/ruptela/vehicle-convert-funcs_gen.go | 7 ---- pkg/ruptela/vehicle-v1-convert_gen.go | 41 --------------------- 5 files changed, 8 insertions(+), 83 deletions(-) diff --git a/pkg/ruptela/multiplier-offset.go b/pkg/ruptela/multiplier-offset.go index b603a29..37a2ead 100644 --- a/pkg/ruptela/multiplier-offset.go +++ b/pkg/ruptela/multiplier-offset.go @@ -131,33 +131,6 @@ func Convert207(rawValue string) (float64, error) { return float64(rawInt)*multiplier + offset, nil } -// Convert30 converts the given raw value to a float64. -// Unit: 'mV' Min: '0' Max: '65535'. -func Convert30(rawValue string) (float64, error) { - const byteSize = 2 - const offset = float64(0) - const nan = 1<<(byteSize*bitsInByte) - 1 - const multiplier = float64(1) - rawInt, err := strconv.ParseUint(rawValue, 16, 64) - if err != nil { - return 0, fmt.Errorf("could not parse uint: %w", err) - } - if rawInt == nan { - return 0, errNotFound - } - - if slices.Contains([]uint64{65535}, rawInt) { - return 0, errNotFound - } - if rawInt < 0 { - return 0, errNotFound - } - if rawInt > 65535 { - return 0, errNotFound - } - return float64(rawInt)*multiplier + offset, nil -} - // Convert483 converts the given raw value to a float64. // Unit: '-' Min: '0' Max: '250'. func Convert483(rawValue string) (float64, error) { diff --git a/pkg/ruptela/payload-status_test.go b/pkg/ruptela/payload-status_test.go index 7b56532..da13713 100644 --- a/pkg/ruptela/payload-status_test.go +++ b/pkg/ruptela/payload-status_test.go @@ -104,7 +104,6 @@ var ( {TokenID: 33, Timestamp: ts, Name: vss.FieldOBDDistanceWithMIL, ValueNumber: 0, Source: "ruptela/TODO"}, {TokenID: 33, Timestamp: ts, Name: vss.FieldPowertrainCombustionEngineTPS, ValueNumber: 0, Source: "ruptela/TODO"}, {TokenID: 33, Timestamp: ts, Name: vss.FieldPowertrainTransmissionTravelledDistance, ValueNumber: 0, Source: "ruptela/TODO"}, - {TokenID: 33, Timestamp: ts, Name: vss.FieldLowVoltageBatteryCurrentVoltage, ValueNumber: 4224, Source: "ruptela/TODO"}, {TokenID: 33, Timestamp: ts, Name: vss.FieldSpeed, ValueNumber: 0, Source: "ruptela/TODO"}, } ) diff --git a/pkg/ruptela/schema/ruptela-definitions.yaml b/pkg/ruptela/schema/ruptela-definitions.yaml index 9a1fb7d..8c62216 100644 --- a/pkg/ruptela/schema/ruptela-definitions.yaml +++ b/pkg/ruptela/schema/ruptela-definitions.yaml @@ -61,13 +61,6 @@ requiredPrivileges: - VEHICLE_NON_LOCATION_DATA -- vspecName: Vehicle.LowVoltageBattery.CurrentVoltage - conversions: - - originalName: "signals.30" # Battery voltage - originalType: string - requiredPrivileges: - - VEHICLE_NON_LOCATION_DATA - - vspecName: Vehicle.OBD.RunTime conversions: - originalName: "signals.107" # OBD time since engine start @@ -188,6 +181,14 @@ originalType: string requiredPrivileges: - VEHICLE_NON_LOCATION_DATA + +# TODO this is the voltage of the device not the vehicle +# - vspecName: Vehicle.LowVoltageBattery.CurrentVoltage +# conversions: +# - originalName: "signals.30" # Battery voltage +# originalType: string +# requiredPrivileges: +# - VEHICLE_NON_LOCATION_DATA # TODO we only get batteryCapacity in percent SOH # - vspecName: Vehicle.Powertrain.TractionBattery.GrossCapacity diff --git a/pkg/ruptela/vehicle-convert-funcs_gen.go b/pkg/ruptela/vehicle-convert-funcs_gen.go index 002bd63..8446539 100644 --- a/pkg/ruptela/vehicle-convert-funcs_gen.go +++ b/pkg/ruptela/vehicle-convert-funcs_gen.go @@ -88,13 +88,6 @@ func ToExteriorAirTemperature0(originalDoc []byte, val string) (float64, error) return Convert97(val) } -// ToLowVoltageBatteryCurrentVoltage0 converts data from field 'signals.30' of type string to 'Vehicle.LowVoltageBattery.CurrentVoltage' of type float64. -// Vehicle.LowVoltageBattery.CurrentVoltage: Current Voltage of the low voltage battery. -// Unit: 'V' -func ToLowVoltageBatteryCurrentVoltage0(originalDoc []byte, val string) (float64, error) { - return Convert30(val) -} - // ToOBDDistanceWithMIL0 converts data from field 'signals.102' of type string to 'Vehicle.OBD.DistanceWithMIL' of type float64. // Vehicle.OBD.DistanceWithMIL: PID 21 - Distance traveled with MIL on // Unit: 'km' diff --git a/pkg/ruptela/vehicle-v1-convert_gen.go b/pkg/ruptela/vehicle-v1-convert_gen.go index 18f9bdc..65b913e 100644 --- a/pkg/ruptela/vehicle-v1-convert_gen.go +++ b/pkg/ruptela/vehicle-v1-convert_gen.go @@ -181,22 +181,6 @@ func SignalsFromV1Data(baseSignal vss.Signal, jsonData []byte) ([]vss.Signal, [] retSignals = append(retSignals, sig) } - val, err = LowVoltageBatteryCurrentVoltageFromV1Data(jsonData) - if err != nil { - if !errors.Is(err, errNotFound) { - errs = append(errs, fmt.Errorf("failed to get 'LowVoltageBatteryCurrentVoltage': %w", err)) - } - } else { - sig := vss.Signal{ - Name: "lowVoltageBatteryCurrentVoltage", - TokenID: baseSignal.TokenID, - Timestamp: baseSignal.Timestamp, - Source: baseSignal.Source, - } - sig.SetValue(val) - retSignals = append(retSignals, sig) - } - val, err = OBDDistanceWithMILFromV1Data(jsonData) if err != nil { if !errors.Is(err, errNotFound) { @@ -641,31 +625,6 @@ func ExteriorAirTemperatureFromV1Data(jsonData []byte) (ret float64, err error) return ret, errs } -// LowVoltageBatteryCurrentVoltageFromV1Data converts the given JSON data to a float64. -func LowVoltageBatteryCurrentVoltageFromV1Data(jsonData []byte) (ret float64, err error) { - var errs error - var result gjson.Result - result = gjson.GetBytes(jsonData, "data.signals.30") - if result.Exists() && result.Value() != nil { - val, ok := result.Value().(string) - if ok { - retVal, err := ToLowVoltageBatteryCurrentVoltage0(jsonData, val) - if err == nil { - return retVal, nil - } - errs = errors.Join(errs, fmt.Errorf("failed to convert 'data.signals.30': %w", err)) - } else { - errs = errors.Join(errs, fmt.Errorf("%w, field 'data.signals.30' is not of type 'string' got '%v' of type '%T'", convert.InvalidTypeError(), result.Value(), result.Value())) - } - } - - if errs == nil { - return ret, fmt.Errorf("%w 'LowVoltageBatteryCurrentVoltage'", errNotFound) - } - - return ret, errs -} - // OBDDistanceWithMILFromV1Data converts the given JSON data to a float64. func OBDDistanceWithMILFromV1Data(jsonData []byte) (ret float64, err error) { var errs error