Addition of the range state window (it sort of works now too!),
refactoring of some DBC code, fixed some DBC calcs, fixed a bug in the frame playback window, incremented version number to show that a lot has been done.
This commit is contained in:
+5
-57
@@ -3,6 +3,7 @@
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
#include <QDebug>
|
||||
#include "utility.h"
|
||||
|
||||
DBCHandler::DBCHandler(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@@ -538,8 +539,7 @@ QString DBCHandler::processSignal(const CANFrame &frame, const DBC_SIGNAL &sig)
|
||||
{
|
||||
|
||||
int64_t result = 0;
|
||||
int bit;
|
||||
int sigSize;
|
||||
bool isSigned = false;
|
||||
if (sig.valType == STRING)
|
||||
{
|
||||
QString buildString;
|
||||
@@ -547,62 +547,10 @@ QString DBCHandler::processSignal(const CANFrame &frame, const DBC_SIGNAL &sig)
|
||||
int bytes = sig.signalSize / 8;
|
||||
for (int x = 0; x < bytes; x++) buildString.append(frame.data[startByte + x]);
|
||||
return buildString;
|
||||
}
|
||||
}
|
||||
|
||||
sigSize = sig.signalSize;
|
||||
|
||||
if (sig.intelByteOrder)
|
||||
{
|
||||
bit = sig.startBit;
|
||||
for (int bitpos = 0; bitpos < sigSize; bitpos++)
|
||||
{
|
||||
if (frame.data[bit / 8] & (1 << (bit % 8)))
|
||||
result += (1ULL << bitpos);
|
||||
|
||||
bit++;
|
||||
}
|
||||
}
|
||||
else //motorola / big endian mode
|
||||
{
|
||||
bit = sig.startBit;
|
||||
for (int bitpos = 0; bitpos < sigSize; bitpos++)
|
||||
{
|
||||
if (frame.data[bit / 8] & (1 << (bit % 8)))
|
||||
result += (1ULL << (sigSize - bitpos - 1));
|
||||
|
||||
if ((bit % 8) == 0)
|
||||
bit += 15;
|
||||
else bit--;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (sig.valType == SIGNED_INT)
|
||||
{
|
||||
int mask = (1 << (sig.signalSize - 1));
|
||||
if ((result & mask) == mask) //is the highest bit possible for this signal size set?
|
||||
{
|
||||
/*
|
||||
* if so we need to also set every bit higher in the result int too.
|
||||
* This leads to the below two lines that are nasty. Here's the theory behind that...
|
||||
* If the value is signed and the highest bit is set then it is negative. To create
|
||||
* a negative value out of this even though the variable result is 64 bit we have to
|
||||
* run 1's all of the way up to bit 63 in result. -1 is all ones for whatever size integer
|
||||
* you have. So, it's 64 1's in this case.
|
||||
* signedMask is done this way:
|
||||
* first you take the signal size and shift 1 up that far. Then subtract one. Lets
|
||||
* see that for a 16 bit signal:
|
||||
* (1 << 16) - 1 = the first 16 bits set as 1's. So far so good. We then negate the whole
|
||||
* thing which flips all bits. Thus signedMask ends up with 1's everwhere that the signal
|
||||
* doesn't take up in the 64 bit signed integer result. Then, result has an OR operation on
|
||||
* it with the old value and -1 masked so that the the 1 bits from -1 don't overwrite bits from the
|
||||
* actual signal. This extends the sign bits out so that the integer result reads as the proper negative
|
||||
* value. We dont need to do any of this if the sign bit wasn't set.
|
||||
*/
|
||||
int signedMask = ~((1 << sig.signalSize) - 1);
|
||||
result = (-1 & signedMask) | result;
|
||||
}
|
||||
}
|
||||
if (sig.valType == SIGNED_INT) isSigned = true;
|
||||
result = Utility::processIntegerSignal(frame.data, sig.startBit, sig.signalSize, sig.intelByteOrder, isSigned);
|
||||
|
||||
double endResult = ((double)result * sig.factor) + sig.bias;
|
||||
result = (int) endResult;
|
||||
|
||||
Reference in New Issue
Block a user