Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4dcdf00c authored by Enrico Granata's avatar Enrico Granata
Browse files

Stub out VTS testing for OBD2 sensors

This commit adds support to VHAL for returning a live and a freeze OBD2 frame filled in with default placeholder values
It also adds a VTS test to check for OBD2 support. Doing anything more interesting is currently blocked.

Test: make vts BUILD_GOOGLE_VTS=true -j32 && vts-tradefed run commandAndExit vts --skip-all-system-status-check --primary-abi-only --skip-preconditions --module VehicleHidlTest -l INFO
Change-Id: I4aad71f7bb65a690841e74d06fefc5fb2076ce5e
parent 9e8ffba9
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -159,6 +159,18 @@ const VehiclePropConfig kVehicleProperties[] = {
        .prop = VehicleProperty::IGNITION_STATE,
        .access = VehiclePropertyAccess::READ,
        .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
    },

    {
        .prop = VehicleProperty::OBD2_LIVE_FRAME,
        .access = VehiclePropertyAccess::READ,
        .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
    },

    {
        .prop = VehicleProperty::OBD2_FREEZE_FRAME,
        .access = VehiclePropertyAccess::READ,
        .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
    }
};

+80 −0
Original line number Diff line number Diff line
@@ -90,6 +90,14 @@ VehicleHal::VehiclePropValuePtr DefaultVehicleHal::get(
        case VehicleProperty::IGNITION_STATE:
            v = pool.obtainInt32(toInt(VehicleIgnitionState::ACC));
            break;
        case VehicleProperty::OBD2_LIVE_FRAME:
            v = pool.obtainComplex();
            *outStatus = fillObd2LiveFrame(&v);
            break;
        case VehicleProperty::OBD2_FREEZE_FRAME:
            v = pool.obtainComplex();
            *outStatus = fillObd2FreezeFrame(&v);
            break;
        default:
            *outStatus = StatusCode::INVALID_ARG;
    }
@@ -197,6 +205,78 @@ StatusCode DefaultVehicleHal::setHvacDefroster(int32_t areaId, bool value) {
    return StatusCode::OK;
}

static std::vector<int32_t> fillObd2IntValues() {
    std::vector<int32_t> intValues(toInt(Obd2IntegerSensorIndex::LAST_SYSTEM_INDEX));
#define SENSOR(name) toInt(Obd2IntegerSensorIndex:: name)
    intValues[SENSOR(FUEL_SYSTEM_STATUS)] = toInt(FuelSystemStatus::CLOSED_LOOP);
    intValues[SENSOR(MALFUNCTION_INDICATOR_LIGHT_ON)] = 0;
    intValues[SENSOR(IGNITION_MONITORS_SUPPORTED)] = toInt(IgnitionMonitorKind::SPARK);
    intValues[SENSOR(IGNITION_SPECIFIC_MONITORS)] =
        CommonIgnitionMonitors::COMPONENTS_AVAILABLE |
        CommonIgnitionMonitors::MISFIRE_AVAILABLE |
        SparkIgnitionMonitors::AC_REFRIGERANT_AVAILABLE |
        SparkIgnitionMonitors::EVAPORATIVE_SYSTEM_AVAILABLE;
    intValues[SENSOR(INTAKE_AIR_TEMPERATURE)] = 35;
    intValues[SENSOR(COMMANDED_SECONDARY_AIR_STATUS)] =
        toInt(SecondaryAirStatus::FROM_OUTSIDE_OR_OFF);
    intValues[SENSOR(NUM_OXYGEN_SENSORS_PRESENT)] = 1;
    intValues[SENSOR(RUNTIME_SINCE_ENGINE_START)] = 500;
    intValues[SENSOR(DISTANCE_TRAVELED_WITH_MALFUNCTION_INDICATOR_LIGHT_ON)] = 0;
    intValues[SENSOR(WARMUPS_SINCE_CODES_CLEARED)] = 51;
    intValues[SENSOR(DISTANCE_TRAVELED_SINCE_CODES_CLEARED)] = 365;
    intValues[SENSOR(ABSOLUTE_BAROMETRIC_PRESSURE)] = 30;
    intValues[SENSOR(CONTROL_MODULE_VOLTAGE)] = 12;
    intValues[SENSOR(AMBIENT_AIR_TEMPERATURE)] = 18;
    intValues[SENSOR(MAX_FUEL_AIR_EQUIVALENCE_RATIO)] = 1;
    intValues[SENSOR(FUEL_TYPE)] = toInt(FuelType::GASOLINE);
#undef SENSOR
    return intValues;
}

static std::vector<float> fillObd2FloatValues() {
    std::vector<float> floatValues(toInt(Obd2FloatSensorIndex::LAST_SYSTEM_INDEX));
#define SENSOR(name) toInt(Obd2FloatSensorIndex:: name)
    floatValues[SENSOR(CALCULATED_ENGINE_LOAD)] = 0.153;
    floatValues[SENSOR(SHORT_TERM_FUEL_TRIM_BANK1)] = -0.16;
    floatValues[SENSOR(LONG_TERM_FUEL_TRIM_BANK1)] = -0.16;
    floatValues[SENSOR(SHORT_TERM_FUEL_TRIM_BANK2)] = -0.16;
    floatValues[SENSOR(LONG_TERM_FUEL_TRIM_BANK2)] = -0.16;
    floatValues[SENSOR(INTAKE_MANIFOLD_ABSOLUTE_PRESSURE)] = 7.5;
    floatValues[SENSOR(ENGINE_RPM)] = 1250.;
    floatValues[SENSOR(VEHICLE_SPEED)] = 40.;
    floatValues[SENSOR(TIMING_ADVANCE)] = 2.5;
    floatValues[SENSOR(THROTTLE_POSITION)] = 19.75;
    floatValues[SENSOR(OXYGEN_SENSOR1_VOLTAGE)] = 0.265;
    floatValues[SENSOR(FUEL_TANK_LEVEL_INPUT)] = 0.824;
    floatValues[SENSOR(EVAPORATION_SYSTEM_VAPOR_PRESSURE)] = -0.373;
    floatValues[SENSOR(CATALYST_TEMPERATURE_BANK1_SENSOR1)] = 190.;
    floatValues[SENSOR(RELATIVE_THROTTLE_POSITION)] = 3.;
    floatValues[SENSOR(ABSOLUTE_THROTTLE_POSITION_B)] = 0.306;
    floatValues[SENSOR(ACCELERATOR_PEDAL_POSITION_D)] = 0.188;
    floatValues[SENSOR(ACCELERATOR_PEDAL_POSITION_E)] = 0.094;
    floatValues[SENSOR(COMMANDED_THROTTLE_ACTUATOR)] = 0.024;
#undef SENSOR
    return floatValues;
}

StatusCode DefaultVehicleHal::fillObd2LiveFrame(VehiclePropValuePtr* v) {
    static std::vector<int32_t> intValues(fillObd2IntValues());
    static std::vector<float> floatValues(fillObd2FloatValues());
    (*v)->value.int32Values = intValues;
    (*v)->value.floatValues = floatValues;
    return StatusCode::OK;
}

StatusCode DefaultVehicleHal::fillObd2FreezeFrame(VehiclePropValuePtr* v) {
    static std::vector<int32_t> intValues(fillObd2IntValues());
    static std::vector<float> floatValues(fillObd2FloatValues());
    (*v)->value.int32Values = intValues;
    (*v)->value.floatValues = floatValues;
    (*v)->value.stringValue = "P0010";
    return StatusCode::OK;
}


}  // impl

}  // namespace V2_0
+2 −0
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ private:
    StatusCode setHvacTemperature(int32_t areaId, float value);
    StatusCode getHvacDefroster(int32_t areaId, bool* outValue);
    StatusCode setHvacDefroster(int32_t areaId, bool value);
    StatusCode fillObd2LiveFrame (VehiclePropValuePtr* v);
    StatusCode fillObd2FreezeFrame (VehiclePropValuePtr* v);
private:
    int32_t mFanSpeed = 3;
    int32_t mBrightness = 7;
+34 −0
Original line number Diff line number Diff line
@@ -84,6 +84,40 @@ class VehicleHidlTest(base_test_with_webdb.BaseTestWithWebDbClass):

        asserts.assertEqual(0, len(mandatoryProps))

    def getSupportInfo(self):
        """Check whether OBD2_{LIVE|FREEZE}_FRAME is supported."""
        isLiveSupported, isFreezeSupported = False, False
        allConfigs = self.vehicle.getAllPropConfigs()
        for config in allConfigs:
            if config['prop'] == self.vtypes.OBD2_LIVE_FRAME:
                isLiveSupported = True
            elif config['prop'] == self.vtypes.OBD2_FREEZE_FRAME:
                isFreezeSupported = True
            if isLiveSupported and isFreezeSupported:
                break
        return isLiveSupported, isFreezeSupported

    def testObd2SensorProperties(self):
        """Test reading the live and freeze OBD2 frame properties.

        OBD2 (On-Board Diagnostics 2) is the industry standard protocol
        for retrieving diagnostic sensor information from vehicles.
        """
        def checkLiveFrameRead():
            """Validates reading the OBD2_LIVE_FRAME (if available)."""
            logging.info("checkLiveFrameRead no-op pass")

        def checkFreezeFrameRead():
            """Validates reading the OBD2_FREEZE_FRAME (if available)."""
            logging.info("checkLiveFrameRead no-op pass")

        isLiveSupported, isFreezeSupported = self.getSupportInfo()
        logging.info("isLiveSupported = %s, isFreezeSupported = %s",
                     isLiveSupported, isFreezeSupported)
        if isLiveSupported:
            checkLiveFrameRead()
        if isFreezeSupported:
            checkFreezeFrameRead()

if __name__ == "__main__":
    test_runner.main()