summaryrefslogtreecommitdiffstats
blob: 6c44626d12dbebef84f7ad5d8b2e4ae35426694a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (C) 2017 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_1_Obd2SensorStore_H_
#define android_hardware_automotive_vehicle_V2_1_Obd2SensorStore_H_

#include <vector>

#include <android/hardware/automotive/vehicle/2.1/types.h>

namespace android {
namespace hardware {
namespace automotive {
namespace vehicle {
namespace V2_1 {

// This class wraps all the logic required to create an OBD2 frame.
// It allows storing sensor values, setting appropriate bitmasks as needed,
// and returning appropriately laid out storage of sensor values suitable
// for being returned via a VehicleHal implementation.
class Obd2SensorStore {
public:
    // Creates a sensor storage with a given number of vendor-specific sensors.
    Obd2SensorStore(size_t numVendorIntegerSensors,
                    size_t numVendorFloatSensors);

    // Stores an integer-valued sensor.
    V2_0::StatusCode setIntegerSensor(Obd2IntegerSensorIndex index, int32_t value);
    // Stores an integer-valued sensor.
    V2_0::StatusCode setIntegerSensor(size_t index, int32_t value);

    // Stores a float-valued sensor.
    V2_0::StatusCode setFloatSensor(Obd2FloatSensorIndex index, float value);
    // Stores a float-valued sensor.
    V2_0::StatusCode setFloatSensor(size_t index, float value);

    // Returns a vector that contains all integer sensors stored.
    const std::vector<int32_t>& getIntegerSensors() const;
    // Returns a vector that contains all float sensors stored.
    const std::vector<float>& getFloatSensors() const;
    // Returns a vector that contains a bitmask for all stored sensors.
    const std::vector<uint8_t>& getSensorsBitmask() const;

    // Given a stringValue, fill in a VehiclePropValue
    void fillPropValue(const std::string& dtc, V2_0::VehiclePropValue *propValue) const;

private:
    class BitmaskInVector {
    public:
        BitmaskInVector(size_t numBits = 0);
        void resize(size_t numBits);
        bool get(size_t index) const;
        void set(size_t index, bool value);

        const std::vector<uint8_t>& getBitmask() const;

    private:
        std::vector<uint8_t> mStorage;
    };

    std::vector<int32_t> mIntegerSensors;
    std::vector<float> mFloatSensors;
    BitmaskInVector mSensorsBitmask;
};

}  // namespace V2_1
}  // namespace vehicle
}  // namespace automotive
}  // namespace hardware
}  // namespace android

#endif  // android_hardware_automotive_vehicle_V2_0_Obd2SensorStore_H_