Fix signal interpretation when signals get near the end of the 64 bits.

This commit is contained in:
Collin Kidder
2018-06-18 22:02:42 -04:00
parent 1a7d229bf2
commit 8842152346
2 changed files with 8 additions and 14 deletions
-10
View File
@@ -67,22 +67,12 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
if (valType == SIGNED_INT) isSigned = true; if (valType == SIGNED_INT) isSigned = true;
if (valType == SIGNED_INT || valType == UNSIGNED_INT) if (valType == SIGNED_INT || valType == UNSIGNED_INT)
{ {
if ( frame.len*8 < (startBit+signalSize) )
{
result = 0;
return false;
}
result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned); result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned);
endResult = ((double)result * factor) + bias; endResult = ((double)result * factor) + bias;
result = (int64_t)endResult; result = (int64_t)endResult;
} }
else if (valType == SP_FLOAT) else if (valType == SP_FLOAT)
{ {
if ( frame.len*8 < (startBit+32) )
{
result = 0;
return false;
}
//The theory here is that we force the integer signal code to treat this as //The theory here is that we force the integer signal code to treat this as
//a 32 bit unsigned integer. This integer is then cast into a float in such a way //a 32 bit unsigned integer. This integer is then cast into a float in such a way
//that the bytes that make up the integer are instead treated as having made up //that the bytes that make up the integer are instead treated as having made up
+8 -4
View File
@@ -189,8 +189,10 @@ public:
bit = startBit; bit = startBit;
for (int bitpos = 0; bitpos < sigSize; bitpos++) for (int bitpos = 0; bitpos < sigSize; bitpos++)
{ {
if (data[bit / 8] & (1 << (bit % 8))) if (bit < 64) {
result += (1ULL << bitpos); if (data[bit / 8] & (1 << (bit % 8)))
result += (1ULL << bitpos);
}
bit++; bit++;
} }
} }
@@ -199,8 +201,10 @@ public:
bit = startBit; bit = startBit;
for (int bitpos = 0; bitpos < sigSize; bitpos++) for (int bitpos = 0; bitpos < sigSize; bitpos++)
{ {
if (data[bit / 8] & (1 << (bit % 8))) if (bit < 64) {
result += (1ULL << (sigSize - bitpos - 1)); if (data[bit / 8] & (1 << (bit % 8)))
result += (1ULL << (sigSize - bitpos - 1));
}
if ((bit % 8) == 0) if ((bit % 8) == 0)
bit += 15; bit += 15;