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++) for (int j = 0; j < msg->sigHandler->getCount(); j++)
{ {
QString sigString; 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(sigString);
tempString.append("\n"); 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");
}
} }
} }
} }
+14 -8
View File
@@ -49,6 +49,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
int bytes = signalSize / 8; int bytes = signalSize / 8;
for (int x = 0; x < bytes; x++) buildString.append(frame.data[startByte + x]); for (int x = 0; x < bytes; x++) buildString.append(frame.data[startByte + x]);
outString = buildString; outString = buildString;
cachedValue = outString;
return true; return true;
} }
@@ -94,6 +95,13 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
endResult = (*((double *)(&result)) * factor) + bias; endResult = (*((double *)(&result)) * factor) + bias;
} }
outString = makePrettyOutput(endResult, result);
cachedValue = endResult;
return true;
}
QString DBC_SIGNAL::makePrettyOutput(double floatVal, int64_t intVal)
{
QString outputString; QString outputString;
outputString = name + ": "; outputString = name + ": ";
@@ -103,22 +111,20 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
bool foundVal = false; bool foundVal = false;
for (int x = 0; x < valList.count(); x++) 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; outputString += valList.at(x).descript;
foundVal = true; foundVal = true;
break; 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) else //otherwise display the actual number and unit (if it exists)
{ {
outputString += QString::number(endResult) + unitName; outputString += QString::number(floatVal) + unitName;
} }
return outputString;
outString = outputString;
return true;
} }
//Works quite a bit like the above version but this one is cut down and only will return int32_t which is perfect for //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; double endResult = ((double)result * factor) + bias;
result = (int32_t)endResult; result = (int32_t)endResult;
cachedValue = result;
outValue = result; outValue = result;
return true; return true;
} }
@@ -230,7 +236,7 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
result = Utility::processIntegerSignal(frame.data, 0, 64, false, false); result = Utility::processIntegerSignal(frame.data, 0, 64, false, false);
endResult = (*((double *)(&result)) * factor) + bias; endResult = (*((double *)(&result)) * factor) + bias;
} }
cachedValue = endResult;
outValue = endResult; outValue = endResult;
return true; return true;
} }
+2
View File
@@ -97,12 +97,14 @@ public: //TODO: this is sloppy. It shouldn't all be public!
DBC_MESSAGE *parentMessage; DBC_MESSAGE *parentMessage;
QString unitName; QString unitName;
QString comment; QString comment;
QVariant cachedValue;
QList<DBC_ATTRIBUTE_VALUE> attributes; QList<DBC_ATTRIBUTE_VALUE> attributes;
QList<DBC_VAL_ENUM_ENTRY> valList; QList<DBC_VAL_ENUM_ENTRY> valList;
bool processAsText(const CANFrame &frame, QString &outString); bool processAsText(const CANFrame &frame, QString &outString);
bool processAsInt(const CANFrame &frame, int32_t &outValue); bool processAsInt(const CANFrame &frame, int32_t &outValue);
bool processAsDouble(const CANFrame &frame, double &outValue); bool processAsDouble(const CANFrame &frame, double &outValue);
QString makePrettyOutput(double floatVal, int64_t intVal);
DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name); DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx); DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
}; };