diff options
Diffstat (limited to 'automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp')
-rw-r--r-- | automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp | 54 |
1 files changed, 42 insertions, 12 deletions
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 dc34a50a..3979ac21 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 | |||
@@ -85,11 +85,6 @@ static std::unique_ptr<Obd2SensorStore> fillDefaultObd2Frame(size_t numVendorInt | |||
85 | return sensorStore; | 85 | return sensorStore; |
86 | } | 86 | } |
87 | 87 | ||
88 | enum class FakeDataCommand : int32_t { | ||
89 | Stop = 0, | ||
90 | Start = 1, | ||
91 | }; | ||
92 | |||
93 | EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore) | 88 | EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore) |
94 | : mPropStore(propStore), | 89 | : mPropStore(propStore), |
95 | mHvacPowerProps(std::begin(kHvacPowerProperties), std::end(kHvacPowerProperties)), | 90 | mHvacPowerProps(std::begin(kHvacPowerProperties), std::end(kHvacPowerProperties)), |
@@ -132,6 +127,8 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( | |||
132 | } | 127 | } |
133 | 128 | ||
134 | StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) { | 129 | StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) { |
130 | static constexpr bool shouldUpdateStatus = false; | ||
131 | |||
135 | if (propValue.prop == kGenerateFakeDataControllingProperty) { | 132 | if (propValue.prop == kGenerateFakeDataControllingProperty) { |
136 | StatusCode status = handleGenerateFakeDataRequest(propValue); | 133 | StatusCode status = handleGenerateFakeDataRequest(propValue); |
137 | if (status != StatusCode::OK) { | 134 | if (status != StatusCode::OK) { |
@@ -182,7 +179,7 @@ StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) { | |||
182 | return StatusCode::NOT_AVAILABLE; | 179 | return StatusCode::NOT_AVAILABLE; |
183 | } | 180 | } |
184 | 181 | ||
185 | if (!mPropStore->writeValue(propValue)) { | 182 | if (!mPropStore->writeValue(propValue, shouldUpdateStatus)) { |
186 | return StatusCode::INVALID_ARG; | 183 | return StatusCode::INVALID_ARG; |
187 | } | 184 | } |
188 | 185 | ||
@@ -204,6 +201,8 @@ static bool isDiagnosticProperty(VehiclePropConfig propConfig) { | |||
204 | 201 | ||
205 | // Parse supported properties list and generate vector of property values to hold current values. | 202 | // Parse supported properties list and generate vector of property values to hold current values. |
206 | void EmulatedVehicleHal::onCreate() { | 203 | void EmulatedVehicleHal::onCreate() { |
204 | static constexpr bool shouldUpdateStatus = true; | ||
205 | |||
207 | for (auto& it : kVehicleProperties) { | 206 | for (auto& it : kVehicleProperties) { |
208 | VehiclePropConfig cfg = it.config; | 207 | VehiclePropConfig cfg = it.config; |
209 | int32_t numAreas = cfg.areaConfigs.size(); | 208 | int32_t numAreas = cfg.areaConfigs.size(); |
@@ -245,7 +244,7 @@ void EmulatedVehicleHal::onCreate() { | |||
245 | } else { | 244 | } else { |
246 | prop.value = it.initialValue; | 245 | prop.value = it.initialValue; |
247 | } | 246 | } |
248 | mPropStore->writeValue(prop); | 247 | mPropStore->writeValue(prop, shouldUpdateStatus); |
249 | } | 248 | } |
250 | } | 249 | } |
251 | initObd2LiveFrame(*mPropStore->getConfigOrDie(OBD2_LIVE_FRAME)); | 250 | initObd2LiveFrame(*mPropStore->getConfigOrDie(OBD2_LIVE_FRAME)); |
@@ -305,6 +304,8 @@ bool EmulatedVehicleHal::isContinuousProperty(int32_t propId) const { | |||
305 | } | 304 | } |
306 | 305 | ||
307 | bool EmulatedVehicleHal::setPropertyFromVehicle(const VehiclePropValue& propValue) { | 306 | bool EmulatedVehicleHal::setPropertyFromVehicle(const VehiclePropValue& propValue) { |
307 | static constexpr bool shouldUpdateStatus = true; | ||
308 | |||
308 | if (propValue.prop == kGenerateFakeDataControllingProperty) { | 309 | if (propValue.prop == kGenerateFakeDataControllingProperty) { |
309 | StatusCode status = handleGenerateFakeDataRequest(propValue); | 310 | StatusCode status = handleGenerateFakeDataRequest(propValue); |
310 | if (status != StatusCode::OK) { | 311 | if (status != StatusCode::OK) { |
@@ -312,7 +313,7 @@ bool EmulatedVehicleHal::setPropertyFromVehicle(const VehiclePropValue& propValu | |||
312 | } | 313 | } |
313 | } | 314 | } |
314 | 315 | ||
315 | if (mPropStore->writeValue(propValue)) { | 316 | if (mPropStore->writeValue(propValue, shouldUpdateStatus)) { |
316 | doHalEvent(getValuePool()->obtain(propValue)); | 317 | doHalEvent(getValuePool()->obtain(propValue)); |
317 | return true; | 318 | return true; |
318 | } else { | 319 | } else { |
@@ -360,10 +361,20 @@ StatusCode EmulatedVehicleHal::handleGenerateFakeDataRequest(const VehiclePropVa | |||
360 | break; | 361 | break; |
361 | } | 362 | } |
362 | case FakeDataCommand::Stop: { | 363 | case FakeDataCommand::Stop: { |
363 | ALOGI("%s, FakeDataCommandStop", __func__); | 364 | ALOGI("%s, FakeDataCommand::Stop", __func__); |
364 | mFakeValueGenerator.stopGeneratingHalEvents(propId); | 365 | mFakeValueGenerator.stopGeneratingHalEvents(propId); |
365 | break; | 366 | break; |
366 | } | 367 | } |
368 | case FakeDataCommand::KeyPress: { | ||
369 | ALOGI("%s, FakeDataCommand::KeyPress", __func__); | ||
370 | int32_t keyCode = request.value.int32Values[2]; | ||
371 | int32_t display = request.value.int32Values[3]; | ||
372 | doHalEvent( | ||
373 | createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_DOWN, keyCode, display)); | ||
374 | doHalEvent(createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_UP, keyCode, display)); | ||
375 | break; | ||
376 | } | ||
377 | |||
367 | default: { | 378 | default: { |
368 | ALOGE("%s: unexpected command: %d", __func__, command); | 379 | ALOGE("%s: unexpected command: %d", __func__, command); |
369 | return StatusCode::INVALID_ARG; | 380 | return StatusCode::INVALID_ARG; |
@@ -372,7 +383,22 @@ StatusCode EmulatedVehicleHal::handleGenerateFakeDataRequest(const VehiclePropVa | |||
372 | return StatusCode::OK; | 383 | return StatusCode::OK; |
373 | } | 384 | } |
374 | 385 | ||
386 | VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::createHwInputKeyProp( | ||
387 | VehicleHwKeyInputAction action, int32_t keyCode, int32_t targetDisplay) { | ||
388 | auto keyEvent = getValuePool()->obtain(VehiclePropertyType::INT32_VEC, 3); | ||
389 | keyEvent->prop = toInt(VehicleProperty::HW_KEY_INPUT); | ||
390 | keyEvent->areaId = 0; | ||
391 | keyEvent->timestamp = elapsedRealtimeNano(); | ||
392 | keyEvent->status = VehiclePropertyStatus::AVAILABLE; | ||
393 | keyEvent->value.int32Values[0] = toInt(action); | ||
394 | keyEvent->value.int32Values[1] = keyCode; | ||
395 | keyEvent->value.int32Values[2] = targetDisplay; | ||
396 | return keyEvent; | ||
397 | } | ||
398 | |||
375 | void EmulatedVehicleHal::onFakeValueGenerated(int32_t propId, float value) { | 399 | void EmulatedVehicleHal::onFakeValueGenerated(int32_t propId, float value) { |
400 | static constexpr bool shouldUpdateStatus = false; | ||
401 | |||
376 | VehiclePropValuePtr updatedPropValue {}; | 402 | VehiclePropValuePtr updatedPropValue {}; |
377 | switch (getPropType(propId)) { | 403 | switch (getPropType(propId)) { |
378 | case VehiclePropertyType::FLOAT: | 404 | case VehiclePropertyType::FLOAT: |
@@ -392,7 +418,7 @@ void EmulatedVehicleHal::onFakeValueGenerated(int32_t propId, float value) { | |||
392 | updatedPropValue->areaId = 0; // Add area support if necessary. | 418 | updatedPropValue->areaId = 0; // Add area support if necessary. |
393 | updatedPropValue->timestamp = elapsedRealtimeNano(); | 419 | updatedPropValue->timestamp = elapsedRealtimeNano(); |
394 | updatedPropValue->status = VehiclePropertyStatus::AVAILABLE; | 420 | updatedPropValue->status = VehiclePropertyStatus::AVAILABLE; |
395 | mPropStore->writeValue(*updatedPropValue); | 421 | mPropStore->writeValue(*updatedPropValue, shouldUpdateStatus); |
396 | auto changeMode = mPropStore->getConfigOrDie(propId)->changeMode; | 422 | auto changeMode = mPropStore->getConfigOrDie(propId)->changeMode; |
397 | if (VehiclePropertyChangeMode::ON_CHANGE == changeMode) { | 423 | if (VehiclePropertyChangeMode::ON_CHANGE == changeMode) { |
398 | doHalEvent(move(updatedPropValue)); | 424 | doHalEvent(move(updatedPropValue)); |
@@ -421,16 +447,20 @@ void EmulatedVehicleHal::initStaticConfig() { | |||
421 | } | 447 | } |
422 | 448 | ||
423 | void EmulatedVehicleHal::initObd2LiveFrame(const VehiclePropConfig& propConfig) { | 449 | void EmulatedVehicleHal::initObd2LiveFrame(const VehiclePropConfig& propConfig) { |
450 | static constexpr bool shouldUpdateStatus = true; | ||
451 | |||
424 | auto liveObd2Frame = createVehiclePropValue(VehiclePropertyType::MIXED, 0); | 452 | auto liveObd2Frame = createVehiclePropValue(VehiclePropertyType::MIXED, 0); |
425 | auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]), | 453 | auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]), |
426 | static_cast<size_t>(propConfig.configArray[1])); | 454 | static_cast<size_t>(propConfig.configArray[1])); |
427 | sensorStore->fillPropValue("", liveObd2Frame.get()); | 455 | sensorStore->fillPropValue("", liveObd2Frame.get()); |
428 | liveObd2Frame->prop = OBD2_LIVE_FRAME; | 456 | liveObd2Frame->prop = OBD2_LIVE_FRAME; |
429 | 457 | ||
430 | mPropStore->writeValue(*liveObd2Frame); | 458 | mPropStore->writeValue(*liveObd2Frame, shouldUpdateStatus); |
431 | } | 459 | } |
432 | 460 | ||
433 | void EmulatedVehicleHal::initObd2FreezeFrame(const VehiclePropConfig& propConfig) { | 461 | void EmulatedVehicleHal::initObd2FreezeFrame(const VehiclePropConfig& propConfig) { |
462 | static constexpr bool shouldUpdateStatus = true; | ||
463 | |||
434 | auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]), | 464 | auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]), |
435 | static_cast<size_t>(propConfig.configArray[1])); | 465 | static_cast<size_t>(propConfig.configArray[1])); |
436 | 466 | ||
@@ -442,7 +472,7 @@ void EmulatedVehicleHal::initObd2FreezeFrame(const VehiclePropConfig& propConfig | |||
442 | sensorStore->fillPropValue(dtc, freezeFrame.get()); | 472 | sensorStore->fillPropValue(dtc, freezeFrame.get()); |
443 | freezeFrame->prop = OBD2_FREEZE_FRAME; | 473 | freezeFrame->prop = OBD2_FREEZE_FRAME; |
444 | 474 | ||
445 | mPropStore->writeValue(*freezeFrame); | 475 | mPropStore->writeValue(*freezeFrame, shouldUpdateStatus); |
446 | } | 476 | } |
447 | } | 477 | } |
448 | 478 | ||