Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ #include <android-base/logging.h> #include <utils/SystemClock.h> #include "DefaultConfig.h" #include "EmulatedVehicleConnector.h" #include "JsonFakeValueGenerator.h" #include "LinearFakeValueGenerator.h" Loading @@ -39,6 +38,10 @@ EmulatedUserHal* EmulatedVehicleConnector::getEmulatedUserHal() { return &mEmulatedUserHal; } void EmulatedVehicleConnector::triggerSendAllValues() { sendAllValuesToClient(); } StatusCode EmulatedVehicleConnector::onSetProperty(const VehiclePropValue& value, bool updateStatus) { if (mEmulatedUserHal.isSupported(value.prop)) { Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.h +3 −1 Original line number Diff line number Diff line Loading @@ -33,11 +33,13 @@ namespace impl { class EmulatedVehicleConnector : public IPassThroughConnector<VehicleHalClient, VehicleHalServer> { public: EmulatedVehicleConnector() {} EmulatedVehicleConnector() = default; EmulatedUserHal* getEmulatedUserHal(); // Methods from VehicleHalServer void triggerSendAllValues() override; StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) override; bool onDump(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override; Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +22 −35 Original line number Diff line number Diff line Loading @@ -105,9 +105,6 @@ EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleH mVehicleClient(client), mEmulatedUserHal(emulatedUserHal) { initStaticConfig(); for (size_t i = 0; i < arraysize(kVehicleProperties); i++) { mPropStore->registerProperty(kVehicleProperties[i].config); } mVehicleClient->registerPropertyValueCallback(std::bind(&EmulatedVehicleHal::onPropertyValue, this, std::placeholders::_1, std::placeholders::_2)); Loading Loading @@ -180,7 +177,13 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( v = getValuePool()->obtain(*internalPropValue); } *outStatus = v != nullptr ? StatusCode::OK : StatusCode::INVALID_ARG; if (!v) { *outStatus = StatusCode::INVALID_ARG; } else if (v->status == VehiclePropertyStatus::AVAILABLE) { *outStatus = StatusCode::OK; } else { *outStatus = StatusCode::TRY_AGAIN; } break; } if (v.get()) { Loading Loading @@ -280,57 +283,41 @@ static bool isDiagnosticProperty(VehiclePropConfig propConfig) { void EmulatedVehicleHal::onCreate() { static constexpr bool shouldUpdateStatus = true; for (auto& it : kVehicleProperties) { VehiclePropConfig cfg = it.config; int32_t numAreas = cfg.areaConfigs.size(); auto configs = mVehicleClient->getAllPropertyConfig(); for (const auto& cfg : configs) { if (isDiagnosticProperty(cfg)) { // do not write an initial empty value for the diagnostic properties // as we will initialize those separately. continue; } // A global property will have only a single area if (isGlobalProp(cfg.prop)) { numAreas = 1; } int32_t numAreas = isGlobalProp(cfg.prop) ? 0 : cfg.areaConfigs.size(); for (int i = 0; i < numAreas; i++) { int32_t curArea; if (isGlobalProp(cfg.prop)) { curArea = 0; } else { curArea = cfg.areaConfigs[i].areaId; } int32_t curArea = isGlobalProp(cfg.prop) ? 0 : cfg.areaConfigs[i].areaId; // Create a separate instance for each individual zone VehiclePropValue prop = { .areaId = curArea, .prop = cfg.prop, .status = VehiclePropertyStatus::UNAVAILABLE, }; if (it.initialAreaValues.size() > 0) { auto valueForAreaIt = it.initialAreaValues.find(curArea); if (valueForAreaIt != it.initialAreaValues.end()) { prop.value = valueForAreaIt->second; } else { ALOGW("%s failed to get default value for prop 0x%x area 0x%x", __func__, cfg.prop, curArea); } } else { prop.value = it.initialValue; if (mInitVhalValueOverride) { for (auto& itOverride : mVehiclePropertiesOverride) { if (itOverride.prop == cfg.prop) { prop.status = VehiclePropertyStatus::AVAILABLE; prop.value = itOverride.value; } } } } mPropStore->writeValue(prop, shouldUpdateStatus); } } mVehicleClient->triggerSendAllValues(); initObd2LiveFrame(*mPropStore->getConfigOrDie(OBD2_LIVE_FRAME)); initObd2FreezeFrame(*mPropStore->getConfigOrDie(OBD2_FREEZE_FRAME)); mInEmulator = isInEmulator(); Loading Loading @@ -414,8 +401,8 @@ void EmulatedVehicleHal::onPropertyValue(const VehiclePropValue& value, bool upd } void EmulatedVehicleHal::initStaticConfig() { for (auto&& it = std::begin(kVehicleProperties); it != std::end(kVehicleProperties); ++it) { const auto& cfg = it->config; auto configs = mVehicleClient->getAllPropertyConfig(); for (auto&& cfg : configs) { VehiclePropertyStore::TokenFunction tokenFunction = nullptr; switch (cfg.prop) { Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.h +1 −1 Original line number Diff line number Diff line Loading @@ -29,10 +29,10 @@ #include <vhal_v2_0/VehicleHal.h> #include "vhal_v2_0/VehiclePropertyStore.h" #include "DefaultConfig.h" #include "EmulatedUserHal.h" #include "EmulatedVehicleConnector.h" #include "GeneratorHub.h" #include "PropertyUtils.h" #include "VehicleEmulator.h" namespace android { Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/VehicleHalClient.h +4 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,10 @@ class VehicleHalClient : public IVehicleClient { // Type of callback function for handling the new property values using PropertyCallBackType = std::function<void(const VehiclePropValue&, bool updateStatus)>; // The server will call sendAllValuesToClient, onPropertyValue will be called when values are // received. virtual void triggerSendAllValues() = 0; // Method from IVehicleClient void onPropertyValue(const VehiclePropValue& value, bool updateStatus) override; Loading Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ #include <android-base/logging.h> #include <utils/SystemClock.h> #include "DefaultConfig.h" #include "EmulatedVehicleConnector.h" #include "JsonFakeValueGenerator.h" #include "LinearFakeValueGenerator.h" Loading @@ -39,6 +38,10 @@ EmulatedUserHal* EmulatedVehicleConnector::getEmulatedUserHal() { return &mEmulatedUserHal; } void EmulatedVehicleConnector::triggerSendAllValues() { sendAllValuesToClient(); } StatusCode EmulatedVehicleConnector::onSetProperty(const VehiclePropValue& value, bool updateStatus) { if (mEmulatedUserHal.isSupported(value.prop)) { Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.h +3 −1 Original line number Diff line number Diff line Loading @@ -33,11 +33,13 @@ namespace impl { class EmulatedVehicleConnector : public IPassThroughConnector<VehicleHalClient, VehicleHalServer> { public: EmulatedVehicleConnector() {} EmulatedVehicleConnector() = default; EmulatedUserHal* getEmulatedUserHal(); // Methods from VehicleHalServer void triggerSendAllValues() override; StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) override; bool onDump(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override; Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +22 −35 Original line number Diff line number Diff line Loading @@ -105,9 +105,6 @@ EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleH mVehicleClient(client), mEmulatedUserHal(emulatedUserHal) { initStaticConfig(); for (size_t i = 0; i < arraysize(kVehicleProperties); i++) { mPropStore->registerProperty(kVehicleProperties[i].config); } mVehicleClient->registerPropertyValueCallback(std::bind(&EmulatedVehicleHal::onPropertyValue, this, std::placeholders::_1, std::placeholders::_2)); Loading Loading @@ -180,7 +177,13 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( v = getValuePool()->obtain(*internalPropValue); } *outStatus = v != nullptr ? StatusCode::OK : StatusCode::INVALID_ARG; if (!v) { *outStatus = StatusCode::INVALID_ARG; } else if (v->status == VehiclePropertyStatus::AVAILABLE) { *outStatus = StatusCode::OK; } else { *outStatus = StatusCode::TRY_AGAIN; } break; } if (v.get()) { Loading Loading @@ -280,57 +283,41 @@ static bool isDiagnosticProperty(VehiclePropConfig propConfig) { void EmulatedVehicleHal::onCreate() { static constexpr bool shouldUpdateStatus = true; for (auto& it : kVehicleProperties) { VehiclePropConfig cfg = it.config; int32_t numAreas = cfg.areaConfigs.size(); auto configs = mVehicleClient->getAllPropertyConfig(); for (const auto& cfg : configs) { if (isDiagnosticProperty(cfg)) { // do not write an initial empty value for the diagnostic properties // as we will initialize those separately. continue; } // A global property will have only a single area if (isGlobalProp(cfg.prop)) { numAreas = 1; } int32_t numAreas = isGlobalProp(cfg.prop) ? 0 : cfg.areaConfigs.size(); for (int i = 0; i < numAreas; i++) { int32_t curArea; if (isGlobalProp(cfg.prop)) { curArea = 0; } else { curArea = cfg.areaConfigs[i].areaId; } int32_t curArea = isGlobalProp(cfg.prop) ? 0 : cfg.areaConfigs[i].areaId; // Create a separate instance for each individual zone VehiclePropValue prop = { .areaId = curArea, .prop = cfg.prop, .status = VehiclePropertyStatus::UNAVAILABLE, }; if (it.initialAreaValues.size() > 0) { auto valueForAreaIt = it.initialAreaValues.find(curArea); if (valueForAreaIt != it.initialAreaValues.end()) { prop.value = valueForAreaIt->second; } else { ALOGW("%s failed to get default value for prop 0x%x area 0x%x", __func__, cfg.prop, curArea); } } else { prop.value = it.initialValue; if (mInitVhalValueOverride) { for (auto& itOverride : mVehiclePropertiesOverride) { if (itOverride.prop == cfg.prop) { prop.status = VehiclePropertyStatus::AVAILABLE; prop.value = itOverride.value; } } } } mPropStore->writeValue(prop, shouldUpdateStatus); } } mVehicleClient->triggerSendAllValues(); initObd2LiveFrame(*mPropStore->getConfigOrDie(OBD2_LIVE_FRAME)); initObd2FreezeFrame(*mPropStore->getConfigOrDie(OBD2_FREEZE_FRAME)); mInEmulator = isInEmulator(); Loading Loading @@ -414,8 +401,8 @@ void EmulatedVehicleHal::onPropertyValue(const VehiclePropValue& value, bool upd } void EmulatedVehicleHal::initStaticConfig() { for (auto&& it = std::begin(kVehicleProperties); it != std::end(kVehicleProperties); ++it) { const auto& cfg = it->config; auto configs = mVehicleClient->getAllPropertyConfig(); for (auto&& cfg : configs) { VehiclePropertyStore::TokenFunction tokenFunction = nullptr; switch (cfg.prop) { Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.h +1 −1 Original line number Diff line number Diff line Loading @@ -29,10 +29,10 @@ #include <vhal_v2_0/VehicleHal.h> #include "vhal_v2_0/VehiclePropertyStore.h" #include "DefaultConfig.h" #include "EmulatedUserHal.h" #include "EmulatedVehicleConnector.h" #include "GeneratorHub.h" #include "PropertyUtils.h" #include "VehicleEmulator.h" namespace android { Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/VehicleHalClient.h +4 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,10 @@ class VehicleHalClient : public IVehicleClient { // Type of callback function for handling the new property values using PropertyCallBackType = std::function<void(const VehiclePropValue&, bool updateStatus)>; // The server will call sendAllValuesToClient, onPropertyValue will be called when values are // received. virtual void triggerSendAllValues() = 0; // Method from IVehicleClient void onPropertyValue(const VehiclePropValue& value, bool updateStatus) override; Loading