35 #ifndef _NEW_EAGLE_DBC_UTILITIES_H 36 #define _NEW_EAGLE_DBC_UTILITIES_H 50 if (bit < 0 || bit >- dlc * 8)
55 int32_t msgBitLength = (int32_t)dlc * 8;
57 int32_t row = (int32_t) bit / 8;
58 int32_t offset = (int32_t)bit % 8;
60 return (msgBitLength - (row + 1) * 8) + offset;
71 int32_t wordSize =
sizeof(data);
83 int32_t bit = (int32_t)(startBit % 8);
85 bool isExactlyByte = ((bit + signal.
GetLength()) % 8 == 0);
86 uint32_t numBytes = (isExactlyByte ? 0 : 1) + ((bit + (int32_t)signal.
GetLength()) / 8);
88 int32_t b = (int32_t)wordSize - ((
int)startBit / 8) - 1;
90 int32_t maskShift = bit;
91 int32_t rightShift = 0;
93 uint32_t unsignedResult = 0;
94 for(int32_t i = 0; i < numBytes; i++)
96 if ((b < 0) || (b >=
sizeof(data)))
98 return std::numeric_limits<int>::quiet_NaN();
108 int32_t extractedByte = (data[b] & mask) >> maskShift;
109 unsignedResult |= (uint32_t)extractedByte << (8 * i - rightShift);
113 if ((b % wordSize) == 0)
115 b += 2 * wordSize - 1;
127 w -= ( 8 - maskShift);
128 rightShift += maskShift;
136 if ((unsignedResult & (1 << (int32_t)signal.
GetLength() - 1)) != 0)
140 uint32_t signExtension = (0xFFFFFFFF << (int32_t)signal.
GetLength());
141 unsignedResult |= signExtension;
145 result = (double)((int32_t)unsignedResult);
150 result = (double)(unsignedResult);
176 int32_t i = (int32_t)tmp;
177 uint32_t u = (uint)i;
186 int8_t wordSize =
sizeof(data);
198 int32_t bit = (int32_t)(startBit % 8);
200 bool isExactlyByte = ((bit + signal.
GetLength()) % 8 == 0);
201 uint32_t numBytes = (isExactlyByte ? 0 : 1) + ((bit + (int32_t)signal.
GetLength()) / 8);
203 int32_t b = (int32_t)wordSize - ((
int)startBit / 8) - 1;
205 int32_t maskShift = bit;
206 int32_t rightShift = 0;
209 uint32_t extractedByte;
211 for(
int i = 0; i < numBytes; i++)
213 if ((b < 0 || (b >=
sizeof(data))))
227 extractedByte = (result >> (8 * i - rightShift)) & 0xFF;
229 data[b] = (uint32_t)(data[b] & ~mask);
230 data[b] |= (uint8_t)((extractedByte << maskShift) & mask);
234 if ((b % wordSize) == 0)
236 b += 2 * wordSize - 1;
248 w -= ( 8 - maskShift);
249 rightShift += maskShift;
257 #endif // _NEW_EAGLE_DBC_UTILITIES_H static double Unpack(uint8_t *data, const NewEagle::DbcSignal &signal)
uint8_t GetLength() const
ByteOrder GetEndianness() const
uint8_t GetStartBit() const
static int32_t ConvertToMTBitOrdering(uint32_t bit, uint32_t dlc)
static void Pack(uint8_t *data, const NewEagle::DbcSignal &signal)