/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef android_hardware_automotive_vehicle_V2_0_impl_EmulatedVehicleHal_H_ #define android_hardware_automotive_vehicle_V2_0_impl_EmulatedVehicleHal_H_ #include #include #include #include #include #include #include #include #include "vhal_v2_0/VehiclePropertyStore.h" #include "DefaultConfig.h" #include "GeneratorHub.h" #include "VehicleEmulator.h" namespace android { namespace hardware { namespace automotive { namespace vehicle { namespace V2_0 { namespace impl { /** Implementation of VehicleHal that connected to emulator instead of real vehicle network. */ class EmulatedVehicleHal : public EmulatedVehicleHalIface { public: EmulatedVehicleHal(VehiclePropertyStore* propStore); ~EmulatedVehicleHal() = default; // Methods from VehicleHal void onCreate() override; std::vector listProperties() override; VehiclePropValuePtr get(const VehiclePropValue& requestedPropValue, StatusCode* outStatus) override; StatusCode set(const VehiclePropValue& propValue) override; StatusCode subscribe(int32_t property, float sampleRate) override; StatusCode unsubscribe(int32_t property) override; // Methods from EmulatedVehicleHalIface bool setPropertyFromVehicle(const VehiclePropValue& propValue) override; std::vector getAllProperties() const override; private: constexpr std::chrono::nanoseconds hertzToNanoseconds(float hz) const { return std::chrono::nanoseconds(static_cast(1000000000L / hz)); } StatusCode handleGenerateFakeDataRequest(const VehiclePropValue& request); void onFakeValueGenerated(const VehiclePropValue& value); VehiclePropValuePtr createApPowerStateReq(VehicleApPowerStateReq req, int32_t param); VehiclePropValuePtr createHwInputKeyProp(VehicleHwKeyInputAction action, int32_t keyCode, int32_t targetDisplay); void onContinuousPropertyTimer(const std::vector& properties); bool isContinuousProperty(int32_t propId) const; void initStaticConfig(); void initObd2LiveFrame(const VehiclePropConfig& propConfig); void initObd2FreezeFrame(const VehiclePropConfig& propConfig); StatusCode fillObd2FreezeFrame(const VehiclePropValue& requestedPropValue, VehiclePropValue* outValue); StatusCode fillObd2DtcInfo(VehiclePropValue* outValue); StatusCode clearObd2FreezeFrames(const VehiclePropValue& propValue); /* Private members */ VehiclePropertyStore* mPropStore; std::unordered_set mHvacPowerProps; RecurrentTimer mRecurrentTimer; GeneratorHub mGeneratorHub; }; } // impl } // namespace V2_0 } // namespace vehicle } // namespace automotive } // namespace hardware } // namespace android #endif // android_hardware_automotive_vehicle_V2_0_impl_EmulatedVehicleHal_H_