Ref #1 Fix motorola data format
This commit is contained in:
1 parent
38ce043ae0
commit
2c057b631d
5 files changed
+257
-13
No files matched your search
+8
-13
@@ -111,31 +111,26 @@ bool DbcDecoder::ExtractMotorola (const std::vector<std::uint8_t> &data,
|
||||
* - startBit points to the most significant bit of the signal
|
||||
* - inside a byte, bit numbering goes 7..0
|
||||
* - crossing byte boundary moves to the next byte, bit 7
|
||||
* Example: a signal starting at 7 follows 7..0, 15..8, 23..16.
|
||||
*/
|
||||
|
||||
value = 0U;
|
||||
|
||||
std::int32_t currentBit = static_cast<std::int32_t> (startBit);
|
||||
std::size_t byteIndex = startBit / 8U;
|
||||
std::uint32_t bitInByte = startBit % 8U;
|
||||
|
||||
for (std::uint32_t bitIndex = 0U; bitIndex < length; ++bitIndex) {
|
||||
if (currentBit < 0)
|
||||
return false;
|
||||
|
||||
const std::uint32_t absoluteBit = static_cast<std::uint32_t> (currentBit);
|
||||
const std::uint32_t byteIndex = absoluteBit / 8U;
|
||||
const std::uint32_t bitFromMsb = absoluteBit % 8U;
|
||||
const std::uint32_t bitInByte = 7U - bitFromMsb;
|
||||
|
||||
if (byteIndex >= data.size())
|
||||
return false;
|
||||
|
||||
value <<= 1U;
|
||||
value |= static_cast<std::uint64_t> ((data[byteIndex] >> bitInByte) & 0x01U);
|
||||
|
||||
if ((absoluteBit % 8U) == 7U)
|
||||
currentBit = static_cast<std::int32_t> ((byteIndex + 1U) * 8U);
|
||||
else
|
||||
--currentBit;
|
||||
if (bitInByte == 0U) {
|
||||
++byteIndex;
|
||||
bitInByte = 7U;
|
||||
} else
|
||||
--bitInByte;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user