Add caching to the DBC signal system so that we can show all the

signals in overwrite mode.
This commit is contained in:
Collin Kidder
2019-03-11 20:53:45 -04:00
parent ef5f41644a
commit c9880be2c5
3 changed files with 24 additions and 10 deletions
+7 -1
View File
@@ -334,11 +334,17 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
for (int j = 0; j < msg->sigHandler->getCount(); j++)
{
QString sigString;
if (msg->sigHandler->findSignalByIdx(j)->processAsText(thisFrame, sigString))
DBC_SIGNAL* sig = msg->sigHandler->findSignalByIdx(j);
if (sig->processAsText(thisFrame, sigString))
{
tempString.append(sigString);
tempString.append("\n");
}
else if (sig->isMultiplexed && overwriteDups) //wasn't in this exact frame but is in the message. Use cached value
{
tempString.append(sig->makePrettyOutput(sig->cachedValue.toDouble(), sig->cachedValue.toLongLong()));
tempString.append("\n");
}
}
}
}
+15 -9
View File
@@ -49,6 +49,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
int bytes = signalSize / 8;
for (int x = 0; x < bytes; x++) buildString.append(frame.data[startByte + x]);
outString = buildString;
cachedValue = outString;
return true;
}
@@ -69,7 +70,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
{
result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned);
endResult = ((double)result * factor) + bias;
result = (int64_t)endResult;
result = (int64_t)endResult;
}
else if (valType == SP_FLOAT)
{
@@ -94,6 +95,13 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
endResult = (*((double *)(&result)) * factor) + bias;
}
outString = makePrettyOutput(endResult, result);
cachedValue = endResult;
return true;
}
QString DBC_SIGNAL::makePrettyOutput(double floatVal, int64_t intVal)
{
QString outputString;
outputString = name + ": ";
@@ -103,22 +111,20 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
bool foundVal = false;
for (int x = 0; x < valList.count(); x++)
{
if (valList.at(x).value == result)
if (valList.at(x).value == intVal)
{
outputString += valList.at(x).descript;
foundVal = true;
break;
}
}
if (!foundVal) outputString += QString::number(endResult) + unitName;
if (!foundVal) outputString += QString::number(intVal) + unitName;
}
else //otherwise display the actual number and unit (if it exists)
{
outputString += QString::number(endResult) + unitName;
outputString += QString::number(floatVal) + unitName;
}
outString = outputString;
return true;
return outputString;
}
//Works quite a bit like the above version but this one is cut down and only will return int32_t which is perfect for
@@ -158,7 +164,7 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue)
double endResult = ((double)result * factor) + bias;
result = (int32_t)endResult;
cachedValue = result;
outValue = result;
return true;
}
@@ -230,7 +236,7 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
result = Utility::processIntegerSignal(frame.data, 0, 64, false, false);
endResult = (*((double *)(&result)) * factor) + bias;
}
cachedValue = endResult;
outValue = endResult;
return true;
}
+2
View File
@@ -97,12 +97,14 @@ public: //TODO: this is sloppy. It shouldn't all be public!
DBC_MESSAGE *parentMessage;
QString unitName;
QString comment;
QVariant cachedValue;
QList<DBC_ATTRIBUTE_VALUE> attributes;
QList<DBC_VAL_ENUM_ENTRY> valList;
bool processAsText(const CANFrame &frame, QString &outString);
bool processAsInt(const CANFrame &frame, int32_t &outValue);
bool processAsDouble(const CANFrame &frame, double &outValue);
QString makePrettyOutput(double floatVal, int64_t intVal);
DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
};