1 /* 2 * Copyright (C) 2020 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 #pragma once 18 19 #include <android-base/macros.h> 20 #include <android/hardware/automotive/can/1.0/types.h> 21 22 namespace android::hardware::automotive::protocan { 23 24 /** 25 * TODO(twasilczyk): right now, only Little Endian signals are supported. 26 */ 27 class Signal { 28 public: 29 using value = uint64_t; 30 31 const value maxValue; 32 33 Signal(uint16_t start, uint8_t length, value defVal = 0); 34 35 value get(const can::V1_0::CanMessage& msg) const; 36 void set(can::V1_0::CanMessage& msg, value val) const; 37 void setDefault(can::V1_0::CanMessage& msg) const; 38 39 private: 40 const uint16_t kFirstByte; ///< Index of first byte that holds the signal 41 const uint8_t kFirstBit; ///< Index of first bit within first byte 42 const uint8_t kFirstByteBits; ///< How many bits of the first byte belong to the signal 43 const uint16_t kLastByte; ///< Index of last byte that holds the signal 44 const uint8_t kLastMask; ///< Bits of the last byte that belong to the signal 45 const uint8_t kFirstMask; ///< Bits of the first byte that belong to the signal 46 47 const value kDefVal; 48 }; 49 50 } // namespace android::hardware::automotive::protocan 51