diff options
5 files changed, 92 insertions, 97 deletions
diff --git a/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehicleConnector.h b/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehicleConnector.h index 56ecd67ea2..d40f122741 100644 --- a/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehicleConnector.h +++ b/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VehicleConnector.h @@ -57,10 +57,14 @@ class IVehicleClient { virtual std::vector<VehiclePropConfig> getAllPropertyConfig() const = 0; // Send the set property request to server - virtual StatusCode setProperty(const VehiclePropValue& value) = 0; + // updateStatus indicate if VHal should change the status of the value + // it should be false except injecting values for e2e tests + virtual StatusCode setProperty(const VehiclePropValue& value, bool updateStatus) = 0; // Receive a new property value from server - virtual void onPropertyValue(const VehiclePropValue& value) = 0; + // updateStatus is true if and only if the value is + // generated by car (ECU/fake generator/injected) + virtual void onPropertyValue(const VehiclePropValue& value, bool updateStatus) = 0; }; /** @@ -84,11 +88,15 @@ class IVehicleServer { // Receive the set property request from HAL. // Process the setting and return the status code - virtual StatusCode onSetProperty(const VehiclePropValue& value) = 0; + // updateStatus indicate if VHal should change the status of the value + // it should be false except injecting values for e2e tests + virtual StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) = 0; // Receive a new property value from car (via direct connection to the car bus or the emulator) // and forward the value to HAL - virtual void onPropertyValueFromCar(const VehiclePropValue& value) = 0; + // updateStatus is true if and only if the value is + // generated by car (ECU/fake generator/injected) + virtual void onPropertyValueFromCar(const VehiclePropValue& value, bool updateStatus) = 0; }; /** @@ -118,12 +126,12 @@ class IPassThroughConnector : public VehicleClientType, public VehicleServerType return this->onGetAllPropertyConfig(); } - StatusCode setProperty(const VehiclePropValue& value) override { - return this->onSetProperty(value); + StatusCode setProperty(const VehiclePropValue& value, bool updateStatus) override { + return this->onSetProperty(value, updateStatus); } - void onPropertyValueFromCar(const VehiclePropValue& value) override { - return this->onPropertyValue(value); + void onPropertyValueFromCar(const VehiclePropValue& value, bool updateStatus) override { + return this->onPropertyValue(value, updateStatus); } // To be implemented: diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.cpp index 168999d829..222fe5e21f 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.cpp +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.cpp @@ -30,12 +30,12 @@ namespace V2_0 { namespace impl { -void EmulatedVehicleClient::onPropertyValue(const VehiclePropValue& value) { +void EmulatedVehicleClient::onPropertyValue(const VehiclePropValue& value, bool updateStatus) { if (!mPropCallback) { LOG(ERROR) << __func__ << ": PropertyCallBackType is not registered!"; return; } - return mPropCallback(value); + return mPropCallback(value, updateStatus); } void EmulatedVehicleClient::registerPropertyValueCallback(PropertyCallBackType&& callback) { @@ -65,12 +65,13 @@ void EmulatedVehicleServer::setValuePool(VehiclePropValuePool* valuePool) { } void EmulatedVehicleServer::onFakeValueGenerated(const VehiclePropValue& value) { + constexpr bool updateStatus = true; LOG(DEBUG) << __func__ << ": " << toString(value); auto updatedPropValue = getValuePool()->obtain(value); if (updatedPropValue) { updatedPropValue->timestamp = value.timestamp; updatedPropValue->status = VehiclePropertyStatus::AVAILABLE; - onPropertyValueFromCar(*updatedPropValue); + onPropertyValueFromCar(*updatedPropValue, updateStatus); } } @@ -86,6 +87,8 @@ std::vector<VehiclePropConfig> EmulatedVehicleServer::onGetAllPropertyConfig() c } StatusCode EmulatedVehicleServer::handleGenerateFakeDataRequest(const VehiclePropValue& request) { + constexpr bool updateStatus = true; + LOG(INFO) << __func__; const auto& v = request.value; if (!v.int32Values.size()) { @@ -153,9 +156,11 @@ StatusCode EmulatedVehicleServer::handleGenerateFakeDataRequest(const VehiclePro int32_t display = request.value.int32Values[3]; // Send back to HAL onPropertyValueFromCar( - *createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_DOWN, keyCode, display)); + *createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_DOWN, keyCode, display), + updateStatus); onPropertyValueFromCar( - *createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_UP, keyCode, display)); + *createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_UP, keyCode, display), + updateStatus); break; } default: { @@ -191,9 +196,41 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleServer::createHwInputKeyProp( return keyEvent; } -StatusCode EmulatedVehicleServer::onSetProperty(const VehiclePropValue& value) { +StatusCode EmulatedVehicleServer::onSetProperty(const VehiclePropValue& value, bool updateStatus) { // Some properties need to be treated non-trivially switch (value.prop) { + case kGenerateFakeDataControllingProperty: + return handleGenerateFakeDataRequest(value); + + // set the value from vehcile side, used in end to end test. + case kSetIntPropertyFromVehcileForTest: { + auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::INT32, 1); + updatedPropValue->prop = value.value.int32Values[0]; + updatedPropValue->value.int32Values[0] = value.value.int32Values[1]; + updatedPropValue->timestamp = value.value.int64Values[0]; + updatedPropValue->areaId = value.areaId; + onPropertyValueFromCar(*updatedPropValue, updateStatus); + return StatusCode::OK; + } + case kSetFloatPropertyFromVehcileForTest: { + auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::FLOAT, 1); + updatedPropValue->prop = value.value.int32Values[0]; + updatedPropValue->value.floatValues[0] = value.value.floatValues[0]; + updatedPropValue->timestamp = value.value.int64Values[0]; + updatedPropValue->areaId = value.areaId; + onPropertyValueFromCar(*updatedPropValue, updateStatus); + return StatusCode::OK; + } + case kSetBooleanPropertyFromVehcileForTest: { + auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::BOOLEAN, 1); + updatedPropValue->prop = value.value.int32Values[1]; + updatedPropValue->value.int32Values[0] = value.value.int32Values[0]; + updatedPropValue->timestamp = value.value.int64Values[0]; + updatedPropValue->areaId = value.areaId; + onPropertyValueFromCar(*updatedPropValue, updateStatus); + return StatusCode::OK; + } + case AP_POWER_STATE_REPORT: switch (value.value.int32Values[0]) { case toInt(VehicleApPowerStateReport::DEEP_SLEEP_EXIT): @@ -201,15 +238,18 @@ StatusCode EmulatedVehicleServer::onSetProperty(const VehiclePropValue& value) { case toInt(VehicleApPowerStateReport::WAIT_FOR_VHAL): // CPMS is in WAIT_FOR_VHAL state, simply move to ON // Send back to HAL - onPropertyValueFromCar( - *createApPowerStateReq(VehicleApPowerStateReq::ON, 0)); + // ALWAYS update status for generated property value + onPropertyValueFromCar(*createApPowerStateReq(VehicleApPowerStateReq::ON, 0), + true /* updateStatus */); break; case toInt(VehicleApPowerStateReport::DEEP_SLEEP_ENTRY): case toInt(VehicleApPowerStateReport::SHUTDOWN_START): // CPMS is in WAIT_FOR_FINISH state, send the FINISHED command // Send back to HAL + // ALWAYS update status for generated property value onPropertyValueFromCar( - *createApPowerStateReq(VehicleApPowerStateReq::FINISHED, 0)); + *createApPowerStateReq(VehicleApPowerStateReq::FINISHED, 0), + true /* updateStatus */); break; case toInt(VehicleApPowerStateReport::ON): case toInt(VehicleApPowerStateReport::SHUTDOWN_POSTPONE): @@ -226,19 +266,12 @@ StatusCode EmulatedVehicleServer::onSetProperty(const VehiclePropValue& value) { } // In the real vhal, the value will be sent to Car ECU. - // We just pretend it is done here. - return StatusCode::OK; -} + // We just pretend it is done here and send back to HAL + auto updatedPropValue = getValuePool()->obtain(value); + updatedPropValue->timestamp = elapsedRealtimeNano(); -StatusCode EmulatedVehicleServer::onSetPropertyFromVehicle(const VehiclePropValue& value) { - if (value.prop == kGenerateFakeDataControllingProperty) { - auto status = handleGenerateFakeDataRequest(value); - return status; - } else { - // Send back to HAL - onPropertyValueFromCar(value); - return StatusCode::OK; - } + onPropertyValueFromCar(*updatedPropValue, updateStatus); + return StatusCode::OK; } EmulatedPassthroughConnectorPtr makeEmulatedPassthroughConnector() { diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.h b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.h index d424cd83e7..5fc6493ba5 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.h +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleConnector.h @@ -35,13 +35,10 @@ namespace impl { class EmulatedVehicleClient : public IVehicleClient { public: // Type of callback function for handling the new property values - using PropertyCallBackType = std::function<void(const VehiclePropValue&)>; + using PropertyCallBackType = std::function<void(const VehiclePropValue&, bool updateStatus)>; // Method from IVehicleClient - void onPropertyValue(const VehiclePropValue& value) override; - - // Request to change the value on the VEHICLE side (for testing) - virtual StatusCode setPropertyFromVehicle(const VehiclePropValue& value) = 0; + void onPropertyValue(const VehiclePropValue& value, bool updateStatus) override; void registerPropertyValueCallback(PropertyCallBackType&& callback); @@ -55,10 +52,7 @@ class EmulatedVehicleServer : public IVehicleServer { std::vector<VehiclePropConfig> onGetAllPropertyConfig() const override; - StatusCode onSetProperty(const VehiclePropValue& value) override; - - // Process the request to change the value on the VEHICLE side (for testing) - StatusCode onSetPropertyFromVehicle(const VehiclePropValue& value); + StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) override; // Set the Property Value Pool used in this server void setValuePool(VehiclePropValuePool* valuePool); @@ -85,16 +79,10 @@ class EmulatedVehicleServer : public IVehicleServer { VehiclePropValuePool* mValuePool{nullptr}; }; -class EmulatedPassthroughConnector - : public IPassThroughConnector<EmulatedVehicleClient, EmulatedVehicleServer> { - public: - StatusCode setPropertyFromVehicle(const VehiclePropValue& value) override { - return this->onSetPropertyFromVehicle(value); - } -}; - // Helper functions +using EmulatedPassthroughConnector = + IPassThroughConnector<EmulatedVehicleClient, EmulatedVehicleServer>; using EmulatedPassthroughConnectorPtr = std::unique_ptr<EmulatedPassthroughConnector>; EmulatedPassthroughConnectorPtr makeEmulatedPassthroughConnector(); diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp index 6508efea2b..5c16bf75c1 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp @@ -98,8 +98,9 @@ EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, for (size_t i = 0; i < arraysize(kVehicleProperties); i++) { mPropStore->registerProperty(kVehicleProperties[i].config); } - mVehicleClient->registerPropertyValueCallback( - std::bind(&EmulatedVehicleHal::onPropertyValue, this, std::placeholders::_1)); + mVehicleClient->registerPropertyValueCallback(std::bind(&EmulatedVehicleHal::onPropertyValue, + this, std::placeholders::_1, + std::placeholders::_2)); } VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( @@ -131,41 +132,15 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( } StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) { - static constexpr bool shouldUpdateStatus = false; - - // set the value from vehcile side, used in end to end test. - if (propValue.prop == kSetIntPropertyFromVehcileForTest) { - auto mockValue = createVehiclePropValue(VehiclePropertyType::INT32, 1); - mockValue->prop = propValue.value.int32Values[0]; - mockValue->value.int32Values[0] = propValue.value.int32Values[1]; - mockValue->timestamp = propValue.value.int64Values[0]; - mockValue->areaId = propValue.areaId; - setPropertyFromVehicle(*mockValue); - return StatusCode::OK; - } - - if (propValue.prop == kSetFloatPropertyFromVehcileForTest) { - auto mockValue = createVehiclePropValue(VehiclePropertyType::FLOAT, 1); - mockValue->prop = propValue.value.int32Values[0]; - mockValue->value.floatValues[0] = propValue.value.floatValues[0]; - mockValue->timestamp = propValue.value.int64Values[0]; - mockValue->areaId = propValue.areaId; - setPropertyFromVehicle(*mockValue); - return StatusCode::OK; - } - if (propValue.prop == kSetBooleanPropertyFromVehcileForTest) { - auto mockValue = createVehiclePropValue(VehiclePropertyType::BOOLEAN, 1); - mockValue->prop = propValue.value.int32Values[1]; - mockValue->value.int32Values[0] = propValue.value.int32Values[0]; - mockValue->timestamp = propValue.value.int64Values[0]; - mockValue->areaId = propValue.areaId; - setPropertyFromVehicle(*mockValue); - return StatusCode::OK; - } + constexpr bool updateStatus = false; if (propValue.prop == kGenerateFakeDataControllingProperty) { - // send the generator controlling request to the server - auto status = mVehicleClient->setPropertyFromVehicle(propValue); + // Send the generator controlling request to the server. + // 'updateStatus' flag is only for the value sent by setProperty (propValue in this case) + // instead of the generated values triggered by it. 'propValue' works as a control signal + // here, since we never send the control signal back, the value of 'updateStatus' flag + // does not matter here. + auto status = mVehicleClient->setProperty(propValue, updateStatus); if (status != StatusCode::OK) { return status; } @@ -212,22 +187,13 @@ StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) { * After checking all conditions, such as the property is available, a real vhal will * sent the events to Car ECU to take actions. */ - VehiclePropValuePtr updatedPropValue = getValuePool()->obtain(propValue); - updatedPropValue->timestamp = elapsedRealtimeNano(); // Send the value to the vehicle server, the server will talk to the (real or emulated) car - auto setValueStatus = mVehicleClient->setProperty(*updatedPropValue); + auto setValueStatus = mVehicleClient->setProperty(propValue, updateStatus); if (setValueStatus != StatusCode::OK) { return setValueStatus; } - if (!mPropStore->writeValue(*updatedPropValue, shouldUpdateStatus)) { - return StatusCode::INTERNAL_ERROR; - } - - getEmulatorOrDie()->doSetValueFromClient(*updatedPropValue); - doHalEvent(std::move(updatedPropValue)); - return StatusCode::OK; } @@ -314,7 +280,6 @@ void EmulatedVehicleHal::onContinuousPropertyTimer(const std::vector<int32_t>& p } if (v.get()) { - v->timestamp = elapsedRealtimeNano(); doHalEvent(std::move(v)); } } @@ -347,18 +312,19 @@ bool EmulatedVehicleHal::isContinuousProperty(int32_t propId) const { } bool EmulatedVehicleHal::setPropertyFromVehicle(const VehiclePropValue& propValue) { - return mVehicleClient->setPropertyFromVehicle(propValue) == StatusCode::OK; + constexpr bool updateStatus = true; + return mVehicleClient->setProperty(propValue, updateStatus) == StatusCode::OK; } std::vector<VehiclePropValue> EmulatedVehicleHal::getAllProperties() const { return mPropStore->readAllValues(); } -void EmulatedVehicleHal::onPropertyValue(const VehiclePropValue& value) { - static constexpr bool shouldUpdateStatus = true; +void EmulatedVehicleHal::onPropertyValue(const VehiclePropValue& value, bool updateStatus) { VehiclePropValuePtr updatedPropValue = getValuePool()->obtain(value); - if (mPropStore->writeValue(*updatedPropValue, shouldUpdateStatus)) { + if (mPropStore->writeValue(*updatedPropValue, updateStatus)) { + getEmulatorOrDie()->doSetValueFromClient(*updatedPropValue); doHalEvent(std::move(updatedPropValue)); } } diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.h b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.h index 98315ec32e..a8378da623 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.h +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.h @@ -68,7 +68,7 @@ private: } StatusCode handleGenerateFakeDataRequest(const VehiclePropValue& request); - void onPropertyValue(const VehiclePropValue& value); + void onPropertyValue(const VehiclePropValue& value, bool updateStatus); void onContinuousPropertyTimer(const std::vector<int32_t>& properties); bool isContinuousProperty(int32_t propId) const; |