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

Commit 27bfe01f authored by Yu Shan's avatar Yu Shan
Browse files

Migrate Obd2SensorStore.

Test: atest FakeObd2FrameTest
Bug: 201830716
Change-Id: Ibd460ab4c129707d567689d90979ca0424551a64
parent a3116319
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@
    },
    {
      "name": "FakeVehicleHalValueGeneratorsTest"
    },
    {
      "name": "FakeObd2FrameTest"
    }
  ]
}
+4 −1
Original line number Diff line number Diff line
@@ -25,7 +25,10 @@ cc_library {
    local_include_dirs: ["include"],
    export_include_dirs: ["include"],
    defaults: ["VehicleHalDefaults"],
    static_libs: ["VehicleHalUtils"],
    static_libs: [
        "VehicleHalUtils",
        "FakeObd2Frame",
    ],
    shared_libs: [
        "libjsoncpp",
    ],
+5 −13
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <type_traits>
#include <typeinfo>

#include <Obd2SensorStore.h>
#include <VehicleUtils.h>
#include <android/binder_enums.h>
#include <utils/Log.h>
@@ -42,16 +43,6 @@ using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropValue;

template <class T>
int getLastIndex() {
    auto range = ::ndk::enum_range<T>();
    auto it = range.begin();
    while (std::next(it) != range.end()) {
        it++;
    }
    return toInt(*it);
}

bool isDiagnosticProperty(int32_t prop) {
    return prop == toInt(VehicleProperty::OBD2_LIVE_FRAME) ||
           prop == toInt(VehicleProperty::OBD2_FREEZE_FRAME);
@@ -84,9 +75,10 @@ void copyMixedValueJson(const Json::Value& jsonValue, RawPropValues& dest) {
}

std::vector<uint8_t> generateDiagnosticBytes(const RawPropValues& diagnosticValue) {
    size_t lastIntegerSensorIndex =
            static_cast<size_t>(getLastIndex<DiagnosticIntegerSensorIndex>());
    size_t lastFloatSensorIndex = static_cast<size_t>(getLastIndex<DiagnosticFloatSensorIndex>());
    size_t lastIntegerSensorIndex = static_cast<size_t>(
            obd2frame::Obd2SensorStore::getLastIndex<DiagnosticIntegerSensorIndex>());
    size_t lastFloatSensorIndex = static_cast<size_t>(
            obd2frame::Obd2SensorStore::getLastIndex<DiagnosticFloatSensorIndex>());

    size_t byteSize = (lastIntegerSensorIndex + lastFloatSensorIndex + 2);
    std::vector<uint8_t> bytes((byteSize + 7) / 8);
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ cc_test {
    static_libs: [
        "VehicleHalUtils",
        "FakeVehicleHalValueGenerators",
        "FakeObd2Frame",
    ],
    shared_libs: [
        "libjsoncpp",
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.
 */

package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

cc_library {
    name: "FakeObd2Frame",
    vendor: true,
    srcs: ["src/*.cpp"],
    local_include_dirs: ["include"],
    export_include_dirs: ["include"],
    defaults: ["VehicleHalDefaults"],
    static_libs: [
        "VehicleHalUtils",
    ],
    export_static_lib_headers: ["VehicleHalUtils"],
}
Loading