1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef android_hardware_automotive_vehicle_V2_0_Obd2SensorStore_H_ 18 #define android_hardware_automotive_vehicle_V2_0_Obd2SensorStore_H_ 19 20 #include <vector> 21 22 #include <android/hardware/automotive/vehicle/2.0/types.h> 23 24 namespace android { 25 namespace hardware { 26 namespace automotive { 27 namespace vehicle { 28 namespace V2_0 { 29 30 // This class wraps all the logic required to create an OBD2 frame. 31 // It allows storing sensor values, setting appropriate bitmasks as needed, 32 // and returning appropriately laid out storage of sensor values suitable 33 // for being returned via a VehicleHal implementation. 34 class Obd2SensorStore { 35 public: 36 // Creates a sensor storage with a given number of vendor-specific sensors. 37 Obd2SensorStore(size_t numVendorIntegerSensors, size_t numVendorFloatSensors); 38 39 // Stores an integer-valued sensor. 40 StatusCode setIntegerSensor(DiagnosticIntegerSensorIndex index, int32_t value); 41 // Stores an integer-valued sensor. 42 StatusCode setIntegerSensor(size_t index, int32_t value); 43 44 // Stores a float-valued sensor. 45 StatusCode setFloatSensor(DiagnosticFloatSensorIndex index, float value); 46 // Stores a float-valued sensor. 47 StatusCode setFloatSensor(size_t index, float value); 48 49 // Returns a vector that contains all integer sensors stored. 50 const std::vector<int32_t>& getIntegerSensors() const; 51 // Returns a vector that contains all float sensors stored. 52 const std::vector<float>& getFloatSensors() const; 53 // Returns a vector that contains a bitmask for all stored sensors. 54 const std::vector<uint8_t>& getSensorsBitmask() const; 55 56 // Given a stringValue, fill in a VehiclePropValue 57 void fillPropValue(const std::string& dtc, VehiclePropValue* propValue) const; 58 59 private: 60 class BitmaskInVector { 61 public: 62 BitmaskInVector(size_t numBits = 0); 63 void resize(size_t numBits); 64 bool get(size_t index) const; 65 void set(size_t index, bool value); 66 67 const std::vector<uint8_t>& getBitmask() const; 68 69 private: 70 std::vector<uint8_t> mStorage; 71 }; 72 73 std::vector<int32_t> mIntegerSensors; 74 std::vector<float> mFloatSensors; 75 BitmaskInVector mSensorsBitmask; 76 }; 77 78 } // namespace V2_0 79 } // namespace vehicle 80 } // namespace automotive 81 } // namespace hardware 82 } // namespace android 83 84 #endif // android_hardware_automotive_vehicle_V2_0_Obd2SensorStore_H_ 85