diff --git a/bin/cangaroo.zip b/bin/cangaroo.zip index be96031..b741932 100644 Binary files a/bin/cangaroo.zip and b/bin/cangaroo.zip differ diff --git a/src/core/CanDbSignal.cpp b/src/core/CanDbSignal.cpp index c039be0..9d01505 100644 --- a/src/core/CanDbSignal.cpp +++ b/src/core/CanDbSignal.cpp @@ -209,7 +209,7 @@ void CanDbSignal::setMuxValue(const uint32_t &muxValue) bool CanDbSignal::isPresentInMessage(const CanMessage &msg) { - if ((_startBit + _length)>(8*msg.getLength())) { + if ((_startBit + _length)>(8*msg.getLength()) && !_isBigEndian) { return false; } diff --git a/src/core/CanMessage.cpp b/src/core/CanMessage.cpp index 386cfbf..cf1ecb9 100644 --- a/src/core/CanMessage.cpp +++ b/src/core/CanMessage.cpp @@ -184,6 +184,34 @@ void CanMessage::setByte(const uint8_t index, const uint8_t value) { uint64_t CanMessage::extractRawSignal(uint8_t start_bit, const uint8_t length, const bool isBigEndian) const { + if(isBigEndian) + { + int firstByte = start_bit / 8; + uint64_t data = _u8[firstByte]; + data &= (0xFF >> (7 - start_bit%8)); + + int lastByte = firstByte; + int len = length - (start_bit%8 + 1); + + if(len > 0) + lastByte += (len/8)+1; + + for(int i = firstByte; i < lastByte; i++) + { + data <<= 8; + data |= _u8[i+1]; + } + + int shiftAmount = start_bit%8 - length%8 + 1; + if(shiftAmount < 0) + shiftAmount += 8; + else if(shiftAmount == 8) + shiftAmount = 0; + data >>= shiftAmount; + + return data; + } + // if ((start_bit+length) > (getLength()*8)) { // return 0; // } @@ -199,17 +227,6 @@ uint64_t CanMessage::extractRawSignal(uint8_t start_bit, const uint8_t length, c data &= mask; - // If the length is greater than 8, we need to byteswap to preserve endianness - if (isBigEndian && (length > 8)) - { - - // Swap bytes - data = __builtin_bswap64(data); - - // Shift out unused bits - data >>= 64 - length; - } - return data; } diff --git a/src/parser/dbc/DbcParser.cpp b/src/parser/dbc/DbcParser.cpp index f12f119..5722438 100644 --- a/src/parser/dbc/DbcParser.cpp +++ b/src/parser/dbc/DbcParser.cpp @@ -552,21 +552,6 @@ bool DbcParser::parseSectionBoSg(CanDb &candb, CanDbMessage *msg, DbcTokenList & if (!expectInt(tokens, &byte_order)) { return false; } signal->setIsBigEndian(byte_order==0); - // If the signal is big endian, convert the start bit to the Intel-style start bit for further parsing - if(signal->isBigEndian()) - { - // This will be the number of 8-bit rows above the message - uint8_t row_position = signal->startBit() >> 3; - - // Bit position in current row (0-7) - uint8_t column_position = signal->startBit() & 0b111; - - // Calcualte the normalized start bit position (bit index starting at 0) - uint8_t normalized_position = (row_position * 8) + (7 - column_position); - - signal->setStartBit(normalized_position); - } - if (expectAndSkipToken(tokens, dbc_tok_plus)) { signal->setUnsigned(true); } else {