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

Commit 56c0c84d authored by Steve Paik's avatar Steve Paik
Browse files

Enable vehicle HAL to be controlled via ADB

Add emulator functionality to DefaultVehicleHal:

- Create default list of properties based upon DefaultConfig.h
- Add socket that is reachable via ADB to set/get vehicle properties.

BUG: 29601815
Test: Tested with Python interface from host.
Change-Id: I6f8e4cba37d927565e10797875eb8f5a1840a94f
parent 46a1accf
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -40,6 +40,28 @@ LOCAL_SHARED_LIBRARIES := \

include $(BUILD_STATIC_LIBRARY)

###############################################################################
# Vehicle HAL Protobuf library
###############################################################################
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-proto-files-under, impl/proto)

LOCAL_PROTOC_OPTIMIZE_TYPE := nano

LOCAL_MODULE := $(module_prefix)-libproto-native
LOCAL_MODULE_CLASS := STATIC_LIBRARIES

LOCAL_MODULE_TAGS := optional

LOCAL_STRIP_MODULE := keep_symbols

generated_sources_dir := $(call local-generated-sources-dir)
LOCAL_EXPORT_C_INCLUDE_DIRS := \
    $(generated_sources_dir)/proto/$(LOCAL_PATH)/impl/proto

include $(BUILD_STATIC_LIBRARY)


###############################################################################
# Vehicle default VehicleHAL implementation
###############################################################################
@@ -55,9 +77,13 @@ LOCAL_SHARED_LIBRARIES := \
    libhidltransport \
    libhwbinder \
    liblog \
    libprotobuf-cpp-lite \
    libutils \
    $(module_prefix) \

LOCAL_STATIC_LIBRARIES := \
    $(module_prefix)-libproto-native

include $(BUILD_STATIC_LIBRARY)


@@ -114,7 +140,11 @@ LOCAL_SHARED_LIBRARIES := \
    libhidltransport \
    libhwbinder \
    liblog \
    libprotobuf-cpp-lite \
    libutils \
    $(module_prefix) \

LOCAL_STATIC_LIBRARIES := \
    $(module_prefix)-libproto-native

include $(BUILD_EXECUTABLE)
+1 −1
Original line number Diff line number Diff line
service vehicle-hal-2.0 /system/bin/hw/android.hardware.automotive.vehicle@2.0-service
    class hal
    user vehicle_network
    group system
    group system inet
+585 −162

File changed.

Preview size limit exceeded, changes collapsed.

+52 −22
Original line number Diff line number Diff line
@@ -21,8 +21,12 @@

#include <VehicleHal.h>
#include <impl/DefaultConfig.h>
#include <vehicle_hal_manager/Obd2SensorStore.h>
#include <sys/socket.h>
#include <thread>
#include <utils/SystemClock.h>
#include <vehicle_hal_manager/Obd2SensorStore.h>
#include "VehicleHalProto.pb.h"


namespace android {
namespace hardware {
@@ -34,6 +38,23 @@ namespace impl {

class DefaultVehicleHal : public VehicleHal {
public:
    DefaultVehicleHal() : mThread() {}
    ~DefaultVehicleHal() override {
        // Notify thread to finish and wait for it to terminate
        mExit = 1;

        // Close emulator socket if it is open
        {
            std::lock_guard<std::mutex> lock(mTxMutex);
            if (mCurSocket != -1) {
                close(mCurSocket);
                mCurSocket = -1;
            }
        }

        mThread.join();
    }

    std::vector<VehiclePropConfig> listProperties() override {
        return std::vector<VehiclePropConfig>(std::begin(kVehicleProperties),
                                              std::end(kVehicleProperties));
@@ -46,38 +67,47 @@ public:

    StatusCode set(const VehiclePropValue& propValue) override;

    StatusCode subscribe(int32_t /*property*/,
                         int32_t /*areas*/,
                         float /*sampleRate*/) override {
        // TODO(pavelm): implement
    StatusCode subscribe(int32_t property, int32_t areas, float sampleRate) {
        ALOGD("%s: not implemented: prop=0x%x, areas=0x%x, rate=%f", __FUNCTION__, property,
              areas, sampleRate);
        return StatusCode::OK;
    }

    StatusCode unsubscribe(int32_t /*property*/) override {
        // TODO(pavelm): implement
    StatusCode unsubscribe(int32_t property) {
        ALOGD("%s: not implemented: prop=0x%x", __FUNCTION__, property);
        return StatusCode::OK;
    }

private:
    StatusCode getHvacTemperature(int32_t areaId, float* outValue);
    StatusCode setHvacTemperature(int32_t areaId, float value);
    StatusCode getHvacDefroster(int32_t areaId, bool* outValue);
    StatusCode setHvacDefroster(int32_t areaId, bool value);
    void doGetConfig(emulator::EmulatorMessage& rxMsg, emulator::EmulatorMessage& respMsg);
    void doGetConfigAll(emulator::EmulatorMessage& rxMsg, emulator::EmulatorMessage& respMsg);
    void doGetProperty(emulator::EmulatorMessage& rxMsg, emulator::EmulatorMessage& respMsg);
    void doGetPropertyAll(emulator::EmulatorMessage& rxMsg, emulator::EmulatorMessage& respMsg);
    void doSetProperty(emulator::EmulatorMessage& rxMsg, emulator::EmulatorMessage& respMsg);
    VehiclePropValue* getVehiclePropValueLocked(int32_t propId, int32_t areaId);
    void initObd2LiveFrame(VehiclePropConfig& obd2LiveFramePropConfig);
    void parseRxProtoBuf(std::vector<uint8_t>& msg);
    void populateProtoVehicleConfig(emulator::VehiclePropConfig* protoCfg,
                                    const VehiclePropConfig& cfg);
    void populateProtoVehiclePropValue(emulator::VehiclePropValue* protoVal,
                                       const VehiclePropValue* val);
    void setDefaultValue(VehiclePropValue* prop);
    void rxMsg(void);
    void rxThread(void);
    void txMsg(emulator::EmulatorMessage& txMsg);
    StatusCode updateProperty(const VehiclePropValue& propValue);
    StatusCode fillObd2LiveFrame(VehiclePropValuePtr* v);
    StatusCode fillObd2FreezeFrame(VehiclePropValuePtr* v);
private:
    int32_t mFanSpeed = 3;
    int32_t mBrightness = 7;
    float mRow1LeftHvacTemperatureSet = 16;
    float mRow1RightHvacTemperatureSet = 22;
    bool mFrontDefroster = false;
    bool mRearDefroster = false;
    bool mHvacPowerOn = true;
    bool mHvacRecircOn = true;
    bool mHvacAcOn = true;
    bool mHvacAutoOn = true;
    VehicleHvacFanDirection mFanDirection = VehicleHvacFanDirection::FACE;
    // TODO:  Use a hashtable to support indexing props
    std::vector<std::unique_ptr<VehiclePropValue>> mProps;
    std::atomic<int> mCurSocket;
    std::atomic<int> mExit;
    std::unique_ptr<Obd2SensorStore> mObd2SensorStore{nullptr};
    std::mutex mPropsMutex;
    int mSocket;
    std::mutex mTxMutex;
    std::thread mThread;
};

}  // impl
+100 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.
 */

syntax = "proto2";
option optimize_for = LITE_RUNTIME;

package emulator;

// CMD messages are from workstation --> VHAL
// RESP messages are from VHAL --> workstation
enum MsgType {
    GET_CONFIG_CMD                      = 0;
    GET_CONFIG_RESP                     = 1;
    GET_CONFIG_ALL_CMD                  = 2;
    GET_CONFIG_ALL_RESP                 = 3;
    GET_PROPERTY_CMD                    = 4;
    GET_PROPERTY_RESP                   = 5;
    GET_PROPERTY_ALL_CMD                = 6;
    GET_PROPERTY_ALL_RESP               = 7;
    SET_PROPERTY_CMD                    = 8;
    SET_PROPERTY_RESP                   = 9;
    SET_PROPERTY_ASYNC                  = 10;
}
enum Status {
    RESULT_OK                           = 0;
    ERROR_UNKNOWN                       = 1;
    ERROR_UNIMPLEMENTED_CMD             = 2;
    ERROR_INVALID_PROPERTY              = 3;
    ERROR_INVALID_AREA_ID               = 4;
    ERROR_PROPERTY_UNINITIALIZED        = 5;
    ERROR_WRITE_ONLY_PROPERTY           = 6;
    ERROR_MEMORY_ALLOC_FAILED           = 7;
    ERROR_INVALID_OPERATION             = 8;
}

message VehicleAreaConfig {
    required int32  area_id             = 1;
    optional sint32 min_int32_value     = 2;
    optional sint32 max_int32_value     = 3;
    optional sint64 min_int64_value     = 4;
    optional sint64 max_int64_value     = 5;
    optional float  min_float_value     = 6;
    optional float  max_float_value     = 7;
}

message VehiclePropConfig {
    required int32             prop                = 1;
    optional int32             access              = 2;
    optional int32             change_mode         = 3;
    optional int32             value_type          = 4;
    optional int32             supported_areas     = 5;
    repeated VehicleAreaConfig area_configs        = 6;
    optional int32             config_flags        = 7;
    repeated int32             config_array        = 8;
    optional string            config_string       = 9;
    optional float             min_sample_rate     = 10;
    optional float             max_sample_rate     = 11;
};

message VehiclePropValue {
    // common data
    required int32  prop                = 1;
    optional int32  value_type          = 2;
    optional int64  timestamp           = 3;    // required for valid data from HAL, skipped for set

    // values
    optional int32  area_id             = 4;
    repeated sint32 int32_values        = 5;    // this also covers boolean value.
    repeated sint64 int64_values        = 6;
    repeated float  float_values        = 7;
    optional string string_value        = 8;
    optional bytes  bytes_value         = 9;
};

// This structure is used to notify what values to get from the Vehicle HAL
message VehiclePropGet {
    required int32 prop                 = 1;
    optional int32 area_id              = 2;
};

message EmulatorMessage {
    required MsgType           msg_type = 1;
    optional Status            status   = 2;    // Only for RESP messages
    repeated VehiclePropGet    prop     = 3;    // Provided for getConfig, getProperty commands
    repeated VehiclePropConfig config   = 4;
    repeated VehiclePropValue  value    = 5;
};